示例#1
0
 private StockCommand ProcessPurchaseEvent(string buyerName, int numberSold)
 {
     if (BuyerName == buyerName)
     {
         Snapshot = Snapshot.Bought(numberSold);
         if (Snapshot.BoughtSoFar >= NumberToBuy)
         {
             Snapshot = Snapshot.Closed();
         }
     }
     return(StockCommand.None());
 }
示例#2
0
        private StockCommand ProcessPriceEvent(int currentPrice, int numberInStock)
        {
            if (currentPrice > MaximumPrice)
            {
                Snapshot = Snapshot.Monitoring(currentPrice, numberInStock);
                return(StockCommand.None());
            }

            Snapshot = Snapshot.Buying(currentPrice, numberInStock);

            int numberToBuy = Math.Min(numberInStock, NumberToBuy);

            return(StockCommand.Buy(currentPrice, numberToBuy));
        }
示例#3
0
        public StockCommand Process(StockEvent stockEvent)
        {
            if (Snapshot.State == BuyerState.Closed)
            {
                return(StockCommand.None());
            }

            switch (stockEvent.Type)
            {
            case StockEventType.Price:
                return(ProcessPriceEvent(stockEvent.CurrentPrice, stockEvent.NumberInStock));

            case StockEventType.Purchase:
                return(ProcessPurchaseEvent(stockEvent.BuyerName, stockEvent.NumberSold));

            case StockEventType.Close:
                return(ProcessCloseEvent());

            default:
                throw new InvalidOperationException();
            }
        }
示例#4
0
 private StockCommand ProcessCloseEvent()
 {
     Snapshot = Snapshot.Closed();
     return(StockCommand.None());
 }