public void GetCustomFieldViewModelsForCentre_returns_populated_list() { // Given var customPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, options: "Clinical\r\nNon-Clinical"); var customPrompt2 = CustomPromptsTestHelper.GetDefaultCustomPrompt(2); var centreCustomPrompts = CustomPromptsTestHelper.GetDefaultCentreCustomPrompts( new List <CustomPrompt> { customPrompt1, customPrompt2 }, 1 ); A.CallTo(() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(1)) .Returns(centreCustomPrompts); // When var result = centreCustomPromptHelper.GetCustomFieldViewModelsForCentre(1, Answer1, Answer2, null, null, null, null); // Then using (new AssertionScope()) { result.Count.Should().Be(2); result[0].CustomFieldId.Should().Be(1); result[1].CustomFieldId.Should().Be(2); } }
public void ValidateCustomPrompts_adds_error_for_too_long_answer() { // Given const string?longAnswer2 = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; var customPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1); var customPrompt2 = CustomPromptsTestHelper.GetDefaultCustomPrompt(2); var centreCustomPrompts = CustomPromptsTestHelper.GetDefaultCentreCustomPrompts( new List <CustomPrompt> { customPrompt1, customPrompt2 }, 1 ); var modelState = new ModelStateDictionary(); A.CallTo(() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(1)) .Returns(centreCustomPrompts); // When centreCustomPromptHelper.ValidateCustomPrompts(1, Answer1, longAnswer2, null, null, null, null, modelState); // Then modelState[Answer1].Should().BeNull(); modelState[Answer2].Errors.Count.Should().Be(1); }
public void GetCustomPromptsForCentreByCentreId_Returns_Populated_CentreCustomPrompts() { // Given var expectedPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, options: null, mandatory: true); var expectedPrompt2 = CustomPromptsTestHelper.GetDefaultCustomPrompt(2, "Department / team", null, true); var customPrompts = new List <CustomPrompt> { expectedPrompt1, expectedPrompt2 }; var expectedCustomerPrompts = CustomPromptsTestHelper.GetDefaultCentreCustomPrompts(customPrompts); A.CallTo(() => centreCustomPromptsDataService.GetCentreCustomPromptsByCentreId(29)) .Returns ( CustomPromptsTestHelper.GetDefaultCentreCustomPromptsResult( customField1Prompt: "Custom Prompt", customField1Options: null ) ); // When var result = centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(29); // Then result.Should().BeEquivalentTo(expectedCustomerPrompts); }
public void EditDetailsPostSave_without_previewing_profile_image_fails_validation() { // Given var myAccountController = new MyAccountController( centreCustomPromptsService, userService, imageResizeService, jobGroupsDataService, centreCustomPromptHelper ).WithDefaultContext().WithMockUser(true, adminId: null); var customPromptLists = new List <CustomPrompt> { CustomPromptsTestHelper.GetDefaultCustomPrompt(1, mandatory: true) }; A.CallTo (() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(2)).Returns( CustomPromptsTestHelper.GetDefaultCentreCustomPrompts(customPromptLists, 2) ); var formData = new MyAccountEditDetailsFormData { ProfileImageFile = A.Fake <FormFile>(), }; var expectedPrompt = new EditCustomFieldViewModel(1, "Custom Prompt", true, new List <string>(), null); var expectedModel = new MyAccountEditDetailsViewModel( formData, new List <(int id, string name)>(), new List <EditCustomFieldViewModel> { 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 GetEditCustomFieldViewModelsForCentre_returns_correctly_mapped_answers_with_gap_in_prompts() { // Given var customPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, options: "Clinical\r\nNon-Clinical"); var customPrompt3 = CustomPromptsTestHelper.GetDefaultCustomPrompt(3); var centreCustomPrompts = CustomPromptsTestHelper.GetDefaultCentreCustomPrompts( new List <CustomPrompt> { customPrompt1, customPrompt3 }, 1 ); A.CallTo(() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(1)) .Returns(centreCustomPrompts); // When var result = centreCustomPromptHelper.GetEditCustomFieldViewModelsForCentre( 1, Answer1, Answer2, Answer3, null, null, null ); // Then using (new AssertionScope()) { result.Count.Should().Be(2); result[0].CustomFieldId.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].CustomFieldId.Should().Be(3); result[1].Options.Count().Should().Be(0); result[1].Answer.Should().BeEquivalentTo(Answer3); } }
public void ValidateCustomPrompts_adds_error_for_missing_mandatory_answer() { // Given var customPrompt1 = CustomPromptsTestHelper.GetDefaultCustomPrompt(1, mandatory: true); var customPrompt2 = CustomPromptsTestHelper.GetDefaultCustomPrompt(2, mandatory: true); var centreCustomPrompts = CustomPromptsTestHelper.GetDefaultCentreCustomPrompts( new List <CustomPrompt> { customPrompt1, customPrompt2 }, 1 ); var modelState = new ModelStateDictionary(); A.CallTo(() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(1)) .Returns(centreCustomPrompts); // When centreCustomPromptHelper.ValidateCustomPrompts(1, null, Answer2, null, null, null, null, modelState); // Then modelState["Answer1"].Errors.Count.Should().Be(1); modelState["Answer2"].Should().BeNull(); }