コード例 #1
0
        private Buyer CreateMonitoringBuyer(string buyerName, int numberInStock = 100, int numberToBuy = 10)
        {
            var buyer = new Buyer(buyerName, 100, numberToBuy);

            buyer.Process(StockEvent.Price(200, numberInStock));
            return(buyer);
        }
コード例 #2
0
        public void Closed_buyer_does_not_react_to_further_messages()
        {
            Buyer buyer = CreateClosedBuyer(maximumPrice: 10);

            StockCommand command = buyer.Process(StockEvent.Price(10, 10));

            command.ShouldEqual(StockCommand.None());
            buyer.Snapshot.State.ShouldEqual(BuyerState.Closed);
        }
コード例 #3
0
        public void Buyer_attempts_to_buy_maximum_amount_available()
        {
            Buyer buyer = CreateJoiningBuyer(maximumPrice: 50, numberToBuy: 10);

            StockCommand command = buyer.Process(StockEvent.Price(10, 5));

            command.ShouldEqual(StockCommand.Buy(10, 5));
            buyer.SnapshotShouldEqual(BuyerState.Buying, 10, 5, 0);
        }
コード例 #4
0
        public void Buyer_buys_when_price_event_with_appropriate_price_arrives()
        {
            Buyer buyer = CreateJoiningBuyer(maximumPrice: 50);

            StockCommand command = buyer.Process(StockEvent.Price(10, 5));

            command.ShouldEqual(StockCommand.Buy(10, 1));
            buyer.SnapshotShouldEqual(BuyerState.Buying, 10, 5, 0);
        }
コード例 #5
0
        public void Buyer_does_not_buy_when_price_event_with_too_high_price_arrives()
        {
            var buyer = CreateJoiningBuyer(maximumPrice: 10);

            StockCommand command = buyer.Process(StockEvent.Price(20, 5));

            command.ShouldEqual(StockCommand.None());
            buyer.SnapshotShouldEqual(BuyerState.Monitoring, 20, 5, 0);
        }
コード例 #6
0
        public void Price_method_returns_a_price_event()
        {
            StockEvent stockEvent = StockEvent.Price(10, 15);

            stockEvent.Type.ShouldEqual(StockEventType.Price);
            stockEvent.CurrentPrice.ShouldEqual(10);
            stockEvent.NumberInStock.ShouldEqual(15);
            stockEvent.ToString().ShouldEqual("Event: PRICE; CurrentPrice: 10; NumberInStock: 15;");
        }