public void SucceedsWhenNoEntitiesMatchFilter() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { repository.Delete(x => x.Id == 999); dbContext.SaveChanges(); } } }
public void SucceedsWhenEntitiesMatchFilter() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { EFTestHelper.CreateCustomerIfNotAlreadyExists(201); EFTestHelper.CreateCustomerIfNotAlreadyExists(202); EFTestHelper.CreateCustomerIfNotAlreadyExists(203); repository.Delete(x => x.Id >= 201 && x.Id <= 203); dbContext.SaveChanges(); Assert.IsNull(repository.GetByKey(201)); Assert.IsNull(repository.GetByKey(202)); Assert.IsNull(repository.GetByKey(203)); } } }
public void DeletesSpecificEntity() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { EFTestHelper.CreateCustomerIfNotAlreadyExists(201); var customer1 = repository.GetByKey(201); Assert.IsNotNull(customer1); repository.Delete(customer1); dbContext.SaveChanges(); var customer2 = repository.GetByKey(201); Assert.IsNull(customer2); } } }
public void ThrowsArgumentNullExceptionForNullEntity() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => repository.Delete((DbContextCustomer)null)); } } }
public void ThrowsArgumentNullExceptionForNullEntity() { using (var dbContext = new TestDbContextContainer()) { using (var repository = new DbContextCustomerRepository(dbContext)) { ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => repository.Delete((DbContextCustomer)null)); } } }