public async Task UpdateCustomerAsync_ValidCustomer_CustomerUpdatedSuccessfully() { var options = new DbContextOptionsBuilder <CustomerDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; using (var context = new CustomerDbContext(options)) { using (var service = new Services.CustomerService.CustomerService(context)) { // Add single customer var customer = service.AddCustomerAsync(new Customer() { FirstName = "jane", LastName = "dow", BirthDate = "01-01-1990" }).Result; // Check that customer is added or not. var customers = service.GetCustomersByNameAsync("JA").Result; customers.Count.Should().Be(1); // update customers first name customer.FirstName = "updated name"; await service.UpdateCustomerAsync(customer.Id, customer); customers = service.GetCustomersByNameAsync("dow").Result; // Now check if customer first name is updated or not. customers.First().FirstName.Should().Be("updated name"); } } }
public void AddCustomerAsync_ValidCustomer_CustomerAddedSuccessfully() { var options = new DbContextOptionsBuilder <CustomerDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; using (var context = new CustomerDbContext(options)) { using (var service = new Services.CustomerService.CustomerService(context)) { // First check that there are no customers. var customers = service.GetCustomersByNameAsync("JA").Result; customers.Count.Should().Be(0); // Add single customer var customer = service.AddCustomerAsync(new Customer() { FirstName = "jane", LastName = "dow", BirthDate = "01-01-1990" }).Result; customers = service.GetCustomersByNameAsync("JA").Result; // Now check if customer is added or not. customers.Count.Should().Be(1); } } }