public async Task <IActionResult> GetCertificate(long uln, string familyName, [SwaggerParameter("Standard Code or Standard Reference Number")] string standard) { var getRequest = new GetBatchCertificateRequest { UkPrn = _headerInfo.Ukprn, Uln = uln, FamilyName = familyName, Standard = standard }; var response = await _apiClient.GetCertificate(getRequest); if (response.ValidationErrors.Any()) { ApiResponse error = new ApiResponse((int)HttpStatusCode.Forbidden, string.Join("; ", response.ValidationErrors)); return(StatusCode(error.StatusCode, error)); } else if (response.Certificate is null) { return(NoContent()); } else { if (CertificateHelpers.IsDraftCertificateDeemedAsReady(response.Certificate)) { response.Certificate.Status.CurrentStatus = CertificateStatus.Ready; } else if (response.Certificate.Status.CurrentStatus == CertificateStatus.Printed || response.Certificate.Status.CurrentStatus == CertificateStatus.Reprint) { response.Certificate.Status.CurrentStatus = CertificateStatus.Submitted; } return(Ok(response.Certificate)); } }
public async Task Arrange() { GetBatchCertificateRequest request = Builder <GetBatchCertificateRequest> .CreateNew() .With(i => i.Uln = 1234567890) .With(i => i.StandardCode = 98) .With(i => i.StandardReference = null) .With(i => i.UkPrn = 99999999) .With(i => i.FamilyName = "Test") .Build(); _validationResult = await Validator.ValidateAsync(request); }
public void SetUp() { _request = Builder <GetBatchCertificateRequest> .CreateNew() .With(r => r.IncludeLogs = true) .Build(); _certificateData = Builder <CertificateData> .CreateNew() .With(d => d.LearnerFamilyName = _request.FamilyName) .With(d => d.EpaDetails = Builder <EpaDetails> .CreateNew() .With(e => e.LatestEpaOutcome = "Pass") .Build()) .Build(); var certDataJson = JsonConvert.SerializeObject(_certificateData); _organisationResponse = Builder <Organisation> .CreateNew().Build(); _certResponse = Builder <Certificate> .CreateNew() .With(c => c.Status = "Submitted") .With(c => c.CertificateData = certDataJson) .Build(); _registeredStandards = Builder <EpoRegisteredStandardsResult> .CreateNew() .With(s => s.PageOfResults = new List <EPORegisteredStandards> { new EPORegisteredStandards { StandardCode = _certResponse.StandardCode } }).Build(); _certificateLogs = Builder <CertificateLog> .CreateListOfSize(3).Build(); _mockCertificateRepository = new Mock <ICertificateRepository>(); _mockStandardRepository = new Mock <IStandardRepository>(); _mockOrganisationQueryRepository = new Mock <IOrganisationQueryRepository>(); _mockOrganisationQueryRepository.Setup(oqr => oqr.GetByUkPrn(_request.UkPrn)).ReturnsAsync(_organisationResponse); _mockStandardRepository.Setup(sr => sr.GetEpaoRegisteredStandards(_organisationResponse.EndPointAssessorOrganisationId, It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(_registeredStandards); _mockCertificateRepository.Setup(cr => cr.GetCertificate(_request.Uln, _request.StandardCode, _request.FamilyName, _request.IncludeLogs)) .ReturnsAsync(_certResponse); _mockCertificateRepository.Setup(cr => cr.GetCertificateLogsFor(_certResponse.Id)) .ReturnsAsync(_certificateLogs as List <CertificateLog>); _handler = new GetBatchCertificateHandler(_mockCertificateRepository.Object, Mock.Of <IContactQueryRepository>(), _mockStandardRepository.Object, _mockOrganisationQueryRepository.Object, Mock.Of <ILogger <GetBatchCertificateHandler> >()); }
public async Task Arrange() { // NOTE: Must ensure there isn't a certificate! This is currently the case. GetBatchCertificateRequest request = Builder <GetBatchCertificateRequest> .CreateNew() .With(i => i.Uln = 5555555555) .With(i => i.StandardCode = 1) .With(i => i.StandardReference = null) .With(i => i.UkPrn = 12345678) .With(i => i.FamilyName = "Test") .Build(); _validationResult = await Validator.ValidateAsync(request); }
public async Task <IActionResult> GetCertificate(long uln, string familyName, [SwaggerParameter("Standard Code or Standard Reference Number")] string standard) { var getRequest = new GetBatchCertificateRequest { UkPrn = _headerInfo.Ukprn, Uln = uln, FamilyName = familyName, Standard = standard }; var response = await _apiClient.GetCertificate(getRequest); if (response.ValidationErrors.Any()) { ApiResponse error = new ApiResponse((int)HttpStatusCode.Forbidden, string.Join("; ", response.ValidationErrors)); return(StatusCode(error.StatusCode, error)); } else if (response.Certificate is null) { return(NoContent()); } if (response.Certificate.Status.CurrentStatus == CertificateStatus.Printed) { response.Certificate.Delivered = new Delivered { Status = "WaitingForDelivery" }; } if (CertificateStatus.HasPrintProcessStatus(response.Certificate.Status.CurrentStatus) is false) // status could be Draft or Deleted (or Privately Funded statuses) { var certificateData = response.Certificate.CertificateData; if (!string.IsNullOrEmpty(certificateData.Standard?.StandardReference) && !string.IsNullOrEmpty(certificateData?.LearningDetails?.Version)) { var standardOptions = await _apiClient.GetStandardOptionsByStandardIdAndVersion(certificateData.Standard.StandardReference, certificateData.LearningDetails.Version); var hasOptions = standardOptions != null && standardOptions.CourseOption?.Count() > 0; if (CertificateHelpers.IsDraftCertificateDeemedAsReady(response.Certificate, hasOptions)) { response.Certificate.Status.CurrentStatus = CertificateStatus.Ready; } } } return(Ok(response.Certificate)); }
public override async Task <GetCertificateResponse> GetCertificate(GetBatchCertificateRequest request) { if (request != null) { _logger.LogInformation($"GetCertificate called with request: {JsonConvert.SerializeObject(request)}"); var details = await GetLearnerDetail(request.Standard, request.Uln); if (details != null) { request.Standard = details.Standard?.ReferenceNumber ?? details.Standard?.StandardId.ToString(); request.UkPrn = details.UkPrn; } } var response = await base.GetCertificate(request); _logger.LogInformation($"GetCertificate returned with response: {JsonConvert.SerializeObject(response)}"); return(response); }
private async Task <Certificate> GetCertificate(GetBatchLearnerRequest request, StandardCollation standard) { Certificate certificate = null; if (standard != null && request.IncludeCertificate) { var certificateRequest = new GetBatchCertificateRequest { Uln = request.Uln, FamilyName = request.FamilyName, StandardCode = standard.StandardId.GetValueOrDefault(), StandardReference = standard.ReferenceNumber, UkPrn = request.UkPrn }; certificate = await _mediator.Send(certificateRequest); } return(certificate); }
public async Task <IActionResult> Get(long uln, string lastname, string standardId, int ukPrn) { var request = new GetBatchCertificateRequest { Uln = uln, FamilyName = lastname, UkPrn = ukPrn, IncludeLogs = true }; var standard = await _mediator.Send(new GetStandardVersionRequest { StandardId = standardId }); if (standard != null) { request.StandardCode = standard.LarsCode; request.StandardReference = standard.IfateReferenceNumber; } var validationResult = await _getValidator.ValidateAsync(request); var isRequestValid = validationResult.IsValid; var validationErrors = validationResult.Errors.Select(error => error.ErrorMessage).ToList(); GetBatchCertificateResponse getResponse = new GetBatchCertificateResponse { Uln = request.Uln, Standard = standardId, FamilyName = request.FamilyName, ValidationErrors = validationErrors }; if (!validationErrors.Any() && isRequestValid) { getResponse.Certificate = await _mediator.Send(request); } return(Ok(getResponse)); }
public async Task Arrange() { _request = Builder <GetBatchCertificateRequest> .CreateNew() .With(i => i.Uln = 1234567890) .With(i => i.StandardCode = 101) .With(i => i.StandardReference = null) .With(i => i.UkPrn = 12345678) .With(i => i.FamilyName = "Test") .Build(); var organisationResponse = Builder <Organisation> .CreateNew().Build(); var certificateResponse = Builder <Certificate> .CreateNew().Build(); OrganisationQueryRepositoryMock.Setup(o => o.GetByUkPrn(_request.UkPrn)) .ReturnsAsync(organisationResponse); CertificateRepositoryMock.Setup(c => c.GetCertificateByUlnOrgIdLastnameAndStandardCode(_request.Uln, organisationResponse.EndPointAssessorOrganisationId, _request.FamilyName, _request.StandardCode)) .ReturnsAsync(certificateResponse); _validationResult = await Validator.ValidateAsync(_request); }
public async Task <IActionResult> Get(long uln, string lastname, string standard, int ukPrn) { var request = new GetBatchCertificateRequest { Uln = uln, FamilyName = lastname, UkPrn = ukPrn }; var collatedStandard = int.TryParse(standard, out int standardCode) ? await GetCollatedStandard(standardCode) : await GetCollatedStandard(standard); if (collatedStandard != null) { request.StandardCode = collatedStandard.StandardId ?? int.MinValue; request.StandardReference = collatedStandard.ReferenceNumber; } var validationResult = await _getValidator.ValidateAsync(request); var isRequestValid = validationResult.IsValid; var validationErrors = validationResult.Errors.Select(error => error.ErrorMessage).ToList(); GetBatchCertificateResponse getResponse = new GetBatchCertificateResponse { Uln = request.Uln, Standard = standard, FamilyName = request.FamilyName, ValidationErrors = validationErrors }; if (!validationErrors.Any() && isRequestValid) { getResponse.Certificate = await _mediator.Send(request); } return(Ok(getResponse)); }
public virtual async Task <GetCertificateResponse> GetCertificate(GetBatchCertificateRequest request) { var apiResponse = await Get <AssessorService.Api.Types.Models.ExternalApi.Certificates.GetBatchCertificateResponse>($"/api/v1/certificates/batch/{request.Uln}/{request.FamilyName}/{request.Standard}/{request.UkPrn}"); return(Mapper.Map <AssessorService.Api.Types.Models.ExternalApi.Certificates.GetBatchCertificateResponse, GetCertificateResponse>(apiResponse)); }