public void GetSalesPersons_NoSalesPersonsFound_ThrowsHttpRequestException( [Frozen] MockHttpMessageHandler handler, [Frozen] HttpClient httpClient, Uri uri, SalesPersonApiClient sut ) { //Arrange httpClient.BaseAddress = uri; handler.When(HttpMethod.Get, $"{uri}*") .Respond(HttpStatusCode.NotFound); //Act Func <Task> func = async() => await sut.GetSalesPersonsAsync(); //Assert func.Should().Throw <HttpRequestException>() .WithMessage("Response status code does not indicate success: 404 (Not Found)."); }
public async Task GetSalesPersons_SalesPersonsFound_ReturnsSalesPersons( [Frozen] MockHttpMessageHandler handler, [Frozen] HttpClient httpClient, Uri uri, List <SalesPerson> salesPersons, SalesPersonApiClient sut ) { //Arrange httpClient.BaseAddress = uri; handler.When(HttpMethod.Get, $"{uri}*") .Respond(HttpStatusCode.OK, new StringContent( JsonSerializer.Serialize( salesPersons, new JsonSerializerOptions { Converters = { new JsonStringEnumConverter() }, IgnoreReadOnlyProperties = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }), Encoding.UTF8, "application/json" ) ); //Act var response = await sut.GetSalesPersonsAsync(); //Assert response.Should().NotBeNull(); response.Should().BeEquivalentTo(salesPersons); }