Exemplo n.º 1
0
        /// <summary>
        /// Checks out each item in the basket, taking into account any
        /// promotions available
        /// </summary>
        /// <returns>an <see cref="IReceiptView"/> instance representing the view to be rendered</returns>
        public IReceiptView Checkout(IEnumerable<BasketItem> basket)
        {
            // Use the CashRegister to computethe receipt entries
            var register = new CashRegister(_promotions);

            //Lookup prices for all the grocery items in the basket
            var groceryItems = basket.Select(i => _priceList[i.Id]);

            //Generate receipt entries
            var receiptEntries = register.Process(groceryItems);

            // Instantiate the view and render it
            return new ConsoleReceiptView(receiptEntries);
        }
Exemplo n.º 2
0
        public static void Process_MultipleItemTypesNoPromotions_CorrectReceiptEntriesMade()
        {
            // Arrange
            var register = new CashRegister(Enumerable.Empty<IPromotion>());
            var groceryItems = new[]
            {
                new GroceryItem("Apples", 1.0m),
                new GroceryItem("Apples", 1.0m),
                new GroceryItem("Oranges", 2.0m),
                new GroceryItem("Oranges", 2.0m),
            };

            // Act
            var receiptEntries = register.Process(groceryItems).ToArray();

            // Assert
            Assert.That(receiptEntries.Count(), Is.EqualTo(2));

            //Test the receipt entry for apples
            var applesEntry = receiptEntries.First(e => e.ItemDescription == "Apples");
            Assert.That(applesEntry.Quantity, Is.EqualTo(2));
            Assert.That(applesEntry.UnitPrice, Is.EqualTo(1.0m));
            Assert.That(applesEntry.TotalPrice, Is.EqualTo(2.0m));
            Assert.That(applesEntry.Promotion, Is.False);

            //Test the receipt entry for oranges
            var orangesEntry = receiptEntries.First(e => e.ItemDescription == "Oranges");
            Assert.That(orangesEntry.Quantity, Is.EqualTo(2));
            Assert.That(orangesEntry.UnitPrice, Is.EqualTo(2.0m));
            Assert.That(orangesEntry.TotalPrice, Is.EqualTo(4.0m));
            Assert.That(orangesEntry.Promotion, Is.False);
        }
Exemplo n.º 3
0
        public static void Process_OneItemTypeOnePromotion_CorrectReceiptEntriesMade(
            string itemId,
            int quantity,
            decimal unitPrice,
            IEnumerable<IPromotion> promotions,
            IEnumerable<ReceiptEntry> expectedReceiptEntreEntries)
        {
            // Arrange
            var items = GetItems(itemId, quantity, unitPrice).ToList();

            var register = new CashRegister(promotions);

            // Act
            var actualReceiptEntries = register.Process(items).ToArray();

            // Assert
            CollectionAssert.AreEqual(actualReceiptEntries, expectedReceiptEntreEntries);
        }