public void TestSessionSubmitActionOnDelete()
        {
            var cust = new Customer
            {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

            this.db.Customers.Insert(cust);

            NorthwindSession ns = new NorthwindSession(this.GetProvider());

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

            ns.Customers.DeleteOnSubmit(cust);
            Assert.Equal(SubmitAction.Delete, ns.Customers.GetSubmitAction(cust));

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

            // modifications after delete don't trigger updates
            cust.City = "SeattleX";
            Assert.Equal(SubmitAction.None, ns.Customers.GetSubmitAction(cust));
        }
Beispiel #2
0
        public void TestSessionSubmitActionOnUpdate()
        {
            var cust = new Customer {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

            db.Customers.Insert(cust);

            var ns = new NorthwindSession(GetProvider());

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

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

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

            cust.City = "SeattleX";
            Assert.Equal(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
Beispiel #3
0
        public void TestSessionSubmitActionOnModify()
        {
            var cust = new Customer {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

            db.Customers.Insert(cust);

            var ns = new NorthwindSession(GetProvider());

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

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

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

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

            // prove actually modified by fetching through provider
            var cust2 = db.Customers.Single(c => c.CustomerID == "XX1");

            Assert.Equal("Contact Modified", cust2.ContactName);

            // ready to be submitted again!
            cust.City = "SeattleX";
            Assert.Equal(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
        public void TestSessionIdentityCache()
        {
            NorthwindSession ns = new NorthwindSession(this.GetProvider());

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

            Assert.NotEqual(null, cust);
            Assert.NotEqual(null, cust2);
            Assert.Equal(cust, cust2);
        }
        public void TestSessionProviderNotIdentityCached()
        {
            NorthwindSession ns  = new NorthwindSession(this.GetProvider());
            Northwind        db2 = new Northwind(ns.Session.Provider);

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

            Assert.NotEqual(null, cust);
            Assert.NotEqual(null, cust2);
            Assert.Equal(cust.CustomerID, cust2.CustomerID);
            Assert.NotEqual(cust, cust2);
        }
Beispiel #6
0
        public void TestInsertThenDeleteSamePK()
        {
            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);

            AssertValue(SubmitAction.None, ns.Customers.GetSubmitAction(cust));
            AssertValue(SubmitAction.None, ns.Customers.GetSubmitAction(cust2));

            ns.Customers.InsertOnSubmit(cust2);
            AssertValue(SubmitAction.None, ns.Customers.GetSubmitAction(cust));
            AssertValue(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust2));

            ns.Customers.DeleteOnSubmit(cust);
            AssertValue(SubmitAction.Delete, ns.Customers.GetSubmitAction(cust));
            AssertValue(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust2));

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

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

            // modifications after insert do trigger updates
            cust2.City = "ChicagoX";
            AssertValue(SubmitAction.Update, ns.Customers.GetSubmitAction(cust2));
        }
Beispiel #7
0
        [ExcludeProvider("Access")] // Access does not auto generate the OrderID
        public void TestSessionGeneratedId()
        {
            TestInsertCustomerNoResult(); // create customer "XX1"

            var ns = new NorthwindSession(GetProvider());

            var order = new Order {
                CustomerID = "XX1",
                OrderDate  = DateTime.Today,
            };

            ns.Orders.InsertOnSubmit(order);

            Assert.Equal(0, order.OrderID);
            ns.SubmitChanges();

            Assert.NotEqual(0, order.OrderID);
        }
Beispiel #8
0
        public void TestSessionSubmitActionOnInsertOrUpdate()
        {
            NorthwindSession ns = new NorthwindSession(this.provider);
            var cust            = new Customer
            {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

            AssertValue(SubmitAction.None, ns.Customers.GetSubmitAction(cust));

            ns.Customers.InsertOrUpdateOnSubmit(cust);
            AssertValue(SubmitAction.InsertOrUpdate, ns.Customers.GetSubmitAction(cust));

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

            cust.City = "SeattleX";
            AssertValue(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
        public async Task TestSessionSubmitChangesAsync()
        {
            NorthwindSession ns = new NorthwindSession(this.GetProvider());
            var cust            = new Customer
            {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

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

            ns.Customers.InsertOnSubmit(cust);
            Assert.Equal(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust));

            await ns.SubmitChangesAsync();

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

            cust.City = "SeattleX";
            Assert.Equal(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
Beispiel #10
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.GetProvider());
            Assert.Equal(SubmitAction.None, ns.Customers.GetSubmitAction(cust));

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

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

            cust.City = "SeattleX";
            Assert.Equal(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
Beispiel #11
0
        public void TestSessionSubmitActionOnModify()
        {
            var cust = new Customer
                {
                    CustomerID = "XX1",
                    CompanyName = "Company1",
                    ContactName = "Contact1",
                    City = "Seattle",
                    Country = "USA"
                };

            this.db.Customers.Insert(cust);

            var ns = new NorthwindSession(this.GetProvider());
            Assert.Equal(SubmitAction.None, ns.Customers.GetSubmitAction(cust));

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

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

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

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

            // ready to be submitted again!
            cust.City = "SeattleX";
            Assert.Equal(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
Beispiel #12
0
        public void TestSessionProviderNotIdentityCached()
        {
            NorthwindSession ns = new NorthwindSession(this.GetProvider());
            Northwind db2 = new Northwind(ns.Session.Provider);

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

            Assert.NotEqual(null, cust);
            Assert.NotEqual(null, cust2);
            Assert.Equal(cust.CustomerID, cust2.CustomerID);
            Assert.NotEqual(cust, cust2);
        }
Beispiel #13
0
        public void TestSessionIdentityCache()
        {
            NorthwindSession ns = new NorthwindSession(this.GetProvider());

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

            Assert.NotEqual(null, cust);
            Assert.NotEqual(null, cust2);
            Assert.Equal(cust, cust2);
        }
Beispiel #14
0
        public void TestInsertThenDeleteSamePK()
        {
            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.GetProvider());
            Assert.Equal(SubmitAction.None, ns.Customers.GetSubmitAction(cust));
            Assert.Equal(SubmitAction.None, ns.Customers.GetSubmitAction(cust2));

            ns.Customers.InsertOnSubmit(cust2);
            Assert.Equal(SubmitAction.None, ns.Customers.GetSubmitAction(cust));
            Assert.Equal(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust2));

            ns.Customers.DeleteOnSubmit(cust);
            Assert.Equal(SubmitAction.Delete, ns.Customers.GetSubmitAction(cust));
            Assert.Equal(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust2));

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

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

            // modifications after insert do trigger updates
            cust2.City = "ChicagoX";
            Assert.Equal(SubmitAction.Update, ns.Customers.GetSubmitAction(cust2));
        }
Beispiel #15
0
        public void TestSessionSubmitActionOnInsert()
        {
            NorthwindSession ns = new NorthwindSession(this.provider);
            var cust = new Customer
                {
                    CustomerID = "XX1",
                    CompanyName = "Company1",
                    ContactName = "Contact1",
                    City = "Seattle",
                    Country = "USA"
                };
            AssertValue(SubmitAction.None, ns.Customers.GetSubmitAction(cust));

            ns.Customers.InsertOnSubmit(cust);
            AssertValue(SubmitAction.Insert, ns.Customers.GetSubmitAction(cust));

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

            cust.City = "SeattleX";
            AssertValue(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
Beispiel #16
0
        public void TestSessionSubmitActionOnDelete()
        {
            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);
            AssertValue(SubmitAction.None, ns.Customers.GetSubmitAction(cust));

            ns.Customers.DeleteOnSubmit(cust);
            AssertValue(SubmitAction.Delete, ns.Customers.GetSubmitAction(cust));

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

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