Browse Source

Add unit test

pull/12/head
sunkaixuna 3 years ago
parent
commit
31b0a715b4
  1. 1
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj
  2. 1
      Src/Asp.Net/SqlServerTest/UnitTest/Main.cs
  3. 38
      Src/Asp.Net/SqlServerTest/UnitTest/UCustom04.cs

1
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -97,6 +97,7 @@
<Compile Include="UnitTest\UCustom01.cs" />
<Compile Include="UnitTest\UCustom02.cs" />
<Compile Include="UnitTest\UCustom03.cs" />
<Compile Include="UnitTest\UCustom04.cs" />
<Compile Include="UnitTest\UDelete.cs" />
<Compile Include="UnitTest\UFastest.cs" />
<Compile Include="UnitTest\UConfig.cs" />

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

@ -34,6 +34,7 @@ namespace OrmTest
UCustom01.Init();
UCustom02.Init();
UCustom03.Init();
UCustom04.Init();
SubQueryTest();
UConfig();
DeleteTest();

38
Src/Asp.Net/SqlServerTest/UnitTest/UCustom04.cs

@ -0,0 +1,38 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class UCustom04
{
public static void Init()
{
var db = NewUnitTest.Db;
var sql = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
JoinType.Left, o.Id == i.OrderId,
JoinType.Left, o.CustomId == c.Id
))
.Select<ViewModel>().ToSql().Key;
UValidate.Check(sql, @"SELECT o.[Name] AS [Name],o.[Price] AS [Price],i.[OrderId] AS [OrderItemOrderId],i.[Price] AS [OrderItemPrice],c.[Name] AS [CustomName] FROM [Order] o Left JOIN [OrderDetail] i ON ( [o].[Id] = [i].[OrderId] ) Left JOIN [Custom] c ON ( [o].[CustomId] = [c].[Id] )","unit");
var list =
db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
JoinType.Left, o.Id == i.OrderId,
JoinType.Left, o.CustomId == c.Id
))
.Where((o,i,c)=>i.ItemId>0&&c.Id>0)
.Select<ViewModel>().ToList();
}
public class ViewModel
{
public string Name { get; set; }
public decimal Price { get; set; }
public int OrderItemOrderId { get; set; }
public int OrderItemPrice { get; set; }
public string CustomName { get; set; }
}
}
}
Loading…
Cancel
Save