public void PurchasePrice_UsesOriginalPrice_WhenNoMarkdown()
        {
            decimal           expectedPrice = 1.89M;
            EachesGroceryItem item          = new EachesGroceryItem("soup", expectedPrice);

            Assert.AreEqual(expectedPrice, item.PurchasePrice);
        }
        public void Constructor_SetsNameAndOriginalPrice()
        {
            decimal           expectedPrice = 1.89M;
            EachesGroceryItem item          = new EachesGroceryItem("soup", expectedPrice);

            Assert.AreEqual("soup", item.Name);
            Assert.AreEqual(expectedPrice, item.OriginalPrice);
        }
        public void CalculatePurchasePrice_UsesPurchasePrice_IfMarkdownIsSetButSpecialIsNotSet()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 1.89M)
            {
                Markdown = new PriceMarkdownStub(1.50M)
            };

            Assert.AreEqual(7.50M, item.CalculatePurchasePrice(5));
        }
        public void CalculatePurchasePrice_AppliesSpecial_IfSpecialIsSet()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 1.89M)
            {
                Special = new EachesGroceryItemSpecialFake(1.00M)
            };

            Assert.AreEqual(5.00M, item.CalculatePurchasePrice(5));
        }
Exemple #5
0
        public void Constructor_SetsItemAndCount()
        {
            int expectedItemCount        = 3;
            EachesGroceryItem      item  = new EachesGroceryItem("soup", 1.89M);
            EachesGroceryItemOrder order = new EachesGroceryItemOrder(item, expectedItemCount);

            Assert.AreEqual(item, order.Item);
            Assert.AreEqual(expectedItemCount, order.Count);
        }
        public void PurchasePrice_GetsResultFromMarkdown()
        {
            decimal           expectedPrice = 1.50M;
            EachesGroceryItem item          = new EachesGroceryItem("soup", 1.89M)
            {
                Markdown = new PriceMarkdownStub(expectedPrice)
            };

            Assert.AreEqual(expectedPrice, item.PurchasePrice);
        }
Exemple #7
0
        public void Combine_ThrowsException_IfItemsAreDifferent()
        {
            EachesGroceryItem soup  = new EachesGroceryItem("soup", 1.89M);
            EachesGroceryItem bread = new EachesGroceryItem("bread", 2.30M);

            EachesGroceryItemOrder a = new EachesGroceryItemOrder(soup, 3);
            EachesGroceryItemOrder b = new EachesGroceryItemOrder(bread, 6);

            Assert.ThrowsException <DifferingItemsException>(() => a.Combine(b));
        }
Exemple #8
0
        public void AbstractCombine_ReturnsNewEachesGroceryItemWithCombinedCount()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 2.00M);
            IGroceryItemOrder a    = new EachesGroceryItemOrder(item, 3);
            IGroceryItemOrder b    = new EachesGroceryItemOrder(item, 6);

            EachesGroceryItemOrder result = (EachesGroceryItemOrder)a.Combine(b);

            Assert.AreEqual(9, result.Count);
        }
Exemple #9
0
        public void Item_IsImplementedForGroceryItemInterface()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 2.00M);

            EachesGroceryItemOrder order = new EachesGroceryItemOrder(item, 3);

            IGroceryItemOrder abstractOrder = order;

            Assert.AreEqual(item, abstractOrder.Item);
        }
Exemple #10
0
        public IGroceryItemOrder CreateOrder(IGroceryItem item)
        {
            EachesGroceryItem eachesItem = item as EachesGroceryItem;

            if (eachesItem == null)
            {
                throw new InvalidGroceryItemTypeException();
            }

            int count = CountSelector.SelectCount(eachesItem);

            return(new EachesGroceryItemOrder(eachesItem, count));
        }
        public void CreateOrder_CreatesOrderWithFiveItems_WhenFactoryCreatedWithCustomDefault()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 1.89M);

            EachesGroceryItemOrderFactory factory =
                new EachesGroceryItemOrderFactory(5);

            IGroceryItemOrder order = factory.CreateOrder(item);

            Assert.IsTrue(order is EachesGroceryItemOrder);
            EachesGroceryItemOrder eachesOrder = ((EachesGroceryItemOrder)order);

            Assert.AreEqual(item, eachesOrder.Item);
            Assert.AreEqual(5, eachesOrder.Count);
        }
        public void CreateOrder_CreatesOrderWithOneItem_IfIsIEachesGroceryItem()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 1.89M);

            EachesGroceryItemOrderFactory factory =
                new EachesGroceryItemOrderFactory();

            IGroceryItemOrder order = factory.CreateOrder(item);

            Assert.IsTrue(order is EachesGroceryItemOrder);
            EachesGroceryItemOrder eachesOrder = ((EachesGroceryItemOrder)order);

            Assert.AreEqual(item, eachesOrder.Item);
            Assert.AreEqual(1, eachesOrder.Count);
        }
        public void CreateOrder_GetsCountFromCountSelector_WhenFactoryCreatedWithCountSelector()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 1.89M);

            Mock <ICountSelector> countSelectorMock = new Mock <ICountSelector>();

            countSelectorMock.Setup(cs => cs.SelectCount(item)).Returns(9);

            EachesGroceryItemOrderFactory factory =
                new EachesGroceryItemOrderFactory(countSelectorMock.Object);

            IGroceryItemOrder order = factory.CreateOrder(item);

            Assert.IsTrue(order is EachesGroceryItemOrder);
            EachesGroceryItemOrder eachesOrder = ((EachesGroceryItemOrder)order);

            Assert.AreEqual(item, eachesOrder.Item);
            Assert.AreEqual(9, eachesOrder.Count);
        }
Exemple #14
0
        public void RemovingEachesOrder_InvalidatesSpecial()
        {
            decimal           priceForThree = 5.00M;
            EachesGroceryItem soup          = new EachesGroceryItem("soup", 2.00M)
            {
                Special = new BuyNForXEachesGroceryItemSpecial(3, priceForThree)
            };

            CheckoutCart cart = new CheckoutCart();

            for (int i = 0; i < 3; i++)
            {
                cart.Orders.Add(new EachesGroceryItemOrder(soup, 1));
            }

            Assert.AreEqual(priceForThree, cart.TotalPrice);
            cart.Orders.Remove(cart.Orders.Last());
            Assert.AreEqual(4.00M, cart.TotalPrice);
        }
        public void CalculatePurchasePrice_UsesOriginalPrice_IfNoMarkdownOrSpecialWasSet()
        {
            EachesGroceryItem item = new EachesGroceryItem("soup", 2.00M);

            Assert.AreEqual(10.00M, item.CalculatePurchasePrice(5));
        }