public void GetCentreRegistrationPromptsThatHaveOptionsByCentreId_only_returns_prompts_with_options()
        {
            // Given
            const int centreId       = 29;
            var       expectedPrompt = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(
                1,
                "Group",
                "Clinical\r\nNon-Clinical",
                true,
                promptId: 3
                );
            var expectedPrompts = new List <CentreRegistrationPrompt> {
                expectedPrompt
            };

            A.CallTo(() => centreRegistrationPromptsDataService.GetCentreRegistrationPromptsByCentreId(centreId))
            .Returns(PromptsTestHelper.GetDefaultCentreRegistrationPromptsResult());

            // When
            var result = centreRegistrationPromptsService.GetCentreRegistrationPromptsThatHaveOptionsByCentreId(centreId);

            // Then
            using (new AssertionScope())
            {
                A.CallTo(() => centreRegistrationPromptsDataService.GetCentreRegistrationPromptsByCentreId(centreId))
                .MustHaveHappenedOnceExactly();
                result.Should().BeEquivalentTo(expectedPrompts);
            }
        }
        public void GetLinkedFieldOptions_returns_expected_filter_options()
        {
            // Given
            var prompt1 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, "Prompt 1");
            var prompt2 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2, "Prompt 2");
            var prompt3 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(3, "Prompt 3");
            var prompt4 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(4, "Prompt 4");
            var prompt5 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(5, "Prompt 5");
            var prompt6 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(6, "Prompt 6");
            var prompts = new[] { prompt1, prompt2, prompt3, prompt4, prompt5, prompt6 };

            // When
            var result = DelegateGroupsViewModelFilterOptions.GetLinkedFieldOptions(prompts).ToList();

            // Then
            using (new AssertionScope())
            {
                result.Count.Should().Be(8);
                result.Single(f => f.DisplayText == "Prompt 1").FilterValue.Should()
                .Be("LinkedToField|LinkedToField|1");
                result.Single(f => f.DisplayText == "Prompt 2").FilterValue.Should()
                .Be("LinkedToField|LinkedToField|2");
                result.Single(f => f.DisplayText == "Prompt 3").FilterValue.Should()
                .Be("LinkedToField|LinkedToField|3");
                result.Single(f => f.DisplayText == "Prompt 4").FilterValue.Should()
                .Be("LinkedToField|LinkedToField|5");
                result.Single(f => f.DisplayText == "Prompt 5").FilterValue.Should()
                .Be("LinkedToField|LinkedToField|6");
                result.Single(f => f.DisplayText == "Prompt 6").FilterValue.Should()
                .Be("LinkedToField|LinkedToField|7");
            }
        }
        public void GetDelegateRegistrationPromptsForCentre_returns_populated_list()
        {
            // Given
            var registrationPrompt1       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, options: "Clinical\r\nNon-Clinical");
            var registrationPrompt2       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2);
            var centreRegistrationPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts(
                new List <CentreRegistrationPrompt> {
                registrationPrompt1, registrationPrompt2
            },
                1
                );

            A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(1))
            .Returns(centreRegistrationPrompts);

            // When
            var result =
                promptsService.GetDelegateRegistrationPromptsForCentre(1, Answer1, Answer2, null, null, null, null);

            // Then
            using (new AssertionScope())
            {
                result.Count.Should().Be(2);
                result[0].PromptNumber.Should().Be(1);
                result[1].PromptNumber.Should().Be(2);
            }
        }
        public void GetCentreRegistrationPromptsByCentreId_Returns_Populated_CentreRegistrationPrompts()
        {
            // Given
            var expectedPrompt1           = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, options: null, mandatory: true, promptId: 3);
            var expectedPrompt2           = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2, "Department / team", null, true);
            var centreRegistrationPrompts = new List <CentreRegistrationPrompt> {
                expectedPrompt1, expectedPrompt2
            };
            var expectedPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts(centreRegistrationPrompts);

            A.CallTo(() => centreRegistrationPromptsDataService.GetCentreRegistrationPromptsByCentreId(29))
            .Returns
            (
                PromptsTestHelper.GetDefaultCentreRegistrationPromptsResult(
                    centreRegistrationPrompt1Prompt: "Custom Prompt",
                    centreRegistrationPrompt1Options: null
                    )
            );

            // When
            var result = centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(29);

            // Then
            result.Should().BeEquivalentTo(expectedPrompts);
        }
        public void ValidateCentreRegistrationPrompts_adds_error_for_too_long_answer()
        {
            // Given
            const string?longAnswer2 =
                "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
            var registrationPrompt1       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1);
            var registrationPrompt2       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2);
            var centreRegistrationPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts(
                new List <CentreRegistrationPrompt> {
                registrationPrompt1, registrationPrompt2
            },
                1
                );
            var modelState = new ModelStateDictionary();

            A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(1))
            .Returns(centreRegistrationPrompts);

            // When
            promptsService.ValidateCentreRegistrationPrompts(1, Answer1, longAnswer2, null, null, null, null, modelState);

            // Then
            modelState[Answer1].Should().BeNull();
            modelState[Answer2].Errors.Count.Should().Be(1);
        }
예제 #6
0
        public void EditDetailsPostSave_without_previewing_profile_image_fails_validation()
        {
            // Given
            var myAccountController = new MyAccountController(
                centreRegistrationPromptsService,
                userService,
                imageResizeService,
                jobGroupsDataService,
                promptsService
                ).WithDefaultContext().WithMockUser(true, adminId: null);
            var customPromptLists = new List <CentreRegistrationPrompt>
            {
                PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, mandatory: true)
            };

            A.CallTo
                (() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(2)).Returns(
                PromptsTestHelper.GetDefaultCentreRegistrationPrompts(customPromptLists, 2)
                );
            var formData = new MyAccountEditDetailsFormData
            {
                ProfileImageFile = A.Fake <FormFile>(),
            };
            var expectedPrompt = new EditDelegateRegistrationPromptViewModel(1, "Custom Prompt", true, new List <string>(), null);
            var expectedModel  = new MyAccountEditDetailsViewModel(
                formData,
                new List <(int id, string name)>(),
                new List <EditDelegateRegistrationPromptViewModel> {
                expectedPrompt
            },
                DlsSubApplication.Default
                );

            // When
            var result = myAccountController.EditDetails(formData, "save", DlsSubApplication.Default);

            // Then
            A.CallTo(() => userService.NewEmailAddressIsValid(A <string> ._, A <int?> ._, A <int?> ._, A <int> ._))
            .MustNotHaveHappened();
            result.As <ViewResult>().Model.As <MyAccountEditDetailsViewModel>().Should().BeEquivalentTo(expectedModel);
            myAccountController.ModelState[nameof(MyAccountEditDetailsFormData.ProfileImageFile)].ValidationState
            .Should().Be(ModelValidationState.Invalid);
        }
        public void GetEditDelegateRegistrationPromptViewModelsForCentre_returns_correctly_mapped_answers_with_gap_in_prompts()
        {
            // Given
            var registrationPrompt1       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, options: "Clinical\r\nNon-Clinical");
            var registrationPrompt3       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(3);
            var centreRegistrationPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts(
                new List <CentreRegistrationPrompt> {
                registrationPrompt1, registrationPrompt3
            },
                1
                );

            A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(1))
            .Returns(centreRegistrationPrompts);

            // When
            var result =
                promptsService.GetEditDelegateRegistrationPromptViewModelsForCentre(
                    1,
                    Answer1,
                    Answer2,
                    Answer3,
                    null,
                    null,
                    null
                    );

            // Then
            using (new AssertionScope())
            {
                result.Count.Should().Be(2);

                result[0].PromptNumber.Should().Be(1);
                result[0].Options.Count().Should().Be(2);
                result[0].Options.First().Value.Should().BeEquivalentTo("Clinical");
                result[0].Answer.Should().BeEquivalentTo(Answer1);

                result[1].PromptNumber.Should().Be(3);
                result[1].Options.Count().Should().Be(0);
                result[1].Answer.Should().BeEquivalentTo(Answer3);
            }
        }
        public void ValidateCentreRegistrationPrompts_adds_error_for_missing_mandatory_answer()
        {
            // Given
            var registrationPrompt1       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(1, mandatory: true);
            var registrationPrompt2       = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(2, mandatory: true);
            var centreRegistrationPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPrompts(
                new List <CentreRegistrationPrompt> {
                registrationPrompt1, registrationPrompt2
            },
                1
                );
            var modelState = new ModelStateDictionary();

            A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsByCentreId(1))
            .Returns(centreRegistrationPrompts);

            // When
            promptsService.ValidateCentreRegistrationPrompts(1, null, Answer2, null, null, null, null, modelState);

            // Then
            modelState["Answer1"].Errors.Count.Should().Be(1);
            modelState["Answer2"].Should().BeNull();
        }
예제 #9
0
        private static (List <CentreRegistrationPrompt> customPrompts, List <FilterModel> filters) GetSampleCustomPromptsAndFilters()
        {
            var customPrompt1 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(
                1,
                "First prompt",
                "Clinical\r\nNon-Clinical"
                );
            var customPrompt3 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(3);
            var customPrompt4 = PromptsTestHelper.GetDefaultCentreRegistrationPrompt(4, "Fourth prompt", "C 1\r\nC 2\r\nC 3");
            var customPrompts = new List <CentreRegistrationPrompt> {
                customPrompt1, customPrompt3, customPrompt4
            };

            var customPrompt1Options = new[]
            {
                new FilterOptionModel(
                    "Clinical",
                    "Answer1(First prompt)" + FilteringHelper.Separator +
                    "Answer1" + FilteringHelper.Separator + "Clinical",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "Non-Clinical",
                    "Answer1(First prompt)" + FilteringHelper.Separator +
                    "Answer1" + FilteringHelper.Separator + "Non-Clinical",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "No option selected",
                    "Answer1(First prompt)" + FilteringHelper.Separator +
                    "Answer1" + FilteringHelper.Separator + FilteringHelper.EmptyValue,
                    FilterStatus.Default
                    ),
            };
            var customPrompt4Options = new[]
            {
                new FilterOptionModel(
                    "C 1",
                    "Answer4(Fourth prompt)" + FilteringHelper.Separator +
                    "Answer4" + FilteringHelper.Separator + "C 1",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "C 2",
                    "Answer4(Fourth prompt)" + FilteringHelper.Separator +
                    "Answer4" + FilteringHelper.Separator + "C 2",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "C 3",
                    "Answer4(Fourth prompt)" + FilteringHelper.Separator +
                    "Answer4" + FilteringHelper.Separator + "C 3",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "No option selected",
                    "Answer4(Fourth prompt)" + FilteringHelper.Separator +
                    "Answer4" + FilteringHelper.Separator + FilteringHelper.EmptyValue,
                    FilterStatus.Default
                    ),
            };
            var customPromptFilters = new List <FilterModel>
            {
                new FilterModel("CentreRegistrationPrompt1", "First prompt", customPrompt1Options),
                new FilterModel("CentreRegistrationPrompt4", "Fourth prompt", customPrompt4Options),
            };

            return(customPrompts, customPromptFilters);
        }