Пример #1
0
        public void ScanSingleItemAndReturnTotalPrice()
        {
            //Arrange
            var product = new Product {
                Sku = "A99", UnitPrice = .50m
            };
            var expectedPrice = .50m;

            //Act
            _checkoutFactory.Setup(x => x.CreateCheckout()).Returns(new List <IItemPriceRule>
            {
                new SingleItemPriceRule(product.Sku, product.UnitPrice)
            });

            _repo.Setup(x => x.DisplayAvailableItems()).Returns(new List <ProductDto>
            {
                new ProductDto
                {
                    Sku       = "A99",
                    UnitPrice = 0.50m
                }
            });


            _checkout = new Service.Checkout(_checkoutFactory.Object, _repo.Object);

            _checkout.ScanItem(product.Sku);

            var actualPrice = _checkout.CalculateTotalPrice();

            //Assert
            Assert.AreEqual(expectedPrice, actualPrice);
        }
Пример #2
0
        public void ScanMultipleThreeAItemsReturnsTotalPrice()
        {
            //Arrange
            var products = new List <Product>
            {
                new Product {
                    Sku = "A99", UnitPrice = .50m
                },
                new Product {
                    Sku = "A99", UnitPrice = .50m
                },
                new Product {
                    Sku = "A99", UnitPrice = .50m
                }
            };

            var expectedPrice = 1.30m;

            //Act
            _checkoutFactory.Setup(x => x.CreateCheckout()).Returns(new List <IItemPriceRule>
            {
                new MultipleItemPriceRule("A99", 1.30m, 3)
            });

            _repo.Setup(x => x.DisplayAvailableItems()).Returns(new List <ProductDto>
            {
                new ProductDto
                {
                    Sku       = "A99",
                    UnitPrice = 0.50m
                }
            });


            _checkout = new Service.Checkout(_checkoutFactory.Object, _repo.Object);

            foreach (var item in products)
            {
                _checkout.ScanItem(item.Sku);
            }


            var actualPrice = _checkout.CalculateTotalPrice();

            //Assert
            Assert.AreEqual(expectedPrice, actualPrice);
        }