public void NorthwindInit()
 {
     provider.Connection.Open();
     db = new Northwind(provider);
     ClearOutTestData();
 }
        public void Extension_Table_SessionProviderNotIdentityCached()
        {
            NorthwindSession ns = new NorthwindSession(provider);
            Northwind db2 = new Northwind(ns.Session.Provider);

            // both objects should be different instances
            var cust = ns.CustomersWithComments.Single(c => c.CustomerID == "ALFKI");
            var cust2 = ns.CustomersWithComments.ProviderTable.Single(c => c.CustomerID == "ALFKI");

            Assert.AreNotEqual(null, cust);
            Assert.AreNotEqual(null, cust2);
            Assert.AreEqual(cust.CustomerID, cust2.CustomerID);
            Assert.IsFalse(Assert.ReferenceEquals(cust, cust2));
        }
        public void TestInsertCustomersIncludeOrders()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders);
            policy.IncludeWith<Order>(o => o.Details);
            Northwind nw = new Northwind(this.provider.New(policy));

            var cust = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };
            var order = new Order
            {
                CustomerID = "XX1",
                OrderDate = DateTime.Today,
            };
            cust.Orders = new List<Order> { order };

            var custs = nw.Customers.Insert(cust);
            var result = nw.Orders.Insert(order);
            cust = nw.Customers.GetById(cust.CustomerID);
            Assert.AreEqual(1, custs);
            //TODO: Complete Assert
            //Assert.IsNotNull(custs[0].Orders);
            //Assert.AreEqual(6, custs[0].Orders.Count);
            //Assert.IsTrue(custs[0].Orders.Any(o => o.OrderID == 10643));
            //Assert.IsNotNull(custs[0].Orders.Single(o => o.OrderID == 10643).Details);
            //Assert.AreEqual(3, custs[0].Orders.Single(o => o.OrderID == 10643).Details.Count);
        }
 public void NorthwidnCUDTestsInit()
 {
     provider.Connection.Open();
     db = new Northwind(provider);
 }
        public void TestCustomersIncludeOrdersDeferred()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders, true);
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            Assert.AreEqual(1, custs.Count);
            Assert.IsNotNull(custs[0].Orders);
            Assert.AreEqual(6, custs[0].Orders.Count);
        }
        public void TestCustomersIncludeThenAssociateOrders()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders);
            policy.AssociateWith<Customer>(c => c.Orders.Where(o => (o.OrderID & 1) == 0));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            Assert.AreEqual(1, custs.Count);
            Assert.IsNotNull(custs[0].Orders);
            Assert.AreEqual(3, custs[0].Orders.Count);
        }
        public void TestCustomersAssociateOrders()
        {
            var policy = new EntityPolicy();
            policy.AssociateWith<Customer>(c => c.Orders.Where(o => (o.OrderID & 1) == 0));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI")
                .Select(c => new { CustomerID = c.CustomerID, FilteredOrdersCount = c.Orders.Count() }).ToList();
            Assert.AreEqual(1, custs.Count);
            Assert.AreEqual(3, custs[0].FilteredOrdersCount);
        }
        public void TestCustomersIncludeOrdersAndDetails()
        {
            var policy = new EntityPolicy();
            policy.IncludeWith<Customer>(c => c.Orders);
            policy.IncludeWith<Order>(o => o.Details);
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.Where(c => c.CustomerID == "ALFKI").ToList();
            Assert.AreEqual(1, custs.Count);
            Assert.IsNotNull(custs[0].Orders);
            Assert.AreEqual(6, custs[0].Orders.Count);
            Assert.IsTrue(custs[0].Orders.Any(o => o.OrderID == 10643));
            Assert.IsNotNull(custs[0].Orders.Single(o => o.OrderID == 10643).Details);
            Assert.AreEqual(3, custs[0].Orders.Single(o => o.OrderID == 10643).Details.Count);
        }
        public void TestCustomersApplyOrder()
        {
            var policy = new EntityPolicy();
            policy.Apply<Customer>(seq => seq.OrderBy(c => c.ContactName));
            Northwind nw = new Northwind(this.provider.New(policy));

            var list = nw.Customers.Where(c => c.City == "London").ToList();

            Assert.AreEqual(6, list.Count);
            var sorted = list.OrderBy(c => c.ContactName).ToList();
            Assert.IsTrue(Enumerable.SequenceEqual(list, sorted));
        }
        public void TestCustomersApplyFilterTwice()
        {
            var policy = new EntityPolicy();
            policy.Apply<Customer>(seq => seq.Where(c => c.City == "London"));
            policy.Apply<Customer>(seq => seq.Where(c => c.Country == "UK"));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.ToList();
            Assert.AreEqual(6, custs.Count);
        }
        public void TestCustomersApplyComputedFilter()
        {
            string ci = "Lon";
            string ty = "don";
            var policy = new EntityPolicy();
            policy.Apply<Customer>(seq => seq.Where(c => c.City == ci + ty));
            Northwind nw = new Northwind(this.provider.New(policy));

            var custs = nw.Customers.ToList();
            Assert.AreEqual(6, custs.Count);
        }
 public void TestOrdersIncludeDetailsWithGroupBy()
 {
     var policy = new EntityPolicy();
     policy.IncludeWith<Order>(o => o.Details);
     Northwind nw = new Northwind(this.provider.New(policy));
     var list = nw.Orders.Where(o => o.CustomerID == "ALFKI").GroupBy(o => o.CustomerID).ToList();
     Assert.AreEqual(1, list.Count);
     var grp = list[0].ToList();
     Assert.AreEqual(6, grp.Count);
     var o10643 = grp.SingleOrDefault(o => o.OrderID == 10643);
     Assert.IsNotNull(o10643);
     Assert.AreEqual(3, o10643.Details.Count);
 }
        public void TestOrdersIncludeDetailsWithFirst()
        {
            EntityPolicy policy = new EntityPolicy();
            policy.IncludeWith<Order>(o => o.Details);

            var ndb = new Northwind(provider.New(policy));
            var q = from o in ndb.Orders
                    where o.OrderID == 10248
                    select o;

            Order so = q.Single();
            Assert.AreEqual(3, so.Details.Count);
            Order fo = q.First();
            Assert.AreEqual(3, fo.Details.Count);
        }