Ejemplo n.º 1
0
        public void Delete_Deletes_Record()
        {
            var newCustomer = new Customer
            {
                FirstName = ("John_DELETE_ME_" + DateTime.Now),
                LastName = ("Doe_DELETE_ME_" + DateTime.Now),
                StreetAddress1 = "This record was inserted for deletion",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            //Re-usable query to query for the matching record.
            var queryForCustomer = new Func<LinqToSqlRepository<Customer>, Customer>
                (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Retrieve the record for deletion.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var customerToDelete = queryForCustomer(customerRepository);
                Assert.That(customerToDelete, Is.Not.Null);
                customerRepository.Delete(customerToDelete);
                scope.Commit();
            }

            //Ensure customer record is deleted.
            using (new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);
            }
        }
Ejemplo n.º 2
0
        public void Delete_Deletes_Record()
        {
            var newCustomer = new Customer
            {
                FirstName      = ("John_DELETE_ME_" + DateTime.Now),
                LastName       = ("Doe_DELETE_ME_" + DateTime.Now),
                StreetAddress1 = "This record was inserted for deletion",
                City           = "Fictional city",
                State          = "LA",
                ZipCode        = "12345"
            };

            //Re-usable query to query for the matching record.
            var queryForCustomer = new Func <LinqToSqlRepository <Customer>, Customer>
                                   (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                                   );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Retrieve the record for deletion.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var customerToDelete   = queryForCustomer(customerRepository);
                Assert.That(customerToDelete, Is.Not.Null);
                customerRepository.Delete(customerToDelete);
                scope.Commit();
            }

            //Ensure customer record is deleted.
            using (new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);
            }
        }
Ejemplo n.º 3
0
        public void Save_New_Customer_Saves_Customer_When_UnitOfWork_Is_Committed()
        {
            var rnd         = new Random();
            var newCustomer = new Customer
            {
                FirstName      = ("John_" + rnd.Next(0, 30000)),
                LastName       = ("Doe_" + rnd.Next(0, 30000)),
                StreetAddress1 = "This record was inserted via a test",
                City           = "Fictional city",
                State          = "LA",
                ZipCode        = "12345"
            };

            var queryForCustomer = new Func <LinqToSqlRepository <Customer>, Customer>
                                   (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                                   );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var recordCheckResult  = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Not.Null);
                Assert.That(recordCheckResult.FirstName, Is.EqualTo(newCustomer.FirstName));
                Assert.That(recordCheckResult.LastName, Is.EqualTo(newCustomer.LastName));
                scope.Commit();
            }
        }
Ejemplo n.º 4
0
        public void Save_Does_Not_Save_New_Customer_When_UnitOfWork_Is_Aborted()
        {
            var rnd         = new Random();
            var newCustomer = new Customer
            {
                FirstName      = ("John_" + rnd.Next(30001, 50000)),
                LastName       = ("Doe_" + rnd.Next(30001, 50000)),
                StreetAddress1 = "This record was inserted via a test",
                City           = "Fictional city",
                State          = "LA",
                ZipCode        = "12345"
            };

            using (new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var recordCheckResult  = (from cust in customerRepository
                                          where cust.FirstName == newCustomer.FirstName &&
                                          cust.LastName == newCustomer.LastName
                                          select cust).FirstOrDefault();
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                //DO NOT CALL COMMIT TO SIMMULATE A ROLLBACK.
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository <Customer>();
                var recordCheckResult  = (from cust in customerRepository
                                          where cust.FirstName == newCustomer.FirstName &&
                                          cust.LastName == newCustomer.LastName
                                          select cust).FirstOrDefault();
                Assert.That(recordCheckResult, Is.Null);
                scope.Commit();
            }
        }
Ejemplo n.º 5
0
        public void Save_New_Customer_Saves_Customer_When_UnitOfWork_Is_Committed()
        {
            var rnd = new Random();
            var newCustomer = new Customer
            {
                FirstName = ("John_" + rnd.Next(0, 30000)),
                LastName = ("Doe_" + rnd.Next(0, 30000)),
                StreetAddress1 = "This record was inserted via a test",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            var queryForCustomer = new Func<LinqToSqlRepository<Customer>, Customer>
                (
                x => (from cust in x
                      where cust.FirstName == newCustomer.FirstName && cust.LastName == newCustomer.LastName
                      select cust).FirstOrDefault()
                );

            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                scope.Commit();
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var recordCheckResult = queryForCustomer(customerRepository);
                Assert.That(recordCheckResult, Is.Not.Null);
                Assert.That(recordCheckResult.FirstName, Is.EqualTo(newCustomer.FirstName));
                Assert.That(recordCheckResult.LastName, Is.EqualTo(newCustomer.LastName));
                scope.Commit();
            }
        }
Ejemplo n.º 6
0
        public void Save_Does_Not_Save_New_Customer_When_UnitOfWork_Is_Aborted()
        {
            var rnd = new Random();
            var newCustomer = new Customer
            {
                FirstName = ("John_" + rnd.Next(30001, 50000)),
                LastName = ("Doe_" + rnd.Next(30001, 50000)),
                StreetAddress1 = "This record was inserted via a test",
                City = "Fictional city",
                State = "LA",
                ZipCode = "12345"
            };

            using (new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var recordCheckResult = (from cust in customerRepository
                                         where cust.FirstName == newCustomer.FirstName &&
                                               cust.LastName == newCustomer.LastName
                                         select cust).FirstOrDefault();
                Assert.That(recordCheckResult, Is.Null);

                customerRepository.Add(newCustomer);
                //DO NOT CALL COMMIT TO SIMMULATE A ROLLBACK.
            }

            //Starting a completely new unit of work and repository to check for existance.
            using (var scope = new UnitOfWorkScope())
            {
                var customerRepository = new LinqToSqlRepository<Customer>();
                var recordCheckResult = (from cust in customerRepository
                                         where cust.FirstName == newCustomer.FirstName &&
                                               cust.LastName == newCustomer.LastName
                                         select cust).FirstOrDefault();
                Assert.That(recordCheckResult, Is.Null);
                scope.Commit();
            }
        }