Beispiel #1
0
        public void AddQuestionReturnsNewQuestionViewWhenModelIsNotValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                controller.ModelState.AddModelError("error for test", "invalid model state");

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

                Assert.AreSame("NewQuestion", result.ViewName);
            }
        }
        public async Task AddQuestionReturnsRedirectToNewSurveyWhenModelIsValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = new SurveyModel();

                var result = await controller.AddQuestion(new Question()) as RedirectToRouteResult;

                Assert.AreEqual("New", result.RouteValues["action"]);
                Assert.AreEqual(null, result.RouteValues["controller"]);
            }
        }
Beispiel #3
0
        public void AddQuestionReturnsNewQuestionAsTitleInTheModelWhenModelIsNotValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                controller.ModelState.AddModelError("error for test", "invalid model state");

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

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreSame("New Question", model.Title);
            }
        }
Beispiel #4
0
        public void AddQuestionReturnsNewQuestionAsModelWhenModelIsNotValidAndQuestionIsNull()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = new SurveyModel();
                controller.ModelState.AddModelError("error for test", "invalid model state");

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

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

                Assert.IsInstanceOfType(model.ContentModel, typeof(Question));
            }
        }
Beispiel #5
0
        public void AddQuestionCopiesCachedSurveyToTempDataWhenModelIsNotValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                controller.ModelState.AddModelError("error for test", "invalid model state");
                var cachedSurvey = new SurveyModel();
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

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

                var cachedSurveyReturnedInTempData = result.TempData[SurveysController.CachedSurvey] as SurveyModel;

                Assert.AreSame(cachedSurvey, cachedSurveyReturnedInTempData);
            }
        }
Beispiel #6
0
        public void AddQuestionReturnsQuestionAsModelWhenModelIsNotValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = new SurveyModel();
                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);
            }
        }
        public async Task AddQuestionReturnsNewQuestionViewWhenModelIsNotValid()
        {
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(r => r.GetTenantAsync(It.IsAny <string>()))
            .ReturnsAsync(new Tenant());

            using (var controller = new SurveysController(null, null, null, mockTenantStore.Object, null))
            {
                controller.ModelState.AddModelError("error for test", "invalid model state");

                var result = await controller.AddQuestion(null) as ViewResult;

                Assert.AreSame("NewQuestion", result.ViewName);
            }
        }
        public async Task AddQuestionReplacesCarriageReturnsInPossibleAnswersWhenModelIsValid()
        {
            using (var controller = new SurveysController(null, null, null, null, null))
            {
                var question = new Question {
                    PossibleAnswers = "possible answers\r\n"
                };
                controller.TempData[SurveysController.CachedSurvey] = new SurveyModel();

                await controller.AddQuestion(question);

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

                var actualQuestion = cachedSurvey.Questions.Single(q => q == question);
                Assert.AreEqual("possible answers\n", actualQuestion.PossibleAnswers);
            }
        }
        public async Task AddQuestionAddsTheNewQuestionToTheCachedSurveyWhenModelIsValid()
        {
            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());
            var question = new Question();

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

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

                Assert.AreEqual(2, actualQuestions.Count);
                Assert.IsTrue(actualQuestions.Contains(question));
            }
        }
        public async Task AddQuestionReturnsNewQuestionAsModelWhenModelIsNotValidAndQuestionIsNull()
        {
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(r => r.GetTenantAsync(It.IsAny <string>()))
            .ReturnsAsync(new Tenant());

            using (var controller = new SurveysController(null, null, null, mockTenantStore.Object, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = new SurveyModel();
                controller.ModelState.AddModelError("error for test", "invalid model state");

                var result = await controller.AddQuestion(null) as ViewResult;

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

                Assert.IsInstanceOfType(model.ContentModel, typeof(Question));
            }
        }
        public async Task AddQuestionCopiesCachedSurveyToTempDataWhenModelIsNotValid()
        {
            var mockTenantStore = new Mock <ITenantStore>();

            mockTenantStore.Setup(r => r.GetTenantAsync(It.IsAny <string>()))
            .ReturnsAsync(new Tenant());

            using (var controller = new SurveysController(null, null, null, mockTenantStore.Object, null))
            {
                controller.ModelState.AddModelError("error for test", "invalid model state");
                var cachedSurvey = new SurveyModel();
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = await controller.AddQuestion(null) as ViewResult;

                var cachedSurveyReturnedInTempData = result.TempData[SurveysController.CachedSurvey] as SurveyModel;

                Assert.AreSame(cachedSurvey, cachedSurveyReturnedInTempData);
            }
        }