Esempio n. 1
0
        AddRegistrationPromptConfigureAnswers_adds_correct_model_error_if_new_answer_surpasses_character_limit(
            string optionsString,
            string newAnswerInput,
            string expectedErrorMessage
            )
        {
            // Given
            var initialSelectPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);

            var inputAnswersViewModel = new RegistrationPromptAnswersViewModel(optionsString, newAnswerInput);

            var initialTempData = new AddRegistrationPromptData
            {
                SelectPromptViewModel = initialSelectPromptModel, ConfigureAnswersViewModel = inputAnswersViewModel
            };

            registrationPromptsController.TempData.Set(initialTempData);

            const string action = "addPrompt";

            // When
            var result =
                registrationPromptsController.AddRegistrationPromptConfigureAnswers(inputAnswersViewModel, action);

            // Then
            using (new AssertionScope())
            {
                result.As <ViewResult>().Model.Should().BeOfType <RegistrationPromptAnswersViewModel>();
                AssertModelStateErrorIsExpected(result, expectedErrorMessage);
            }
        }
Esempio n. 2
0
        public void RegistrationPromptBulkPost_updates_temp_data_and_redirects_to_configure_answers()
        {
            // Given
            var inputViewModel     = new BulkRegistrationPromptAnswersViewModel("Test\r\nAnswer", true, null);
            var initialPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);
            var initialConfigureAnswersViewModel = new RegistrationPromptAnswersViewModel("Test");
            var expectedViewModel = new RegistrationPromptAnswersViewModel("Test\r\nAnswer");

            var initialTempData = new AddRegistrationPromptData
            {
                SelectPromptViewModel     = initialPromptModel,
                ConfigureAnswersViewModel = initialConfigureAnswersViewModel,
            };

            registrationPromptsController.TempData.Set(initialTempData);

            // When
            var result = registrationPromptsController.AddRegistrationPromptBulkPost(inputViewModel);

            // Then
            using (new AssertionScope())
            {
                AssertSelectPromptViewModelIsExpectedModel(initialPromptModel);
                AssertPromptAnswersViewModelIsExpectedModel(expectedViewModel);
                result.Should().BeRedirectToActionResult().WithActionName("AddRegistrationPromptConfigureAnswers");
            }
        }
Esempio n. 3
0
        public void AddRegistrationPromptConfigureAnswers_delete_removes_configured_answer()
        {
            // Given
            var initialPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);

            var initialViewModel  = new RegistrationPromptAnswersViewModel("Test\r\nAnswer");
            var expectedViewModel = new RegistrationPromptAnswersViewModel("Answer");

            const string action = "delete0";

            var initialTempData = new AddRegistrationPromptData
            {
                SelectPromptViewModel = initialPromptModel, ConfigureAnswersViewModel = initialViewModel
            };

            registrationPromptsController.TempData.Set(initialTempData);

            // When
            var result = registrationPromptsController.AddRegistrationPromptConfigureAnswers(initialViewModel, action);

            // Then
            using (new AssertionScope())
            {
                AssertSelectPromptViewModelIsExpectedModel(initialPromptModel);
                AssertPromptAnswersViewModelIsExpectedModel(expectedViewModel);
                result.As <ViewResult>().Model.Should().BeOfType <RegistrationPromptAnswersViewModel>();
            }
        }
Esempio n. 4
0
        public void AddRegistrationPromptConfigureAnswers_add_configures_new_answer_and_updates_temp_data()
        {
            // Given
            var initialSelectPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);

            var inputAnswersViewModel            = new RegistrationPromptAnswersViewModel("Test", "Answer");
            var expectedConfigureAnswerViewModel = new RegistrationPromptAnswersViewModel("Test\r\nAnswer");

            var initialTempData = new AddRegistrationPromptData
            {
                SelectPromptViewModel = initialSelectPromptModel, ConfigureAnswersViewModel = inputAnswersViewModel
            };

            registrationPromptsController.TempData.Set(initialTempData);

            const string action = "addPrompt";

            // When
            var result =
                registrationPromptsController.AddRegistrationPromptConfigureAnswers(inputAnswersViewModel, action);

            // Then
            using (new AssertionScope())
            {
                AssertSelectPromptViewModelIsExpectedModel(initialSelectPromptModel);
                AssertPromptAnswersViewModelIsExpectedModel(expectedConfigureAnswerViewModel);
                result.As <ViewResult>().Model.Should().BeOfType <RegistrationPromptAnswersViewModel>();
            }
        }
Esempio n. 5
0
 public AddRegistrationPromptSummaryViewModel(
     AddRegistrationPromptData data,
     string promptName
     )
 {
     PromptName = promptName;
     Mandatory  = data.SelectPromptViewModel.Mandatory ? "Yes" : "No";
     Answers    = NewlineSeparatedStringListHelper.SplitNewlineSeparatedList(
         data.ConfigureAnswersViewModel.OptionsString
         );
 }
Esempio n. 6
0
        public void Index_should_clear_TempData_and_go_to_index_page()
        {
            var expectedTempData = new AddRegistrationPromptData();

            registrationPromptsController.TempData.Set(expectedTempData);

            // When
            var result = registrationPromptsController.Index();

            // Then
            registrationPromptsController.TempData.Peek <AddRegistrationPromptData>().Should().BeNull();
            result.Should().BeViewResult().WithDefaultViewName();
        }
Esempio n. 7
0
        public void AddRegistrationPromptSelectPrompt_post_updates_temp_data_and_redirects()
        {
            var expectedPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);
            var initialTempData     = new AddRegistrationPromptData();

            registrationPromptsController.TempData.Set(initialTempData);

            // When
            var result = registrationPromptsController.AddRegistrationPromptSelectPrompt(expectedPromptModel);

            // Then
            AssertSelectPromptViewModelIsExpectedModel(expectedPromptModel);
            result.Should().BeRedirectToActionResult().WithActionName("AddRegistrationPromptConfigureAnswers");
        }
Esempio n. 8
0
        public void AddRegistrationPromptSelectPrompt_loads_existing_temp_data()
        {
            var expectedTempData = new AddRegistrationPromptData();

            registrationPromptsControllerWithMockHttpContext.TempData.Set(expectedTempData);

            // When
            var result = registrationPromptsControllerWithMockHttpContext.AddRegistrationPromptSelectPrompt();

            // Then
            registrationPromptsControllerWithMockHttpContext.TempData.Peek <AddRegistrationPromptData>().Should()
            .BeEquivalentTo(expectedTempData);
            result.Should().BeViewResult().WithDefaultViewName();
        }
Esempio n. 9
0
        public void AddRegistrationPromptConfigureAnswers_next_updates_temp_data()
        {
            // Given
            var expectedPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);
            var initialTempData     = new AddRegistrationPromptData {
                SelectPromptViewModel = expectedPromptModel
            };

            registrationPromptsController.TempData.Set(initialTempData);
            var          expectedAnswerModel = new RegistrationPromptAnswersViewModel("Test");
            const string action = "next";

            // When
            var result =
                registrationPromptsController.AddRegistrationPromptConfigureAnswers(expectedAnswerModel, action);

            // Then
            AssertSelectPromptViewModelIsExpectedModel(expectedPromptModel);
            AssertPromptAnswersViewModelIsExpectedModel(expectedAnswerModel);
            result.Should().BeRedirectToActionResult().WithActionName("AddRegistrationPromptSummary");
        }
Esempio n. 10
0
        public void AddRegistrationPromptSummary_calls_custom_prompt_service_and_redirects_to_index()
        {
            // Given
            var initialPromptModel = new AddRegistrationPromptSelectPromptViewModel(1, true);
            var initialViewModel   = new RegistrationPromptAnswersViewModel("Test\r\nAnswer");
            var initialTempData    = new AddRegistrationPromptData
            {
                SelectPromptViewModel = initialPromptModel, ConfigureAnswersViewModel = initialViewModel
            };

            registrationPromptsController.TempData.Set(initialTempData);
            A.CallTo(
                () => centreCustomPromptsService.AddCustomPromptToCentre(
                    ControllerContextHelper.CentreId,
                    1,
                    true,
                    "Test\r\nAnswer"
                    )
                ).Returns(true);

            // When
            var result = registrationPromptsController.AddRegistrationPromptSummaryPost();

            // Then
            using (new AssertionScope())
            {
                A.CallTo(
                    () => centreCustomPromptsService.AddCustomPromptToCentre(
                        ControllerContextHelper.CentreId,
                        1,
                        true,
                        "Test\r\nAnswer"
                        )
                    ).MustHaveHappened();
                registrationPromptsController.TempData.Peek <AddRegistrationPromptData>().Should().BeNull();
                result.Should().BeRedirectToActionResult().WithActionName("Index");
            }
        }