Add unit test

This commit is contained in:
sunkaixuan 2023-10-04 19:26:14 +08:00
parent 5bd21e81e4
commit 4b37b51e73
2 changed files with 62 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using SqlSugar;
using SqlSeverTest.UnitTest;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
@ -30,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UnitBulkMerge.Init();
UnitBool.Init();
UnitGridSave.Init();
UnitNavDynamic.Init();

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using OrmTest;
namespace SqlSeverTest.UnitTest
{
internal class UnitBulkMerge
{
public static void Init()
{
var db = NewUnitTest.Db;
db.CodeFirst.InitTables<UnitaafdsTest>();
db.DbMaintenance.TruncateTable<UnitaafdsTest>();
var count = db.Fastest<UnitaafdsTest>()
.BulkMerge(new List<UnitaafdsTest>() { new UnitaafdsTest() { Id=Guid.NewGuid()
, CreateTime=DateTime.Now, Name="a"} });
var list = db.Queryable<UnitaafdsTest>().ToList();
if (list[0].Name != "a") { throw new Exception("unit error"); }
list[0].Name = "j";
var count2 = db.Fastest<UnitaafdsTest>()
.BulkMerge(list);
var list2 = db.Queryable<UnitaafdsTest>().ToList();
if (list2[0].Name != "j" || count2 != 1) { throw new Exception("unit error"); }
list2.Add(new UnitaafdsTest()
{
Id = Guid.NewGuid(),
CreateTime = DateTime.Now,
Name = "a"
});
list2.Add(new UnitaafdsTest()
{
Id = Guid.NewGuid(),
CreateTime = DateTime.Now,
Name = "a"
});
db.Fastest<UnitaafdsTest>()
.BulkMerge(list2);
var count3 = db.Queryable<UnitaafdsTest>()
.Count();
if (count3 != 3)
{
throw new Exception("unit error");
}
for (int i = 0; i < 1000; i++)
{
db.Fastest<UnitaafdsTest>()
.BulkMerge(list);
}
}
}
public class UnitaafdsTest
{
[SqlSugar.SugarColumn(IsPrimaryKey = true)]
public Guid Id { get; set; }
public string Name { get; set; }
public DateTime CreateTime { get; set; }
}
}