コード例 #1
0
        public void DisplayCallsStoreWithTenantAndIdForSurveyToGet()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(new Survey());

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                controller.Display("tenant", "slug");
            }

            mockSurveyStore.Verify(
                r => r.GetSurveyByTenantAndSlugName(
                    It.Is<string>(t => "tenant" == t),
                    It.Is<string>(s => "slug" == s),
                    It.Is<bool>(b => b)),
                    Times.Once());
        }
コード例 #2
0
        public void DisplayCopiesTheSurveyQuestionTextToTheSurveyAnswerReturnedInTheContentModel()
        {
            var survey = new Survey
            {
                Questions = new List<Question>(
                    new[]
                                     {
                                        new Question { Text = "question text to copy" },
                                     })
            };

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                .Returns(survey);

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Display("tenant", string.Empty) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData<SurveyAnswer>;
                Assert.AreEqual("question text to copy", model.ContentModel.QuestionAnswers.First().QuestionText);
            }
        }
コード例 #3
0
        public void ThankYouReturnsModel()
        {
            using (var controller = new SurveysController(null, null))
            {
                var result = controller.ThankYou() as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreEqual("Thank you for filling the survey", model.Title);
            }
        }
コード例 #4
0
        public void IndexReturnsTitleInTheModel()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Index() as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreEqual("Existing surveys", model.Title);
            }
        }
コード例 #5
0
        public void IndexReturnsRecentSurveysFromStoreInTheModel()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            var surveys = new List<Survey>();
            mockSurveyStore.Setup(r => r.GetRecentSurveys()).Returns(surveys);

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Index() as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData<IEnumerable<Survey>>;
                Assert.AreSame(surveys, model.ContentModel);
            }
        }
コード例 #6
0
        public void IndexGetsRecentSurveysFromStore()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                controller.Index();
            }

            mockSurveyStore.Verify(r => r.GetRecentSurveys(), Times.Once());
        }
コード例 #7
0
        public void DisplayWhenPostThrowsIfSaveSurveyAnswersReadFromSurveyStoreHaveDifferentCountToTheSurveyAnswerParameter()
        {
            var surveyWith1Question = new Survey
            {
                Questions = new List<Question>(new[] { new Question() })
            };

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(surveyWith1Question);
            var surveyAnswerWithoutQuestions = new SurveyAnswer();

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                controller.Display(string.Empty, string.Empty, surveyAnswerWithoutQuestions);
            }
        }
コード例 #8
0
        public void DisplayWhenPostReturnsSurveyTitleAsTitleInTheModelWhenModelIsNotValid()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            var survey = new Survey
            {
                Title = "title",
                Questions = new List<Question>(new[] { new Question() })
            };
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);
            var surveyAnswer = new SurveyAnswer
            {
                QuestionAnswers = new List<QuestionAnswer>(new[] { new QuestionAnswer() })
            };

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

                var result = controller.Display(string.Empty, string.Empty, surveyAnswer) as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreSame("title", model.Title);
            }
        }
コード例 #9
0
        public void DisplayWhenPostReturnsRedirectToThankYouAction()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(new Survey());
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();

            using (var controller = new SurveysController(mockSurveyStore.Object, mockSurveyAnswerStore.Object))
            {
                var result = controller.Display("tenant", string.Empty, new SurveyAnswer()) as RedirectToRouteResult;

                Assert.AreEqual("ThankYou", result.RouteValues["action"]);
                Assert.AreEqual(null, result.RouteValues["controller"]);
            }
        }
コード例 #10
0
        public void DisplayWhenPostReturnsModelWithTheAnswersReadFromTheParameterWhenModelIsNotValid()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            var survey = new Survey
            {
                Questions = new List<Question>(new[] { new Question() })
            };
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);
            var surveyAnswer = new SurveyAnswer
            {
                QuestionAnswers = new List<QuestionAnswer>(new[] { new QuestionAnswer { Answer = "answer" } })
            };

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

                var result = controller.Display(string.Empty, string.Empty, surveyAnswer) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData<SurveyAnswer>;
                Assert.AreEqual("answer", model.ContentModel.QuestionAnswers.First().Answer);
            }
        }
コード例 #11
0
        public void DisplayWhenPostCallsSaveSurveyAnswerFromSurveyAnswerStoreWithTheTenantReadFromTheControllerWhenModelIsValid()
        {
            var survey = new Survey();

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();

            using (var controller = new SurveysController(mockSurveyStore.Object, mockSurveyAnswerStore.Object))
            {
                controller.Display("tenant", string.Empty, new SurveyAnswer());
            }

            mockSurveyAnswerStore.Verify(
                r => r.SaveSurveyAnswer(
                    It.Is<SurveyAnswer>(sa => "tenant" == sa.Tenant)),
                Times.Once());
        }
コード例 #12
0
        public void DisplayWhenPostCallsSaveSurveyAnswerFromSurveyAnswerStoreWithQuestionTypeReadFromTheSurveyWhenModelIsValid()
        {
            var survey = new Survey
            {
                Questions = new List<Question>(
                    new[]
                                     {
                                        new Question { Type = QuestionType.SimpleText },
                                     })
            };

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();
            var surveyAnswer = new SurveyAnswer
            {
                QuestionAnswers = new List<QuestionAnswer>(new[] { new QuestionAnswer() })
            };

            using (var controller = new SurveysController(mockSurveyStore.Object, mockSurveyAnswerStore.Object))
            {
                controller.Display(string.Empty, string.Empty, surveyAnswer);
            }

            mockSurveyAnswerStore.Verify(
                r => r.SaveSurveyAnswer(
                    It.Is<SurveyAnswer>(sa => QuestionType.SimpleText == sa.QuestionAnswers[0].QuestionType)),
                Times.Once());
        }
コード例 #13
0
        public void DisplayTransformsAllTheSurveyQuestionsToQuestionAnswerRetrnedInTheContentModel()
        {
            var survey = new Survey
            {
                Questions = new List<Question>(
                    new[]
                                     {
                                        new Question(),
                                        new Question()
                                     })
            };

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Display("tenant", string.Empty) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData<SurveyAnswer>;
                Assert.AreEqual(2, model.ContentModel.QuestionAnswers.Count());
            }
        }
コード例 #14
0
        public void DisplayReturnsSurveyTitleAsTitleInTheModel()
        {
            var survey = new Survey { Title = "title" };

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Display("tenant", string.Empty) as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreSame("title", model.Title);
            }
        }
コード例 #15
0
        public void DisplayReturnsEmptyViewName()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(new Survey());

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Display("tenant", string.Empty) as ViewResult;

                Assert.AreEqual(string.Empty, result.ViewName);
            }
        }
コード例 #16
0
        public void DisplayCopiesTheSurveyTitleToTheSurveyAnswerReturnedInTheContentModel()
        {
            var survey = new Survey { Title = "title to be copied" };

            var mockSurveyStore = new Mock<ISurveyStore>();
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>()))
                                              .Returns(survey);

            using (var controller = new SurveysController(mockSurveyStore.Object, default(ISurveyAnswerStore)))
            {
                var result = controller.Display("tenant", string.Empty) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData<SurveyAnswer>;
                Assert.AreEqual("title to be copied", model.ContentModel.Title);
            }
        }