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); }
public void Buyer_closes_when_it_buys_enough_items() { Buyer buyer = CreateMonitoringBuyer("Buyer", numberToBuy: 5); StockCommand command = buyer.Process(StockEvent.Purchase("Buyer", 5)); command.ShouldEqual(StockCommand.None()); buyer.Snapshot.State.ShouldEqual(BuyerState.Closed); }
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); }
public void Closes_when_item_closes() { var buyer = CreateJoiningBuyer(); StockCommand command = buyer.Process(StockEvent.Close()); command.ShouldEqual(StockCommand.None()); buyer.SnapshotShouldEqual(BuyerState.Closed, 0, 0, 0); }
public void Buyer_does_not_react_to_a_purchase_event_related_to_another_buyer() { Buyer buyer = CreateMonitoringBuyer("Buyer"); StockCommand command = buyer.Process(StockEvent.Purchase("Some other buyer", 1)); command.ShouldEqual(StockCommand.None()); buyer.Snapshot.State.ShouldEqual(BuyerState.Monitoring); buyer.Snapshot.BoughtSoFar.ShouldEqual(0); }
public void Buyer_updates_items_bought_so_far_when_purchase_event_with_the_same_user_name_arrives() { Buyer buyer = CreateMonitoringBuyer("name", numberInStock: 10); StockCommand command = buyer.Process(StockEvent.Purchase("name", 1)); command.ShouldEqual(StockCommand.None()); buyer.Snapshot.State.ShouldEqual(BuyerState.Monitoring); buyer.Snapshot.BoughtSoFar.ShouldEqual(1); buyer.Snapshot.NumberInStock.ShouldEqual(9); }
private void StockMessageRecieved(string message) { StockEvent stockEvent = StockEvent.From(message); StockCommand stockCommand = _buyer.Process(stockEvent); if (stockCommand != StockCommand.None()) { _connection.SendMessage(stockCommand.ToString()); } _repository.Save(ItemId, _buyer); Notify(nameof(CurrentPrice)); Notify(nameof(NumberInStock)); Notify(nameof(BoughtSoFar)); Notify(nameof(State)); }