private void SetUpGenerateGroupFakes(
            DateTime timeNow,
            IEnumerable <CentreRegistrationPrompt>?centreRegistrationPrompts = null,
            IEnumerable <Group>?groupsAtCentre = null
            )
        {
            GivenCurrentTimeIs(timeNow);

            if (centreRegistrationPrompts != null)
            {
                A.CallTo(() => centreRegistrationPromptsService.GetCentreRegistrationPromptsThatHaveOptionsByCentreId(A <int> ._))
                .Returns(centreRegistrationPrompts);
            }

            A.CallTo(() => groupsDataService.GetGroupsForCentre(A <int> ._)).Returns(groupsAtCentre ?? new List <Group>());

            A.CallTo(() => groupsDataService.AddDelegateGroup(A <GroupDetails> ._)).Returns(NewGroupId);

            A.CallTo(
                () => groupsDataService.AddDelegatesWithMatchingAnswersToGroup(
                    A <int> ._,
                    A <DateTime> ._,
                    A <int> ._,
                    A <int> ._,
                    A <string> ._,
                    null
                    )
                )
            .DoesNothing();
        }
        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);
            }
        }
Exemple #3
0
        public IActionResult GenerateGroups(GenerateGroupsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.RegistrationFieldOptions = GetRegistrationFieldOptionsSelectList(model.RegistrationFieldOptionId);
                return(View(model));
            }

            var adminId           = User.GetAdminIdKnownNotNull() !;
            var centreId          = User.GetCentreId();
            var registrationField = (RegistrationField)model.RegistrationFieldOptionId;

            var fieldIsValid = centreRegistrationPromptsService
                               .GetCentreRegistrationPromptsThatHaveOptionsByCentreId(centreId).Select(cp => cp.RegistrationField.Id)
                               .Contains(registrationField !.Id) || registrationField.Equals(RegistrationField.JobGroup);

            if (!fieldIsValid)
            {
                return(StatusCode(500));
            }

            var groupDetails = new GroupGenerationDetails(
                adminId,
                centreId,
                registrationField,
                model.PrefixGroupName,
                model.PopulateExisting,
                model.AddNewRegistrants,
                model.SyncFieldChanges,
                model.SkipDuplicateNames
                );

            groupsService.GenerateGroupsFromRegistrationField(groupDetails);

            return(RedirectToAction("Index"));
        }
        private (List <(int id, string name)>, string groupNamePrefix) GetCentreRegistrationPromptsAndPrefix(
            int centreId,
            int registrationFieldOptionId
            )
        {
            var registrationPrompt = centreRegistrationPromptsService
                                     .GetCentreRegistrationPromptsThatHaveOptionsByCentreId(centreId).Single(
                cp => cp.RegistrationField.Id == registrationFieldOptionId
                );
            var customPromptOptions = registrationPrompt.Options.Select((option, index) => (index, option))
                                      .ToList <(int id, string name)>();
            var groupNamePrefix = registrationPrompt.PromptText;

            return(customPromptOptions, groupNamePrefix);
        }
Exemple #5
0
        public void GenerateGroups_GET_should_populate_registration_field_options_correctly()
        {
            // Given
            const string customPromptName1 = "Role";
            const string customPromptName2 = "Team";
            const int    centreId          = 2;

            var customPromptSelectListItem1 = new SelectListItem(customPromptName1, "1");
            var customPromptSelectListItem2 = new SelectListItem(customPromptName2, "2");
            var jobGroupSelectListItem      = new SelectListItem("Job group", "7");
            var registrationFieldOptions    = new List <SelectListItem>
            {
                customPromptSelectListItem1, customPromptSelectListItem2, jobGroupSelectListItem
            };

            var customPrompt1 = new CentreRegistrationPrompt(1, 1, customPromptName1, "Test", false);
            var customPrompt2 = new CentreRegistrationPrompt(2, 2, customPromptName2, "Test", false);
            var customPrompts = new List <CentreRegistrationPrompt> {
                customPrompt1, customPrompt2
            };

            A.CallTo(
                () => centreRegistrationPromptsService.GetCentreRegistrationPromptsThatHaveOptionsByCentreId(
                    centreId
                    )
                )
            .Returns(customPrompts);

            // When
            var result = delegateGroupsController.GenerateGroups();

            // Then
            using (new AssertionScope())
            {
                A.CallTo(
                    () => centreRegistrationPromptsService.GetCentreRegistrationPromptsThatHaveOptionsByCentreId(
                        A <int> ._
                        )
                    )
                .MustHaveHappenedOnceExactly();
                result.Should().BeViewResult().ModelAs <GenerateGroupsViewModel>().RegistrationFieldOptions.Should()
                .BeEquivalentTo(registrationFieldOptions);
            }
        }