public void TestCase1()
        {
            // arrange
            _posTerminal.Scan("ABCDABA");

            // act, assert
            Assert.AreEqual(13.25, _posTerminal.CalculateTotal());
        }
        static void Main(string[] args)
        {
            var products = new List <ProductDTO>
            {
                new ProductDTO {
                    Code = "A", RetailPrice = 1.25m, VolumePrice = 3m, VolumeQuantity = 3
                },
                new ProductDTO {
                    Code = "B", RetailPrice = 4.25m
                },
                new ProductDTO {
                    Code = "C", RetailPrice = 1m, VolumePrice = 5m, VolumeQuantity = 6
                },
                new ProductDTO {
                    Code = "D", RetailPrice = 0.75m
                }
            };

            PointOfSaleTerminal terminal1 = new PointOfSaleTerminal();

            terminal1.SetPricing(products);
            terminal1.Scan("A");
            terminal1.Scan("B");
            terminal1.Scan("C");
            terminal1.Scan("D");
            terminal1.Scan("A");
            terminal1.Scan("B");
            terminal1.Scan("A");

            Console.WriteLine($"ABCDABA - 13.25???{terminal1.CalculateTotal()}");

            PointOfSaleTerminal terminal2 = new PointOfSaleTerminal();

            terminal2.SetPricing(products);
            terminal2.Scan("C");
            terminal2.Scan("C");
            terminal2.Scan("C");
            terminal2.Scan("C");
            terminal2.Scan("C");
            terminal2.Scan("C");
            terminal2.Scan("C");

            Console.WriteLine($"CCCCCCC - 6???{terminal2.CalculateTotal()}");

            PointOfSaleTerminal terminal3 = new PointOfSaleTerminal();

            terminal3.SetPricing(products);
            terminal3.Scan("A");
            terminal3.Scan("B");
            terminal3.Scan("C");
            terminal3.Scan("D");

            Console.WriteLine($"ABCD - 7.25???{terminal3.CalculateTotal()}");

            Console.ReadLine();
        }
Example #3
0
        public void Scan_NullProductCodeShouldRaiseException()
        {
            string productCode = null;

            Action act = () => terminal.Scan(productCode);

            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(act);

            Assert.Equal(nameof(productCode), exception.ParamName);
        }
        public void ShouldCalculateTotalCorrectly(string[] productCodes, decimal expectedTotalPrice)
        {
            foreach (var code in productCodes)
            {
                _terminal.Scan(code);
            }
            var totalPrice = _terminal.CalculateTotal();

            Assert.Equal(expectedTotalPrice, totalPrice);
        }
 private void ScanStringAsChars(PointOfSaleTerminal terminal, string productCodes)
 {
     foreach (char ch in productCodes)
     {
         terminal.Scan(ch.ToString());
     }
 }
        public void CalculateTotal_Should_Return_Correct_Sum(string productCodes, double totalPrice)
        {
            // arrange
            IPointOfSaleTerminal terminal = new PointOfSaleTerminal();
            IReadOnlyDictionary <string, ProductPricingSettings> settings = new Dictionary <string, ProductPricingSettings>
            {
                { "A", new ProductPricingSettings(1.25, 3, 3) },
                { "B", new ProductPricingSettings(4.25) },
                { "C", new ProductPricingSettings(1, 5, 6) },
                { "D", new ProductPricingSettings(0.75) },
                { "E", new ProductPricingSettings(1, 0.75, 1) }
            };

            terminal.SetPricing(settings);

            foreach (char productCode in productCodes)
            {
                terminal.Scan(productCode.ToString());
            }

            // act
            double result = terminal.CalculateTotal();

            // assert
            Assert.Equal(totalPrice, result);
        }
Example #7
0
        public void Scan_WhenABCD_ThenPriceIs7_25()
        {
            // Arrange
            PointOfSaleTerminal terminal = new PointOfSaleTerminal();

            terminal.SetPricing();
            terminal.Scan("A");
            terminal.Scan("B");
            terminal.Scan("C");
            terminal.Scan("D");

            // Act
            decimal result = terminal.GetSaleTotal();

            // Assert
            Assert.Equal(7.25m, result);
        }
        public void Scan_Should_Throw_ArgumentNullException_If_ProductCode_Is_Null_or_Empty(string productCode)
        {
            // arrange
            IPointOfSaleTerminal terminal = new PointOfSaleTerminal();

            // assert
            Assert.Throws <ArgumentNullException>(() => terminal.Scan(productCode));
        }
Example #9
0
        public void Scan()
        {
            var terminal = new PointOfSaleTerminal(new Cart(), this._mockProductRepository.Object);

            var ex = Should.Throw <ProductNotFoundException>(() => terminal.Scan("B"));

            ex.ProductName.ShouldBe("B");
        }
Example #10
0
        public void ShouldRaiseExceptionIfScanUnknownProduct()
        {
            var sut = new PointOfSaleTerminal();

            sut.SetPricing(new ProductCatalog());

            Assert.Throws <ProductNotFoundException>(() => sut.Scan("A"));
        }
Example #11
0
        public void Scan_ProductNotFoundException()
        {
            // arrange
            var posTerminal = new PointOfSaleTerminal();

            // act
            // assert
            posTerminal.Scan("A");
        }
        public void Test(string itemList, decimal expectedTotal)
        {
            foreach (var itemName in itemList.ToCharArray())
            {
                _terminal.Scan(itemName.ToString());
            }

            Assert.AreEqual(expectedTotal, _terminal.CalculateTotal());
        }
Example #13
0
        private void Perform_ATest(string productCode, double expected)
        {   //Arrange
            productOrder = terminal.Scan(productCode, productOrder);
            productOrder = terminal.SetPricing(productOrder);
            //Act
            double actual = terminal.CalculateTotal(productOrder);

            //Assert
            Assert.AreEqual(expected, actual);
        }
Example #14
0
        public decimal?CalculatePrice(IEnumerable <string> inputs)
        {
            _terminal.SetPricing(_pricesRepository.GetPrices());
            foreach (var productName in inputs)
            {
                _terminal.Scan(productName);
            }

            return(_terminal.CalculateTotal());
        }
Example #15
0
        public void Scan_Success()
        {
            // arrange
            var posTerminal = new PointOfSaleTerminal();

            posTerminal.SetPricing(new Product('A', 1));

            // act
            // assert
            posTerminal.Scan("A");
        }
Example #16
0
        public void Scan_ShouldAddAnItemToAnOrderList_WhenScannerCanFindAStockItem()
        {
            string  itemCode = "A";
            decimal priceA   = 1.25m;
            var     item     = SetupScannerWithStockItem(itemCode);

            SetupPricingService(item, priceA);

            _sut.Scan(itemCode);

            _codeScannerMock.VerifyAll();
            _orderListMock.Verify(i => i.AddItem(item, priceA), Times.Once);
        }
        public void Should_ThrowException_When_PricesNotDefined()
        {
            //Arrange
            string productCode = "NotDefinedProduct";

            //Act-Assert
            var ex = Assert.ThrowsException <PricesNotSpecifiedException>(() => _terminal.Scan(productCode));
        }
        public void Scan()
        {
            var mockCart = new Mock <ICart>();

            mockCart.Setup(
                c => c.Add(It.IsAny <IProduct>())
                ).Verifiable();

            var terminal = new PointOfSaleTerminal(mockCart.Object, this._mockProductRepository.Object);

            terminal.Scan(PRODUCT_NAME);

            mockCart.Verify(c => c.Add(It.Is <IProduct>(p => p.Id == this._mockProduct.Object.Id)), Times.Once);
        }
        public void CalculateTotal_PassDifferentOrders_ShouldReturnActualSum(string orders, double expectedTotalPrice)
        {
            //Arrange
            foreach (var order in orders)
            {
                _terminal.Scan(order.ToString());
            }

            //Act
            var actualTotalPrice = _terminal.CalculateTotal();

            //Assert
            Assert.AreEqual(expectedTotalPrice, actualTotalPrice);
        }
Example #20
0
        public void Scan_ScanProductThatIsNotRegistered_ReturnsFailedOperation(string productId)
        {
            var sut    = new PointOfSaleTerminal();
            var result = sut.Scan(productId);

            using (new AssertionScope())
            {
                result.Success.Should().BeFalse();
                result.Errors.Count.Should().Be(1);
                result.Errors.First().Message
                .Should()
                .Be($"Product with id {productId} could not be scanned. No info how much does it cost.");
            }
        }
Example #21
0
        public void Scan_ScannedItemIsRegistered_ReturnsSucceededOperation(Generator <PricingRule> generator)
        {
            var rules = generator.Take(5).ToList();

            rules.ForEach(r => r.Count = 1);

            var sut = new PointOfSaleTerminal();

            sut.SetPricing(rules);
            var result = sut.Scan(rules[3].Id);

            using (new AssertionScope())
            {
                result.Success.Should().BeTrue();
            }
        }
Example #22
0
        public void CalculateTotal_DifferentCorrectItemsScanned_CalculatesCorrectly(string productIds, decimal expected)
        {
            var sut = new PointOfSaleTerminal();

            sut.SetPricing(Rules);

            foreach (var s in productIds)
            {
                sut.Scan(s.ToString());
            }

            var actual = sut.CalculateTotal();

            using (new AssertionScope())
            {
                actual.Should().Be(expected);
            }
        }
Example #23
0
        private static void Main()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();
            var shop = new Shop();

            configuration.GetSection("Shop").Bind(shop);
            var terminal = new PointOfSaleTerminal();

            terminal.SetPricing(shop);
            var products = Console.ReadLine();

            products?.ToCharArray().ToList().ForEach(p => terminal.Scan(p.ToString()));
            Console.WriteLine($"Total price is: {terminal.Checkout()}");
            Console.Read();
        }
Example #24
0
        public void Scan_ScanProductWithEmptyId_ReturnsFailedOperation(Generator <PricingRule> generator)
        {
            var rules = generator.Take(5).ToList();

            rules.ForEach(r => r.Count = 1);

            var sut = new PointOfSaleTerminal();

            sut.SetPricing(rules);
            var result = sut.Scan(null);

            using (new AssertionScope())
            {
                result.Success.Should().BeFalse();
                result.Errors.Count.Should().Be(1);
                result.Errors.First().Message
                .Should()
                .Be("Product with null or empty id could not be scanned.");
            }
        }
Example #25
0
        public void Scan_WhenCCCCCC_ThenPriceIs6()
        {
            // Arrange
            PointOfSaleTerminal terminal = new PointOfSaleTerminal();

            terminal.SetPricing();
            terminal.Scan("C");
            terminal.Scan("C");
            terminal.Scan("C");
            terminal.Scan("C");
            terminal.Scan("C");
            terminal.Scan("C");
            terminal.Scan("C");

            // Act
            decimal result = terminal.GetSaleTotal();

            // Assert
            Assert.Equal(6m, result);
        }
Example #26
0
 static void Main( string[] args )
 {
     if (1 != args.Length)
     {
         System.Console.WriteLine("Usage: PointOfSaleTernimal <command file>");
     }
     else
     {
         PointOfSaleTerminal terminal = new PointOfSaleTerminal();
         System.IO.StreamReader priceFile = new System.IO.StreamReader(args[0]);
         string line = priceFile.ReadLine();
         if (null != line)
         {
             terminal.SetPricing(line);
             while ((line = priceFile.ReadLine()) != null)
             {
                 terminal.Scan(line);
             }
         }
         System.Console.WriteLine("Total sale: $" + terminal.CalculateTotal());
     }
 }
        public void CalculateTotal_Should_Throw_Exception_If_ProductPricingSettings_Were_Not_Found_For_Product(string productCodes)
        {
            // arrange
            IPointOfSaleTerminal terminal = new PointOfSaleTerminal();
            IReadOnlyDictionary <string, ProductPricingSettings> settings = new Dictionary <string, ProductPricingSettings>
            {
                { "A", new ProductPricingSettings(1.25, 3, 3) },
                { "B", new ProductPricingSettings(4.25) },
                { "C", new ProductPricingSettings(1, 5, 6) },
                { "D", new ProductPricingSettings(0.75) }
            };

            terminal.SetPricing(settings);

            foreach (char productCode in productCodes)
            {
                terminal.Scan(productCode.ToString());
            }


            // assert
            Assert.Throws <Exception>(() => terminal.CalculateTotal());
        }
Example #28
0
        static void Main(string[] args)
        {
            var prices = new[]
            {
                new ProductPrice("A", 1.25M, new VolumePrice(3M, 3)),
                new ProductPrice("B", 4.25M),
                new ProductPrice("C", 1.00M, new VolumePrice(5M, 6)),
                new ProductPrice("D", 0.75M)
            };

            var terminal = new PointOfSaleTerminal(prices);

            terminal.Scan("A");
            terminal.Scan("A");
            terminal.Scan("A");
            terminal.Scan("A");
            terminal.Scan("C");
            terminal.Scan("D");

            Console.WriteLine(terminal.PrintReceipt());
            Console.WriteLine($"Total Price: {terminal.CalculateTotal()}");
        }
Example #29
0
        public void Scan_ShouldAddExistingItem()
        {
            _sut.Scan("A");

            Assert.Equal(1.25m, _sut.Balance);
        }
        public void When_ScanProductCodeThatExistInPricing_Expected_NoException()
        {
            IPointOfSaleTerminal terminal = new PointOfSaleTerminal(components.Resolve <ICart>(), components.Resolve <IPricing>(), null);

            Assert.DoesNotThrow(() => terminal.Scan("A"));
        }
        public void When_ScanProductCodeThatMissingInPricing_Expected_exception()
        {
            IPointOfSaleTerminal terminal = new PointOfSaleTerminal(components.Resolve <ICart>(), components.Resolve <IPricing>(), null);

            Assert.Throws <KeyNotFoundException>(() => terminal.Scan("Dino"));
        }