public void Run()
        {
            // Simulate adding valid discounts and products to the shopping basket
            // for given scenarios
            _shoppingBasket.AddDiscount(_dataUtilities.GetDiscount("0"));
            _shoppingBasket.AddDiscount(_dataUtilities.GetDiscount("1"));

            _shoppingBasket.AddItem(_dataUtilities.GetItem("1"), 1); // Milk
            _shoppingBasket.AddItem(_dataUtilities.GetItem("0"), 1); // Butter
            _shoppingBasket.AddItem(_dataUtilities.GetItem("2"), 1); // Bread
            _shoppingBasket.GetTotalSum();
            _shoppingBasket.EmptyBasket();

            _shoppingBasket.AddItem(_dataUtilities.GetItem("0"), 2); // Butter
            _shoppingBasket.AddItem(_dataUtilities.GetItem("2"), 2); // Bread
            _shoppingBasket.GetTotalSum();
            _shoppingBasket.EmptyBasket();

            _shoppingBasket.AddItem(_dataUtilities.GetItem("1"), 4); // Milk
            _shoppingBasket.GetTotalSum();
            _shoppingBasket.EmptyBasket();

            _shoppingBasket.AddItem(_dataUtilities.GetItem("1"), 8); // Milk
            _shoppingBasket.AddItem(_dataUtilities.GetItem("0"), 2); // Butter
            _shoppingBasket.AddItem(_dataUtilities.GetItem("2"), 1); // Bread
            _shoppingBasket.GetTotalSum();
            _shoppingBasket.EmptyBasket();
        }
        public void WhenTheFollowingItemsAreAdded(Table table)
        {
            var itemsForBasket = table.CreateSet <TestShoppingItem>()
                                 .Select(row =>
            {
                var taxRules = GetTaxRulesFromIds(row.TaxRuleIds);
                return(new TestShoppingItem
                {
                    Quantity = row.Quantity,
                    ShoppingItem = CreateItem <DefaultShoppingItem>(row.Id, row.Name, row.UnitPrice.IntoDecimal(), taxRules)
                });
            });

            foreach (var item in itemsForBasket)
            {
                Func <object> addItem = () => _shoppingBasket.AddItem(item.ShoppingItem);

                if (String.IsNullOrEmpty(item.Quantity))
                {
                    _shoppingBasket.AddItem(item.ShoppingItem);
                }
                else
                {
                    var isIntegerQuantity = int.TryParse(item.Quantity, out int quantity);
                    if (!isIntegerQuantity)
                    {
                        throw new ArgumentOutOfRangeException("Quanity is not a valid integer.");
                    }

                    try
                    {
                        _shoppingBasket.AddItem(item.ShoppingItem, quantity);
                    }
                    catch (Exception e)
                    {
                        _exception  = e;
                        _invocation = addItem;
                    }
                }
            }
        }
Exemple #3
0
        public void After_Adding_A_Single_Item_To_An_Empty_Basket_Both_The_Subtotal_Of_The_Item_And_Basket_Should_Equal_The_Items_Unit_Price(int itemId, string itemName, decimal itemPrice)
        {
            //Arrange
            IShoppingItem item = new ShoppingItem(itemId, itemName, itemPrice, new List <ITaxRule>()
            {
                TaxRules.NoTax
            });

            //Act
            _basket.AddItem(item);

            //Assert
            List <IShoppingBasketItem> basketItems = _basket.Items as List <IShoppingBasketItem>;

            IShoppingBasketItem basketItem = basketItems.FirstOrDefault(x => x.Id == itemId);

            basketItem.SubTotal.Should().Be(basketItem.UnitPrice);
            _basket.SubTotal.Should().Be(basketItem.UnitPrice);
        }
 private void AddItems(string barCode)
 {
     _shoppingBasket.AddItem(barCode, _quantity);
 }
        public void Adding_An_Item_Without_An_Explicit_Quantity_Results_In_A_Quantity_Of_1_For_The_Item(int itemId, string itemName, decimal itemPrice)
        {
            //Arrange
            IShoppingItem item = new ShoppingItem(itemId, itemName, itemPrice);

            //Act
            _basket.AddItem(item);

            //Assert
            List <IShoppingBasketItem> basketItems = _basket.Items as List <IShoppingBasketItem>;

            basketItems.FirstOrDefault(x => x.Id == itemId).Quantity.Should().Be(1);
        }