From 9a4f14d378515ed35621551bfbf0727fca6b3633 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Thu, 20 Jul 2023 00:23:10 +0800 Subject: [PATCH] Add unit test --- .../SqlSeverTest/UnitTest/AnimalTest.cs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Src/Asp.NetCore2/SqlSeverTest/UnitTest/AnimalTest.cs diff --git a/Src/Asp.NetCore2/SqlSeverTest/UnitTest/AnimalTest.cs b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/AnimalTest.cs new file mode 100644 index 000000000..e10d9aad6 --- /dev/null +++ b/Src/Asp.NetCore2/SqlSeverTest/UnitTest/AnimalTest.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OrmTest; +using SqlSugar; +namespace OrmTest +{ + internal class AnimalTest + { + public static void Init() + { + var db = NewUnitTest.Db; + db.CodeFirst.InitTables(); + db.DbMaintenance.TruncateTable(); + var dog = new Dog { Name = "Buddy", Breed = "Golden Retriever" }; + db.Insertable(dog).ExecuteCommand(); + var cat = new Cat { Name = "Whiskers", Color = "Gray" }; + db.Insertable(cat).ExecuteCommand(); + + var catList=db.Queryable().ToList(); + var dogList = db.Queryable().ToList(); + var dt=db.Queryable().Select("*").ToDataTable(); + if (catList.Count() != 1 || dogList.Count() != 1 || dt.Rows.Count != 2) + { + throw new Exception("unit error"); + } + if (catList.First().Color!= "Gray"|| dogList.First().Breed != "Golden Retriever") + { + throw new Exception("unit error"); + } + } + } + [SugarTable("Animal",IsDisabledDelete =true)] + public class Animal + { + [SugarColumn(IsIdentity =true,IsPrimaryKey =true)] + public int AnimalId { get; set; } + public string Name { get; set; } + } + [SugarTable("Animal",Discrimator ="Type:1", IsDisabledDelete = true)] + public class Dog : Animal + { + [SugarColumn(IsNullable =true)] + public int DogId { get; set; } + [SugarColumn(IsNullable = true)] + public string Breed { get; set; } + } + [SugarTable("Animal", Discrimator = "Type:2", IsDisabledDelete = true)] + public class Cat : Animal + { + [SugarColumn(IsNullable = true)] + public int CatId { get; set; } + [SugarColumn(IsNullable = true)] + public string Color { get; set; } + } +}