This commit is contained in:
sunkaixuan
2017-05-17 00:22:43 +08:00
22 changed files with 178 additions and 52 deletions

View File

@@ -61,9 +61,10 @@
<Compile Include="PerformanceTesting\PerformanceBase.cs" />
<Compile Include="PerformanceTesting\SqlSugarPerformance.cs" />
<Compile Include="UnitTest\Delete.cs" />
<Compile Include="UnitTest\ExpressionTest\ExpTestBase.cs" />
<Compile Include="UnitTest\UnitTestBase.cs" />
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
<Compile Include="UnitTest\Insert.cs" />
<Compile Include="UnitTest\Mapping .cs" />
<Compile Include="UnitTest\Query\JoinQuery.cs" />
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
<Compile Include="UnitTest\ExpressionTest\Select.cs" />

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace OrmTest
{
public class Delete : ExpTestBase
public class Delete : UnitTestBase
{
private Delete() { }
public Delete(int eachCount)

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Field : ExpTestBase
public class Field : UnitTestBase
{
private Field() { }
public Field(int eachCount)

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Method : ExpTestBase
public class Method : UnitTestBase
{
private Method() { }
public Method(int eachCount)

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Select : ExpTestBase
public class Select : UnitTestBase
{
private Select() { }
public Select(int eachCount)

View File

@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Where : ExpTestBase
public class Where : UnitTestBase
{
private Where() { }
public Where(int eachCount)

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Insert : ExpTestBase
public class Insert : UnitTestBase
{
private Insert() { }
public Insert(int eachCount)
@@ -19,34 +19,40 @@ namespace OrmTest.UnitTest
public void Init() {
var db = GetInstance();
var insertObj = new Student() { Name="jack",CreateTime=DateTime.Now };
var insertObjs = new List<Student>() { insertObj }.ToArray();
db.IgnoreColumns.Add("TestId", "Student");
//db.MappingColumns.Add("id","dbid", "Student");
var s1= db.Insertable<Student>(insertObj).ToSql();
var s1= db.Insertable(insertObj).ToSql();
//Insert reutrn Command Count
var s2=db.Insertable<Student>(insertObj).ExecuteCommand();
var s2=db.Insertable(insertObj).ExecuteCommand();
db.IgnoreColumns = null;
//Only insert Name
var s3 = db.Insertable<Student>(insertObj).InsertColumns(it => new {it.Name}).ToSql();
var s3 = db.Insertable(insertObj).InsertColumns(it => new {it.Name}).ToSql();
//Ignore Name and TestId
var s4=db.Insertable<Student>(insertObj).IgnoreColumns(it => new{ it.Name,it.TestId }).ToSql();
var s4=db.Insertable(insertObj).IgnoreColumns(it => new{ it.Name,it.TestId }).ToSql();
//Ignore Name and TestId
var s5 = db.Insertable<Student>(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
var s5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
//Use Lock
var s6 =db.Insertable<Student>(insertObj).With(SqlWith.UpdLock).ToSql();
var s6 =db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
//ToSql
var s7= db.Insertable<Student>(insertObj).With(SqlWith.UpdLock)
var s7= db.Insertable(insertObj).With(SqlWith.UpdLock)
.InsertColumns(it => new { it.Name }).ToSql();
db.IgnoreColumns = new IgnoreComumnList();
db.IgnoreColumns.Add("TestId", "Student");
//Insert List<T>
var s8= db.Insertable<Student>(insertObjs).With(SqlWith.UpdLock).ToSql();
var insertObjs = new List<Student>();
for (int i = 0; i < 1000; i++)
{
insertObjs.Add(new Student() { Name="name"+i });
}
var s8= db.Insertable(insertObjs.ToArray()).InsertColumns(it=>new{ it.Name}).With(SqlWith.UpdLock).ToSql();
}
public SqlSugarClient GetInstance()

View File

@@ -0,0 +1,31 @@
using OrmTest.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Mapping:UnitTestBase
{
private Mapping() { }
public Mapping(int eachCount)
{
this.Count = eachCount;
}
public void Init() {
var db = GetInstance();
var s1= db.Queryable<Student>().ToSql();
}
public SqlSugarClient GetInstance()
{
SqlSugarClient db = new SqlSugarClient(new AttrbuitesCofnig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true, EntityNamespace= "OrmTest.Models" });
return db;
}
}
}

View File

@@ -8,7 +8,7 @@ using System.Linq.Expressions;
using OrmTest.Models;
namespace OrmTest.UnitTest
{
public class JoinQuery : ExpTestBase
public class JoinQuery : UnitTestBase
{
private JoinQuery() { }
public JoinQuery(int eachCount)

View File

@@ -8,7 +8,7 @@ using System.Linq.Expressions;
using OrmTest.Models;
namespace OrmTest.UnitTest
{
public class SelectQuery : ExpTestBase
public class SelectQuery : UnitTestBase
{
private SelectQuery() { }
public SelectQuery(int eachCount)

View File

@@ -8,7 +8,7 @@ using System.Linq.Expressions;
using OrmTest.Models;
namespace OrmTest.UnitTest
{
public class SingleQuery : ExpTestBase
public class SingleQuery : UnitTestBase
{
private SingleQuery() { }
public SingleQuery(int eachCount)

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class Attribute : ExpTestBase
public class Attribute : UnitTestBase
{
public Attribute(int eachCount)
{

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class AutoClose : ExpTestBase
public class AutoClose : UnitTestBase
{
public AutoClose(int eachCount)
{

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class MapColumn : ExpTestBase
public class MapColumn : UnitTestBase
{
public SqlSugarClient GetInstance()
{

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace OrmTest.UnitTest
{
public class MapTable : ExpTestBase
public class MapTable : UnitTestBase
{
public void Init()
{

View File

@@ -4,7 +4,7 @@ using SqlSugar;
using System.Linq;
namespace OrmTest.UnitTest
{
public class ExpTestBase
public class UnitTestBase
{
public int Count { get; set; }
private DateTime BeginTime { get; set; }