2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / System.Data.Linq / src / DbLinq / Test / Providers / Linq_101_Samples / UnionAll_Union_Intersect.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Linq;\r
4 using System.Text;\r
5 using Test_NUnit;\r
6 using NUnit.Framework;\r
7 using Test_NUnit.Linq_101_Samples;\r
8 \r
9 using nwind;\r
10 \r
11 // test ns Linq_101_Samples\r
12 #if MYSQL\r
13     namespace Test_NUnit_MySql.Linq_101_Samples\r
14 #elif ORACLE && ODP\r
15     namespace Test_NUnit_OracleODP.Linq_101_Samples\r
16 #elif ORACLE\r
17     namespace Test_NUnit_Oracle.Linq_101_Samples\r
18 #elif POSTGRES\r
19     namespace Test_NUnit_PostgreSql.Linq_101_Samples\r
20 #elif SQLITE\r
21     namespace Test_NUnit_Sqlite.Linq_101_Samples\r
22 #elif INGRES\r
23     namespace Test_NUnit_Ingres.Linq_101_Samples\r
24 #elif MSSQL && MONO_STRICT\r
25     namespace Test_NUnit_MsSql_Strict.Linq_101_Samples\r
26 #elif MSSQL\r
27     namespace Test_NUnit_MsSql.Linq_101_Samples\r
28 #elif FIREBIRD\r
29     namespace Test_NUnit_Firebird.Linq_101_Samples\r
30 #endif\r
31 {\r
32     [TestFixture]\r
33     public class UnionAll_Union_Intersect : TestBase\r
34     {\r
35         [Test(Description = "Concat - Simple. This sample uses Concat to return a sequence of all Customer and Employee phone/fax numbers.")]\r
36         public void LinqToSqlUnion01()\r
37         {\r
38             Northwind db = CreateDB();\r
39 \r
40             var q = (from c in db.Customers select c.Phone).Concat(\r
41                      from c in db.Customers select c.Fax).Concat(\r
42                      from e in db.Employees select e.HomePhone);\r
43 \r
44             var list = q.ToList();\r
45             Assert.IsTrue(list.Count > 0);\r
46         }\r
47 \r
48         [Test(Description = "Concat - Compound. This sample uses Concat to return a sequence of all Customer and Employee name and phone number mappings.")]\r
49         public void LinqToSqlUnion02()\r
50         {\r
51             Northwind db = CreateDB();\r
52 \r
53             var q = (from c in db.Customers\r
54                      select new { Name = c.CompanyName, Phone = c.Phone })\r
55                      .Concat(from e in db.Employees\r
56                              select new { Name = e.FirstName + " " + e.LastName, Phone = e.HomePhone });\r
57 \r
58             var list = q.ToList();\r
59             Assert.IsTrue(list.Count > 0);\r
60         }\r
61 \r
62         [Test(Description = "Union. This sample uses Union to return a sequence of all countries that either Customers or Employees are in.")]\r
63         public void LinqToSqlUnion03()\r
64         {\r
65             Northwind db = CreateDB();\r
66 \r
67             var q = (from c in db.Customers\r
68                      select c.Country).Union(from e in db.Employees\r
69                                              select e.Country);\r
70 \r
71             var list = q.ToList();\r
72             Assert.IsTrue(list.Count > 0);\r
73         }\r
74 \r
75         [Test(Description = "Intersect. This sample uses Intersect to return a sequence of all countries that both Customers and Employees live in.")]\r
76         public void LinqToSqlUnion04()\r
77         {\r
78             Northwind db = CreateDB();\r
79 \r
80             var q = (from c in db.Customers\r
81                      select c.Country).Intersect(from e in db.Employees\r
82                                                  select e.Country);\r
83 \r
84             var list = q.ToList();\r
85             if (list.Count == 0)\r
86                 Assert.Ignore("Please check test validity");\r
87             //Assert.IsTrue(list.Count > 0);\r
88         }\r
89 \r
90         [Test(Description = "Except. This sample uses Except to return a sequence of all countries that Customers live in but no Employees live in.")]\r
91         public void LinqToSqlUnion05()\r
92         {\r
93             Northwind db = CreateDB();\r
94 \r
95             var q = (from c in db.Customers\r
96                      select c.Country).Except(from e in db.Employees select e.Country);\r
97 \r
98             var list = q.ToList();\r
99             Assert.IsTrue(list.Count > 0);\r
100         }\r
101     }\r
102 }\r