public void Delete_GivenPersonId_ShouldCallSaveAllChanges() { //---------------Set up test pack------------------- var people = GetPeopleList(); var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, people); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- repo.Delete(1); context.Received().SaveChanges(); //---------------Test Result ----------------------- }
public void Delete_GivenPersonIdDoesNotExist_ShouldNotCallSaveAllChangesAndRemove() { //---------------Set up test pack------------------- var people = GetPeopleList(); var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, people); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- repo.Delete(5); context.DidNotReceive().SaveChanges(); context.People.DidNotReceive().Remove(Arg.Any<PersonDto>()); //---------------Test Result ----------------------- }
public void Delete_GivenPersonId_ShouldDeleteThatPerson() { //---------------Set up test pack------------------- var people = GetPeopleList(); var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, people); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- repo.Delete(1); var result = context.People.Where(p => p.Id == 1); //---------------Test Result ----------------------- Assert.AreEqual(0, result.Count()); }