Example #1
0
            public void GetStateProvinces_NoStateProvincesFound_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.GetStatesProvincesAsync();

                //Assert
                func.Should().Throw <HttpRequestException>()
                .WithMessage("Response status code does not indicate success: 404 (Not Found).");
            }
Example #2
0
            public async Task GetStateProvinces_StateProvincesFound_ReturnsStateProvinces(
                [Frozen] MockHttpMessageHandler handler,
                [Frozen] HttpClient httpClient,
                Uri uri,
                List <ApiClients.ReferenceDataApi.Models.GetStateProvinces.StateProvince> statesProvinces,
                ReferenceDataApiClient sut
                )
            {
                //Arrange
                httpClient.BaseAddress = uri;

                handler.When(HttpMethod.Get, $"{uri}*")
                .Respond(HttpStatusCode.OK,
                         new StringContent(
                             JsonSerializer.Serialize(
                                 statesProvinces,
                                 new JsonSerializerOptions
                {
                    Converters =
                    {
                        new JsonStringEnumConverter()
                    },
                    IgnoreReadOnlyProperties = true,
                    PropertyNamingPolicy     = JsonNamingPolicy.CamelCase
                }),
                             Encoding.UTF8,
                             "application/json"
                             )
                         );

                //Act
                var response = await sut.GetStatesProvincesAsync();

                //Assert
                response.Should().BeEquivalentTo(statesProvinces);
            }