コード例 #1
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);
            }
コード例 #2
0
        public async Task GetSalesOrders_ReturnsViewModel(
            [Frozen] Mock <ISalesOrderApiClient> salesOrderApiClient,
            SalesOrdersResult salesOrdersResult,
            [Frozen] Mock <IReferenceDataApiClient> referenceDataApiClient,
            List <Territory> territories,
            SalesOrderViewModelService sut
            )
        {
            //Arrange
            salesOrdersResult.TotalSalesOrders = 21;

            salesOrderApiClient.Setup(x => x.GetSalesOrdersAsync(
                                          It.IsAny <int>(), It.IsAny <int>(),
                                          It.IsAny <string>(), It.IsAny <CustomerType?>()
                                          ))
            .ReturnsAsync(salesOrdersResult);

            referenceDataApiClient.Setup(x => x.GetTerritoriesAsync())
            .ReturnsAsync(territories);

            //Act
            var result = await sut.GetSalesOrders(
                0,
                10,
                null,
                null
                );

            //Assert
            result.SalesOrders.Count.Should().Be(salesOrdersResult.SalesOrders.Count);
            result.Territories[0].Should().BeEquivalentTo(new SelectListItem("All", "", true));
            result.Territories.Count.Should().Be(territories.Count + 1);
            result.CustomerTypes[0].Should().BeEquivalentTo(new SelectListItem("All", "", true));
            result.CustomerTypes[1].Should().BeEquivalentTo(new SelectListItem("Individual", "Individual"));
            result.CustomerTypes[2].Should().BeEquivalentTo(new SelectListItem("Store", "Store"));
            result.PaginationInfo.ActualPage.Should().Be(0);
            result.PaginationInfo.ItemsPerPage.Should().Be(salesOrdersResult.SalesOrders.Count);
            result.PaginationInfo.TotalItems.Should().Be(salesOrdersResult.TotalSalesOrders);
            result.PaginationInfo.TotalPages.Should().Be(3);
            result.PaginationInfo.Previous.Should().Be("disabled");
            result.PaginationInfo.Next.Should().Be("");
        }