mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 13:06:50 +08:00
Add unit test
This commit is contained in:
parent
2da4ece3c9
commit
c4cad253c5
@ -95,6 +95,7 @@
|
||||
<Compile Include="UnitTest\UCustom06.cs" />
|
||||
<Compile Include="UnitTest\UInsert.cs" />
|
||||
<Compile Include="UnitTest\UnitCustom01.cs" />
|
||||
<Compile Include="UnitTest\UnitSameKeyBug.cs" />
|
||||
<Compile Include="UnitTest\UOneManyMany.cs" />
|
||||
<Compile Include="UnitTest\UQueue.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
@ -31,6 +31,7 @@ namespace OrmTest
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
UnitSameKeyBug.Init();
|
||||
UOneManyMany.init();
|
||||
UDelete.Init();
|
||||
UCustom012.Init();
|
||||
|
85
Src/Asp.Net/MySqlTest/UnitTest/UnitSameKeyBug.cs
Normal file
85
Src/Asp.Net/MySqlTest/UnitTest/UnitSameKeyBug.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
namespace OrmTest
|
||||
{
|
||||
internal class UnitSameKeyBug
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
var db = NewUnitTest.Db;
|
||||
db.CodeFirst.InitTables(typeof(ServiceManage), typeof(UserInfo));
|
||||
db.DbMaintenance.TruncateTable<ServiceManage, UserInfo>();
|
||||
#region 第一次插入数据
|
||||
int a = db.Insertable(new UserInfo() { ContacAll = new List<ContactInfo>() { new ContactInfo() { Name="a"} }, Name = "a" }).ExecuteCommand();
|
||||
int b = db.Insertable(new UserInfo() { ContacAll = new List<ContactInfo>() { new ContactInfo() { Name = "z" } }, Name = "b" }).ExecuteCommand();
|
||||
|
||||
int c = db.Insertable(new ServiceManage() { ProjectName = "ceshi", userId = 1, careId = 2 }).ExecuteCommand();
|
||||
#endregion
|
||||
var list = db.Queryable<ServiceManage>()
|
||||
.LeftJoin<UserInfo>((s, ss) => s.userId == ss.Id)
|
||||
.LeftJoin<UserInfo>((s, ss, sss) => s.careId == sss.Id)
|
||||
.Select((s, ss, sss) => new ServiceManagementViewModel
|
||||
{ serviceManage = s, userInfo = ss, careUserInfo=sss }).ToList();
|
||||
if (!list.First().careUserInfo.ContacAll.Any())
|
||||
{
|
||||
throw new Exception("unit error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public class UserInfo
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
[SugarColumn(Length = 20, IsNullable = true)]
|
||||
public string Name { get; set; }
|
||||
[SugarColumn(IsJson = true)]
|
||||
public List<ContactInfo> ContacAll { get; set; }
|
||||
}
|
||||
public class ContactInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 姓名
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 关系
|
||||
/// </summary>
|
||||
public string Relationship { get; set; }
|
||||
/// <summary>
|
||||
/// 手机号
|
||||
/// </summary>
|
||||
public string Phone { get; set; }
|
||||
/// <summary>
|
||||
/// 备用手机号
|
||||
/// </summary>
|
||||
public string Phone2 { get; set; }
|
||||
/// <summary>
|
||||
/// 联系地址
|
||||
/// </summary>
|
||||
public string Address { get; set; }
|
||||
|
||||
}
|
||||
public class ServiceManagementViewModel
|
||||
{
|
||||
public ServiceManage serviceManage { get; set; }
|
||||
public UserInfo userInfo { get; set; }
|
||||
public UserInfo careUserInfo { get; set; }
|
||||
}
|
||||
public class ServiceManage
|
||||
{
|
||||
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[SugarColumn(Length = 20, IsNullable = true)]
|
||||
public string ProjectName { get; set; }
|
||||
public int userId { get; set; }
|
||||
public int careId { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user