comparison UnitTests/CS/Data/Sql/FromTest.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 using NUnit.Framework;
4
5 using BLToolkit.Data.Sql;
6
7 namespace Data.Sql
8 {
9 [TestFixture]
10 public class FromTest
11 {
12 public static SqlTable Order = new SqlTable
13 {
14 Name = "Order",
15 Fields = { new SqlField { Name = "ID" }, new SqlField { Name = "Number" } }
16 };
17
18 public static SqlTable OrderItem = new SqlTable
19 {
20 Name = "OrderItem",
21 Fields = { new SqlField { Name = "ID" }, new SqlField { Name = "OrderID" } }
22 };
23
24 public static SqlTable OrderItem2 = new SqlTable(OrderItem);
25 public static SqlTable OrderItem3 = new SqlTable(OrderItem);
26 public static SqlTable OrderItem4 = new SqlTable(OrderItem);
27 public static SqlTable OrderItem5 = new SqlTable(OrderItem);
28
29 [Test]
30 public void Test1()
31 {
32 var sb = new SqlQuery();
33
34 sb
35 .Select
36 .Field(Order["ID"])
37 .Field(Order["Number"])
38 .From
39 .Table(Order)
40 ;
41
42 sb.FinalizeAndValidate(true, true);
43
44 Assert.AreEqual(1, sb.From.Tables.Count);
45 Assert.AreEqual(0, sb.From.Tables[0].Joins.Count);
46 }
47
48 [Test]
49 public void Test2()
50 {
51 var sb = new SqlQuery();
52
53 sb
54 .Select
55 .Field(Order["ID"])
56 .Field(OrderItem.All)
57 .Field(OrderItem4["ID"])
58 .From
59 .Table(Order,
60 OrderItem. Join ().Field(Order["ID"]).Equal.Field(OrderItem["OrderID"]),
61 OrderItem2.WeakJoin(),
62 OrderItem3.WeakJoin(
63 OrderItem5.WeakLeftJoin(),
64 OrderItem4.LeftJoin ().Field(OrderItem4["ID"]).Equal.Field(OrderItem3["ID"]))
65 )
66 .Where
67 .Not.Field(Order["ID"]).Like("1234").Or
68 .Field(Order["ID"]).Equal.Value("!%")
69 .GroupBy
70 .Field(Order["ID"])
71 .OrderBy
72 .Field(Order["ID"])
73 ;
74
75 Assert.AreEqual(1, sb.From.Tables.Count);
76 Assert.AreEqual(3, sb.From.Tables[0].Joins.Count);
77 Assert.AreEqual(2, sb.From.Tables[0].Joins[2].Table.Joins.Count);
78
79 sb.FinalizeAndValidate(true, true);
80
81 Assert.AreEqual(2, sb.From.Tables[0].Joins.Count);
82 Assert.AreEqual(1, sb.From.Tables[0].Joins[1].Table.Joins.Count);
83 }
84 }
85 }