SqlSugar/Src/Asp.Net/SqlServerTest/OldTest/UnitTest/UnitTestBase.cs

61 lines
2.1 KiB
C#
Raw Normal View History

2017-01-27 18:35:48 +08:00
using System;
using System.Collections.Generic;
using SqlSugar;
using System.Linq;
2017-03-04 15:07:58 +08:00
namespace OrmTest.UnitTest
2017-01-27 18:35:48 +08:00
{
2017-05-16 13:55:57 +08:00
public class UnitTestBase
2017-01-27 18:35:48 +08:00
{
public int Count { get; set; }
private DateTime BeginTime { get; set; }
private DateTime EndTime { get; set; }
public void Begin()
{
this.BeginTime = DateTime.Now;
}
public void End(string title)
{
this.EndTime = DateTime.Now;
Console.WriteLine(title + " \r\nCount: " + this.Count + "\r\nTime: " + (this.EndTime - this.BeginTime).TotalSeconds + " Seconds \r\n");
}
2017-01-27 18:39:13 +08:00
internal void Check(string value, List<SugarParameter> pars, string validValue, List<SugarParameter> validPars, string errorMessage)
2017-01-27 18:35:48 +08:00
{
2017-01-27 18:39:13 +08:00
if (value.Trim() != validValue.Trim())
2017-01-27 18:35:48 +08:00
{
throw new Exception(errorMessage);
}
if (pars != null && pars.Count > 0)
{
if (pars.Count != validPars.Count)
{
throw new Exception(errorMessage);
}
else
{
foreach (var item in pars)
{
2017-05-24 20:35:23 +08:00
if (!validPars.Any(it => it.ParameterName.Equals(item.ParameterName) && it.Value.ObjToString().Equals(item.Value.ObjToString())))
2017-01-27 18:35:48 +08:00
{
throw new Exception(errorMessage);
}
}
}
}
}
2017-07-15 19:31:49 +08:00
public SqlSugarClient GetInstance()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
return db;
}
2017-11-02 16:08:23 +08:00
public SqlSugarClient GetInstanceByAttribute()
{
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { InitKeyType=InitKeyType.Attribute, ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
return db;
}
2017-01-27 18:35:48 +08:00
}
}