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 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 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);
        }
예제 #4
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();
        }