public void IndexAction_ReturnsValidViewResult()
        {
            var controller = new DummyRegistrationController();
            controller.TemplateName = "TestTemplate";

            var result = controller.Index();

            Assert.IsNotNull(result, "The action result is null.");
            Assert.IsInstanceOfType(result, typeof(ViewResult), "The action result is not of the expected type.");

            var viewResult = (ViewResult)result;
            Assert.AreEqual("Registration.TestTemplate", viewResult.ViewName, "The Index did not return the configured view according to its convention.");
            Assert.IsNotNull(viewResult.Model, "The Index action did not assign a view model.");
            Assert.IsInstanceOfType(viewResult.Model, typeof(RegistrationViewModel), "The Index action did not assign a view model of the expected type.");
        }
        public void IndexPostAction_InvalidModel_ReturnsConfiguredViewWithSameModel()
        {
            var controller = new DummyRegistrationController();
            controller.TemplateName = "TestTemplate";
            var viewModel = new RegistrationViewModel();
            controller.ModelState.AddModelError("TestError", "Test error message");

            var result = controller.Index(viewModel);

            Assert.IsNotNull(result, "The action result is null.");
            Assert.IsInstanceOfType(result, typeof(ViewResult), "The action result is not of the expected type.");

            var viewResult = (ViewResult)result;
            Assert.AreEqual("Registration.TestTemplate", viewResult.ViewName, "The Index did not return the configured view according to its convention.");
            Assert.IsNotNull(viewResult.Model, "The Index action did not assign a view model.");
            Assert.IsInstanceOfType(viewResult.Model, typeof(RegistrationViewModel), "The Index action did not assign a view model of the expected type.");
            Assert.AreSame(viewModel, viewResult.Model, "The model in the result is not the same as the one passed to the action.");
        }
        public void IndexPostAction_ValidModelFailedRegistration_ReturnsConfiguredViewWithSameModelAndErrorMessage()
        {
            var controller = new DummyRegistrationController();
            controller.TemplateName = "TestTemplate";
            var viewModel = new RegistrationViewModel();

            // "Fail" is a magical UserName that tells the Dummy Model to fail the registration.
            viewModel.UserName = "******";

            var result = controller.Index(viewModel);

            Assert.IsNotNull(result, "The action result is null.");
            Assert.IsInstanceOfType(result, typeof(ViewResult), "The action result is not of the expected type.");

            Assert.AreEqual(MembershipCreateStatus.InvalidUserName.ToString(), controller.ViewBag.Error, "ViewBag did not containg the expected error message.");

            var viewResult = (ViewResult)result;
            Assert.AreEqual("Registration.TestTemplate", viewResult.ViewName, "The Index did not return the configured view according to its convention.");
            Assert.IsNotNull(viewResult.Model, "The Index action did not assign a view model.");
            Assert.IsInstanceOfType(viewResult.Model, typeof(RegistrationViewModel), "The Index action did not assign a view model of the expected type.");
            Assert.AreSame(viewModel, viewResult.Model, "The model in the result is not the same as the one passed to the action.");
        }
        public void IndexPostAction_ValidModelRedirectAction_Redirects()
        {
            var controller = new DummyRegistrationController();
            controller.TemplateName = "TestTemplate";
            var viewModel = new RegistrationViewModel();
            controller.Model.SuccessfulRegistrationPageId = new Guid("3bf29da0-1074-4a71-bb23-7ae43f36d8f9");
            controller.Model.SuccessfulRegistrationAction = SuccessfulRegistrationAction.RedirectToPage;

            var result = controller.Index(viewModel);

            Assert.IsNotNull(result, "The action result is null.");
            Assert.IsInstanceOfType(result, typeof(RedirectResult), "The action result is not of the expected type.");

            var redirectResult = (RedirectResult)result;
            Assert.AreEqual("http://3bf29da0-1074-4a71-bb23-7ae43f36d8f9", redirectResult.Url, true, "The action did not redirect to the expected URL.");
        }
        public void IndexPostAction_ValidModelShowMessageAction_ShowsSuccessMessage()
        {
            var controller = new DummyRegistrationController();
            controller.TemplateName = "TestTemplate";
            var viewModel = new RegistrationViewModel();
            controller.Model.SuccessfulRegistrationAction = SuccessfulRegistrationAction.ShowMessage;

            var result = controller.Index(viewModel);

            Assert.IsNotNull(result, "The action result is null.");
            Assert.IsInstanceOfType(result, typeof(ViewResult), "The action result is not of the expected type.");

            Assert.AreEqual(controller.ViewBag.ShowSuccessfulRegistrationMsg, true, "The result did not contain the expected message.");
        }