Пример #1
0
        public void TestSessionSubmitActionOnModify()
        {
            var cust = new Customer {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

            this.Northwind.Customers.Insert(cust);

            NorthwindSession ns = new NorthwindSession(this.Northwind.Provider);

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

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

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

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

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

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

            // ready to be submitted again!
            cust.City = "SeattleX";
            Assert.AreEqual(SubmitAction.Update, ns.Customers.GetSubmitAction(cust));
        }
        public void DbEntitySessionBaseTests_InsertWithoutReturningTheAutoGeneratedPrimaryKeyValue_Test()
        {
            var context  = new NorthwindContext(@"Northwind.dbc");
            var session  = new NorthwindSession(context);
            var category = new Category {
                CategoryName = "SessionCat"
            };

            session.Categories.SetSubmitAction(category, SubmitAction.Insert);
            session.SubmitChanges();
            Assert.AreEqual(0, category.CategoryId);
            Assert.IsNotNull(context.Categories.Where(x => x.CategoryName == category.CategoryName).SingleOrDefault());
        }
Пример #3
0
        public void TestSessionInsertCustomer()
        {
            NorthwindSession ns = new NorthwindSession(this.Northwind.Provider);

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

            ns.Customers.InsertOnSubmit(cust);
            ns.SubmitChanges();
        }
Пример #4
0
        public void TestSessionSubmitActionOnInsertOrUpdate()
        {
            NorthwindSession ns = new NorthwindSession(this.Northwind.Provider);
            var cust            = new Customer {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            };

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

            ns.Customers.InsertOrUpdateOnSubmit(cust);
            Assert.AreEqual(SubmitAction.InsertOrUpdate, 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));
        }
Пример #5
0
        public void TestSessionUpdateCustomer()
        {
            this.Northwind.Customers.Insert(
                new Customer {
                CustomerID  = "XX1",
                CompanyName = "Company1",
                ContactName = "Contact1",
                City        = "Seattle",
                Country     = "USA"
            });

            var ns = new NorthwindSession(this.Northwind.Provider);

            // fetch the previously inserted customer
            var cust = ns.Customers.Single(c => c.CustomerID == "XX1");

            cust.ContactName = "Contact Modified";

            ns.SubmitChanges();

            var cust2 = this.Northwind.Customers.Single(c => c.CustomerID == "XX1");

            Assert.AreEqual("Contact Modified", cust2.ContactName);
        }