コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
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));
        }
コード例 #6
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));
        }