SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.0 KiB

8 years ago
using OrmTest.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrmTest.UnitTest
{
public class DataTest : UnitTestBase
{
private DataTest() { }
public DataTest(int eachCount)
{
this.Count = eachCount;
}
public void Init()
{
8 years ago
var guid = Guid.Parse("d8268a7e-a2d1-4329-9990-9bd801292415");
8 years ago
var db = GetInstance();
db.DbMaintenance.TruncateTable("DataTestInfo");
var insertObject = new DataTestInfo()
{
Datetime1 = DateTime.Now,
Datetime2 = DateTime.Now,
Decimal1 = 1,
Decimal2 = 2,
Float1 = 3,
Float2 = 4,
8 years ago
Guid1 = guid,
Guid2 = guid,
8 years ago
Image1 = new byte[] { 1, 2 },
Image2 = new byte[] { 2, 3 },
Int2 = 6,
Money1 = 7,
Money2 = 8,
Varbinary1 = new byte[] { 4, 5 },
Varbinary2 = null,
String = "string"
};
7 years ago
var id = db.Insertable<DataTestInfo>(insertObject).ExecuteReturnIdentity();
8 years ago
var data = db.Queryable<DataTestInfo>().InSingle(id);
if (
8 years ago
insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||
8 years ago
insertObject.Decimal1 != data.Decimal1 ||
insertObject.Float1 != data.Float1 ||
insertObject.Float2 != data.Float2 ||
insertObject.Int2 != data.Int2 ||
insertObject.Money1 != data.Money1 ||
8 years ago
insertObject.Guid2!=data.Guid2||
8 years ago
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
insertObject.String != data.String)
{
throw new Exception("DataTest Error");
}
data.Float1= data.Float1+1;
db.Updateable(data).ExecuteCommand();
data = db.Queryable<DataTestInfo>().InSingle(id);
if (
8 years ago
insertObject.Datetime1.ToString("yyyy-MM-dd") != data.Datetime1.ToString("yyyy-MM-dd") ||
8 years ago
insertObject.Decimal1 != data.Decimal1 ||
(insertObject.Float1+1) != data.Float1 ||
insertObject.Float2 != data.Float2 ||
insertObject.Int2 != data.Int2 ||
insertObject.Money1 != data.Money1 ||
string.Join(",", insertObject.Varbinary1) != string.Join(",", data.Varbinary1) ||
insertObject.String != data.String)
{
throw new Exception("DataTest Error");
}
}
public SqlSugarClient GetInstance()
{
8 years ago
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true });
8 years ago
return db;
}
}
}