public void UnitOfWork_Can_commit() { // Generate Test Data _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); Customer customer = testDataActions.CreateCustomerStub(); // Setup required services var scopeFactory = this.ServiceProvider.GetService <IUnitOfWorkScopeFactory>(); // Start Test using (var scope = scopeFactory.Create()) { var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; repo.Add(customer); scope.Commit(); } Customer savedCustomer = null; savedCustomer = testDataActions.GetCustomerById(customer.CustomerId); Assert.IsNotNull(savedCustomer); Assert.AreEqual(savedCustomer.CustomerId, customer.CustomerId); }
public void UnitOfWork_nested_commit_works() { // Generate Test Data _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); var customer = testDataActions.CreateCustomerStub(); var order = testDataActions.CreateOrderStub(); // Setup required services var scopeFactory = this.ServiceProvider.GetService <IUnitOfWorkScopeFactory>(); using (var scope = scopeFactory.Create(TransactionMode.Default)) { var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; repo.Add(customer); //scope.Commit(); using (var scope2 = scopeFactory.Create(TransactionMode.Default)) { var repo2 = this.ServiceProvider.GetService <IEagerFetchingRepository <Order> >(); repo2.DataStoreName = "TestDbContext"; repo2.Add(order); scope2.Commit(); } scope.Commit(); } Customer savedCustomer = null; Order savedOrder = null; savedCustomer = testDataActions.GetCustomerById(customer.CustomerId); savedOrder = testDataActions.GetOrderById(order.OrderId); Assert.IsNotNull(savedCustomer); Assert.AreEqual(customer.CustomerId, savedCustomer.CustomerId); Assert.IsNotNull(savedOrder); Assert.AreEqual(order.OrderId, savedOrder.OrderId); }
public async Task Can_Add_Async() { // Generate Test Data _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); Customer customer = testDataActions.CreateCustomerStub(x => x.FirstName = "Severnus"); // Start Test var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; await repo.AddAsync(customer); Customer savedCustomer = null; savedCustomer = testDataActions.GetFirstCustomer(x => x.FirstName == "Severnus"); Assert.IsNotNull(savedCustomer); Assert.AreEqual(savedCustomer.FirstName, customer.FirstName); }
public void Can_Add_Entity() { // Generate Test Data _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); Customer customer = testDataActions.CreateCustomerStub(); // Start Test var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; repo.Add(customer); Customer savedCustomer = null; savedCustomer = testDataActions.GetCustomerById(customer.CustomerId); Assert.IsNotNull(savedCustomer); Assert.AreEqual(savedCustomer.CustomerId, customer.CustomerId); }