Browse Source

Update unit test

pull/10/head
sunkaixuna 3 years ago
parent
commit
4a035e63ca
  1. 28
      Src/Asp.Net/OracleTest/UnitTest/UAdo.cs
  2. 10
      Src/Asp.Net/OracleTest/UnitTest/UJson.cs
  3. 36
      Src/Asp.Net/OracleTest/UnitTest/UQueryable.cs

28
Src/Asp.Net/OracleTest/UnitTest/UAdo.cs

@ -11,47 +11,47 @@ namespace OrmTest
public static void Ado() public static void Ado()
{ {
var task1 = Db.Ado.GetScalarAsync("select 1"); var task1 = Db.Ado.GetScalarAsync("select 1 from dual");
task1.Wait(); task1.Wait();
UValidate.Check(1, task1.Result, "ado"); UValidate.Check(1, task1.Result, "ado");
var task2 = Db.Ado.GetIntAsync("select 2"); var task2 = Db.Ado.GetIntAsync("select 2 from dual");
task2.Wait(); task2.Wait();
UValidate.Check(2, task2.Result, "ado"); UValidate.Check(2, task2.Result, "ado");
var task3 = Db.Ado.GetLongAsync("select 3"); var task3 = Db.Ado.GetLongAsync("select 3 from dual");
task3.Wait(); task3.Wait();
UValidate.Check(3, task3.Result, "ado"); UValidate.Check(3, task3.Result, "ado");
var task4 = Db.Ado.GetDataTableAsync("select 4 as id"); var task4 = Db.Ado.GetDataTableAsync("select 4 as id from dual");
task4.Wait(); task4.Wait();
UValidate.Check(4, task4.Result.Rows[0]["id"], "ado"); UValidate.Check(4, task4.Result.Rows[0]["id"], "ado");
var task5 = Db.Ado.GetInt("select @id as id",new { id=5}); var task5 = Db.Ado.GetInt("select @id as id from dual", new { id=5});
UValidate.Check(5, task5, "ado"); UValidate.Check(5, task5, "ado");
var task6 = Db.Ado.SqlQuery<dynamic>("select @id as id", new { id = 5 }); var task6 = Db.Ado.SqlQuery<dynamic>("select @id as id from dual", new { id = 5 });
UValidate.Check(5, task6[0].id, "ado"); UValidate.Check(5, task6[0].ID, "ado");
var task7 = Db.Ado.SqlQueryAsync<dynamic>("select @id as id", new { id = 7 }); var task7 = Db.Ado.SqlQueryAsync<dynamic>("select @id as id from dual", new { id = 7 });
task7.Wait(); task7.Wait();
UValidate.Check(7, task7.Result[0].id, "ado"); UValidate.Check(7, task7.Result[0].ID, "ado");
var task8 = Db.Ado.SqlQueryAsync<dynamic>("select 8 as id"); var task8 = Db.Ado.SqlQueryAsync<dynamic>("select 8 as id from dual");
task8.Wait(); task8.Wait();
UValidate.Check(8, task8.Result[0].id, "ado"); UValidate.Check(8, task8.Result[0].ID, "ado");
var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail"); //var task9=Db.Ado.SqlQuery<Order, OrderItem>("select * from [order];select * from OrderDetail");
var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from [order];select * from OrderDetail"); //var task10 = Db.Ado.SqlQueryAsync<Order, OrderItem>("select * from [order];select * from OrderDetail");
task10.Wait(); //task10.Wait();
} }
} }
} }

10
Src/Asp.Net/OracleTest/UnitTest/UJson.cs

@ -13,12 +13,12 @@ namespace OrmTest
{ {
Db.CodeFirst.InitTables<UnitJsonTest>(); Db.CodeFirst.InitTables<UnitJsonTest>();
Db.DbMaintenance.TruncateTable<UnitJsonTest>(); Db.DbMaintenance.TruncateTable<UnitJsonTest>();
Db.Insertable(new UnitJsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand(); Db.Insertable(new UnitJsonTest() { Id=1,Order2 = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
var list = Db.Queryable<UnitJsonTest>().ToList(); var list = Db.Queryable<UnitJsonTest>().ToList();
UValidate.Check("order1", list.First().Order.Name, "Json"); UValidate.Check("order1", list.First().Order2.Name, "Json");
Db.Updateable(new UnitJsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand(); Db.Updateable(new UnitJsonTest() { Id = 1, Order2 = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
list= Db.Queryable<UnitJsonTest>().ToList(); list= Db.Queryable<UnitJsonTest>().ToList();
UValidate.Check("order2", list.First().Order.Name, "Json"); UValidate.Check("order2", list.First().Order2.Name, "Json");
var list2 = Db.Queryable<UnitJsonTest>().ToList(); var list2 = Db.Queryable<UnitJsonTest>().ToList();
} }
} }
@ -29,6 +29,6 @@ namespace OrmTest
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; } public int Id { get; set; }
[SqlSugar.SugarColumn(ColumnDataType = "varchar(2000)", IsJson = true)] [SqlSugar.SugarColumn(ColumnDataType = "varchar(2000)", IsJson = true)]
public Order Order { get; set; } public Order Order2 { get; set; }
} }
} }

36
Src/Asp.Net/OracleTest/UnitTest/UQueryable.cs

@ -33,24 +33,24 @@ namespace OrmTest
Db.Queryable<Order>().Where(it => SqlSugar.SqlFunc.Equals(it.CreateTime.Date, it.CreateTime.Date)).ToList(); Db.Queryable<Order>().Where(it => SqlSugar.SqlFunc.Equals(it.CreateTime.Date, it.CreateTime.Date)).ToList();
var sql = Db.Queryable<UnitSelectTest>().Select(it => new UnitSelectTest() // var sql = Db.Queryable<UnitSelectTest>().Select(it => new UnitSelectTest()
{ // {
DcNull = it.Dc, // DcNull = it.Dc,
Dc = it.Int // Dc = it.Int
}).ToSql().Key; // }).ToSql().Key;
UValidate.Check(sql, "SELECT [Dc] AS [DcNull] , [Int] AS [Dc] FROM [UnitSelectTest]", "Queryable"); // UValidate.Check(sql, "SELECT [Dc] AS [DcNull] , [Int] AS [Dc] FROM [UnitSelectTest]", "Queryable");
sql = Db.Updateable<UnitSelectTest2>(new UnitSelectTest2()).ToSql().Key; // sql = Db.Updateable<UnitSelectTest2>(new UnitSelectTest2()).ToSql().Key;
UValidate.Check(sql, @"UPDATE [UnitSelectTest2] SET // UValidate.Check(sql, @"UPDATE [UnitSelectTest2] SET
[Dc]=@Dc,[IntNull]=@IntNull WHERE [Int]=@Int", "Queryable"); //[Dc]=@Dc,[IntNull]=@IntNull WHERE [Int]=@Int", "Queryable");
sql = Db.Queryable<Order>().IgnoreColumns(it => it.CreateTime).ToSql().Key; // sql = Db.Queryable<Order>().IgnoreColumns(it => it.CreateTime).ToSql().Key;
UValidate.Check(sql, "SELECT [Id],[Name],[Price],[CustomId] FROM [Order] ", "Queryable"); // UValidate.Check(sql, "SELECT [Id],[Name],[Price],[CustomId] FROM [Order] ", "Queryable");
sql = Db.Queryable<Order>().IgnoreColumns(it => new { it.Id, it.Name }).ToSql().Key; // sql = Db.Queryable<Order>().IgnoreColumns(it => new { it.Id, it.Name }).ToSql().Key;
UValidate.Check(sql, "SELECT [Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable"); // UValidate.Check(sql, "SELECT [Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
sql = Db.Queryable<Order>().IgnoreColumns("id").ToSql().Key; // sql = Db.Queryable<Order>().IgnoreColumns("id").ToSql().Key;
UValidate.Check(sql, "SELECT [Name],[Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable"); // UValidate.Check(sql, "SELECT [Name],[Price],[CreateTime],[CustomId] FROM [Order] ", "Queryable");
var cts = IEnumerbleContains.Data(); var cts = IEnumerbleContains.Data();
var list2=Db.Queryable<Order>() var list2=Db.Queryable<Order>()

Loading…
Cancel
Save