public ActionResult Edit(int id)
 {
     var personDto = _personRepo.GetPersonById(id);
     var map = new PersonMapper();
     var person = map.MapPerson(personDto);
     return View(person);
 }
 public ViewResult Details(int id)
 {
     var personDto = _personRepo.GetPersonById(id);
     var mapper = new PersonMapper();
     var person = mapper.MapPerson(personDto);
     return View(person);
 }
 public void MapPerson_GivenNullPersonDto_ShouldReturnNull()
 {
     //---------------Set up test pack-------------------
     var mapper = new PersonMapper();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     PersonViewModel person = mapper.MapPerson(null);
     //---------------Test Result -----------------------
     Assert.IsNull(person);
 } 
 public void MapPerson_GivenOnePersonDto_ShouldReturnPerson()
 {
     //---------------Set up test pack-------------------
     var personDto = CreateValidPersonDto();
     var mapper = new PersonMapper();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     PersonViewModel person = mapper.MapPerson(personDto);
     //---------------Test Result -----------------------
     Assert.AreEqual(personDto.Id, person.Id);
 }
        public ActionResult Delete(int id)
        {
            var personDto = _personRepo.GetPersonById(id);
            if (personDto == null)
            {
                return View();
            }
            var mapper = new PersonMapper();
            var person = mapper.MapPerson(personDto);

            return View(person);
        }
        public void Details_GivenPersonId_ShouldReturnViewWithPersonDetails()
        {
            //---------------Set up test pack-------------------
            var repo = Substitute.For<IPersonRepository>();
            var personDto = new PersonDto { Id = 1, PersonName = "Ntokozo"};

            repo.GetPersonById(personDto.Id).Returns(personDto);

            var controller = new PersonController(repo);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var result = controller.Details(1) as ViewResult;
            //---------------Test Result -----------------------
            var resultPerson = (PersonViewModel) result?.ViewData.Model;

            Assert.IsNotNull(resultPerson);

            var mapper = new PersonMapper();
            var expectedItem = mapper.MapPerson(personDto);

            Assert.AreSame(expectedItem.Name, resultPerson.Name);

        }