public async Task Should_ReturnOnlyFiveProducts_When_DataSourceContainsMoreThanFive(string no1, string no2, string no3, string no4, string no5, string no6)
        {
            dataSourceMock.GetInProgressOrdersAsyncMock(OrderFactory.CreateOrders(
                                                            OrderFactory.CreateOrdersWithLines(no1),
                                                            OrderFactory.CreateOrdersWithLines(no2, no3),
                                                            OrderFactory.CreateOrdersWithLines(no4),
                                                            OrderFactory.CreateOrdersWithLines(no5),
                                                            OrderFactory.CreateOrdersWithLines(no6)
                                                            ));
            dataSourceMock.GetProductsAsyncMock(ProductFactory.CreateProducts(no1, no2, no3, no4, no5, no6));
            var topSoldProductService = new TopSoldProductService(dataSourceMock.Object);

            var products = await topSoldProductService.GetOrderTopSoldProducts();

            Assert.Equal(5, products.Count());
        }
Esempio n. 2
0
        public void CanCreateProduct()
        {
            var line1 = "pippo";
            var line2 = "paperino";

            _parser.Setup(prop => prop.Parse(line1))
            .Returns(new InputProductLine {
                Description = "pluto",
                Imported    = true,
                LinePrice   = 55.11m,
                Qty         = 10
            });

            _parser.Setup(prop => prop.Parse(line2))
            .Returns(new InputProductLine {
                Description = "clarabella",
                Imported    = false,
                LinePrice   = 99.66m,
                Qty         = 12
            });



            _productRegister.Setup(p => p.GetTaxCategory("pluto"))
            .Returns(TaxCategory.Drug);
            _productRegister.Setup(p => p.GetTaxCategory("clarabella"))
            .Returns(TaxCategory.Book);

            var sut = new ProductFactory(_productRegister.Object, _parser.Object);

            var res = sut.CreateProducts(new[] { line1, line2 });

            var product = res.First();

            Assert.AreEqual("pluto", product.Description);
            Assert.IsTrue(product.Imported);
            Assert.AreEqual(55.11m, product.NetLinePrice);
            Assert.AreEqual(10, product.Qty);
            Assert.AreEqual(TaxCategory.Drug, product.TaxCategory);

            product = res.Last();
            Assert.AreEqual("clarabella", product.Description);
            Assert.IsFalse(product.Imported);
            Assert.AreEqual(99.66m, product.NetLinePrice);
            Assert.AreEqual(12, product.Qty);
            Assert.AreEqual(TaxCategory.Book, product.TaxCategory);
        }
        public async Task Should_FillProductsNames(string no1, string no2, string no3, string no4, string no5, string no6)
        {
            dataSourceMock.GetProductsAsyncMock(ProductFactory.CreateProducts(no1, no2, no3, no4, no5, no6));

            topSoldProductServiceMock.GetOrderTopSoldProducts(LineFactory.CreateLines(
                                                                  LineFactory.CreateLine(no1),
                                                                  LineFactory.CreateLine(no2),
                                                                  LineFactory.CreateLine(no3),
                                                                  LineFactory.CreateLine(no4),
                                                                  LineFactory.CreateLine(no5)
                                                                  ));
            var handler = new GetTopSoldProductsQueryHandler(dataSourceMock.Object, topSoldProductServiceMock.Object);

            var products = await handler.Handle(new GetTopSoldProductsQuery(), CancellationToken.None);

            Assert.All(products, x => Assert.NotNull(x.Name));
        }