Browse Source

Add unit test

pull/23/head
sunkaixuan 2 years ago
parent
commit
a8bf2590a5
  1. 1
      Src/Asp.Net/SqliteTest/SqliteTest.csproj
  2. 1
      Src/Asp.Net/SqliteTest/UnitTest/Main.cs
  3. 62
      Src/Asp.Net/SqliteTest/UnitTest/UnitNavInsertIssue.cs

1
Src/Asp.Net/SqliteTest/SqliteTest.csproj

@ -77,6 +77,7 @@
<Compile Include="Models\TestTree.cs" />
<Compile Include="Models\Tree.cs" />
<Compile Include="Models\ViewOrder.cs" />
<Compile Include="UnitTest\UnitNavInsertIssue.cs" />
<Compile Include="UnitTest\UnitInsertNavN.cs" />
<Compile Include="UnitTest\Main.cs" />
<Compile Include="UnitTest\Models\Export.cs" />

1
Src/Asp.Net/SqliteTest/UnitTest/Main.cs

@ -31,6 +31,7 @@ namespace OrmTest
}
public static void Init()
{
UnitNavInsertIssue.Init();
UnitInsertNavN.Init();
UNavTest.Init();
UnitTestReturnPkList.Init();

62
Src/Asp.Net/SqliteTest/UnitTest/UnitNavInsertIssue.cs

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlSugar;
namespace OrmTest
{
public class UnitNavInsertIssue
{
public static void Init()
{
ConnectionConfig cfg = new ConnectionConfig()
{
DbType = DbType.MySql,
ConnectionString = "随便填一个本地的吧"
};
var sqlSugarScope = NewUnitTest.Db;
sqlSugarScope.DbMaintenance.CreateDatabase();
sqlSugarScope.CodeFirst.InitTables(typeof(Mail), typeof(MailAttachment));
Mail mail = new Mail()
{
TraceId = "abcd",
Subject = "subject",
Content = "content"
};
sqlSugarScope
.InsertNav(mail)
.Include(p => p.Attachments)
.ExecuteCommand();
}
}
[SugarTable(nameof(Mail))]
public class Mail
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(IsNullable = false, Length = 20)]
public string TraceId { get; set; }
[SugarColumn(IsNullable = false, Length = 500)]
public string Subject { get; set; }
[SugarColumn(IsNullable = false, Length = 2000)]
public string Content { get; set; }
[Navigate(NavigateType.OneToMany, nameof(MailAttachment.MailTraceId), nameof(TraceId))]
public List<MailAttachment> Attachments { get; set; }
}
[SugarTable(nameof(MailAttachment))]
public class MailAttachment
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(IsNullable = false, Length = 20)]
public string MailTraceId { get; set; }
[SugarColumn(IsNullable = false, Length = 100)]
public string FileName { get; set; }
}
}
Loading…
Cancel
Save