public InjectionTestCase(Guid applyingContactId, Guid organisationId, string endPointAssessorOrganisationId, int standardCode, DateTime effectiveFrom, string deliveryAreas, bool isOrganisationStandardTaken, string epaoStandardId, string warningMessage) { var warningMessages = new List <string>(); if (!string.IsNullOrEmpty(warningMessage)) { warningMessages.Add(warningMessage); } IsOrganisationStandardTaken = isOrganisationStandardTaken; var response = new CreateOrganisationStandardFromApplyResponse { WarningMessages = warningMessages, EpaoStandardId = epaoStandardId }; Command = new CreateOrganisationStandardCommand { OrganisationId = organisationId, EndPointAssessorOrganisationId = endPointAssessorOrganisationId, StandardCode = standardCode, EffectiveFrom = DateTime.Parse(effectiveFrom.ToString()), DeliveryAreas = deliveryAreas?.Split(",").ToList(), ApplyingContactId = applyingContactId, }; ExpectedResponse = response; }
public async Task <CreateOrganisationStandardFromApplyResponse> InjectApplyOrganisationStandardDetailsIntoRegister(CreateOrganisationStandardCommand command) { var response = new CreateOrganisationStandardFromApplyResponse { WarningMessages = new List <string>() }; var warningMessages = new List <string>(); // Organisation checks //////////////////////////////// RaiseWarningIfNoEpaoId(command.EndPointAssessorOrganisationId, warningMessages); RaiseWarningIfEpaoIdIsInvalid(command.EndPointAssessorOrganisationId, warningMessages); // Standard checks /////////////////////////////////// RaiseWarningIfStandardCodeIsInvalid(command.StandardCode, warningMessages); var standard = await MapCommandToOrganisationStandardRequest(command); // If we passed basic pre-checks; then validate fully if (warningMessages.Count == 0) { var validationResponse = await _assessorValidationService.ValidateNewOrganisationStandardRequest(standard); if (!validationResponse.IsValid) { var validationResponseErrors = validationResponse.Errors.Select(err => err.ErrorMessage); warningMessages.AddRange(validationResponseErrors); _logger.LogInformation($"Inject standard failed on Validation Service. OrganisationId: {command.OrganisationId} - Warnings: {string.Join(",", validationResponseErrors)}"); } } else { _logger.LogInformation($"Inject standard failed at pre-check. OrganisationId: {command.OrganisationId} - Warnings: {string.Join(",", warningMessages)}"); } // If everything has checked out; approve the standard if (warningMessages.Count == 0) { _logger.LogInformation("Injecting new standard into register"); response.EpaoStandardId = await _apiClient.CreateEpaOrganisationStandard(standard); } else { _logger.LogWarning($"Cannot inject standard details into register at this time. OrganisationId: {command.OrganisationId} - Warnings: {string.Join(", ", warningMessages)}"); } response.WarningMessages = warningMessages; return(response); }