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 Orders_CanAddEachesItem() { EachesGroceryItemOrder eachesOrder = new EachesGroceryItemOrder(null, 3); CheckoutCart cart = new CheckoutCart(); Assert.AreEqual(0, cart.Orders.Count); cart.Orders.Add(eachesOrder); Assert.AreEqual(1, cart.Orders.Count); }
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)); }
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); }
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); }
public void Price_CalculatesUsingItemMethod() { Mock <IGroceryItem <int> > itemMock = new Mock <IGroceryItem <int> >(); itemMock.Setup(item => item.CalculatePurchasePrice(It.IsAny <int>())) .Returns((int count) => count * 1.00M); EachesGroceryItemOrder order = new EachesGroceryItemOrder(itemMock.Object, 3); Assert.AreEqual(3.00M, order.Price); }
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_DefaultsToOneForEachesItems() { IGroceryItemOrderFactory orderFactory = new AggregateGroceryItemOrderFactory( new EachesGroceryItemOrderFactory(), new WeighedGroceryItemOrderFactory() ); string itemName = "soup"; GroceryItemScanner scanner = new GroceryItemScanner(orderFactory); scanner.Items.Add(new EachesGroceryItem(itemName, 1.89M)); EachesGroceryItemOrder soupOrder = (EachesGroceryItemOrder)scanner.CreateOrder(itemName); Assert.AreEqual(1, soupOrder.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); }