Exemple #1
0
        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.");
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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");
        }
Exemple #4
0
        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");
        }
Exemple #5
0
        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!");
        }