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_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_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 Extension_Table_SessionIdentityCache()
        {
            NorthwindSession ns = new NorthwindSession(provider);

            // both objects should be the same instance
            var cust = ns.CustomersWithComments.Single(c => c.CustomerID == "ALFKI");
            var cust2 = ns.CustomersWithComments.Single(c => c.CustomerID == "ALFKI");

            Assert.IsNotNull(cust);
            Assert.IsNotNull(cust2);
            Assert.ReferenceEquals(cust, cust2);
        }
        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));
        }
Esempio n. 7
0
        public void TestSessionSubmitActionOnUpdate()
        {
            var cust = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };
            this.db.Customers.Insert(cust);

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

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

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

            cust.City = "SeattleX";
            Assert.AreEqual(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
Esempio n. 8
0
        public void TestDeleteThenInsertSamePK()
        {
            var cust = new Customer
            {
                CustomerID = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City = "Seattle",
                Country = "USA"
            };

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

            this.db.Customers.Insert(cust);

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

            ns.Customers.DeleteOnSubmit(cust);
            Assert.AreEqual(SubmitAction.Delete, ns.Customers.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.None, ns.Customers.GetSubmitAction(cust2));

            ns.Customers.InsertOnSubmit(cust2);
            Assert.AreEqual(SubmitAction.Delete, ns.Customers.GetSubmitAction(cust));
            Assert.AreEqual(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust2));

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

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

            // modifications after insert do trigger updates
            cust2.City = "ChicagoX";
            Assert.AreEqual(SubmitAction.Update, ns.Customers.GetSubmitAction(cust2));
        }