GenerateGroupsFromRegistrationField_calls_data_service_methods_with_correct_values_for_custom_prompt()
        {
            // Given
            const string groupName       = "Manager";
            const string groupNamePrefix = "Role";

            const int linkedToField     = 1;
            var       registrationField = RegistrationField.CentreRegistrationField1;

            var timeNow = DateTime.UtcNow;
            var groupGenerationDetails = new GroupGenerationDetails(
                1,
                101,
                registrationField,
                false,
                true,
                false,
                true,
                true
                );

            var centreRegistrationPrompt  = new CentreRegistrationPrompt(1, 1, groupNamePrefix, groupName, false);
            var centreRegistrationPrompts = new List <CentreRegistrationPrompt> {
                centreRegistrationPrompt
            };

            SetUpGenerateGroupFakes(timeNow, centreRegistrationPrompts);

            // When
            groupsService.GenerateGroupsFromRegistrationField(groupGenerationDetails);

            // Then
            AssertCorrectMethodsAreCalledForGenerateGroups(
                groupGenerationDetails,
                timeNow,
                linkedToField,
                groupName,
                groupName
                );
        }
示例#2
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"));
        }
示例#3
0
        public void GenerateGroups_POST_should_call_service_and_redirect_to_index()
        {
            // Given
            const string groupNamePrefix = "Role";

            var registrationField          = RegistrationField.CentreRegistrationField1;
            var customPromptSelectListItem = new SelectListItem(groupNamePrefix, registrationField.Id.ToString());
            var jobGroup = new SelectListItem("Job group", "2");
            var registrationFieldOptions = new List <SelectListItem> {
                customPromptSelectListItem, jobGroup
            };

            var customPrompt1 = new CentreRegistrationPrompt(1, 1, groupNamePrefix, "Test", false);
            var customPrompts = new List <CentreRegistrationPrompt> {
                customPrompt1
            };

            var model = new GenerateGroupsViewModel(
                registrationFieldOptions,
                registrationField.Id,
                false,
                true,
                false,
                true,
                false
                );

            A.CallTo(
                () => centreRegistrationPromptsService.GetCentreRegistrationPromptsThatHaveOptionsByCentreId(
                    A <int> ._
                    )
                )
            .Returns(customPrompts);

            A.CallTo(() => groupsService.GenerateGroupsFromRegistrationField(A <GroupGenerationDetails> ._))
            .DoesNothing();

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

            // Then
            using (new AssertionScope())
            {
                A.CallTo(
                    () => groupsService.GenerateGroupsFromRegistrationField(
                        A <GroupGenerationDetails> .That.Matches(
                            gd =>
                            gd.AdminId == 7 &&
                            gd.CentreId == 2 &&
                            gd.RegistrationField.Equals(registrationField) &&
                            gd.PrefixGroupName == model.PrefixGroupName &&
                            gd.PopulateExisting == model.PopulateExisting &&
                            gd.SyncFieldChanges == model.SyncFieldChanges &&
                            gd.AddNewRegistrants == model.AddNewRegistrants &&
                            gd.PopulateExisting == model.PopulateExisting
                            )
                        )
                    )
                .MustHaveHappenedOnceExactly();
                result.Should().BeRedirectToActionResult().WithActionName("Index");
            }
        }