public void CreateSubscribeController_CallTheIndexAction_EnsuresIsEmpty()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController())
            {
                controller.MockModel = new DummySubscribeFormModel();

                // Act
                var view = controller.Index();

                // Assert
                Assert.IsNull(view);
            }
        }
        public void CreateSubscribeController_CallTheIndexAction_EnsuresDefaultModelPropertiesArePresented()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController())
            {
                // Act
                var view = controller.Index() as ViewResult;

                // Assert
                Assert.IsNotNull(view);
                Assert.IsTrue(view.ViewName == "SubscribeForm.SubscribeForm");
                Assert.IsNotNull(view.Model);
                Assert.IsTrue(view.Model is SubscribeFormViewModel);
            }
        }
        public void CreateSubscribeController_CallTheIndexAction_EnsuresMessageWhenModuleIsDeactivated()
        {
            var httpContext = new DummyHttpContext();

            httpContext.Items[SystemManager.PageDesignModeKey] = true;

            SystemManager.RunWithHttpContext(
                          httpContext,
                          () =>
                          {
                              // Arrange
                              using (var controller = new DummySubscribeFormController(isModuleActivated: false))
                              {
                                  // Act
                                  var view = controller.Index() as ContentResult;

                                  // Assert
                                  Assert.IsNotNull(view);
                                  Assert.IsTrue(view.Content == "NewslettersModuleDeactivatedMessage");
                              }
                          });
        }
        public void CreateSubscribeController_CallThePostIndexAction_EnsuresViewNameIsChanged()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController())
            {
                controller.TemplateName = "CustomName";

                // Act
                var view = controller.Index(new SubscribeFormViewModel()) as ViewResult;

                // Assert
                Assert.IsNotNull(view);
                Assert.IsTrue(view.ViewName == "SubscribeForm.CustomName");
                Assert.IsNotNull(view.Model);
                Assert.IsTrue(view.Model is SubscribeFormViewModel);
            }
        }
        public void CreateSubscribeController_CallThePostIndexAction_EnsuresRedirectIsCalled()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController())
            {
                controller.MockModel = new DummySubscribeFormModel { SuccessfullySubmittedForm = SuccessfullySubmittedForm.OpenSpecificPage };

                // Act
                var view = controller.Index(new SubscribeFormViewModel
                {
                    Email = "my email",
                    RedirectPageUrl = "www.sitefinity.com"
                }) as RedirectResult;

                // Assert
                Assert.IsNotNull(view);
                Assert.IsTrue(view.Url == "www.sitefinity.com");
            }
        }
        public void CreateSubscribeController_CallThePostIndexAction_EnsuresMessageWithInvalidState()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController())
            {
                controller.ModelState.AddModelError("Email", "Email is empty");

                // Act
                var view = controller.Index(new SubscribeFormViewModel()) as ViewResult;

                // Assert
                Assert.IsNotNull(view.Model);
                Assert.IsTrue(view.ViewBag.Error == null);
                Assert.IsTrue(view.ViewBag.IsSucceeded == null);
                Assert.IsTrue(view.ViewBag.Email == null);
            }
        }
        public void CreateSubscribeController_CallThePostIndexAction_EnsuresMessageWhenNoLicense()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController(isLicensed: false))
            {
                // Act
                var view = controller.Index(new SubscribeFormViewModel()) as ContentResult;

                // Assert
                Assert.IsNotNull(view);
                Assert.IsTrue(view.Content == "No valid license");
            }
        }
        public void CreateSubscribeController_CallThePostIndexAction_EnsuresDefaultModelPropertiesArePresented()
        {
            // Arrange
            using (var controller = new DummySubscribeFormController())
            {
                // Act
                var view = controller.Index(new SubscribeFormViewModel { Email = "my email" }) as ViewResult;

                // Assert
                Assert.IsNotNull(view);
                Assert.IsTrue(view.ViewName == "SubscribeForm.SubscribeForm");
                Assert.IsNotNull(view.Model);
                Assert.IsTrue(view.ViewBag.Error is string);
                Assert.IsTrue(view.ViewBag.IsSucceeded);
                Assert.IsTrue(view.ViewBag.Email == "my email");
            }
        }