Exemplo n.º 1
0
        public async void ListProducts_ReturnsProducts()
        {
            //Arrange
            var mockLogger             = new Mock <ILogger <ProductApi> >();
            var mockHttpRequestFactory = new Mock <IHttpRequestFactory>();

            mockHttpRequestFactory.Setup(x => x.Get(
                                             It.IsAny <string>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <string>()
                                             )
                                         )
            .ReturnsAsync(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new JsonContent(new ListProductsResponse
                {
                    Products = new List <Core.Abstractions.Api.ProductApi.ListProducts.Product>
                    {
                        new Core.Abstractions.Api.ProductApi.ListProducts.Product {
                            ProductNumber = "ST-1401"
                        },
                        new Core.Abstractions.Api.ProductApi.ListProducts.Product {
                            ProductNumber = "ST-1402"
                        },
                    }
                })
            });

            var baseAddress = "BaseAddress";

            var sut = new ProductApi(
                mockLogger.Object,
                mockHttpRequestFactory.Object,
                baseAddress
                );

            //Act
            var response = await sut.ListProductsAsync(new ListProductsRequest());

            //Assert
            mockHttpRequestFactory.Verify(x => x.Get(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >(), It.IsAny <string>()));
            response.Products[0].ProductNumber.Should().Be("ST-1401");
            response.Products[1].ProductNumber.Should().Be("ST-1402");
        }