private void SavePetFormDataToRepository(AddPetFormResponse addPetFormResponse)
 {
     var pet = new Pet
                   {
                       Name = addPetFormResponse.Name,
                       Breed = addPetFormResponse.Breed,
                       Age = addPetFormResponse.Age.Value,
                       HealthHistory = addPetFormResponse.HealthHistory,
                       ModifiedBy = "anonymous web user"
                   };
     _petRepository.SavePet(pet);
 }
 public ActionResult SavePet(AddPetFormResponse addPetFormResponse)
 {
     if (ModelState.IsValid)
     {
         SavePetFormDataToRepository(addPetFormResponse);
         TempData.Add("message", string.Format("{0} has been added to VetAdmin.", addPetFormResponse.Name));
         return RedirectToAction("Success");
     }
     else
     {
         //ModelState.AddModelError(string.Empty, addPetFormResponse.Error);
         return View("AddPet",addPetFormResponse);
         //ViewData.Add("message", addPetFormResponse.Error);
     }
 }
        public void SavePetMethod_AddPetFormReponseInputsAreValid_SavesToRepository()
        {
            var apfr = new AddPetFormResponse
                                          {Name = "Fido", Breed = "pug", Age = 3, HealthHistory = "breathing problems"};

            var pet = new Pet
            {
                Name = apfr.Name,
                Breed = apfr.Breed,
                Age = apfr.Age.HasValue ? apfr.Age.Value : 0,
                HealthHistory = apfr.HealthHistory,
                ModifiedBy = "unit test"
            };
            _petRepository.SavePet(pet);

            var sut = new PetManagementController(_petRepository);
            var redirectToRouteResult = (RedirectToRouteResult) sut.SavePet(apfr);

            sut.TempData["Message"].ShouldBe(string.Format("{0} has been added to VetAdmin.", apfr.Name));
            redirectToRouteResult.AssertActionRedirect().ToAction("Success");
        }
 public ViewResult AddPet()
 {
     ViewData.Add("message", "Please enter details for this pet.");
     var model = new AddPetFormResponse();
     return View(model);
 }