public void Edit_GivenNonExistingPersonDto_ShouldAddPersonInDbContext() { //---------------Set up test pack------------------- var lwa = new PersonDto() { Id = 5, PersonName = "Lwando" }; var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, new List<PersonDto>()); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- repo.Update(lwa); var addedPerson = repo.GetPersonById(lwa.Id); //---------------Test Result ----------------------- context.Received().SaveChanges(); Assert.IsNotNull(addedPerson); Assert.AreEqual(lwa, addedPerson); }
public void Edit_GivenExistingPersonDto_ShouldUpdatePersonInDbContext() { //---------------Set up test pack------------------- var people = GetPeopleList(); var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, people); var existingPerson = people[0]; //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- Assert.IsNotNull(existingPerson); existingPerson.Email = "*****@*****.**"; repo.Update(existingPerson); //---------------Test Result ----------------------- context.Received().SaveChanges(); var actual = context.People.FirstOrDefault(i => i.Id == 1); Assert.IsNotNull(actual); Assert.AreEqual(existingPerson.Email, actual.Email); }