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 async Task SaveResponse_InvalidModel_RedirectsToSummary() { Mock <ISurveyResponses> mockSurveyResponse = new Mock <ISurveyResponses>(); SurveyController surveyController = new SurveyController(); surveyController.ModelState.AddModelError("test", "test"); SummaryModel summaryModel = new SummaryModel(); RedirectToActionResult result = (RedirectToActionResult)await surveyController.SaveResponse(mockSurveyResponse.Object, summaryModel); Assert.IsNotNull(result); Assert.AreEqual("Summary", result.ActionName); mockSurveyResponse.Verify(s => s.SaveSurveyResponse(It.IsAny <LightingSurvey>()), Times.Never); }