public void ActivateTwice() { MessageBus bus = new MessageBus(); Items items = new Items(bus); items.Activate(); Action act = () => items.Activate(); act.Should().Throw <InvalidOperationException>().WithMessage("Cannot Activate again."); }
public void LookCountsItems() { MessageBus bus = new MessageBus(); Items items = new Items(bus); items.Activate(); items.Add("one", new TestItem(bus)); items.Add("two", new TestItem(bus)); int count = items.Look("{0}"); count.Should().Be(2); }
public void SkipCustomActionForItemNotPresent() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); Items items = new Items(bus); items.Add("ball", new TestItem(bus)); items.Activate(); bus.Subscribe <SentenceMessage>(m => messages.Add($"Don't {m.Verb} the {m.Noun}")); bus.Send(new SentenceMessage(new Word("throw", "TOSS"), new Word("party", "PARTY"))); messages.Should().ContainSingle().Which.Should().Be("Don't TOSS the PARTY"); }
public void SkipCustomActionForItemThatHasNoActions() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); Items items = new Items(bus); items.Add("ball", new TestItemNoActions(bus)); items.Activate(); bus.Subscribe <SentenceMessage>(m => messages.Add($"Don't {m.Verb} the {m.Noun}")); bus.Send(new SentenceMessage(new Word("eat", "CONSUME"), new Word("ball", "BALL"))); messages.Should().ContainSingle().Which.Should().Be("Don't CONSUME the BALL"); }
public void DoCustomActionForItem() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); Items items = new Items(bus); items.Add("ball", new TestItem(bus)); items.Activate(); bus.Subscribe <SentenceMessage>(m => messages.Add($"Don't {m.Verb} the {m.Noun}")); bus.Send(new SentenceMessage(new Word("throw", "TOSS"), new Word("ball", "BASEBALL"))); messages.Should().ContainSingle().Which.Should().Be("You threw the BASEBALL!"); }