コード例 #1
0
        public void AddQuestionReplacesCarriageReturnsInPossibleAnswersWhenModelIsValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null, null))
            {
                var question = new Question { PossibleAnswers = "possible answers\r\n" };
                controller.TempData[SurveysController.CachedSurvey] = new Survey();

                controller.AddQuestion(question);

                var cachedSurvey = controller.TempData[SurveysController.CachedSurvey] as Survey;

                var actualQuestion = cachedSurvey.Questions.Single(q => q == question);
                Assert.AreEqual("possible answers\n", actualQuestion.PossibleAnswers);
            }
        }
コード例 #2
0
        public void AddQuestionAddsTheNewQuestionToTheCachedSurveyWhenModelIsValid()
        {
            var cachedSurvey = new Survey();
            cachedSurvey.Questions.Add(new Question());
            var question = new Question();

            using (var controller = new SurveysController(null, null, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;
                controller.AddQuestion(question);

                var actualQuestions = (controller.TempData[SurveysController.CachedSurvey] as Survey).Questions;

                Assert.AreEqual(2, actualQuestions.Count);
                Assert.IsTrue(actualQuestions.Contains(question));
            }
        }
コード例 #3
0
        public void AddQuestionReturnsQuestionAsModelWhenModelIsNotValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = new Survey();
                controller.ModelState.AddModelError("error for test", "invalid model state");
                var question = new Question();

                var result = controller.AddQuestion(question) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData<Question>;

                Assert.AreSame(question, model.ContentModel);
            }
        }