Exemplo n.º 1
0
        private AuctionCommand ProcessCloseEvent()
        {
            if (Snapshot.State == SniperState.Winning)
            {
                Snapshot = Snapshot.Won();
            }
            else
            {
                Snapshot = Snapshot.Lost();
            }

            return(AuctionCommand.None());
        }
Exemplo n.º 2
0
        private AuctionCommand ProcessPriceEvent(int currentPrice, int increment, string bidder)
        {
            if (Bidder == bidder)
            {
                Snapshot = Snapshot.Winning(currentPrice);
                return(AuctionCommand.None());
            }

            int newBid = currentPrice + increment;

            if (newBid > StopPrice)
            {
                Snapshot = Snapshot.Losing(currentPrice);
                return(AuctionCommand.None());
            }
            else
            {
                Snapshot = Snapshot.Bidding(currentPrice, newBid);
                return(AuctionCommand.Bid(newBid));
            }
        }
Exemplo n.º 3
0
        public AuctionCommand Process(AuctionEvent auctionEvent)
        {
            if (Snapshot.State == SniperState.Failed)
            {
                return(AuctionCommand.None());
            }

            switch (auctionEvent.Type)
            {
            case AuctionEventType.Price:
                return(ProcessPriceEvent(auctionEvent.CurrentPrice, auctionEvent.Increment, auctionEvent.Bidder));

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

            case AuctionEventType.Unknown:
                return(ProcessUnknownEvent());

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 4
0
 private AuctionCommand ProcessUnknownEvent()
 {
     Snapshot = Snapshot.Failed();
     return(AuctionCommand.None());
 }