Skip to content
Permalink
Browse files

Room - ProcessRoomAction

  • Loading branch information...
bobbymcr committed Dec 22, 2018
1 parent f8828f9 commit c9f0579d238e321fffd0346961955ceea92b0a79
Showing with 38 additions and 0 deletions.
  1. +18 −0 core/src/Messages/RoomActionMessage.cs
  2. +2 −0 core/src/Room.cs
  3. +18 −0 core/test/RoomTest.cs
@@ -0,0 +1,18 @@
// <copyright file="RoomActionMessage.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure.Messages
{
using System;

public sealed class RoomActionMessage
{
public RoomActionMessage(Action<Room> act)
{
this.Act = act;
}

public Action<Room> Act { get; }
}
}
@@ -16,6 +16,7 @@ public abstract class Room

private IDisposable process;
private IDisposable look;
private IDisposable act;

protected Room(MessageBus bus)
{
@@ -36,6 +37,7 @@ public void Enter()
this.items.Activate();
this.process = this.bus.Subscribe<SentenceMessage>(m => this.Process(m));
this.look = this.bus.Subscribe<LookItemMessage>(m => this.LookAt(m.Noun));
this.act = this.bus.Subscribe<RoomActionMessage>(m => m.Act(this));
this.EnterCore();
this.Look(new Word(string.Empty, string.Empty));
}
@@ -485,6 +485,24 @@ public void ProcessQuit()
quitText.Should().Be("You quit. Game over.");
}

[Fact]
public void ProcessRoomAction()
{
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();
bus.Send(new RoomActionMessage(r => r.Add("coin", new TestCoin(bus))));
bus.Send(new SentenceMessage(new Word("look", "LOOK"), new Word(string.Empty, string.Empty)));

output.Should().Equal(
"You are in a test room.",
"You are in a test room.",
"There is a coin here.");
}

private static void TestSend(Word verb, Word noun, string expectedOutput)
{
MessageBus bus = new MessageBus();

0 comments on commit c9f0579

Please sign in to comment.
You can’t perform that action at this time.