public void Delete_GivenBorrowerItemExists_ShouldDeleteBorrowerAndCallSavedChanges() { //---------------Set up test pack------------------- var borrower = new BorrowerBuilder() .WithRandomProps().Build(); var dbContext = new TestDbContextBuilder() .WithBorrowers(borrower) .Build(); var repository = CreateBuilder().WithDbContext(dbContext).Build(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- repository.Delete(borrower); //---------------Test Result ----------------------- Assert.AreEqual(0, dbContext.Borrowers.Count()); dbContext.Received().SaveChanges(); }
public void Save_GivenNewBorrower_ShouldSave() { //---------------Set up test pack------------------- var borrower = new BorrowerBuilder() .WithRandomProps() .WithNewId() .Build(); var dbContext = new TestDbContextBuilder().Build(); var repository = CreateBuilder().WithDbContext(dbContext).Build(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- repository.Save(borrower); //---------------Test Result ----------------------- dbContext.Received().AttachEntity(borrower); dbContext.Received().SaveChanges(); }