public async Task NewWhenHttpVerbIsPostCopiesQuestionsFromCachedSurveyToSurveyWhenModelStateIsNotValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var questionsToBeCopied = new List <Question>();

            questionsToBeCopied.Add(new Question());
            var cachedSurvey = new SurveyModel {
                Questions = questionsToBeCopied
            };

            var mockTenantStore = new Mock <ITenantStore>();

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

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

                var result = await controller.New(new SurveyModel()) as ViewResult;

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

                Assert.AreSame(model.ContentModel.Questions, questionsToBeCopied);
            }
        }
Exemple #2
0
        public void NewWhenHttpVerbIsPostCopiesQuestionsFromCachedSurveyToSurveyWhenCallingSaveFromSurveyStoreWhenModelStateIsValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var survey = new SurveyModel("slug-name");
            var questionsToBeCopied = new List <Question>();

            questionsToBeCopied.Add(new Question());
            var cachedSurvey = new SurveyModel {
                Questions = questionsToBeCopied
            };

            using (var controller = new SurveysController(mockSurveyStore.Object, null, null, null, null))
            {
                controller.TenantName = "Tenant";
                controller.Tenant     = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                controller.New(survey);
            }

            mockSurveyStore.Verify(r => r.SaveSurvey(It.Is <Survey>(actual => questionsToBeCopied == actual.Questions)));
        }
        public async Task NewWhenHttpVerbIsPostSavedTenantIdIsSameAsControllerWhenModelStateIsValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());

            var mockTenantStore = new Mock <ITenantStore>();

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

            using (var controller = new SurveysController(mockSurveyStore.Object, null, null, mockTenantStore.Object, null))
            {
                controller.TenantId = "Tenant";
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                await controller.New(new SurveyModel());
            }

            mockSurveyStore.Verify(r => r.SaveSurveyAsync(It.Is <Survey>(s => s.TenantId == "Tenant")), Times.Once());
        }
        public async Task NewWhenHttpVerbIsPostCopiesQuestionsFromCachedSurveyToSurveyWhenCallingSaveFromSurveyStoreWhenModelStateIsValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var survey = new SurveyModel("slug-name");
            var questionsToBeCopied = new List <Question>();

            questionsToBeCopied.Add(new Question());
            var cachedSurvey = new SurveyModel {
                Questions = questionsToBeCopied
            };

            var mockTenantStore = new Mock <ITenantStore>();

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

            using (var controller = new SurveysController(mockSurveyStore.Object, null, null, mockTenantStore.Object, null))
            {
                controller.TenantId = "Tenant";
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                await controller.New(survey);
            }

            mockSurveyStore.Verify(r => r.SaveSurveyAsync(It.Is <Survey>(actual => questionsToBeCopied == actual.Questions)));
        }
        public async Task NewWhenHttpVerbIsPostReturnsRedirectToMySurveysWhenModelStateIsValid()
        {
            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());

            var mockTenantStore = new Mock <ITenantStore>();

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

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, mockTenantStore.Object, null))
            {
                controller.TenantId = "Tenant";
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = await controller.New(new SurveyModel()) as RedirectToRouteResult;

                Assert.AreEqual("Index", result.RouteValues["action"]);
                Assert.AreEqual(null, result.RouteValues["controller"]);
            }
        }
Exemple #6
0
        public void NewWhenHttpVerbIsPostReturnsEmptyViewNameWhenModelStateIsNotValid()
        {
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.ModelState.AddModelError("error for test", "invalid model state");
                controller.TempData[SurveysController.CachedSurvey] = new SurveyModel();

                var result = controller.New(new SurveyModel()) as ViewResult;

                Assert.AreEqual(string.Empty, result.ViewName);
            }
        }
        public async Task NewWhenHttpVerbIsPostReturnsRedirectToTheNewActionWhenCachedSurveyIsNull()
        {
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = null;

                var result = await controller.New(new SurveyModel()) as RedirectToRouteResult;

                Assert.AreEqual("New", result.RouteValues["action"]);
                Assert.AreEqual(null, result.RouteValues["controller"]);
            }
        }
Exemple #8
0
        public void NewWhenHttpVerbIsGetReturnsEmptyViewName()
        {
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.Tenant = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };

                var result = controller.New() as ViewResult;

                Assert.AreEqual(string.Empty, result.ViewName);
            }
        }
Exemple #9
0
        public void NewWhenHttpVerbIsPostSavesCachedSurveyInTempDataWhenModelStateIsNotValid()
        {
            var cachedSurvey = new SurveyModel();

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

                var result = controller.New(new SurveyModel()) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData <Survey>;
                Assert.AreSame(cachedSurvey, controller.TempData[SurveysController.CachedSurvey]);
            }
        }
Exemple #10
0
        public void NewWhenHttpVerbIsPostReturnsTitleInTheModelWhenModelStateIsNotValid()
        {
            var survey = new SurveyModel();

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

                var result = controller.New(survey) as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreSame("New Survey", model.Title);
            }
        }
Exemple #11
0
        public void NewWhenHttpVerbIsGetReturnsNewSurveyAsTitleInTheModel()
        {
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.Tenant = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };

                var result = controller.New() as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreSame("New Survey", model.Title);
            }
        }
Exemple #12
0
        public void NewWhenHttpVerbIsPostReturnsErrorInModelStateWhenCachedSurveyHasNoQuestions()
        {
            var cachedSurvey = new SurveyModel {
                Questions = new List <Question>()
            };

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = controller.New(new SurveyModel()) as ViewResult;

                Assert.IsTrue(controller.ModelState.Keys.Contains("ContentModel.Questions"));
            }
        }
Exemple #13
0
        public void NewWhenHttpVerbIsPostReturnsNewSurveyAsTitleInTheModelWhenCachedSurveyHasNoQuestions()
        {
            var cachedSurvey = new SurveyModel {
                Questions = new List <Question>()
            };

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = controller.New(new SurveyModel()) as ViewResult;
                var model  = result.ViewData.Model as TenantMasterPageViewData;

                Assert.AreSame("New Survey", model.Title);
            }
        }
Exemple #14
0
        public void NewWhenHttpVerbIsPostSavesCachedSurveyInTempDataWhenCachedSurveyHasNoQuestions()
        {
            var cachedSurvey = new SurveyModel {
                Questions = new List <Question>()
            };

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = controller.New(new SurveyModel()) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData <Survey>;
                Assert.AreSame(cachedSurvey, controller.TempData[SurveysController.CachedSurvey]);
            }
        }
Exemple #15
0
        public void NewWhenHttpVerbIsGetReturnsANewSurveyInTheModelWhenCachedSurveyDoesNotExistInTempData()
        {
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.Tenant = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = null;

                var result = controller.New() as ViewResult;

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

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

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

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, mockTenantStore.Object, null))
            {
                var result = await controller.New() as ViewResult;

                Assert.AreEqual(string.Empty, result.ViewName);
            }
        }
Exemple #17
0
        public void NewWhenHttpVerbIsPostReturnsTheSameModelWhenCachedSurveyHasNoQuestions()
        {
            var cachedSurvey = new SurveyModel {
                Questions = new List <Question>()
            };
            var survey = new SurveyModel();

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = controller.New(survey) as ViewResult;
                var model  = result.ViewData.Model as TenantPageViewData <SurveyModel>;

                Assert.AreSame(survey, model.ContentModel);
            }
        }
        public async Task NewWhenHttpVerbIsPostReturnsEmptyViewNameWhenModelStateIsNotValid()
        {
            var mockTenantStore = new Mock <ITenantStore>();

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

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

                var result = await controller.New(new SurveyModel()) as ViewResult;

                Assert.AreEqual(string.Empty, result.ViewName);
            }
        }
Exemple #19
0
        public void NewWhenHttpVerbIsGetReturnsTheCachedSurveyInTheModelWhenCachedSurveyExistsInTempData()
        {
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                var survey = new SurveyModel();
                controller.Tenant = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = survey;

                var result = controller.New() as ViewResult;

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

                Assert.AreSame(survey, model.ContentModel);
            }
        }
        public async Task NewWhenHttpVerbIsGetReturnsNewSurveyAsTitleInTheModel()
        {
            var mockTenantStore = new Mock <ITenantStore>();

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

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, mockTenantStore.Object, null))
            {
                var result = await controller.New() as ViewResult;

                var model = result.ViewData.Model as TenantMasterPageViewData;
                Assert.AreSame("New Survey", model.Title);
            }
        }
        public async Task NewWhenHttpVerbIsPostSavesCachedSurveyInTempDataWhenModelStateIsNotValid()
        {
            var cachedSurvey = new SurveyModel();

            var mockTenantStore = new Mock <ITenantStore>();

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

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

                var result = await controller.New(new SurveyModel()) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData <Survey>;
                Assert.AreSame(cachedSurvey, controller.TempData[SurveysController.CachedSurvey]);
            }
        }
        public async Task NewWhenHttpVerbIsPostReturnsErrorInModelStateWhenCachedSurveyHasNoQuestions()
        {
            var mockTenantStore = new Mock <ITenantStore>();

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

            var cachedSurvey = new SurveyModel {
                Questions = new List <Question>()
            };

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, mockTenantStore.Object, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = await controller.New(new SurveyModel()) as ViewResult;

                Assert.IsTrue(controller.ModelState.Keys.Contains("ContentModel.Questions"));
            }
        }
Exemple #23
0
        public void NewWhenHttpVerbIsPostCleansCachedSurveyWhenModelStateIsValid()
        {
            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TenantName = "Tenant";
                controller.Tenant     = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                controller.New(new SurveyModel());

                Assert.IsNull(controller.TempData[SurveysController.CachedSurvey]);
            }
        }
        public async Task NewWhenHttpVerbIsGetReturnsANewSurveyInTheModelWhenCachedSurveyDoesNotExistInTempData()
        {
            var mockTenantStore = new Mock <ITenantStore>();

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

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, mockTenantStore.Object, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = null;

                var result = await controller.New() as ViewResult;

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

                Assert.IsInstanceOfType(model.ContentModel, typeof(SurveyModel));
            }
        }
Exemple #25
0
        public void NewWhenHttpVerbIsPostReturnsRedirectToMySurveysWhenModelStateIsValid()
        {
            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null))
            {
                controller.TenantName = "Tenant";
                controller.Tenant     = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = controller.New(new SurveyModel()) as RedirectToRouteResult;

                Assert.AreEqual("Index", result.RouteValues["action"]);
                Assert.AreEqual(null, result.RouteValues["controller"]);
            }
        }
        public async Task NewWhenHttpVerbIsPostSavesCachedSurveyInTempDataWhenCachedSurveyHasNoQuestions()
        {
            var mockTenantStore = new Mock <ITenantStore>();

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

            var cachedSurvey = new SurveyModel {
                Questions = new List <Question>()
            };

            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, mockTenantStore.Object, null))
            {
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                var result = await controller.New(new SurveyModel()) as ViewResult;

                var model = result.ViewData.Model as TenantPageViewData <Survey>;
                Assert.AreSame(cachedSurvey, controller.TempData[SurveysController.CachedSurvey]);
            }
        }
        public void NewWhenHttpVerbIsGetReturnsTheCachedSurveyInTheModelWhenCachedSurveyExistsInTempData()
        {
            var mockDictionary = new Mock <IUDFDictionary>();

            mockDictionary.Setup(d => d.AreValidFor <SurveyRow>(It.IsAny <string>(), null)).Returns(true);
            using (var controller = new SurveysController(new Mock <ISurveyStore>().Object, null, null, null, null, mockDictionary.Object))
            {
                var survey = new Survey();
                controller.Tenant = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = survey;

                var result = controller.New() as ViewResult;

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

                Assert.AreSame(survey, model.ContentModel);
            }
        }
Exemple #28
0
        public void NewWhenHttpVerbIsPostSavedTenantNameIsSameAsControllerWhenModelStateIsValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());

            using (var controller = new SurveysController(mockSurveyStore.Object, null, null, null, null))
            {
                controller.TenantName = "Tenant";
                controller.Tenant     = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                controller.New(new SurveyModel());
            }

            mockSurveyStore.Verify(r => r.SaveSurvey(It.Is <Survey>(s => s.Tenant == "Tenant")), Times.Once());
        }
Exemple #29
0
        public void NewWhenHttpVerbIsPostCallsSaveFromSurveyStoreWithSurveyParameterWhenModelStateIsValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var survey       = new SurveyModel("slug-name");
            var cachedSurvey = new SurveyModel();

            cachedSurvey.Questions.Add(new Question());

            using (var controller = new SurveysController(mockSurveyStore.Object, null, null, null, null))
            {
                controller.TenantName = "Tenant";
                controller.Tenant     = new Tenant()
                {
                    SubscriptionKind = SubscriptionKind.Standard
                };
                controller.TempData[SurveysController.CachedSurvey] = cachedSurvey;

                controller.New(survey);
            }

            mockSurveyStore.Verify(r => r.SaveSurvey(survey), Times.Once());
        }
Exemple #30
0
        public void NewWhenHttpVerbIsPostCopiesQuestionsFromCachedSurveyToSurveyWhenModelStateIsNotValid()
        {
            var mockSurveyStore = new Mock <ISurveyStore>();

            var questionsToBeCopied = new List <Question>();

            questionsToBeCopied.Add(new Question());
            var cachedSurvey = new SurveyModel {
                Questions = questionsToBeCopied
            };

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

                var result = controller.New(new SurveyModel()) as ViewResult;

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

                Assert.AreSame(model.ContentModel.Questions, questionsToBeCopied);
            }
        }