Update unit test

This commit is contained in:
sunkaixuna 2021-12-16 01:45:54 +08:00
parent fca2a2d59d
commit c7d6d529a6
3 changed files with 116 additions and 0 deletions

View File

@ -96,6 +96,7 @@
<Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\UDelete.cs" />
<Compile Include="UnitTest\UFastest.cs" />
<Compile Include="UnitTest\UConfig.cs" />
<Compile Include="UnitTest\USplit.cs" />
<Compile Include="UnitTest\Models\TB_AdminUser.cs" />
<Compile Include="UnitTest\Models\TB_ClientConfig.cs" />

View File

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UConfig();
DeleteTest();
Fastest2();
SplitTest();

View File

@ -0,0 +1,114 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static void UConfig()
{
SqlSugarScope db = new SqlSugarScope(new ConnectionConfig()
{
ConfigId="1",
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (s, p) =>
{
Console.WriteLine(s);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
},
MoreSettings=new ConnMoreSettings() {
IsWithNoLockQuery=true
}
});
var sql=db.Queryable<Order>().ToSql();
if (!sql.Key.Contains("WITH(NOLOCK)")) throw new Exception("unit config error");
db.CurrentConnectionConfig.MoreSettings = null;
sql = db.Queryable<Order>().ToSql();
if (sql.Key.Contains("WITH(NOLOCK)")) throw new Exception("unit config error");
if (db.CurrentConnectionConfig.ConfigId!="1") throw new Exception("unit config error");
db.CurrentConnectionConfig.IsAutoCloseConnection = false;
Task.Run(() =>
{
if (db.CurrentConnectionConfig.IsAutoCloseConnection==false) throw new Exception("unit config error");
});
System.Threading.Thread.Sleep(1000);
if (db.CurrentConnectionConfig.IsAutoCloseConnection == true) throw new Exception("unit config error");
if (!db.IsAnyConnection("0"))
{
db.AddConnection(new ConnectionConfig()
{
ConfigId = "0",
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (s, p) =>
{
Console.WriteLine(s);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
},
MoreSettings = new ConnMoreSettings()
{
IsWithNoLockQuery = true
}
});
}
var x=db.GetConnection("0");
if (db.IsAnyConnection("0")==false) throw new Exception("unit config error");
Task.Run(() =>
{
if (db.IsAnyConnection("0"))
{
throw new Exception("unit config error");
}
else
{
db.AddConnection(new ConnectionConfig()
{
ConfigId = "11",
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
AopEvents = new AopEvents
{
OnLogExecuting = (s, p) =>
{
Console.WriteLine(s);
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
}
},
MoreSettings = new ConnMoreSettings()
{
IsWithNoLockQuery = true
}
});
}
});
System.Threading.Thread.Sleep(1000);
}
}
}