public void AddsNonExistingEntity() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { var customer = EFTestHelper.CreateCustomer(1234); repository.Add(customer); dbContext.SaveChanges(); var fetchedCustomer = repository.GetByKey(1234); Assert.AreEqual(customer, fetchedCustomer); } } }
public static void CreateCustomerIfNotAlreadyExists(int id) { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { var existingCustomer = repository.FirstOrDefault(x => x.Id == id); if (existingCustomer == null) { var customer = CreateCustomer(id); repository.Add(customer); dbContext.SaveChanges(); } } } }
public void ThrowsArgumentNullExceptionForNullEntity() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => repository.Add(null)); } } }
public void ThrowsArgumentNullExceptionForNullEntity() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => repository.Add(null)); } } }