public void Scan_ReturnsCorrespondingItem_IfExists() { GroceryItemScanner scanner = new GroceryItemScanner(null); IGroceryItem expected = new WeighedGroceryItem("bananas", 2.38M); scanner.Items.Add(expected); IGroceryItem result = scanner.Scan("bananas"); Assert.AreEqual(expected, result); }
public IGroceryItemOrder CreateOrder(IGroceryItem item) { WeighedGroceryItem weighedItem = item as WeighedGroceryItem; if (weighedItem == null) { throw new InvalidGroceryItemTypeException(); } decimal weight = WeightSelector.SelectWeight(weighedItem); return(new WeighedGroceryItemOrder(weighedItem, weight)); }
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 IGroceryItemOrder CreateOrder(IGroceryItem item) { foreach (IGroceryItemOrderFactory factory in Factories) { try { return(factory.CreateOrder(item)); } catch (InvalidGroceryItemTypeException) { // when a factory throws an exception, // ignore the exception and try the next factory } } throw new InvalidGroceryItemTypeException(); }
public IGroceryItemOrder CombineOrdersForItem(IGroceryItem item) { return(OrdersCombinedByItem.First(combinedOrder => combinedOrder.Item == item)); }
public GroceryItemOrderFake(IGroceryItem item, decimal price) { this.Item = item; this.Price = price; }
public int SelectCount(IGroceryItem <int> item) { return(StaticCount); }
public GroceryItemOrder(IGroceryItem <TQuantity> item, TQuantity quantity) { this.Item = item; this.Quantity = quantity; }
public WeighedGroceryItemOrder(IGroceryItem <decimal> item, decimal weight) : base(item, weight) { }
public decimal SelectWeight(IGroceryItem <decimal> item) { return(StaticWeight); }
public EachesGroceryItemOrder(IGroceryItem <int> item, int count = 1) : base(item, count) { }
public IGroceryItemOrder CreateOrder(string name) { IGroceryItem item = Scan(name); return(OrderFactory.CreateOrder(item)); }