コード例 #1
0
        public void AttachNewTest()
        {
            var cust = new Customer()
            {
                Company   = "East Wind Technologies",
                FirstName = "Jimmy",
                LastName  = "Ropain",
            };

            using (var custBus = new busCustomer())
            {
                custBus.Attach(cust, true);
                Assert.IsTrue(custBus.Save(), custBus.ErrorMessage);
            }

            int custId = cust.Id;

            // load new bus/context to force load from disk
            // otherwise load loads from cached context
            using (var custBus = new busCustomer())
            {
                Customer cust2 = custBus.Load(custId);
                Assert.IsNotNull(cust2, custBus.ErrorMessage);

                Assert.AreEqual(cust.Company, cust2.Company);

                Assert.IsTrue(custBus.Delete(custId), custBus.ErrorMessage);
            }

            Console.WriteLine(custId);
        }
コード例 #2
0
        public void NewEntity1Test()
        {
            int      custId;
            Customer cust = null;

            using (var custBus = new busCustomer())
            {
                cust = custBus.NewEntity();

                cust.FirstName = "Oscar";
                cust.LastName  = "Grouch";
                cust.Company   = "Groucho Inc.";
                cust.Entered   = DateTime.Now;

                Assert.IsTrue(custBus.Save(), custBus.ErrorMessage);

                // cust.Id is updated after save operation
                custId = cust.Id;
            }

            // New bus object to ensure new context is used
            // and data is loaded from disk - normally not required.
            using (var custBus = new busCustomer())
            {
                // check to ensure record was created
                var cust2 = custBus.Load(custId);
                Assert.AreEqual(cust2.Company, cust.Company);

                // Remove the new record
                Assert.IsTrue(custBus.Delete(custId), custBus.ErrorMessage);
            }
        }
コード例 #3
0
        public void NewEntityWithTransactionTest()
        {
            int custId;

            using (var custBus = new busCustomer())
            {
                var cust = new Customer()
                {
                    FirstName = "John",
                    LastName  = "Farrow 2",
                    Company   = "Faraway2 Travel",
                    LastOrder = DateTime.Now,
                    Address   = "111 adsasdasdasd"
                };

                // Attach cust to Context and fire
                // NewEntity hooks
                custBus.NewEntity(cust);

                Assert.IsTrue(custBus.Save(useTransactionScope: true), custBus.ErrorMessage);

                // cust.Id is updated after save operation
                custId = cust.Id;

                // Use a new bus object/context to force
                // reload from disk - existing context loads from memory
                // which doesn't test properly
                using (var custBus2 = new busCustomer())
                {
                    // load and compare
                    var cust2 = custBus2.Load(custId);
                    Assert.AreEqual(cust2.Company, cust.Company);
                    // Remove the new record
                    Assert.IsTrue(custBus2.Delete(custId), custBus2.ErrorMessage);
                }
            }
        }