public void LeaveTwice() { Room room = new TestRoom(new MessageBus()); room.Enter(); room.Leave(); Action act = () => room.Leave(); act.Should().Throw <InvalidOperationException>().WithMessage("Cannot Leave before Enter."); }
public void UnsubscribeOnLeave() { MessageBus bus = new MessageBus(); Room room = new TestRoom(bus); string lastOutput = null; Action <OutputMessage> subscriber = m => lastOutput = m.Text; room.Enter(); room.Leave(); bus.Subscribe(subscriber); bus.Send(new SentenceMessage(new Word("hello", "hello"), new Word("world", "world"))); lastOutput.Should().BeNull(); }
public void ProcessLookItemAfterLeave() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); Room room = new TestRoom(bus); room.Enter(); room.Leave(); bus.Send(new LookItemMessage(new Word("key", "KEY"))); messages.Should().Equal("You are in a test room."); }
public void ProcessRoomActionAfterLeave() { MessageBus bus = new MessageBus(); List <string> output = new List <string>(); bus.Subscribe <OutputMessage>(m => output.Add(m.Text)); Room room = new TestRoom(bus); room.Enter(); room.Leave(); bus.Send(new ActionMessage <Room>(r => r.Add("coin", new TestCoin(bus)))); room.Enter(); output.Should().Equal( "You are in a test room.", "You are in a test room."); }
public void ProcessCustomItemActionAfterLeave() { MessageBus bus = new MessageBus(); string lastOutput = null; Action <OutputMessage> subscriber = m => lastOutput = m.Text; bus.Subscribe(subscriber); TestRoom room = new TestRoom(bus); room.Add("key", new TestKey(bus)); room.Add("coin", new TestCoin(bus)); room.Enter(); room.Leave(); bus.Send(new SentenceMessage(new Word("flip", "FLIP"), new Word("coin", "COIN"))); lastOutput.Should().Be("There is a coin here."); }