public void GetTerritories_NoTerritoriesFound_ThrowsHttpRequestException( [Frozen] MockHttpMessageHandler handler, [Frozen] HttpClient httpClient, Uri uri, ReferenceDataApiClient sut ) { //Arrange httpClient.BaseAddress = uri; handler.When(HttpMethod.Get, $"{uri}*") .Respond(HttpStatusCode.NotFound); //Act Func <Task> func = async() => await sut.GetTerritoriesAsync(); //Assert func.Should().Throw <HttpRequestException>() .WithMessage("Response status code does not indicate success: 404 (Not Found)."); }
private async Task <List <SelectListItem> > GetTerritories() { logger.LogInformation("GetTerritories called."); var territories = await referenceDataApiClient.GetTerritoriesAsync(); var items = territories .Select(t => new SelectListItem() { Value = t.Name, Text = $"{t.Name} ({t.CountryRegionCode})" }) .OrderBy(b => b.Text) .ToList(); var allItem = new SelectListItem() { Value = "", Text = "All", Selected = true }; items.Insert(0, allItem); return(items); }
public async Task GetTerritories_TerritoriesFound_ReturnsTerritories( [Frozen] MockHttpMessageHandler handler, [Frozen] HttpClient httpClient, Uri uri, List <ApiClients.ReferenceDataApi.Models.GetTerritories.Territory> territories, ReferenceDataApiClient sut ) { //Arrange httpClient.BaseAddress = uri; handler.When(HttpMethod.Get, $"{uri}*") .Respond(HttpStatusCode.OK, new StringContent( JsonSerializer.Serialize( territories, new JsonSerializerOptions { Converters = { new JsonStringEnumConverter() }, IgnoreReadOnlyProperties = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }), Encoding.UTF8, "application/json" ) ); //Act var response = await sut.GetTerritoriesAsync(); //Assert response.Should().NotBeNull(); response.Should().BeEquivalentTo(territories); }