コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }