public void Extension_Table_UpdateCustomerWithUpdateCheckThatDoesNotSucceed()
        {
            Extension_Table_InsertCustomerNoResult(); // create customer "XX1"

            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Portland", // moved to Portland!
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.Update(cust, d => d.City == "Detroit");
            Assert.AreEqual(-1, result); //Returns -1 due to existance check
            var customer = db.CustomersWithComments.Single(c => c.CustomerID == "XX1");
            Assert.AreEqual("Seattle",customer.City); //City should be unchanged
        }
        public void Extension_Table_UpsertExistingCustomerWithUpdateCheck()
        {
            Extension_Table_InsertCustomerNoResult();

            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Portland", // moved to Portland!
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.InsertOrUpdate(cust, d => d.City == "Seattle");
            Assert.AreEqual(2, result);
        }
        public void Extension_Table_SessionSubmitActionOnUpdate()
        {
            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };
            db.CustomersWithComments.Insert(cust);

            NorthwindSession ns = new NorthwindSession(provider);
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            ns.CustomersWithComments.UpdateOnSubmit(cust);
            Assert.AreEqual(SubmitAction.Update, ns.CustomersWithComments.GetSubmitAction(cust));

            ns.SubmitChanges();
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            cust.City = "SeattleX";
            Assert.AreEqual(SubmitAction.Update, ns.CustomersWithComments.GetSubmitAction(cust));
        }
        public void Extension_Table_UpdateCustomerWithResult()
        {
            Extension_Table_InsertCustomerNoResult(); // create customer "XX1"

            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Portland", // moved to Portland!
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.Update(cust, null, c => c.City);
            Assert.AreEqual("Portland", result);
        }
        public void Extension_Table_SessionSubmitActionOnDelete()
        {
            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };
            db.CustomersWithComments.Insert(cust);

            NorthwindSession ns = new NorthwindSession(provider);
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            ns.CustomersWithComments.DeleteOnSubmit(cust);
            var custHash1 = cust.GetHashCode();
            var custHash2 = cust.GetHashCode();
            var custSessTable1 = ns.CustomersWithComments.GetHashCode();
            var custSessTable2 = ns.CustomersWithComments.GetHashCode();
            var custSessionTable = ns.CustomersWithComments;
            custSessionTable.DeleteOnSubmit(cust);

            Assert.AreEqual(SubmitAction.Delete, ns.CustomersWithComments.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.Delete, custSessionTable.GetSubmitAction(cust));//ns.CustomersWithComments.GetSubmitAction(cust));

            ns.SubmitChanges();
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            // modifications after delete don't trigger updates
            cust.City = "SeattleX";
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));
        }
        public void Extension_Table_SessionSubmitActionOnModify()
        {
            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };

            this.db.CustomersWithComments.Insert(cust);

            var ns = new NorthwindSession(this.provider);
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            // fetch the previously inserted customer
            cust = ns.CustomersWithComments.Single(c => c.CustomerID == "XX1");
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            cust.ContactName = "Contact Modified";
            Assert.AreEqual(SubmitAction.Update, ns.CustomersWithComments.GetSubmitAction(cust));

            ns.SubmitChanges();
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            // prove actually modified by fetching through provider
            var cust2 = this.db.CustomersWithComments.Single(c => c.CustomerID == "XX1");
            Assert.AreEqual("Contact Modified", cust2.ContactName);

            // ready to be submitted again!
            cust.City = "SeattleX";
            Assert.AreEqual(SubmitAction.Update, ns.CustomersWithComments.GetSubmitAction(cust));
        }
 public void Extension_Table_InsertCustomerWithResult()
 {
     var cust = new CustomerWithComments
     {
         CustomerID = "XX1",
         CompanyName = "Company1",
         ContactName = "Contact1",
         City = "Seattle",
         Country = "USA",
         Comment = "New Comment"
     };
     var result = db.CustomersWithComments.Insert(cust, c => c.City);
     Assert.AreEqual(result, "Seattle");  // should be value we asked for
 }
        public void Extension_Table_InsertThenDeleteSamePK()
        {
            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };

            var cust2 = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company2",
                ContactName = "Contact2",
                City = "Chicago",
                Country = "USA",
                Comment = "New Comment"
            };

            db.CustomersWithComments.Insert(cust);

            NorthwindSession ns = new NorthwindSession(provider);
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust2));

            ns.CustomersWithComments.InsertOnSubmit(cust2);
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.Insert, ns.CustomersWithComments.GetSubmitAction(cust2));

            ns.CustomersWithComments.DeleteOnSubmit(cust);
            Assert.AreEqual(SubmitAction.Delete, ns.CustomersWithComments.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.Insert, ns.CustomersWithComments.GetSubmitAction(cust2));

            ns.SubmitChanges();
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust2));

            // modifications after delete don't trigger updates
            cust.City = "SeattleX";
            Assert.AreEqual(SubmitAction.None, ns.CustomersWithComments.GetSubmitAction(cust));

            // modifications after insert do trigger updates
            cust2.City = "ChicagoX";
            Assert.AreEqual(SubmitAction.Update, ns.CustomersWithComments.GetSubmitAction(cust2));
        }
 public void Extension_Table_InsertCustomerNoResult()
 {
     var cust = new CustomerWithComments
     {
         CustomerID = "XX1",
         CompanyName = "Company1",
         ContactName = "Contact1",
         City = "Seattle",
         Country = "USA",
         Comment = "New Comment"
     };
     var result = db.CustomersWithComments.Insert(cust);
     Assert.AreEqual(2, result);
 }
        public void Extension_Table_DeleteCustomerWithDeleteCheckThatSucceeds()
        {
            Extension_Table_InsertCustomerNoResult();

            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.Delete(cust, d => d.City == "Seattle");
            Assert.AreEqual(2, result);
        }
        public void Extension_Table_DeleteCustomerWithDeleteCheckThatDoesNotSucceed()
        {
            Extension_Table_InsertCustomerNoResult();

            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.Delete(cust, d => d.City == "Portland");
            Assert.AreEqual(-1, result); //Expected result due to Exists Check
            var check = db.CustomersWithComments.Single(c => c.CustomerID == "XX1");
            Assert.IsNotNull(check); //Verify that the customer has not been deleted
        }
        public void Extension_Table_DeleteCustomerForNonExistingCustomer()
        {
            Extension_Table_InsertCustomerNoResult();

            var cust = new CustomerWithComments
            {
                CustomerID = "XX2",
                CompanyName = "Company2",
                ContactName = "Contact2",
                City = "Seattle",
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.Delete(cust);
            Assert.AreEqual(0, result);
        }
        public void Extension_Table_UpsertNewCustomerWithResult()
        {
            var cust = new CustomerWithComments
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle", // moved to Portland!
                Country = "USA",
                Comment = "New Comment"
            };

            var result = db.CustomersWithComments.InsertOrUpdate(cust, null, d => d.City);
            Assert.AreEqual("Seattle", result);
        }