コード例 #1
0
            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).");
            }
コード例 #2
0
        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);
        }
コード例 #3
0
            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);
            }