예제 #1
0
        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();
        }
예제 #2
0
        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.");
        }
예제 #3
0
        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.");
        }
예제 #4
0
        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.");
        }
예제 #5
0
        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.");
        }
예제 #6
0
        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);
        }