public async Task Can_eager_load_repository_and_query_async() { _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); var customer = testDataActions.CreateCustomer(); for (int i = 0; i < 10; i++) { testDataActions.CreateOrderForCustomer(customer); } var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.EagerlyWith(x => x.Orders); repo.DataStoreName = "TestDbContext"; //var repo = this.ServiceProvider.GetService<IEFCoreRepository<Customer>>(); var savedCustomer = await repo .FindSingleOrDefaultAsync(x => x.CustomerId == customer.CustomerId); Assert.IsNotNull(savedCustomer); Assert.IsTrue(savedCustomer.CustomerId == customer.CustomerId); Assert.IsTrue(savedCustomer.Orders != null); Assert.IsTrue(savedCustomer.Orders.Count == 10); }
public void Can_perform_simple_query() { _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); var customer = testDataActions.CreateCustomer(x => x.FirstName = "Albus"); var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; //var repo = this.ServiceProvider.GetService<IEFCoreRepository<Customer>>(); var savedCustomer = repo .Find(customer.CustomerId); Assert.IsNotNull(savedCustomer); Assert.IsTrue(savedCustomer.CustomerId == customer.CustomerId); Assert.IsTrue(savedCustomer.FirstName == "Albus"); }
public async Task Can_Delete_Async() { // Generate Test Data _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); Customer customer = testDataActions.CreateCustomer(); // Start Test var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; await repo.DeleteAsync(customer); Customer savedCustomer = null; savedCustomer = testDataActions.GetCustomerById(customer.CustomerId); Assert.IsNull(savedCustomer); }
public void Can_Update_Entity() { // Generate Test Data _context = new TestDbContext(this.Configuration); var testData = new EFTestData(_context); var testDataActions = new EFTestDataActions(testData); Customer customer = testDataActions.CreateCustomer(); // Start Test var repo = this.ServiceProvider.GetService <IEagerFetchingRepository <Customer> >(); repo.DataStoreName = "TestDbContext"; customer.FirstName = "Darth"; customer.LastName = "Vader"; repo.Update(customer); Customer savedCustomer = null; savedCustomer = testDataActions.GetCustomerById(customer.CustomerId); Assert.IsNotNull(savedCustomer); Assert.AreEqual(savedCustomer.FirstName, customer.FirstName); Assert.AreEqual(savedCustomer.LastName, customer.LastName); }