Beispiel #1
0
 public Buyer(string itemId, int maximumPrice, int numberToBuy, IStockItem stockItem)
 {
     _numberToBuy  = numberToBuy;
     _maximumPrice = maximumPrice;
     _stockItem    = stockItem;
     Snapshot      = BuyerSnapshot.Joining(itemId);
 }
Beispiel #2
0
 public void ItemPurchased(int numberSold, PurchaseSource purchaseSource)
 {
     if (purchaseSource == PurchaseSource.FromBuyer)
     {
         Snapshot = Snapshot.Bought(numberSold);
         if (Snapshot.BoughtSoFar >= _numberToBuy)
         {
             Snapshot = Snapshot.Closed();
         }
         NotifyChange();
     }
 }
Beispiel #3
0
        public void CurrentPrice(int price, int numberInStock)
        {
            if (Snapshot.State == BuyerState.Closed)
            {
                return;
            }

            if (price > _maximumPrice)
            {
                Snapshot = Snapshot.Monitoring(price, numberInStock);
            }
            else
            {
                int numberToBuy = Math.Min(numberInStock, _numberToBuy);
                _stockItem.Buy(price, numberToBuy);
                Snapshot = Snapshot.Buying(price, numberInStock);
            }
            NotifyChange();
        }
Beispiel #4
0
 public void ItemClosed()
 {
     Snapshot = Snapshot.Closed();
     NotifyChange();
 }