public async Task When_Calling_UkrlpGetAll_Then_Returns_Data_From_Client() { var ukprns = new List <long> { 1, 2, 3 }; var response = new UkprnLookupResponse { Success = true }; var mockService = new Mock <IUkrlpApiClient>(); mockService .Setup(service => service.GetListOfTrainingProviders(ukprns)) .ReturnsAsync(response); var controller = new UkrlpLookupController( Mock.Of <ILogger <UkrlpLookupController> >(), mockService.Object); var result = await controller.UkrlpGetAll(ukprns) as OkObjectResult; result.Value.Should().Be(response); var actualResult = result.Value as UkprnLookupResponse; actualResult.Success.Should().BeTrue(); }
public async Task <UkprnLookupResponse> GetTrainingProviderByUkprn(long ukprn) { // Due to a bug in .net core, we have to parse the SOAP XML from UKRLP by hand // If this ever gets fixed then look to remove this code and replace with 'Add connected service' // https://github.com/dotnet/wcf/issues/3228 var request = _serializer.BuildUkrlpSoapRequest(ukprn, _config.UkrlpApiAuthentication.StakeholderId, _config.UkrlpApiAuthentication.QueryId); var requestMessage = new HttpRequestMessage(HttpMethod.Post, _config.UkrlpApiAuthentication.ApiBaseAddress) { Content = new StringContent(request, Encoding.UTF8, "text/xml") }; var responseMessage = await _httpClient.SendAsync(requestMessage); if (!responseMessage.IsSuccessStatusCode) { var failureResponse = new UkprnLookupResponse { Success = false, Results = new List <ProviderDetails>() }; return(await Task.FromResult(failureResponse)); } string soapXml = await responseMessage.Content.ReadAsStringAsync(); var matchingProviderRecords = _serializer.DeserialiseMatchingProviderRecordsResponse(soapXml); ProviderDetails providerDetails = null; if (matchingProviderRecords != null) { providerDetails = Mapper.Map <ProviderDetails>(matchingProviderRecords); var result = new List <ProviderDetails> { providerDetails }; var resultsFound = new UkprnLookupResponse { Success = true, Results = result }; return(await Task.FromResult(resultsFound)); } else { var noResultsFound = new UkprnLookupResponse { Success = true, Results = new List <ProviderDetails>() }; return(await Task.FromResult(noResultsFound)); } }
public void Service_throws_exception_if_no_ukrlp_details_returned() { _ukrlpDetails = null; _roatpApiClient.Setup(x => x.GetUkrlpDetails(_ukprn)).ReturnsAsync(_ukrlpDetails); Action serviceCall = () => _service.GetExternalApiCheckDetails(_applicationId).GetAwaiter().GetResult(); serviceCall.Should().Throw <ServiceUnavailableException>(); }
public void Before_each_test() { Mapper.Reset(); Mapper.Initialize(cfg => { cfg.AddProfile <UkrlpCharityCommissionProfile>(); cfg.AddProfile <UkrlpCompaniesHouseProfile>(); }); Mapper.AssertConfigurationIsValid(); _ukprn = "10001234"; _applicationId = Guid.NewGuid(); _companiesHouseApiClient = new Mock <CompaniesHouseApiClient>(); _outerApiClient = new Mock <IOuterApiClient>(); _roatpApiClient = new Mock <IRoatpApiClient>(); _qnaApiClient = new Mock <IInternalQnaApiClient>(); _logger = new Mock <ILogger <GatewayApiChecksService> >(); _qnaApiClient.Setup(x => x.GetQuestionTag(_applicationId, RoatpWorkflowQuestionTags.UKPRN)).ReturnsAsync(_ukprn); _ukrlpDetails = new UkprnLookupResponse { Success = true, Results = new List <ProviderDetails> { new ProviderDetails { UKPRN = _ukprn, ProviderName = "Test Provider", VerificationDetails = new List <VerificationDetails> { new VerificationDetails { PrimaryVerificationSource = true, VerificationAuthority = "Government statute" } } } } }; _roatpApiClient.Setup(x => x.GetUkrlpDetails(_ukprn)).ReturnsAsync(_ukrlpDetails); _registerStatus = new OrganisationRegisterStatus { UkprnOnRegister = false }; _roatpApiClient.Setup(x => x.GetOrganisationRegisterStatus(_ukprn)).ReturnsAsync(_registerStatus); _service = new GatewayApiChecksService(_companiesHouseApiClient.Object, _outerApiClient.Object, _roatpApiClient.Object, _qnaApiClient.Object, _logger.Object); }
private async Task <UkprnLookupResponse> GetUkprnLookupResponse(string request) { var requestMessage = new HttpRequestMessage(HttpMethod.Post, _config.UkrlpApiAuthentication.ApiBaseAddress) { Content = new StringContent(request, Encoding.UTF8, "text/xml") }; var responseMessage = await _httpClient.SendAsync(requestMessage); if (!responseMessage.IsSuccessStatusCode) { var failureResponse = new UkprnLookupResponse { Success = false, Results = new List <ProviderDetails>() }; return(await Task.FromResult(failureResponse)); } var soapXml = await responseMessage.Content.ReadAsStringAsync(); var matchingProviderRecords = _serializer.DeserialiseMatchingProviderRecordsResponse(soapXml); if (matchingProviderRecords != null) { var result = matchingProviderRecords.Select(Mapper.Map <ProviderDetails>).ToList(); var resultsFound = new UkprnLookupResponse { Success = true, Results = result }; return(await Task.FromResult(resultsFound)); } else { var noResultsFound = new UkprnLookupResponse { Success = true, Results = new List <ProviderDetails>() }; return(await Task.FromResult(noResultsFound)); } }
public async Task <IActionResult> UkrlpGetAll([FromQuery] List <long> ukprns) { UkprnLookupResponse providerData; try { providerData = await _retryPolicy.ExecuteAsync(context => _apiClient.GetListOfTrainingProviders(ukprns), new Context()); } catch (Exception ex) { _logger.LogError("Unable to retrieve results from UKRLP", ex); providerData = new UkprnLookupResponse { Success = false, Results = new List <ProviderDetails>() }; } return(Ok(providerData)); }
public async Task <IActionResult> UkrlpLookup(string ukprn) { UkprnLookupResponse providerData; long ukprnValue = Convert.ToInt64(ukprn); try { providerData = await _retryPolicy.ExecuteAsync(context => _apiClient.GetTrainingProviderByUkprn(ukprnValue), new Context()); } catch (Exception ex) { _logger.LogError("Unable to retrieve results from UKRLP", ex); providerData = new UkprnLookupResponse { Success = false, Results = new List <ProviderDetails>() }; } return(Ok(providerData)); }