public async Task SaveResponse_ValidModel_SavesResponse() { Mock <ISurveyResponses> mockSurveyResponse = new Mock <ISurveyResponses>(); SurveyController surveyController = new SurveyController(); HttpContext context = new DefaultHttpContext(); surveyController.TempData = new TempDataDictionary(new DefaultHttpContext(), new Mock <ITempDataProvider>().Object); SummaryModel summaryModel = new SummaryModel(); NameModel nameModel = new NameModel(); EmailModel emailModel = new EmailModel(); AddressModel addressModel = new AddressModel(); LightingLevelModel lightingLevelModel = new LightingLevelModel(); lightingLevelModel.HappyWithLightingLevel = true; BrightnessModel brightnessModel = new BrightnessModel(); brightnessModel.BrightnessLevel = 5; summaryModel.Name = nameModel; summaryModel.Email = emailModel; summaryModel.Address = addressModel; summaryModel.LightingLevel = lightingLevelModel; summaryModel.Brightness = brightnessModel; RedirectToActionResult result = (RedirectToActionResult)await surveyController.SaveResponse(mockSurveyResponse.Object, summaryModel); Assert.IsNotNull(result); Assert.AreEqual("Confirmation", result.ActionName); mockSurveyResponse.Verify(s => s.SaveSurveyResponse(It.IsAny <LightingSurvey>()), Times.Once); }
public IActionResult Brightness() { BrightnessModel brightnessModel = new BrightnessModel(); if (TempData.ContainsKey(BrightnessTag) && TempData.Peek(BrightnessTag) != null) { brightnessModel.BrightnessLevel = (int)TempData.Peek(BrightnessTag); } return(View(brightnessModel)); }
public IActionResult SetBrightness(BrightnessModel brightnessModel) { if (brightnessModel.BrightnessLevel.HasValue) { TempData[BrightnessTag] = brightnessModel.BrightnessLevel; } if (ModelState.IsValid) { return(RedirectToAction(SummaryTag)); } return(RedirectToAction(BrightnessTag)); }
public IActionResult Summary() { NameModel nameModel = new NameModel() { FullName = (string)TempData.Peek(NameTag) }; EmailModel emailModel = new EmailModel() { Email = (string)TempData.Peek(EmailTag) }; AddressModel addressModel = new AddressModel() { Address1 = (string)TempData.Peek(AddressTag), Address2 = (string)TempData.Peek(Address2Tag), Town = (string)TempData.Peek(Town), County = (string)TempData.Peek(County), Postcode = (string)TempData.Peek(Postcode) }; LightingLevelModel lightingLevelModel = new LightingLevelModel() { HappyWithLightingLevel = (bool)TempData.Peek(LightingLevelTag) }; BrightnessModel brightnessModel = new BrightnessModel() { BrightnessLevel = (int)TempData.Peek(BrightnessTag) }; SummaryModel summary = new SummaryModel() { Name = nameModel, Email = emailModel, Address = addressModel, LightingLevel = lightingLevelModel, Brightness = brightnessModel }; return(View(summary)); }