public void GetPersonById_GivenPersonIdDoesNotExist_ShouldReturnNull() { //---------------Set up test pack------------------- var people = GetPeopleList(); var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, people); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var result = repo.GetPersonById(5); //---------------Test Result ----------------------- Assert.IsNull(result); }
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 GetPersonById_GivenPersonId_ShouldReturnPersonDto() { //---------------Set up test pack------------------- var people = GetPeopleList(); var context = Substitute.For<ILendingLibraryContext>(); var repo = new PersonRepository(context); SetContextWithDtos(context, people); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var actual = repo.GetPersonById(1); //---------------Test Result ----------------------- Assert.IsNotNull(actual); Assert.IsInstanceOf(typeof(PersonDto), actual); Assert.AreEqual(1, actual.Id); }