public Customer[] CreateCustomersInState(string state, int count) { var customers = new Customer[count]; for (var i = 0; i < count; i++) customers[i] = CreateCustomerInState(state); return customers; }
public Customer CreateCustomer() { var customer = new Customer { FirstName = "John" + RandomString(), LastName = "Doe" + RandomString() }; _generator.Container.Store(customer); _generator.EntitiesPersisted.Add(customer); return customer; }
public void Delete_Deletes_Record() { //Adding a dummy record. var newAddress = new Address { StreetAddress1 = "This record was inserted for deletion", City = "Fictional city", State = "LA", ZipCode = "12345" }; var newCustomer = new Customer { FirstName = ("John_DELETE_ME_" + DateTime.Now), LastName = ("Doe_DELETE_ME_" + DateTime.Now), Address = newAddress }; //Re-usable query to query for the matching record. var queryForCustomer = new Func<Db4oRepository<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 Db4oRepository<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 Db4oRepository<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 Db4oRepository<Customer>(); var recordCheckResult = queryForCustomer(customerRepository); Assert.That(recordCheckResult, Is.Null); } }
public Order CreateOrderForCustomer(Customer customer) { var order = new Order { Customer = customer, OrderDate = DateTime.Now.AddDays(-5), ShipDate = DateTime.Now.AddDays(5) }; _generator.Container.Store(order); _generator.EntitiesPersisted.Add(order); return order; }
public void Save_New_Customer_Saves_Customer_When_UnitOfWork_Is_Committed() { var newAddress = new Address { StreetAddress1 = "This record was inserted via a test", City = "Fictional city", State = "LA", ZipCode = "12345" }; var newCustomer = new Customer { FirstName = ("John_" + DateTime.Now), LastName = ("Doe_" + DateTime.Now), Address = newAddress }; var queryForCustomer = new Func<Db4oRepository<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 Db4oRepository<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 Db4oRepository<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(); } }
public void Save_Does_Not_Save_New_Customer_When_UnitOfWork_Is_Aborted() { var rnd = new Random(); var newAddress = new Address { StreetAddress1 = "This record was inserted via a test", City = "Fictional city", State = "LA", ZipCode = "12345" }; var newCustomer = new Customer { FirstName = ("John_" + rnd.Next(60000, 80000)), LastName = ("Doe_" + rnd.Next(60000, 80000)), Address = newAddress }; using (new UnitOfWorkScope()) { var customerRepository = new Db4oRepository<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 Db4oRepository<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(); } }