Пример #1
0
        public async Task <ActionResult <double> > Test([FromBody] ScannedProductsRequest request)
        {
            var command = new CalculcateTotalSumCommand(request.Products.Names, request.Deals.Name, request.Deals.ProductsInvolved);
            ScannedProductsResponse response = new ScannedProductsResponse();

            response.FinalPrice = await Mediator.Send(command);

            return(Ok(response.FinalPrice));
        }
Пример #2
0
        public void CalculateTotalSum_With_TheCoresponding_Deal()
        {
            //Arrange
            var productsToMeasure = new string[3]
            {
                "tomato",
                "apple",
                "tomato"
            };

            string deal = "2 for 3";

            var productsInDeal = new string[3]
            {
                "tomato",
                "apple",
                "potato"
            };

            var repository = new MockRepository(MockBehavior.Strict)
            {
                DefaultValue = DefaultValue.Mock
            };
            var mockRepo = repository.Create <IReadableRepository <Product> >();

            var productsUoWMock = new Mock <IProductDataUnitOfWork>();

            productsUoWMock.Setup(k => k.ReadProducts.GetByNameAsync(It.IsAny <string[]>()))
            .ReturnsAsync(() => new List <Product>()
            {
                new Product()
                {
                    Name  = "tomato",
                    Price = 3.00
                },
                new Product()
                {
                    Name  = "apple",
                    Price = 1.66
                }
            });

            productsUoWMock
            .Setup(k => k.Products.UpdateAllAsync(It.IsAny <List <Product> >()))
            .Returns(() => Task.CompletedTask);

            var command = new CalculcateTotalSumCommand(productsToMeasure, deal, productsInDeal);
            var handler = new CalculateTotalSumCommandHandler(productsUoWMock.Object);

            //Act
            var finalSum = handler.Handle(command, new System.Threading.CancellationToken());

            //Assert
            Assert.AreEqual(finalSum, 6);
        }