//------------------------------------------------------------------------------
// <auto-generated>
//     Copyright (C) 2009-2010 ORMBattle.NET.
//     All rights reserved.
//     For conditions of distribution and use, see license.
//     Created by: Alexis Kochetov
//     Created:    2009.07.31
//     Updated by: Svyatoslav Danyliv
//     Updated:    2015.12.14
//
//     This file is generated from LinqTests.tt
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;

using NUnit.Framework;

using LinqToDB;

using static Tests.Model.Northwind;

namespace Tests.OrmBattle
{
	using Tests.Model;
	using Tests.OrmBattle.Helper;

	[TestFixture]
	public class OrmBattleTests : TestBase
	{
		private const double doubleDelta = 1E-9;
		private string _currentContext;
		protected NorthwindDB db;

		protected void Setup(string context)
		{
			if (_currentContext == context)
				return;

			using (db)
				db = null;

			using (new DisableLogging())
			{
				db = new NorthwindDB(context);

				Customers = db.Customer.ToList();
				Employees = db.Employee.ToList();
				Order = db.Order.ToList();
				Products = db.Product.ToList();

				foreach (var o in Order)
				{
					o.Customer = Customers.SingleOrDefault(c => c.CustomerID == o.CustomerID);
					o.Employee = Employees.SingleOrDefault(e => e.EmployeeID == o.EmployeeID);
				}

				foreach (var c in Customers)
					c.Orders = Order.Where(o => c.CustomerID == o.CustomerID).ToList();
			}

			_currentContext = context;
		}

		[TearDown]
		protected void TearDown()
		{
			_currentContext = null;

			using (db)
				db = null;
		}
		List<Northwind.Customer> Customers;
		List<Northwind.Employee> Employees;
		List<Northwind.Order> Order;
		List<Northwind.Product> Products;
//		List<Northwind.Category> Categories;
//		List<Northwind.Supplier> Suppliers;
//		List<Northwind.Product> DiscontinuedProducts;
//		List<Northwind.OrderDetail> OrderDetails;

		// DTO for testing purposes.
		public class OrderDTO
		{
			public int Id { get; set; }
			public string CustomerId { get; set; }
			public DateTime? OrderDate { get; set; }
		}

		#region Filtering tests

		[Test]
		public void WhereTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				where o.ShipCity == "Seattle"
				select o;
			var expected = from o in Order
				where o.ShipCity == "Seattle"
				select o;
			var list = result.ToList();
			Assert.AreEqual(14, list.Count);
			Assert.AreEqual(0, expected.Except(list).Count());
		}

		[Test]
		public void WhereParameterTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var city = "Seattle";
			var result = from o in db.Order
				where o.ShipCity == city
				select o;
			var expected = from o in Order
				where o.ShipCity == city
				select o;
			var list = result.ToList();
			Assert.AreEqual(14, list.Count);
			Assert.AreEqual(0, expected.Except(list).Count());

			city = "Rio de Janeiro";
			list = result.ToList();
			Assert.AreEqual(34, list.Count);
			Assert.AreEqual(0, expected.Except(list).Count());
		}

		[Test]
		public void WhereConditionsTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from p in db.Product
				where p.UnitsInStock < p.ReorderLevel && p.UnitsOnOrder == 0
				select p;
			var list = result.ToList();
			Assert.AreEqual(1, list.Count);
		}

		[Test]
		public void WhereNullTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				where o.ShipRegion == null
				select o;
			var list = result.ToList();
			Assert.AreEqual(507, list.Count);
		}

		[Test]
		public void WhereNullParameterTest([NorthwindDataContext] string context)
		{
			Setup(context);
			string region = null;
			var result = from o in db.Order
				where o.ShipRegion == region
				select o;
			var list = result.ToList();
			Assert.AreEqual(507, list.Count);

			region = "WA";
			list = result.ToList();
			Assert.AreEqual(19, list.Count);
		}

		[Test]
		public void WhereNullableTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				where !o.ShippedDate.HasValue
				select o;
			var list = result.ToList();
			Assert.AreEqual(21, list.Count);
		}

		[Test]
		public void WhereNullableParameterTest([NorthwindDataContext] string context)
		{
			Setup(context);
			DateTime? shippedDate = null;
			var result = from o in db.Order
				where o.ShippedDate == shippedDate
				select o;
			var list = result.ToList();
			Assert.AreEqual(21, list.Count);
		}

		[Test]
		public void WhereCoalesceTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				where (o.ShipRegion ?? "N/A") == "N/A"
				select o;
			var list = result.ToList();
			Assert.AreEqual(507, list.Count);
		}

		[Test]
		public void WhereConditionalTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				where (o.ShipCity == "Seattle" ? "Home" : "Other") == "Home"
				select o;
			var list = result.ToList();
			Assert.AreEqual(14, list.Count);
		}

		[Test]
		public void WhereConditionalBooleanTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				where o.ShipCity == "Seattle" ? true : false
				select o;
			var list = result.ToList();
			Assert.AreEqual(14, list.Count);
		}

		[Test]
		public void WhereAnonymousParameterTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var cityRegion = new {City = "Seattle", Region = "WA"};
			var result = from o in db.Order
				where new {City = o.ShipCity, Region = o.ShipRegion} == cityRegion
				select o;
			var list = result.ToList();
			Assert.AreEqual(14, list.Count);
		}

		[Test]
		public void WhereEntityParameterTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var order = db.Order.OrderBy(o => o.OrderDate).First();
			var result = from o in db.Order
				where o == order
				select o;
			var list = result.ToList();
			Assert.AreEqual(1, list.Count);
			Assert.AreEqual(order, list[0]);
			//Assert.AreSame(order, list[0]);
		}

		#endregion

		#region Projection tests

		[Test]
		public void SelectTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				select o.ShipRegion;
			var expected = from o in Order
				select o.ShipRegion;
			var list = result.ToList();
			Assert.AreEqual(expected.Count(), list.Count);
			Assert.AreEqual(0, expected.Except(list).Count());
		}

		[Test]
		public void SelectBooleanTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				select o.ShipRegion == "WA";
			var expected = from o in Order
				select o.ShipRegion == "WA";
			var list = result.ToList();
			Assert.AreEqual(expected.Count(), list.Count);
			Assert.AreEqual(0, expected.Except(list).Count());
		}

		[Test]
		public void SelectCalculatedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				select o.Freight * 1000;
			var expected = from o in Order
				select o.Freight * 1000;
			var list = result.ToList();
			var expectedList = expected.ToList();
			list.Sort();
			expectedList.Sort();

			// Assert.AreEqual(expectedList.Count, list.Count);
			// expectedList.Zip(list, (i, j) => {
			//                       Assert.AreEqual(i,j);
			//                       return true;
			//                     });
			CollectionAssert.AreEquivalent(expectedList, list);
		}

		[Test]
		public void SelectNestedCalculatedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from r in
				from o in db.Order
				select o.Freight * 1000
				where r > 100000
				select r / 1000;
			var expected = from o in Order
				where o.Freight > 100
				select o.Freight;
			var list = result.ToList();
			var expectedList = expected.ToList();
			list.Sort();
			expectedList.Sort();
			Assert.AreEqual(187, list.Count);
			// Assert.AreEqual(expectedList.Count, list.Count);
			// expectedList.Zip(list, (i, j) => {
			//                       Assert.AreEqual(i,j);
			//                       return true;
			//                     });
			CollectionAssert.AreEquivalent(expectedList, list);
		}

		[Test]
		public void SelectAnonymousTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				select new {OrderID = o.OrderID, o.OrderDate, o.Freight};
			var expected = from o in Order
				select new {OrderID = o.OrderID, o.OrderDate, o.Freight};
			var list = result.ToList();
			Assert.AreEqual(expected.Count(), list.Count);
			Assert.AreEqual(0, expected.Except(list).Count());
		}

		[Test]
		public void SelectSubqueryTest([NorthwindDataContext] string context)
		{
			Setup(context);
			Assert.AreNotEqual(db.GetType().FullName, "OrmBattle.EF7Model.NorthwindContext",
				"EF7 has infinite loop here");

			var result = from o in db.Order
				select db.Customer.Where(c => c.CustomerID == o.Customer.CustomerID);
			var expected = from o in Order
				select Customers.Where(c => c.CustomerID == o.Customer.CustomerID);
			var list = result.ToList();

			var expectedList = expected.ToList();
			CollectionAssert.AreEquivalent(expectedList, list);

			//Assert.AreEqual(expected.Count(), list.Count);
			//expected.Zip(result, (expectedCustomers, actualCustomers) => {
			//                       Assert.AreEqual(expectedCustomers.Count(), actualCustomers.Count());
			//                       Assert.AreEqual(0, expectedCustomers.Except(actualCustomers));
			//                       return true;
			//                     });
		}

		[Test]
		public void SelectDtoTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from o in db.Order
				select new OrderDTO {Id = o.OrderID, CustomerId = o.Customer.CustomerID, OrderDate = o.OrderDate};
			var list = result.ToList();
			Assert.AreEqual(Order.Count(), list.Count);
		}

		[Test]
		public void SelectNestedDtoTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from r in
				from o in db.Order
				select new OrderDTO {Id = o.OrderID, CustomerId = o.Customer.CustomerID, OrderDate = o.OrderDate}
				where r.OrderDate > new DateTime(1998, 01, 01)
				select r;
			var list = result.ToList();
			Assert.AreEqual(267, list.Count);
		}

		[Test]
		public void SelectManyAnonymousTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from c in db.Customer
				from o in c.Orders
				where o.Freight < 500.00M
				select new {CustomerId = c.CustomerID, o.OrderID, o.Freight};
			var list = result.ToList();
			Assert.AreEqual(817, list.Count);
		}

		[Test]
		public void SelectManyLetTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from c in db.Customer
				from o in c.Orders
				let freight = o.Freight
				where freight < 500.00M
				select new {CustomerId = c.CustomerID, o.OrderID, freight};
			var list = result.ToList();
			Assert.AreEqual(817, list.Count);
		}

		[Test]
		public void SelectManyGroupByTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Order
				.GroupBy(o => o.Customer)
				.Where(g => g.Count() > 20)
				.SelectMany(g => g.Select(o => o.Customer));

			var list = result.ToList();
			Assert.AreEqual(89, list.Count);
		}

		[Test]
		public void SelectManyOuterProjectionTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.SelectMany(i => i.Orders.Select(t => i));

			var list = result.ToList();
			Assert.AreEqual(830, list.Count);
		}

		[Test]
		public void SelectManyLeftJoinTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				from o in c.Orders.Select(o => new {o.OrderID, c.CompanyName}).DefaultIfEmpty()
				select new {c.ContactName, o};

			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		#endregion

		#region Take / Skip tests

		[Test]
		public void TakeTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = (from o in db.Order
				orderby o.OrderDate, o.OrderID
				select o).Take(10);
			var expected = (from o in Order
				orderby o.OrderDate, o.OrderID
				select o).Take(10);
			var list = result.ToList();
			Assert.AreEqual(10, list.Count);
			Assert.IsTrue(expected.SequenceEqual(list));
		}

		[Test]
		public void SkipTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = (from o in db.Order
				orderby o.OrderDate, o.OrderID
				select o).Skip(10);
			var expected = (from o in Order
				orderby o.OrderDate, o.OrderID
				select o).Skip(10);
			var list = result.ToList();
			Assert.AreEqual(820, list.Count);
			Assert.IsTrue(expected.SequenceEqual(list));
		}

		[Test]
		public void TakeSkipTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = (from o in db.Order
				orderby o.OrderDate, o.OrderID
				select o).Skip(10).Take(10);
			var expected = (from o in Order
				orderby o.OrderDate, o.OrderID
				select o).Skip(10).Take(10);
			var list = result.ToList();
			Assert.AreEqual(10, list.Count);
			Assert.IsTrue(expected.SequenceEqual(list));
		}

		[Test]
		public void TakeNestedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				select new {Customer = c, TopOrder = c.Orders.OrderByDescending(o => o.OrderDate).Take(5)};
			var expected =
				from c in Customers
				select new {Customer = c, TopOrder = c.Orders.OrderByDescending(o => o.OrderDate).Take(5)};
			var list = result.ToList();
			Assert.AreEqual(expected.Count(), list.Count);
			foreach (var anonymous in list)
			{
				var count = anonymous.TopOrder.ToList().Count;
				Assert.GreaterOrEqual(count, 0);
				Assert.LessOrEqual(count, 5);
			}
		}

		[Test]
		public void ComplexTakeSkipTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var original = db.Order.ToList()
				.OrderBy(o => o.OrderDate)
				.Skip(100)
				.Take(50)
				.OrderBy(o => o.RequiredDate)
				.Where(o => o.OrderDate != null)
				.Select(o => o.RequiredDate)
				.Distinct()
				.OrderByDescending(_ => _)
				.Skip(10);
			var result = db.Order
				.OrderBy(o => o.OrderDate)
				.Skip(100)
				.Take(50)
				.OrderBy(o => o.RequiredDate)
				.Where(o => o.OrderDate != null)
				.Select(o => o.RequiredDate)
				.Distinct()
				.OrderByDescending(_ => _)
				.Skip(10);
			var originalList = original.ToList();
			var resultList = result.ToList();
			Assert.AreEqual(originalList.Count, resultList.Count);
			Assert.IsTrue(originalList.SequenceEqual(resultList));
		}

		#endregion

		#region Ordering tests

		[Test]
		public void OrderByTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				orderby o.OrderDate, o.ShippedDate descending, o.OrderID
				select o;
			var expected =
				from o in Order
				orderby o.OrderDate, o.ShippedDate descending, o.OrderID
				select o;

			var list = result.ToList();
			var expectedList = expected.ToList();
			Assert.AreEqual(expectedList.Count, list.Count);
			Assert.IsTrue(expected.SequenceEqual(list));
		}

		[Test]
		public void OrderByWhereTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = (from o in db.Order
				orderby o.OrderDate, o.OrderID
				where o.OrderDate > new DateTime(1997, 1, 1)
				select o).Take(10);
			var expected = (from o in Order
				where o.OrderDate > new DateTime(1997, 1, 1)
				orderby o.OrderDate, o.OrderID
				select o).Take(10);
			var list = result.ToList();
			Assert.AreEqual(10, list.Count);
			Assert.IsTrue(expected.SequenceEqual(list));
		}

		[Test]
		public void OrderByCalculatedColumnTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				orderby o.Freight * o.OrderID descending
				select o;
			var expected =
				from o in Order
				orderby o.Freight * o.OrderID descending
				select o;
			Assert.IsTrue(expected.SequenceEqual(result));
		}

		[Test]
		public void OrderByEntityTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				orderby o
				select o;
			var expected =
				from o in Order
				orderby o.OrderID
				select o;
			Assert.IsTrue(expected.SequenceEqual(result, new GenericEqualityComparer<Order>(o => o.OrderID)));
		}

		[Test]
		public void OrderByAnonymousTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				orderby new {o.OrderDate, o.ShippedDate, o.OrderID}
				select o;
			var expected =
				from o in Order
				orderby o.OrderDate, o.ShippedDate, o.OrderID
				select o;
			Assert.IsTrue(expected.SequenceEqual(result, new GenericEqualityComparer<Order>(o => o.OrderID)));
		}

		[Test]
		[ActiveIssue("Bad database data", Configuration = TestProvName.AllSQLiteNorthwind)]
		public void OrderByDistinctTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer
				.OrderBy(c => c.CompanyName)
				.Select(c => c.City)
				.Distinct()
				.OrderBy(c => c)
				.Select(c => c);
			var expected = Customers
				.OrderBy(c => c.CompanyName)
				.Select(c => c.City)
				.Distinct()
				.OrderBy(c => c)
				.Select(c => c);
			Assert.IsTrue(expected.SequenceEqual(result));
		}

		[Test]
		[ActiveIssue("Bad database data", Configuration = TestProvName.AllSQLiteNorthwind)]
		public void OrderBySelectManyTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer.OrderBy(c => c.ContactName)
				from o in db.Order.OrderBy(o => o.OrderDate)
				where c == o.Customer
				select new {c.ContactName, o.OrderDate};
			var expected =
				from c in Customers.OrderBy(c => c.ContactName)
				from o in Order.OrderBy(o => o.OrderDate)
				where c == o.Customer
				select new {c.ContactName, o.OrderDate};
			Assert.IsTrue(expected.SequenceEqual(result));
		}

		[Test]
		public void OrderByPredicateTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				db.Order.OrderBy(o => o.Freight > 0 && o.ShippedDate != null).ThenBy(o => o.OrderID).Select(o => o.OrderID);
			var list = result.ToList();
			var original =
				Order.OrderBy(o => o.Freight > 0 && o.ShippedDate != null).ThenBy(o => o.OrderID).Select(o => o.OrderID).ToList();
			Assert.IsTrue(list.SequenceEqual(original));
		}

		#endregion

		#region Grouping tests

		[Test]
		public void GroupByTest([NorthwindDataContext] string context)
		{
			using (new GuardGrouping(false))
			{
				Setup(context);
				var result = from o in db.Order
							 group o by o.OrderDate;
				var list = result.ToList();
				Assert.AreEqual(480, list.Count);
			}
		}

		[Test]
		public void GroupByReferenceTest([NorthwindDataContext] string context)
		{
			using (new GuardGrouping(false))
			{
				Setup(context);
				var result = from o in db.Order
							 group o by o.Customer;
				var list = result.ToList();
				Assert.AreEqual(89, list.Count);
			}
		}

		[Test]
		public void GroupByWhereTest([NorthwindDataContext] string context)
		{
			using (new GuardGrouping(false))
			{
				Setup(context);
				var result =
					from o in db.Order
					group o by o.OrderDate
					into g
					where g.Count() > 5
					select g;
				var list = result.ToList();
				Assert.AreEqual(1, list.Count);
			}
		}

		[Test]
		public void GroupByTestAnonymous([NorthwindDataContext] string context)
		{
			using (new GuardGrouping(false))
			{
				Setup(context);
				var result = from c in db.Customer
							 group c by new { c.Region, c.City };
				var list = result.ToList();
				Assert.AreEqual(69, list.Count);
			}
		}

		[Test]
		public void GroupByCalculatedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				group o by o.Freight > 50 ? o.Freight > 100 ? "expensive" : "average" : "cheap"
				into g
				select g;
			var list = result.ToList();
			Assert.AreEqual(3, list.Count);
		}

		[Test]
		public void GroupBySelectManyTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer
				.GroupBy(c => c.City)
				.SelectMany(g => g);

			var list = result.ToList();
			Assert.AreEqual(91, list.Count);
		}

		[Test]
		public void GroupByCalculateAggregateTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				group o by o.Customer
				into g
				select g.Sum(o => o.Freight);

			var list = result.ToList();
			Assert.AreEqual(89, list.Count);
		}

		[Test]
		public void GroupByCalculateManyAggreagetes([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from o in db.Order
				group o by o.Customer
				into g
				select new
				{
					Sum = g.Sum(o => o.Freight),
					Min = g.Min(o => o.Freight),
					Max = g.Max(o => o.Freight),
					Avg = g.Average(o => o.Freight)
				};

			var list = result.ToList();
			Assert.AreEqual(89, list.Count);
		}

		[Test]
		public void GroupByAggregate([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				group c by c.Orders.Average(o => o.Freight) >= 80;
			var list = result.ToList();
			Assert.AreEqual(2, list.Count);
			var firstGroupList = list.First(g => !g.Key).ToList();
			Assert.AreEqual(71, firstGroupList.Count);
		}

		[Test]
		public void ComplexGroupingTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				select new
				{
					c.CompanyName,
					YearGroups =
					from o in c.Orders
					group o by o.OrderDate.Value.Year
					into yg
					select new
					{
						Year = yg.Key,
						MonthGroups =
						from o in yg
						group o by o.OrderDate.Value.Month
						into mg
						select new {Month = mg.Key, Order = mg}
					}
				};
			var list = result.ToList();
			foreach (var customer in list)
			{
				var OrderList = customer.YearGroups.ToList();
				Assert.LessOrEqual(OrderList.Count, 3);
			}
		}

		#endregion

		#region Set operations / Distinct tests

		[Test]
		public void ConcatTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.Where(c => c.Orders.Count <= 1)
				.Concat(db.Customer.Where(c => c.Orders.Count > 1));
			var list = result.ToList();
			Assert.AreEqual(91, list.Count);
		}

		[Test]
		public void UnionTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = (
					from c in db.Customer
					select c.Phone)
				.Union(
					from c in db.Customer
					select c.Fax)
				.Union(
					from e in db.Employee
					select e.HomePhone
				);

			var list = result.ToList();
			Assert.AreEqual(167, list.Count);
		}

		[Test]
		public void ExceptTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				db.Customer.Except(db.Customer.Where(c => c.Orders.Count() > 0));
			var list = result.ToList();
			Assert.AreEqual(2, list.Count);
		}

		[Test]
		public void IntersectTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				db.Customer.Intersect(db.Customer.Where(c => c.Orders.Count() > 0));
			var list = result.ToList();
			Assert.AreEqual(89, list.Count);
		}

		[Test]
		public void DistinctTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Order.Select(c => c.Freight).Distinct();
			var list = result.ToList();
			Assert.AreEqual(799, list.Count);
		}

		[Test]
		public void DistinctTakeLastTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
			(from o in db.Order
				orderby o.OrderDate
				select o.OrderDate).Distinct().Take(5);
			var list = result.ToList();
			Assert.AreEqual(5, list.Count);
		}

		[Test]
		public void DistinctTakeFirstTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
			(from o in db.Order
				orderby o.OrderDate
				select o.OrderDate).Take(5).Distinct();
			var list = result.ToList();
			Assert.AreEqual(4, list.Count);
		}

		[Test]
		public void DistinctEntityTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.Distinct();
			var list = result.ToList();
			Assert.AreEqual(91, list.Count);
		}

		[Test]
		public void DistinctAnonymousTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.Select(c => new {c.Region, c.City}).Distinct();
			var list = result.ToList();
			Assert.AreEqual(69, list.Count);
		}

		#endregion

		#region Type casts

		[Test]
		public void TypeCastIsChildTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Product.Where(p => p is DiscontinuedProduct);
			var expected = db.Product.ToList().Where(p => p is DiscontinuedProduct);
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			Assert.AreEqual(expected.Count(), list.Count);
		}

		[Test]
		public void TypeCastIsParentTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Product.Where(p => p is Product);
			var expected = db.Product.ToList();
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			Assert.AreEqual(expected.Count(), list.Count);
		}

		[Test, ActiveIssue(573)]
		public void TypeCastIsChildConditionalTest([NorthwindDataContext] string context)
		{
			//TODO: sdanyliv: strange test for me
			Setup(context);
			var result = db.Product
				.Select(x => x is DiscontinuedProduct
					? x
					: null);

			var expected = db.Product.ToList()
				.Select(x => x is DiscontinuedProduct
					? x
					: null);

			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			Assert.AreEqual(expected.Count(), list.Count);
			Assert.IsTrue(list.Except(expected).Count() == 0);
			Assert.IsTrue(list.Contains(null));
		}

		[Test]
		public void TypeCastOfTypeTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Product.OfType<DiscontinuedProduct>();
			var expected = db.Product.ToList().OfType<DiscontinuedProduct>();
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			Assert.AreEqual(expected.Count(), list.Count);
		}

		[Test]
		public void TypeCastAsTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.DiscontinuedProduct
				.Select(discontinuedProduct => discontinuedProduct as Product)
				.Select(product =>
					product == null
						? "NULL"
						: product.ProductName);

			var expected = db.DiscontinuedProduct.ToList()
				.Select(discontinuedProduct => discontinuedProduct as Product)
				.Select(product =>
					product == null
						? "NULL"
						: product.ProductName);

			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			Assert.AreEqual(expected.Count(), list.Count);
			Assert.IsTrue(list.Except(expected).Count() == 0);
		}

		#endregion

		#region Element operations

		[Test]
		public void FirstTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void FirstOrDefaultTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.CustomerID == "ALFKI").FirstOrDefault();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void FirstPredicateTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.First(c => c.CustomerID == "ALFKI");
			Assert.IsNotNull(customer);
		}

		[Test]
		public void NestedFirstOrDefaultTest([IncludeDataSources(TestProvName.AllNorthwind)] string context)
		{
			Setup(context);
			var result =
				from p in db.Product
				select new
				{
					ProductID = p.ProductID,
					MaxOrder = db.OrderDetail
						.Where(od => od.Product == p)
						.OrderByDescending(od => od.UnitPrice * od.Quantity)
						.FirstOrDefault()
						.Order
				};
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		[Test]
		public void FirstOrDefaultEntitySetTest([IncludeDataSources(TestProvName.AllNorthwind)] string context)
		{
			Setup(context);
			var customersCount = Customers.Count;
			var result = db.Customer.Select(c => c.Orders.FirstOrDefault());
			var list = result.ToList();
			Assert.AreEqual(customersCount, list.Count);
		}

		[Test]
		public void NestedSingleOrDefaultTest([IncludeDataSources(TestProvName.AllNorthwind)] string context)
		{
			Setup(context);
			var customersCount = Customers.Count;
			var result = db.Customer.Select(c => c.Orders.Take(1).SingleOrDefault());
			var list = result.ToList();
			Assert.AreEqual(customersCount, list.Count);
		}

		[Test]
		public void NestedSingleTest([IncludeDataSources(TestProvName.AllNorthwind)] string context)
		{
			Setup(context);
			var result = db.Customer.Where(c => c.Orders.Count() > 0).Select(c => c.Orders.Take(1).Single());
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		[Test]
		public void ElementAtTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.OrderBy(c => c.CustomerID).ElementAt(15);
			Assert.IsNotNull(customer);
			Assert.AreEqual("CONSH", customer.CustomerID);
		}

		[Test]
		public void NestedElementAtTest([IncludeDataSources(TestProvName.AllNorthwind)] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				where c.Orders.Count() > 5
				select c.Orders.ElementAt(3);

			var list = result.ToList();
			Assert.AreEqual(63, list.Count);
		}

		#endregion

		#region Contains / Any / All tests

		[Test]
		public void AllNestedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				where
				db.Order.Where(o => o.Customer == c)
					.All(o => db.Employee.Where(e => o.Employee == e).Any(e => e.FirstName.StartsWith("A")))
				select c;
			var list = result.ToList();
			Assert.AreEqual(2, list.Count);
		}

		[Test]
		public void ComplexAllTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				(from o in db.Order
				where
				db.Customer.Where(c => c == o.Customer).All(c => c.CompanyName.StartsWith("A")) ||
				db.Employee.Where(e => e == o.Employee).All(e => e.FirstName.EndsWith("t"))
				select o).ToList();
			var expected =
				from o in Order
				where
				Customers.Where(c => c == o.Customer).All(c => c.CompanyName.StartsWith("A")) ||
				Employees.Where(e => e == o.Employee).All(e => e.FirstName.EndsWith("t"))
				select o;

			Assert.AreEqual(0, expected.Except(result).Count());
			Assert.AreEqual(result.ToList().Count, 366);
		}

		[Test]
		public void ContainsNestedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = from c in db.Customer
				select new
				{
					Customer = c,
					HasNewOrder = db.Order
						.Where(o => o.OrderDate > new DateTime(2001, 1, 1))
						.Select(o => o.Customer)
						.Contains(c)
				};

			var resultList = result.ToList();

			var expected =
				from c in Customers
				select new
				{
					Customer = c,
					HasNewOrder = Order
						.Where(o => o.OrderDate > new DateTime(2001, 1, 1))
						.Select(o => o.Customer)
						.Contains(c)
				};
			Assert.AreEqual(0, expected.Except(resultList).Count());
			Assert.AreEqual(0, resultList.Count(i => i.HasNewOrder));
		}

		[Test]
		public void AnyTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.Where(c => c.Orders.Any(o => o.Freight > 400)).ToList();
			var expected = Customers.Where(c => c.Orders.Any(o => o.Freight > 400));
			Assert.AreEqual(0, expected.Except(result).Count());
			Assert.AreEqual(10, result.ToList().Count);
		}

		[Test]
		public void AnyParameterizedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var ids = new[] {"ABCDE", "ALFKI"};
			var result = db.Customer.Where(c => ids.Any(id => c.CustomerID == id));
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		[Test]
		public void ContainsParameterizedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customerIDs = new[] {"ALFKI", "ANATR", "AROUT", "BERGS"};
			var result = db.Order.Where(o => customerIDs.Contains(o.Customer.CustomerID));
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			Assert.AreEqual(41, list.Count);
		}

		#endregion

		#region Aggregates tests

		[Test]
		public void SumTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var sum = db.Order.Select(o => o.Freight).Sum();
			var sum1 = Order.Select(o => o.Freight).Sum();
			Assert.AreEqual((double)sum1, (double)sum, doubleDelta);
		}

		[Test]
		public void CountPredicateTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var count = db.Order.Count(o => o.OrderID > 10);
			var count1 = Order.Count(o => o.OrderID > 10);
			Assert.AreEqual(count1, count);
		}

		[Test]
		public void NestedCountTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.Where(c => db.Order.Count(o => o.Customer.CustomerID == c.CustomerID) > 5);
			var expected = Customers.Where(c => db.Order.Count(o => o.Customer.CustomerID == c.CustomerID) > 5);

			Assert.IsTrue(expected.Except(result).Count() == 0);
		}

		[Test]
		public void NullableSumTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var sum = db.Order.Select(o => (int?) o.OrderID).Sum();
			var sum1 = Order.Select(o => (int?) o.OrderID).Sum();
			Assert.AreEqual(sum1, sum);
		}

		[Test]
		public void MaxCountTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var max = db.Customer.Max(c => db.Order.Count(o => o.Customer.CustomerID == c.CustomerID));
			var max1 = Customers.Max(c => Order.Count(o => o.Customer.CustomerID == c.CustomerID));
			Assert.AreEqual(max1, max);
		}

		#endregion

		#region Join tests

		[Test]
		public void GroupJoinTest([NorthwindDataContext] string context)
		{
			//TODO: sdanyliv: o.Customer.CustomerID - it is association that means additional JOIN. We have to decide if it is a bug.
			Setup(context);
			var result =
				from c in db.Customer
				join o in db.Order on c.CustomerID equals o.Customer.CustomerID into go
				join e in db.Employee on c.City equals e.City into ge
				select new
				{
					OrderCount = go.Count(),
					EmployeesCount = ge.Count()
				};
			var list = result.ToList();
			Assert.AreEqual(91, list.Count);
		}

		[Test]
		public void JoinTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from p in db.Product
				join s in db.Supplier on p.Supplier.SupplierID equals s.SupplierID
				select new {p.ProductName, s.ContactName, s.Phone};

			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		[Test]
		public void JoinByAnonymousTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				join o in db.Order on new {Customer = c, Name = c.ContactName} equals
				new {o.Customer, Name = o.Customer.ContactName}
				select new {c.ContactName, o.OrderDate};

			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		[Test]
		public void LeftJoinTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Category
				join p in db.Product on c.CategoryID equals p.Category.CategoryID into g
				from p in g.DefaultIfEmpty()
				select new {Name = p == null ? "Nothing!" : p.ProductName, c.CategoryName};

			var list = result.ToList();
			Assert.AreEqual(77, list.Count);
		}

		#endregion

		#region References tests

		[Test]
		public void JoinByReferenceTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				join o in db.Order on c equals o.Customer
				select new {c.ContactName, o.OrderDate};

			var list = result.ToList();
			Assert.AreEqual(830, list.Count);
		}

		[Test]
		public void CompareReferenceTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from c in db.Customer
				from o in db.Order
				where c == o.Customer
				select new {c.ContactName, o.OrderDate};

			var list = result.ToList();
			Assert.AreEqual(830, list.Count);
		}

		[Test]
		public void ReferenceNavigationTestTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result =
				from od in db.OrderDetail
				where od.Product.Category.CategoryName == "Seafood"
				select new {od.Order, od.Product};

			var list = result.ToList();
			Assert.AreEqual(330, list.Count);
			foreach (var anonymous in list)
			{
				Assert.IsNotNull(anonymous);
				Assert.IsNotNull(anonymous.Order);
				Assert.IsNotNull(anonymous.Product);
			}
		}

		[Test]
		public void EntitySetCountTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Category.Where(c => c.Products.Count > 10);
			var list = result.ToList();
			Assert.AreEqual(4, list.Count);
		}

		#endregion

		#region Complex tests

		[Test]
		public void ComplexTest1([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Supplier.Select(
					supplier => db.Product.Select(
						product => db.Product.Where(p =>
							p.ProductID == product.ProductID && p.Supplier.SupplierID == supplier.SupplierID)))
				.ToList();
			var count = result.Count;
			Assert.Greater(count, 0);
			foreach (var queryable in result)
			{
				foreach (var queryable1 in queryable)
				{
					foreach (var product in queryable1)
					{
						Assert.IsNotNull(product);
					}
				}
			}
		}

		[Test, ActiveIssue(573, Details = "'k.CompanyName' cannot be converted to SQL.")]
		public void ComplexTest2([NorthwindDataContext] string context)
		{
			Setup(context);

			//TODO: sdanyliv: It can be replaced by the following linq expression. We have to decide that we have time to implement.
			var r = from c in db.Customer
				group c by c.Country
				into g
				from gi in g
				where gi.CompanyName.Substring(0, 1) == g.Key.Substring(0, 1)
				select gi;

			var result = db.Customer
				.GroupBy(c => c.Country,
					(country, customers) =>
						customers.Where(k => k.CompanyName.Substring(0, 1) == country.Substring(0, 1)))
				.SelectMany(k => k);
			var expected = Customers
				.GroupBy(c => c.Country,
					(country, customers) =>
						customers.Where(k => k.CompanyName.Substring(0, 1) == country.Substring(0, 1)))
				.SelectMany(k => k);

			Assert.AreEqual(0, expected.Except(result).Count());
		}

		[Test]
		public void ComplexTest3([NorthwindDataContext] string context)
		{
			Setup(context);
			var products  = db.Product;
			var suppliers = db.Supplier;
			var result = from p in products
				select new
				{
					Product = p,
					Suppliers = suppliers
						.Where(s => s.SupplierID == p.Supplier.SupplierID)
						.Select(s => s.CompanyName)
				};
			var list = result.ToList();
			Assert.Greater(list.Count, 0);
			foreach (var p in list)
			foreach (var companyName in p.Suppliers)
				Assert.IsNotNull(companyName);
		}

		[Test, ActiveIssue(573)]
		public void ComplexTest4([NorthwindDataContext] string context)
		{
			//TODO: sdanyliv: This is a bug
			Setup(context);
			var result = db.Customer
				.Take(2)
				.Select(
					c =>
						db.Order.Select(o => db.Employee.Take(2).Where(e => e.Orders.Contains(o)))
							.Where(o => o.Count() > 0))
				.Select(os => os);

			var list = result.ToList();
			Assert.Greater(list.Count, 0);

			foreach (var item in list)
				item.ToList();
		}

		[Test]
		public void ComplexTest5([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer
				.Select(c => new {Customer = c, Order = db.Order})
				.Select(i => i.Customer.Orders);

			var list = result.ToList();
			Assert.Greater(list.Count, 0);

			foreach (var item in list)
				item.ToList();
		}

		[Test]
		public void ComplexTest6([NorthwindDataContext] string context)
		{
			Setup(context);
			var r =
				from c in db.Customer
				from o in db.Order
				where o.Customer == c
				select new
				{
					Customer = c,
					Order = o
				};

			var result = db.Customer
				.Select(c => new {Customer = c, Order = db.Order.Where(o => o.Customer == c)})
				.SelectMany(i => i.Order.Select(o => new {i.Customer, Order = o}));

			var list = result.ToList();
			Assert.Greater(list.Count, 0);
		}

		#endregion

		#region Standard functions tests

		[Test]
		public void StringStartsWithTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Customer.Where(c => c.CustomerID.StartsWith("A") || c.CustomerID.StartsWith("L"));

			var list = result.ToList();
			Assert.AreEqual(13, list.Count);
		}

		[Test]
		public void StringStartsWithParameterizedTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var likeA = "A";
			var likeL = "L";
			var result = db.Customer.Where(c => c.CustomerID.StartsWith(likeA) || c.CustomerID.StartsWith(likeL));

			var list = result.ToList();
			Assert.AreEqual(13, list.Count);
		}

		[Test]
		public void StringLengthTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.City.Length == 7).First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void StringContainsTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.ContactName.Contains("and")).First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void StringToLowerTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.City.ToLower() == "seattle").First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void StringRemoveTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.City.Remove(3) == "Sea").First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void StringIndexOfTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.City.IndexOf("tt") == 3).First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void StringLastIndexOfTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.City.LastIndexOf("t", 1, 3) == 3).First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void StringPadLeftTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => "123" + c.City.PadLeft(8) == "123 Seattle").First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void DateTimeTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var order = db.Order.Where(o => o.OrderDate >= new DateTime(o.OrderDate.Value.Year, 1, 1)).First();
			Assert.IsNotNull(order);
		}

		[Test]
		public void DateTimeDayTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var order = db.Order.Where(o => o.OrderDate.Value.Day == 5).First();
			Assert.IsNotNull(order);
		}

		[Test]
		public void DateTimeDayOfWeek([NorthwindDataContext] string context)
		{
			Setup(context);
			var order = db.Order.Where(o => o.OrderDate.Value.DayOfWeek == DayOfWeek.Friday).First();
			Assert.IsNotNull(order);
		}

		[Test]
		public void DateTimeDayOfYear([NorthwindDataContext] string context)
		{
			Setup(context);
			var order = db.Order.Where(o => o.OrderDate.Value.DayOfYear == 360).First();
			Assert.IsNotNull(order);
		}

		[Test]
		public void MathAbsTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var order = db.Order.Where(o => Math.Abs(o.OrderID) == 10 || o.OrderID > 0).First();
			Assert.IsNotNull(order);
		}

		[Test]
		public void MathTrignometricTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var order = db.Order.Where(o => Math.Asin(Math.Cos(o.OrderID)) == 0 || o.OrderID > 0).First();
			Assert.IsNotNull(order);
		}

		[Test]
		public void MathFloorTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var result = db.Order.Where(o => Math.Floor(o.Freight) == 140);
			var list = result.ToList();
			Assert.AreEqual(2, list.Count);
		}

		[Test]
		public void MathCeilingTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var result = db.Order.Where(o => Math.Ceiling(o.Freight) == 141);
			var list = result.ToList();
			Assert.AreEqual(2, list.Count);
		}

		[Test]
		public void MathTruncateTest([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var result = db.Order.Where(o => Math.Truncate(o.Freight) == 141);
			var list = result.ToList();
			Assert.AreEqual(2, list.Count);
		}

		[Test]
		public void MathRoundAwayFromZeroTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Order.Where(o => Math.Round(o.Freight / 10, 1, MidpointRounding.AwayFromZero) == 6.5m);
			var list = result.ToList();
			Assert.AreEqual(7, list.Count);
		}

		[Test]
		public void MathRoundToEvenTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Order.Where(o => Math.Round(o.Freight / 10, 1, MidpointRounding.ToEven) == 6.5m);
			var list = result.ToList();
			Assert.AreEqual(6, list.Count);
		}

		[Test]
		public void MathRoundDefaultTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var result = db.Order.Where(o => Math.Round(o.Freight / 10, 1) == 6.5m);
			var list = result.ToList();
			Assert.AreEqual(6, list.Count);
		}

		[Test]
		public void ConvertToInt32([NorthwindDataContext(false, true)] string context)
		{
			Setup(context);
			var expected = Order.Where(o => Convert.ToInt32(o.Freight * 10) == 592);
			var result = db.Order.Where(o => Convert.ToInt32(o.Freight * 10) == 592);
			var list = result.ToList();
			Assert.AreEqual(expected.Count(), list.Count);
		}

		[Test]
		public void StringCompareToTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => c.City.CompareTo("Seattle") >= 0).First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void ComparisonWithNullTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => null != c.City).First();
			Assert.IsNotNull(customer);
		}

		[Test]
		public void EqualsWithNullTest([NorthwindDataContext] string context)
		{
			Setup(context);
			var customer = db.Customer.Where(c => !c.Address.Equals(null)).First();
			Assert.IsNotNull(customer);
		}

		#endregion
	}
}
