public void GetTotalPriceForOneItemReturnsCorrectResult(string barcode, double price)
        {
            // Arrange
            var sut = new PointOfSaleServiceBuilder()
                      .WithQuery(new InMemoryItemRegistry())
                      .WithGenerator(new Mock <TransactionIdGenerator>().Object)
                      .Build();
            var expected = new decimal(price);

            // Act
            sut.OnBarcodeScan(barcode);

            // Assert
            Assert.Equal(expected, sut.SubTotal, numOfDecimalPlaces);
        }
        public void ItemWithRegisteredBarcodeIsStoredInsideScannedItems(string barcode)
        {
            // Arrange
            var registry = new InMemoryItemRegistry();
            var sut      = new PointOfSaleServiceBuilder()
                           .WithQuery(registry)
                           .WithGenerator(new Mock <TransactionIdGenerator>().Object)
                           .Build();
            var expected = registry.Read(barcode);

            // Act
            sut.OnBarcodeScan(barcode);

            // Assert
            sut.ScannedItems.Should().Contain(expected);
        }
        public void GetTotalPriceOnEmptyBarcodeReturns0Price()
        {
            // Arrange
            var sut = new PointOfSaleServiceBuilder()
                      .WithQuery(new InMemoryItemRegistry())
                      .WithGenerator(new Mock <TransactionIdGenerator>().Object)
                      .Build();
            string emptyBarcode = "";

            // Act
            sut.OnBarcodeScan(emptyBarcode);

            // Assert
            var expected = new decimal(0);

            Assert.Equal(expected, sut.SubTotal, numOfDecimalPlaces);
        }
        public void ScannedItemIsDisplayed()
        {
            // Arrange
            var    registry = new InMemoryItemRegistry();
            var    sut      = new Mock <Display>();
            string barcode  = "123456";
            var    sale     = new PointOfSaleServiceBuilder()
                              .WithQuery(new InMemoryItemRegistry())
                              .WithGenerator(new Mock <TransactionIdGenerator>().Object)
                              .WithDisplay(sut.Object)
                              .Build();
            var expected = new ScannedBarcodeEventArgs(registry.Read(barcode));

            // Act
            sale.OnBarcodeScan(barcode);

            // Assert
            sut.Verify(s => s.BarcodeHandler(sale, expected));
        }
        public void CompleteSaleDisplaysReceiptAndClearsScannedItems(int transactionId, string barcode)
        {
            // Arrange
            var sut           = new Mock <Display>();
            var stubGenerator = new Mock <TransactionIdGenerator>();

            stubGenerator.Setup(s => s.GenerateTransactionId()).Returns(transactionId);
            var sale = new PointOfSaleServiceBuilder()
                       .WithDisplay(sut.Object)
                       .WithQuery(new InMemoryItemRegistry())
                       .WithGenerator(stubGenerator.Object)
                       .Build();

            sale.OnBarcodeScan(barcode);
            var expected = new CompleteSaleEventArgs(transactionId, sale.ScannedItems);

            // Act
            sale.OnCompleteSale();

            // Assert
            sut.Verify(s => s.CompleteSaleHandler(sale, expected));
            sale.ScannedItems.Should().BeEmpty();
        }