5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
27 using System.Globalization;
\r
28 using System.Collections.Generic;
\r
31 using System.Linq.Expressions;
\r
32 using NUnit.Framework;
\r
39 namespace Test_NUnit_MySql
\r
41 namespace Test_NUnit_OracleODP
\r
43 namespace Test_NUnit_Oracle
\r
45 namespace Test_NUnit_PostgreSql
\r
47 namespace Test_NUnit_Sqlite
\r
49 namespace Test_NUnit_Ingres
\r
50 #elif MSSQL && L2SQL
\r
51 namespace Test_NUnit_MsSql_Strict
\r
53 namespace Test_NUnit_MsSql
\r
55 namespace Test_NUnit_Firebird
\r
59 /// this test class will exercise various operands, such as 'a&&b', 'a>=b', ""+a, etc.
\r
62 public class ReadTest_Operands : TestBase
\r
66 public void H1_SelectConcat()
\r
68 Northwind db = CreateDB();
\r
70 var q = from p in db.Products select p.ProductName + " " + p.SupplierID;
\r
72 foreach (string s in q)
\r
75 continue; //concat('X',NULL) -> NULL
\r
77 bool ok = Char.IsLetterOrDigit(s[0]) && s.Contains(' ');
\r
78 Assert.IsTrue(ok, "Concat string should start with product name, instead got:" + s);
\r
81 Assert.IsTrue(count > 0, "Expected concat strings, got none");
\r
85 public void H2_SelectGreaterOrEqual()
\r
87 Northwind db = CreateDB();
\r
89 var q = db.Products.Where(p => p.ProductID >= 5);
\r
91 foreach (Product p in q)
\r
93 Assert.IsTrue(p.ProductID >= 5, "Failed on ProductID>=20");
\r
96 Assert.IsTrue(count > 0, "Expected some products with ProductID>=5, got none");
\r
99 public struct ProductWrapper1
\r
101 public int ProductID { get; set; }
\r
102 public int? SupplierID { get; set; }
\r
105 public class ProductWrapper2
\r
107 public int ProductID { get; set; }
\r
108 public int? SupplierID { get; set; }
\r
111 public class ProductWrapper3
\r
113 public int ProductID { get; set; }
\r
114 public int? SupplierID { get; set; }
\r
115 public ProductWrapper3(int p, int? s) { ProductID = p; SupplierID = s; }
\r
116 public ProductWrapper3(int p, int? s, bool unused) { ProductID = p; SupplierID = s; }
\r
120 public void H3_Select_MemberInit_Struct()
\r
122 Northwind db = CreateDB();
\r
123 var q = from p in db.Products
\r
124 where p.ProductID > 5
\r
125 select new ProductWrapper1 { ProductID = (int)p.ProductID, SupplierID = (int?)p.SupplierID };
\r
127 foreach (ProductWrapper1 p in q)
\r
129 Assert.IsTrue(p.ProductID > 5, "Failed on ProductID>=20");
\r
132 Assert.IsTrue(count > 0, "Expected some products with ProductID>5, got none");
\r
136 public void H4_Select_MemberInit_Class()
\r
138 Northwind db = CreateDB();
\r
139 var q = from p in db.Products
\r
140 where p.ProductID > 5
\r
141 select new ProductWrapper2 { ProductID = (int)p.ProductID, SupplierID = (int?)p.SupplierID };
\r
143 foreach (ProductWrapper2 p in q)
\r
145 Assert.IsTrue(p.ProductID > 5, "Failed on ProductID>=20");
\r
148 Assert.IsTrue(count > 0, "Expected some products with ProductID>5, got none");
\r
152 public void H5_Select_MemberInit_Class2()
\r
154 Northwind db = CreateDB();
\r
155 var q = from p in db.Products
\r
156 where p.ProductID > 5
\r
157 select new ProductWrapper3((int)p.ProductID, (int?)p.SupplierID);
\r
159 foreach (ProductWrapper3 p in q)
\r
161 Assert.IsTrue(p.ProductID > 5, "Failed on ProductID>=20");
\r
164 Assert.IsTrue(count > 0, "Expected some products with ProductID>5, got none");
\r
168 public void H6_SelectNotEqual()
\r
170 Northwind db = CreateDB();
\r
171 var q = from p in db.Products
\r
172 where p.ProductID != 1
\r
175 foreach (Product p in q)
\r
177 Assert.IsFalse(p.ProductID == 1, "Failed on ProductID != 1");
\r
180 Assert.IsTrue(count > 0, "Expected some products with ProductID != 1, got none");
\r
183 #if !DEBUG && (SQLITE || (MSSQL && !L2SQL))
\r
187 public void J1_LocalFunction_DateTime_ParseExact()
\r
189 Northwind db = CreateDB();
\r
191 //Lookup EmployeeID 1:
\r
192 //Andy Fuller - HireDate: 1989-01-01 00:00:00
\r
194 string hireDate = "1992.08.14";
\r
196 // Ingres assumes UTC on all date queries
\r
197 var q = from e in db.Employees
\r
199 where e.HireDate == DateTime.ParseExact(hireDate, "yyyy.MM.dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal)
\r
201 where e.HireDate == DateTime.ParseExact(hireDate, "yyyy.MM.dd", CultureInfo.InvariantCulture)
\r
204 var empLastName = q.Single(); //MTable_Projected.GetQueryText()
\r
205 Assert.AreEqual("Fuller", empLastName);
\r