Example #1
0
        public void FailedValidationAutoValidateTest()
        {
            var customerBus = new busCustomer()
            {
                // Validates on Save automatically
                AutoValidate = true
            };


            var custExisting = customerBus.Load(1);

            var cust = new Customer()
            {
                // create dupe values which should fail validation
                FirstName = custExisting.FirstName,
                LastName  = custExisting.LastName,
                Company   = custExisting.Company
            };

            cust = customerBus.NewEntity(cust);

            Assert.IsFalse(customerBus.Save());
            Assert.IsFalse(string.IsNullOrEmpty(customerBus.ErrorMessage));
            Console.WriteLine("Validation Failed (test passed): " + customerBus.ErrorMessage);
        }
Example #2
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);
        }
Example #3
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);
            }
        }
Example #4
0
        public void AttachExistingTest()
        {
            string newCompany = "West Wind " + DateTime.Now;
            int    custId     = 1;

            var cust = new Customer()
            {
                Id        = custId,
                Company   = newCompany,
                FirstName = "Ricky",
                LastName  = "Strahl",
                Address   = "33 Kaiea Place"
            };

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

            // 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(cust2.Company, newCompany);
            }
        }
Example #5
0
        public void AttachExistingTest()
        {
            int      custId = 0;
            Customer cust;
            DateTime time = DateTime.Now;


            using (var custBo = new busCustomer())
            {
                // grab existing customer id we can update
                custId = custBo.Context.Customers
                         .Where(c => c.LastName == "Strahl")
                         .Select(c => c.Id)
                         .First();

                cust = new Customer()
                {
                    Id        = custId,
                    FirstName = "Ricky",
                    LastName  = "Strahl",
                    Company   = "West Wind",
                    Entered   = time,
                    Address   = "31 Kaiea Place"
                };

                custBo.Attach(cust);
                Assert.IsTrue(custBo.Save(), custBo.ErrorMessage);
            }

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

                Assert.IsTrue(cust2.Entered.ToString() == cust.Entered.ToString());
            }
        }
Example #6
0
        public void UpdateEntityTest()
        {
            string newCompanyName = "West Wind " + DateTime.Now;

            // load and update first
            using (var custBus = new busCustomer())
            {
                var cust = custBus.Load(1);
                Assert.IsNotNull(cust);

                cust.Company = newCompanyName;
                Assert.IsTrue(custBus.Save(), custBus.ErrorMessage);
            }

            // reload from disk via new context and check for validity
            using (var custBus = new busCustomer())
            {
                // reload entity
                var cust = custBus.Load(1);
                Assert.IsNotNull(cust);
                Assert.AreEqual(newCompanyName, cust.Company);
            }
        }
Example #7
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);
                }
            }
        }