コード例 #1
0
        public async Task <SalesOrderIndexViewModel> GetSalesOrders(int pageIndex, int pageSize, string territory, CustomerType?customerType)
        {
            logger.LogInformation("GetSalesOrders called");

            var response = await salesOrderApiClient.GetSalesOrdersAsync(
                pageIndex,
                pageSize,
                territory,
                customerType
                );

            var vm = new SalesOrderIndexViewModel
            {
                SalesOrders    = mapper.Map <List <SalesOrderViewModel> >(response.SalesOrders),
                Territories    = await GetTerritories(),
                CustomerTypes  = GetCustomerTypes(),
                PaginationInfo = new PaginationInfoViewModel()
                {
                    ActualPage   = pageIndex,
                    ItemsPerPage = response.SalesOrders.Count,
                    TotalItems   = response.TotalSalesOrders,
                    TotalPages   = int.Parse(Math.Ceiling(((decimal)response.TotalSalesOrders / pageSize)).ToString())
                }
            };

            vm.PaginationInfo.Next     = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "disabled" : "";
            vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "disabled" : "";

            return(vm);
        }
コード例 #2
0
            public async Task GetSalesOrders_SalesOrdersFound_ReturnsSalesOrders(
                [Frozen] MockHttpMessageHandler handler,
                [Frozen] HttpClient httpClient,
                Uri uri,
                List <SalesOrder> salesOrders,
                SalesOrderApiClient sut,
                int pageIndex,
                int pageSize,
                string territory,
                CustomerType customerType
                )
            {
                //Arrange
                httpClient.BaseAddress = uri;

                var salesOrdersResult = new SalesOrdersResult
                {
                    SalesOrders      = salesOrders,
                    TotalSalesOrders = salesOrders.Count
                };

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

                //Act
                var response = await sut.GetSalesOrdersAsync(pageIndex, pageSize, territory, customerType);

                //Assert
                response.Should().BeEquivalentTo(salesOrdersResult);
            }
コード例 #3
0
            public void GetSalesOrders_NoSalesOrdersFound_ThrowsHttpRequestException(
                [Frozen] MockHttpMessageHandler handler,
                [Frozen] HttpClient httpClient,
                Uri uri,
                SalesOrderApiClient sut
                )
            {
                //Arrange
                httpClient.BaseAddress = uri;

                handler.When(HttpMethod.Get, $"{uri}*")
                .Respond(HttpStatusCode.NotFound);

                //Act
                Func <Task> func = async() => await sut.GetSalesOrdersAsync(0, 10, null, null);

                //Assert
                func.Should().Throw <HttpRequestException>()
                .WithMessage("Response status code does not indicate success: 404 (Not Found).");
            }