コード例 #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);
        }
コード例 #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);
                }
            }
        }