public void ProcessTakeUnavailableItem() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); Item actualItem = null; bus.Subscribe <TakeItemMessage>(m => { messages.Add($"You {m.Verb} the {m.Noun}!"); actualItem = m.Item; }); TestRoom room = new TestRoom(bus); room.Add("key", new TestKey(bus, false)); room.Add("coin", new TestCoin(bus)); room.Enter(); bus.Send(new SentenceMessage(new Word("take", "TAKE"), new Word("key", "KEY"))); bus.Send(new SentenceMessage(new Word("look", "LOOK"), new Word(string.Empty, string.Empty))); messages.Should().Equal( "You are in a test room.", "There is a key here.", "There is a coin here.", "I won't let you take this!", "You are in a test room.", "There is a key here.", "There is a coin here."); actualItem.Should().BeNull(); }
public void ProcessUnknownCustomItemAction() { 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(); bus.Send(new SentenceMessage(new Word("flip", "FLIP"), new Word("key", "KEY"))); lastOutput.Should().Be("You can't do that."); }
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."); }
public void AddTwoItems() { MessageBus bus = new MessageBus(); List <string> output = new List <string>(); Action <OutputMessage> subscriber = m => output.Add(m.Text); bus.Subscribe(subscriber); TestRoom room = new TestRoom(bus); room.Add("key", new TestKey(bus)); room.Add("coin", new TestCoin(bus)); room.Enter(); output.Should().Equal( "You are in a test room.", "There is a key here.", "There is a coin here."); }
public void ProcessLookItem() { MessageBus bus = new MessageBus(); string lastOutput = null; Action <OutputMessage> subscriber = m => lastOutput = m.Text; bus.Subscribe(subscriber); Room room = new TestRoom(bus); room.Add("key", new TestKey(bus)); room.Enter(); bus.Send(new SentenceMessage(new Word("look", "LOOK"), new Word("key", "KEY"))); lastOutput.Should().Be("It is solid gold."); }
public void RemoveOneItem() { MessageBus bus = new MessageBus(); List <string> output = new List <string>(); Action <OutputMessage> subscriber = m => output.Add(m.Text); bus.Subscribe(subscriber); TestRoom room = new TestRoom(bus); Item expected = new TestKey(bus); room.Add("key", expected); Item removed = room.Remove("key"); room.Enter(); output.Should().Equal( "You are in a test room."); removed.Should().BeSameAs(expected); }