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_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); }
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_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); }
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); }
public void Two_commands_are_equal_if_their_contents_match() { StockCommand command1 = StockCommand.Buy(123, 10); StockCommand command2 = StockCommand.Buy(123, 10); bool areEqual1 = command1.Equals(command2); bool areEqual2 = command1 == command2; bool areEqual3 = command1.GetHashCode() == command2.GetHashCode(); areEqual1.ShouldBeTrue(); areEqual2.ShouldBeTrue(); areEqual3.ShouldBeTrue(); }
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)); }
public void Buy_command_is_of_appropriate_content() { StockCommand command = StockCommand.Buy(123, 10); command.ToString().ShouldEqual("Command: BUY; Price: 123; Number: 10"); }