示例#1
0
        public void MyAccountViewModel_CustomFields_ShouldBePopulated()
        {
            // Given
            var delegateUser  = UserTestHelper.GetDefaultDelegateUser();
            var customPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPromptsWithAnswers(
                new List <CentreRegistrationPromptWithAnswer>
            {
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(1),
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(2),
            }
                );

            // When
            var returnedModel = new MyAccountViewModel(null, delegateUser, customPrompts, DlsSubApplication.Default);

            // Then
            using (new AssertionScope())
            {
                returnedModel.DelegateRegistrationPrompts.Should().NotBeNullOrEmpty();
                returnedModel.DelegateRegistrationPrompts[0].PromptNumber.Should().Be(1);
                returnedModel.DelegateRegistrationPrompts[0].Prompt.Should()
                .BeEquivalentTo(customPrompts.CustomPrompts[0].PromptText);
                returnedModel.DelegateRegistrationPrompts[0].Answer.Should().BeEquivalentTo(delegateUser.Answer1);
                returnedModel.DelegateRegistrationPrompts[0].Mandatory.Should().BeFalse();

                returnedModel.DelegateRegistrationPrompts[1].PromptNumber.Should().Be(2);
                returnedModel.DelegateRegistrationPrompts[1].Prompt.Should()
                .BeEquivalentTo(customPrompts.CustomPrompts[1].PromptText);
                returnedModel.DelegateRegistrationPrompts[1].Answer.Should().BeEquivalentTo(delegateUser.Answer1);
                returnedModel.DelegateRegistrationPrompts[1].Mandatory.Should().BeFalse();
            }
        }
        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);
        }
示例#3
0
        public void MyAccountViewModel_DelegateUser_no_AdminUser_populates_expected_values()
        {
            // Given
            var delegateUser  = UserTestHelper.GetDefaultDelegateUser();
            var customPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPromptsWithAnswers(
                new List <CentreRegistrationPromptWithAnswer>
            {
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(1),
            }
                );

            // When
            var returnedModel = new MyAccountViewModel(null, delegateUser, customPrompts, DlsSubApplication.Default);

            // Then
            using (new AssertionScope())
            {
                returnedModel.FirstName.Should().BeEquivalentTo(delegateUser.FirstName);
                returnedModel.Centre.Should().BeEquivalentTo(delegateUser.CentreName);
                returnedModel.Surname.Should().BeEquivalentTo(delegateUser.LastName);
                returnedModel.ProfilePicture.Should().BeEquivalentTo(delegateUser.ProfileImage);
                returnedModel.DelegateNumber.Should().BeEquivalentTo(delegateUser.CandidateNumber);
                returnedModel.User.Should().BeEquivalentTo(delegateUser.EmailAddress);
                returnedModel.JobGroup.Should().BeEquivalentTo(delegateUser.JobGroupName);
                returnedModel.DelegateRegistrationPrompts.Should().NotBeNullOrEmpty();
            }
        }
        GetUnapprovedDelegatesWithRegistrationPromptAnswersForCentre_returns_unapproved_delegates_with_registration_prompt_answers_for_centre()
        {
            // Given
            var expectedDelegateUser = UserTestHelper.GetDefaultDelegateUser();
            var expectedUserList     = new List <DelegateUser> {
                expectedDelegateUser
            };
            var expectedRegistrationPrompts = new List <CentreRegistrationPromptWithAnswer>
            {
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(
                    1,
                    options: null,
                    mandatory: true,
                    answer: "answer"
                    )
            };

            A.CallTo(() => userDataService.GetUnapprovedDelegateUsersByCentreId(2))
            .Returns(expectedUserList);
            A.CallTo(
                () => centreRegistrationPromptsService.GetCentreRegistrationPromptsWithAnswersByCentreIdForDelegateUsers(
                    2,
                    expectedUserList
                    )
                )
            .Returns(
                new List <(DelegateUser delegateUser, List <CentreRegistrationPromptWithAnswer> prompts)>
            {
                (expectedDelegateUser, expectedRegistrationPrompts)
            }
        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 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 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 GetCourseAdminFieldsWithAnswersForCourse_Returns_Populated_List_of_CourseAdminFieldWithAnswer()
        {
            // Given
            const string answer1   = "ans1";
            const string answer2   = "ans2";
            var          expected1 = PromptsTestHelper.GetDefaultCourseAdminFieldWithAnswer(
                1,
                "System Access Granted",
                "Test",
                answer1
                );
            var expected2 = PromptsTestHelper.GetDefaultCourseAdminFieldWithAnswer(
                2,
                "Priority Access",
                answer: answer2
                );
            var expected = new List <CourseAdminFieldWithAnswer> {
                expected1, expected2
            };

            A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(100))
            .Returns(PromptsTestHelper.GetDefaultCourseAdminFieldsResult());
            var delegateCourseInfo = new DelegateCourseInfo {
                Answer1 = answer1, Answer2 = answer2, CustomisationId = 100
            };

            // When
            var result = courseAdminFieldsService.GetCourseAdminFieldsWithAnswersForCourse(delegateCourseInfo);

            // Then
            result.Should().BeEquivalentTo(expected);
        }
        public void UnapprovedDelegate_delegateUser_and_customPrompts_populate_expected_values()
        {
            // Given
            var delegateUser  = UserTestHelper.GetDefaultDelegateUser();
            var customPrompts = new List <CentreRegistrationPromptWithAnswer>
            {
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(1),
            };

            // When
            var returnedModel = new UnapprovedDelegate(delegateUser, customPrompts);

            // Then
            using (new AssertionScope())
            {
                returnedModel.Id.Should().Be(delegateUser.Id);
                returnedModel.CandidateNumber.Should().Be(delegateUser.CandidateNumber);
                returnedModel.TitleName.Should().Be(
                    $"{delegateUser.FirstName} {delegateUser.LastName}"
                    );
                returnedModel.Email.Should().Be(delegateUser.EmailAddress);
                returnedModel.DateRegistered.Should().Be(delegateUser.DateRegistered);
                returnedModel.JobGroup.Should().Be(delegateUser.JobGroupName);
                returnedModel.DelegateRegistrationPrompts.Should().NotBeNullOrEmpty();

                var promptModel = returnedModel.DelegateRegistrationPrompts.First();
                var promptData  = customPrompts.First();
                promptModel.Answer.Should().Be(promptData.Answer);
                promptModel.Prompt.Should().Be(promptData.PromptText);
                promptModel.PromptNumber.Should().Be(promptData.RegistrationField.Id);
                promptModel.Mandatory.Should().Be(promptData.Mandatory);
            }
        }
        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 GetCentreRegistrationPromptsWithAnswersByCentreIdForDelegateUsers_Returns_Populated_Tuple()
        {
            // Given
            const string answer1         = "Answer 1";
            const string answer2         = "Answer 2";
            var          delegateUser1   = UserTestHelper.GetDefaultDelegateUser(answer1: answer1);
            var          delegateUser2   = UserTestHelper.GetDefaultDelegateUser(answer1: answer2);
            var          expectedPrompt1 = PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(
                1,
                options: null,
                mandatory: true,
                answer: answer1,
                promptId: 3
                );
            var expectedPrompt2 =
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(2, "Department / team", null, true);
            var expectedPrompt3 = PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(
                1,
                options: null,
                mandatory: true,
                answer: answer2,
                promptId: 3
                );

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

            // When
            var result = centreRegistrationPromptsService.GetCentreRegistrationPromptsWithAnswersByCentreIdForDelegateUsers(
                29,
                new[] { delegateUser1, delegateUser2 }
                );

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

                var first = result.First();
                first.Item1.Should().BeEquivalentTo(delegateUser1);
                first.Item2.Count.Should().Be(2);
                first.Item2[0].Should().BeEquivalentTo(expectedPrompt1);
                first.Item2[1].Should().BeEquivalentTo(expectedPrompt2);

                var second = result.Last();
                second.Item1.Should().BeEquivalentTo(delegateUser2);
                second.Item2.Count.Should().Be(2);
                second.Item2[0].Should().BeEquivalentTo(expectedPrompt3);
                second.Item2[1].Should().BeEquivalentTo(expectedPrompt2);
            }
        }
        private static (List <CourseAdminField> adminFields, List <FilterModel> filters) GetSampleAdminFieldsAndFilters()
        {
            var adminField1 = PromptsTestHelper.GetDefaultCourseAdminField(
                1,
                "System access",
                "Yes\r\nNo"
                );
            var adminField3 = PromptsTestHelper.GetDefaultCourseAdminField(3, "Some Free Text Field");
            var adminFields = new List <CourseAdminField> {
                adminField1, adminField3
            };

            var adminField1Options = new[]
            {
                new FilterOptionModel(
                    "Yes",
                    "Answer1(System access)" + FilteringHelper.Separator +
                    "Answer1" + FilteringHelper.Separator + "Yes",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "No",
                    "Answer1(System access)" + FilteringHelper.Separator +
                    "Answer1" + FilteringHelper.Separator + "No",
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "No option selected",
                    "Answer1(System access)" + FilteringHelper.Separator +
                    "Answer1" + FilteringHelper.Separator + FilteringHelper.EmptyValue,
                    FilterStatus.Default
                    ),
            };
            var adminField3Options = new[]
            {
                new FilterOptionModel(
                    "Not blank",
                    "Answer3(Some Free Text Field)" + FilteringHelper.Separator +
                    "Answer3" + FilteringHelper.Separator + FilteringHelper.FreeTextNotBlankValue,
                    FilterStatus.Default
                    ),
                new FilterOptionModel(
                    "Blank",
                    "Answer3(Some Free Text Field)" + FilteringHelper.Separator +
                    "Answer3" + FilteringHelper.Separator + FilteringHelper.FreeTextBlankValue,
                    FilterStatus.Default
                    ),
            };
            var adminFieldFilters = new List <FilterModel>
            {
                new FilterModel("CourseAdminField1", "System access", adminField1Options),
                new FilterModel("CourseAdminField3", "Some Free Text Field", adminField3Options),
            };

            return(adminFields, adminFieldFilters);
        }
        public void GetCourseAdminFieldsWithAnswerCountsForCourse_counts_configured_answers_admin_fields_correctly()
        {
            // Given
            const int customisationId             = 1;
            const int centreId                    = 1;
            const int totalDelegatesCount         = 10;
            const int numberOfDelegatesWithAnswer = 3;
            const int numberOfDelegatesWithTest   = 2;

            A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(customisationId))
            .Returns(
                PromptsTestHelper.GetDefaultCourseAdminFieldsResult(
                    "System Access Granted",
                    "Test\r\nAnswer",
                    null
                    )
                );

            var delegateAnswers = Builder <DelegateCourseAdminFieldAnswers> .CreateListOfSize(totalDelegatesCount)
                                  .TheFirst(numberOfDelegatesWithAnswer)
                                  .With(a => a.Answer1 = "Answer")
                                  .TheNext(numberOfDelegatesWithTest)
                                  .With(a => a.Answer1 = "Test")
                                  .TheRest()
                                  .With(a => a.Answer1 = null)
                                  .Build();

            A.CallTo(
                () => courseAdminFieldsDataService.GetDelegateAnswersForCourseAdminFields(customisationId, centreId)
                )
            .Returns(delegateAnswers);

            // When
            var result = courseAdminFieldsService
                         .GetCourseAdminFieldsWithAnswerCountsForCourse(customisationId, centreId)
                         .ToList();

            // Then
            using (new AssertionScope())
            {
                result.Should().HaveCount(1);
                result.First().ResponseCounts.Should()
                .BeEquivalentTo(
                    new List <ResponseCount>
                {
                    new ResponseCount("Test", numberOfDelegatesWithTest),
                    new ResponseCount("Answer", numberOfDelegatesWithAnswer),
                    new ResponseCount(
                        "blank",
                        totalDelegatesCount - numberOfDelegatesWithAnswer - numberOfDelegatesWithTest
                        ),
                }
                    );
            }
        }
        public void GetCentreRegistrationPromptsByCentreId_Returns_populated_CentreRegistrationPromptsResult()
        {
            // Given
            var expectedCentreRegistrationPromptsResult = PromptsTestHelper.GetDefaultCentreRegistrationPromptsResult();

            // When
            var returnedCentreRegistrationPromptsResult = centreRegistrationPromptsDataService.GetCentreRegistrationPromptsByCentreId(29);

            // Then
            returnedCentreRegistrationPromptsResult.Should().BeEquivalentTo(expectedCentreRegistrationPromptsResult);
        }
        public void GetCentreRegistrationPromptsByCentreId_with_options_splits_correctly()
        {
            // Given
            A.CallTo(() => centreRegistrationPromptsDataService.GetCentreRegistrationPromptsByCentreId(29))
            .Returns(PromptsTestHelper.GetDefaultCentreRegistrationPromptsResult());

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

            // Then
            using (new AssertionScope())
            {
                result.CustomPrompts.Should().NotBeNull();
                result.CustomPrompts[0].Options.Count.Should().Be(2);
                result.CustomPrompts[0].Options[0].Should().BeEquivalentTo("Clinical");
                result.CustomPrompts[0].Options[1].Should().BeEquivalentTo("Non-Clinical");
            }
        }
示例#16
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 GetCourseAdminFieldsForCourse_Returns_Populated_CourseAdminFields()
        {
            // Given
            var expectedPrompt1 =
                PromptsTestHelper.GetDefaultCourseAdminField(1, "System Access Granted", "Test");
            var expectedPrompt2   = PromptsTestHelper.GetDefaultCourseAdminField(2, "Priority Access");
            var courseAdminFields = new List <CourseAdminField> {
                expectedPrompt1, expectedPrompt2
            };
            var expectedCourseAdminFields = PromptsTestHelper.GetDefaultCourseAdminFields(courseAdminFields);

            A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(100))
            .Returns(PromptsTestHelper.GetDefaultCourseAdminFieldsResult());

            // When
            var result = courseAdminFieldsService.GetCourseAdminFieldsForCourse(100);

            // Then
            result.Should().BeEquivalentTo(expectedCourseAdminFields);
        }
        public void AddAdminFieldToCourse_adds_prompt_to_course_at_next_prompt_number()
        {
            // Given
            A.CallTo
            (
                () => courseAdminFieldsDataService.UpdateAdminFieldForCourse(100, A <int> ._, A <int> ._, null)
            ).DoesNothing();
            A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(100))
            .Returns(PromptsTestHelper.GetDefaultCourseAdminFieldsResult());

            // When
            var result = courseAdminFieldsService.AddAdminFieldToCourse(100, 3, null);

            // Then
            A.CallTo
            (
                () => courseAdminFieldsDataService.UpdateAdminFieldForCourse(100, 3, 3, null)
            ).MustHaveHappened();
            result.Should().BeTrue();
        }
        public void AdminFields_returns_AdminFields_page_when_appropriate_course_found_and_clears_TempData()
        {
            // Given
            var courseAdminField1 =
                PromptsTestHelper.GetDefaultCourseAdminField(1, "System Access Granted", "Yes\r\nNo");
            var courseAdminFields = new List <CourseAdminField> {
                courseAdminField1
            };

            A.CallTo(() => courseAdminFieldsService.GetCourseAdminFieldsForCourse(A <int> ._))
            .Returns(PromptsTestHelper.GetDefaultCourseAdminFields(courseAdminFields));
            controller.TempData.Set(courseAdminField1);

            // When
            var result = controller.Index(1);

            // Then
            controller.TempData.Peek <CourseAdminField>().Should().BeNull();
            result.Should().BeViewResult().WithDefaultViewName().ModelAs <AdminFieldsViewModel>();
        }
示例#21
0
        public void GetCourseAdminFields_returns_populated_CourseAdminFieldsResult()
        {
            // Given
            var expectedCourseAdminFieldsResult =
                PromptsTestHelper.GetDefaultCourseAdminFieldsResult(
                    "System Access Granted",
                    "Test",
                    "Priority Access",
                    null,
                    null,
                    null,
                    2
                    );

            // When
            var returnedCourseAdminFieldsResult = courseAdminFieldsDataService.GetCourseAdminFields(100);

            // Then
            returnedCourseAdminFieldsResult.Should().BeEquivalentTo(expectedCourseAdminFieldsResult);
        }
示例#22
0
        public void MyAccountViewModel_where_user_has_not_been_asked_for_prn_says_not_yet_provided()
        {
            // Given
            var delegateUser = UserTestHelper.GetDefaultDelegateUser(
                hasBeenPromptedForPrn: false,
                professionalRegistrationNumber: null
                );
            var customPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPromptsWithAnswers(
                new List <CentreRegistrationPromptWithAnswer> {
            }
                );

            // When
            var returnedModel = new MyAccountViewModel(null, delegateUser, customPrompts, DlsSubApplication.Default);

            // Then
            using (new AssertionScope())
            {
                returnedModel.ProfessionalRegistrationNumber.Should().Be("Not yet provided");
            }
        }
        public void AddAdminFieldToCourse_does_not_add_admin_field_if_course_has_all_fields_defined()
        {
            // Given
            A.CallTo
            (
                () => courseAdminFieldsDataService.UpdateAdminFieldForCourse(100, A <int> ._, A <int> ._, null)
            ).DoesNothing();
            A.CallTo(() => courseAdminFieldsDataService.GetCourseAdminFields(100))
            .Returns(
                PromptsTestHelper.GetDefaultCourseAdminFieldsResult(
                    "System Access Granted",
                    "Test",
                    "Priority Access",
                    "",
                    "Access Permissions"
                    )
                );

            // When
            var result = courseAdminFieldsService.AddAdminFieldToCourse(
                100,
                3,
                "Adding a fourth prompt"
                );

            // Then
            using (new AssertionScope())
            {
                A.CallTo(
                    () => courseAdminFieldsDataService.UpdateAdminFieldForCourse(
                        100,
                        A <int> ._,
                        A <int> ._,
                        "Adding a fourth prompt"
                        )
                    )
                .MustNotHaveHappened();
                result.Should().BeFalse();
            }
        }
        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();
        }
        public void GetCentreRegistrationPromptsWithAnswersByCentreIdAndDelegateUser_Returns_Populated_CentreRegistrationPrompts()
        {
            // Given
            var answer1         = "Answer 1";
            var delegateUser    = UserTestHelper.GetDefaultDelegateUser(answer1: answer1);
            var expectedPrompt1 =
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(
                    1,
                    options: null,
                    mandatory: true,
                    answer: answer1,
                    promptId: 3
                    );
            var expectedPrompt2 =
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(2, "Department / team", null, true);
            var centreRegistrationPrompts = new List <CentreRegistrationPromptWithAnswer> {
                expectedPrompt1, expectedPrompt2
            };
            var expectedCustomerPrompts =
                PromptsTestHelper.GetDefaultCentreRegistrationPromptsWithAnswers(centreRegistrationPrompts);

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

            // When
            var result =
                centreRegistrationPromptsService.GetCentreRegistrationPromptsWithAnswersByCentreIdAndDelegateUser(29, delegateUser);

            // Then
            result.Should().BeEquivalentTo(expectedCustomerPrompts);
        }
示例#26
0
        public void MyAccountViewModel_with_prn_displays_prn()
        {
            // Given
            var delegateUser = UserTestHelper.GetDefaultDelegateUser(
                hasBeenPromptedForPrn: true,
                professionalRegistrationNumber: "12345678"
                );
            var customPrompts = PromptsTestHelper.GetDefaultCentreRegistrationPromptsWithAnswers(
                new List <CentreRegistrationPromptWithAnswer>
            {
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(1),
                PromptsTestHelper.GetDefaultCentreRegistrationPromptWithAnswer(2),
            }
                );

            // When
            var returnedModel = new MyAccountViewModel(null, delegateUser, customPrompts, DlsSubApplication.Default);

            // Then
            using (new AssertionScope())
            {
                returnedModel.ProfessionalRegistrationNumber.Should().Be(delegateUser.ProfessionalRegistrationNumber);
            }
        }
示例#27
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);
        }
示例#28
0
        public void GetDetailedCourseProgress_returns_progress_composed_from_data_if_progress_found()
        {
            // Given
            var testCourseProgress = new Progress
            {
                ProgressId  = 1, CustomisationId = 4, CandidateId = 5, DiagnosticScore = 42, Completed = null,
                RemovedDate = null,
            };
            var testSectionProgress = new List <DetailedSectionProgress>
            {
                new DetailedSectionProgress {
                    SectionId = 2, SectionName = "Section2"
                },
                new DetailedSectionProgress {
                    SectionId = 3, SectionName = "Section3"
                },
            };
            var testTutorialProgress1 = new List <DetailedTutorialProgress>
            {
                new DetailedTutorialProgress
                {
                    TutorialName  = "Tut1", TutorialStatus = "Passed", AvgTime = 2, TimeTaken = 9, DiagnosticScore = 7,
                    PossibleScore = 8,
                },
                new DetailedTutorialProgress
                {
                    TutorialName    = "Tut2", TutorialStatus = "Not Passed", AvgTime = 3, TimeTaken = 8,
                    DiagnosticScore = 5, PossibleScore = 5,
                },
            };
            var testTutorialProgress2 = new List <DetailedTutorialProgress>
            {
                new DetailedTutorialProgress
                {
                    TutorialName    = "Tut3", TutorialStatus = "Not Passed", AvgTime = 4, TimeTaken = 7,
                    DiagnosticScore = 0, PossibleScore = 1,
                },
                new DetailedTutorialProgress
                {
                    TutorialName  = "Tut4", TutorialStatus = "Passed", AvgTime = 5, TimeTaken = 6, DiagnosticScore = 0,
                    PossibleScore = 5,
                },
            };
            var adminField = PromptsTestHelper.GetDefaultCourseAdminFieldWithAnswer(
                2,
                "Priority Access",
                answer: "answer2"
                );
            var testCourseAdminFields = new List <CourseAdminFieldWithAnswer> {
                adminField
            };
            var testCourseInfo = new DelegateCourseInfo
            {
                DelegateLastName  = "lastName",
                DelegateEmail     = "email",
                DelegateId        = 99,
                CandidateNumber   = "five",
                LastUpdated       = DateTime.UnixEpoch,
                Enrolled          = DateTime.MinValue,
                Completed         = DateTime.Today,
                CompleteBy        = DateTime.Now,
                CustomisationId   = 10,
                IsAssessed        = true,
                CourseAdminFields = testCourseAdminFields
            };

            A.CallTo(() => progressDataService.GetProgressByProgressId(1)).Returns(testCourseProgress);
            A.CallTo(() => progressDataService.GetSectionProgressDataForProgressEntry(1)).Returns(testSectionProgress);
            A.CallTo(() => progressDataService.GetTutorialProgressDataForSection(1, 2)).Returns(testTutorialProgress1);
            A.CallTo(() => progressDataService.GetTutorialProgressDataForSection(1, 3)).Returns(testTutorialProgress2);
            A.CallTo(() => courseDataService.GetDelegateCourseInfoByProgressId(1)).Returns(testCourseInfo);
            A.CallTo(
                () => courseAdminFieldsService.GetCourseAdminFieldsWithAnswersForCourse(
                    testCourseInfo
                    )
                ).Returns(testCourseAdminFields);

            var testSectionProgressWithTutorials = new List <DetailedSectionProgress>
            {
                new DetailedSectionProgress
                {
                    SectionId = 2, SectionName = "Section2", Tutorials = testTutorialProgress1
                },
                new DetailedSectionProgress
                {
                    SectionId = 3, SectionName = "Section3", Tutorials = testTutorialProgress2
                },
            };
            var expectedResult = new DetailedCourseProgress(
                testCourseProgress,
                testSectionProgressWithTutorials,
                testCourseInfo
                );

            // When
            var result = progressService.GetDetailedCourseProgress(1);

            // Then
            result.Should().BeEquivalentTo(expectedResult);
        }