예제 #1
0
        public async Task GetTop5ProductsSoldFromOrders_Should_ReturnListOfProductDtos()
        {
            var expected = new ProductDtosBuilder()
                           .WithProductDtoIs("ProductNo1", 200, "Name1", "EAN1", 300)
                           .WithProductDtoIs("ProductNo2", 150, "Name2", "EAN2", 200)
                           .WithProductDtoIs("ProductNo3", 50, "Name3", "EAN3", 50)
                           .Build();

            var lines1 = new MerchantOrderLineResponsesBuilder()
                         .WithMerchantOrderLineResponseIs("ProductNo3", 50)
                         .WithMerchantOrderLineResponseIs("ProductNo2", 100)
                         .WithMerchantOrderLineResponseIs("ProductNo1", 50)
                         .Build();

            var lines2 = new MerchantOrderLineResponsesBuilder()
                         .WithMerchantOrderLineResponseIs("ProductNo1", 50)
                         .WithMerchantOrderLineResponseIs("ProductNo2", 50)
                         .WithMerchantOrderLineResponseIs("ProductNo1", 100)
                         .Build();

            var merchantOrderResponses = new MerchantOrderResponsesBuilder()
                                         .WithmerchantOrderResponseIs(lines1)
                                         .WithmerchantOrderResponseIs(lines2)
                                         .Build();

            var collectionMerchantOrderResponse = new CollectionOfMerchantOrderResponse()
            {
                Content = merchantOrderResponses
            };

            var productRespones = new MerchantProductResponsesBuilder()
                                  .WithMerchantProductResponseIs("ProductNo3", "Name3", "EAN3", 50)
                                  .WithMerchantProductResponseIs("ProductNo2", "Name2", "EAN2", 200)
                                  .WithMerchantProductResponseIs("ProductNo1", "Name1", "EAN1", 300)
                                  .Build();

            var collectionMerchantProductResponse = new CollectionOfMerchantProductResponse()
            {
                Content = productRespones
            };

            var mockedchannelEngineHttpClient = new Mock <IChannelEngineHttpClient>();

            mockedchannelEngineHttpClient.Setup(c => c.GetProducts(It.IsAny <List <string> >())).ReturnsAsync(collectionMerchantProductResponse);

            var sut = new ProductsFromOrdersHandler(mockedchannelEngineHttpClient.Object);

            //Act
            var result = await sut.GetTop5ProductsSoldFromOrders(collectionMerchantOrderResponse);

            //Assert
            result.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());
        }
        private List <ProductDto> MapProductsResponseToProductDtos(CollectionOfMerchantProductResponse productsResponse, List <ProductDto> products)
        {
            MerchantProductResponse productResponse;

            foreach (var product in products)
            {
                productResponse = productsResponse.Content.Single(p => p.MerchantProductNo == product.MerchantProductNo);
                product.Name    = productResponse.Name;
                product.EAN     = productResponse.Ean;
                product.Stock   = productResponse.Stock;
            }
            return(products);
        }