Mercurial > pub > bltoolkit
view UnitTests/CS/Data/Sql/FromTest.cs @ 9:1e85f66cf767 default tip
update bltoolkit
author | nickolay |
---|---|
date | Thu, 05 Apr 2018 20:53:26 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using NUnit.Framework; using BLToolkit.Data.Sql; namespace Data.Sql { [TestFixture] public class FromTest { public static SqlTable Order = new SqlTable { Name = "Order", Fields = { new SqlField { Name = "ID" }, new SqlField { Name = "Number" } } }; public static SqlTable OrderItem = new SqlTable { Name = "OrderItem", Fields = { new SqlField { Name = "ID" }, new SqlField { Name = "OrderID" } } }; public static SqlTable OrderItem2 = new SqlTable(OrderItem); public static SqlTable OrderItem3 = new SqlTable(OrderItem); public static SqlTable OrderItem4 = new SqlTable(OrderItem); public static SqlTable OrderItem5 = new SqlTable(OrderItem); [Test] public void Test1() { var sb = new SqlQuery(); sb .Select .Field(Order["ID"]) .Field(Order["Number"]) .From .Table(Order) ; sb.FinalizeAndValidate(true, true); Assert.AreEqual(1, sb.From.Tables.Count); Assert.AreEqual(0, sb.From.Tables[0].Joins.Count); } [Test] public void Test2() { var sb = new SqlQuery(); sb .Select .Field(Order["ID"]) .Field(OrderItem.All) .Field(OrderItem4["ID"]) .From .Table(Order, OrderItem. Join ().Field(Order["ID"]).Equal.Field(OrderItem["OrderID"]), OrderItem2.WeakJoin(), OrderItem3.WeakJoin( OrderItem5.WeakLeftJoin(), OrderItem4.LeftJoin ().Field(OrderItem4["ID"]).Equal.Field(OrderItem3["ID"])) ) .Where .Not.Field(Order["ID"]).Like("1234").Or .Field(Order["ID"]).Equal.Value("!%") .GroupBy .Field(Order["ID"]) .OrderBy .Field(Order["ID"]) ; Assert.AreEqual(1, sb.From.Tables.Count); Assert.AreEqual(3, sb.From.Tables[0].Joins.Count); Assert.AreEqual(2, sb.From.Tables[0].Joins[2].Table.Joins.Count); sb.FinalizeAndValidate(true, true); Assert.AreEqual(2, sb.From.Tables[0].Joins.Count); Assert.AreEqual(1, sb.From.Tables[0].Joins[1].Table.Joins.Count); } } }