public ViewResult Details(int id)
 {
     var personDto = _personRepo.GetPersonById(id);
     var mapper = new PersonMapper();
     var person = mapper.MapPerson(personDto);
     return View(person);
 }
 public ActionResult Edit(int id)
 {
     var personDto = _personRepo.GetPersonById(id);
     var map = new PersonMapper();
     var person = map.MapPerson(personDto);
     return View(person);
 }
        public ActionResult Index()
        {
            var peopleDtoList = _personRepo.GetPeopleList();
            var mapper = new PersonMapper();
            var peopleList = mapper.MapPeopleList(peopleDtoList);

            return View(peopleList);
        }
 public void MapPersonDto_GivenNullPerson_ShouldReturnNull()
 {
     //---------------Set up test pack-------------------
     var mapper = new PersonMapper();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var personDto = mapper.MapPersonDto(null);
     //---------------Test Result -----------------------
     Assert.IsNull(personDto);
 }
 public void MapPersonList_GivenListOfPersonDtos_ShouldReturnListOfPeople()
 {
     //---------------Set up test pack-------------------
     var expectedPeopleDtoList = CreatePeopleDtoList();
     var mapper = new PersonMapper();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     var actualPeopleList = mapper.MapPeopleList(expectedPeopleDtoList);
     //---------------Test Result -----------------------
     Assert.AreEqual(expectedPeopleDtoList.Count, actualPeopleList.Count());
 }
 public void MapPersonDto_GivenPerson_ShouldReturnPersonDto()
 {
     //---------------Set up test pack-------------------
     var person = CreateValidPerson();
     var mapper = new PersonMapper();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     PersonDto personDto = mapper.MapPersonDto(person);
     //---------------Test Result -----------------------
     Assert.AreEqual(person.Id, personDto.Id);
 }
 public ActionResult Create(PersonViewModel person)
 {
     if (ModelState.IsValid)
     {
         var personRepo = _personRepo;
         var mapper = new PersonMapper();
         var dto = mapper.MapPersonDto(person);
         personRepo.Add(dto);
         return RedirectToAction("Index");
     }
     return View();
 }
        public ActionResult Edit(PersonViewModel item)
        {
            try
            {
                var map = new PersonMapper();
                var personDto = map.MapPersonDto(item);
                _personRepo.Update(personDto);

                return RedirectToAction("Index");
            }
            catch (Exception e)
            {
                var x = e;
                return View();
            }

        }
        public void Index_GivenRepositoryHasPeople_ShouldReturnViewWithListOfPeople()
        {
            //---------------Set up test pack-------------------
            var repo = Substitute.For<IPersonRepository>();
            var dtoList = new List<PersonDto>();
            repo.GetPeopleList().Returns(dtoList);
            var controller = new PersonController(repo);

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var result = controller.Index() as ViewResult;
            //---------------Test Result -----------------------
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Model as IEnumerable);

            var mapper = new PersonMapper();
            var peopleList = mapper.MapPeopleList(dtoList);

            CollectionAssert.AreEqual((IEnumerable)result.Model, peopleList);
        }
        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);

        }