Skip to content
Permalink
Browse files

RoomMap - ConnectRoomToItself

  • Loading branch information...
bobbymcr committed Dec 16, 2018
1 parent 704c8e2 commit 16ea4b6c12b8e47d79502faa419f8a8832a8187a
Showing with 23 additions and 2 deletions.
  1. +1 −2 core/src/RoomMap.cs
  2. +22 −0 core/test/RoomMapTest.cs
@@ -69,7 +69,7 @@ private void Go(string direction)

private void Next(Point next)
{
if (this.current != next)
if (next != null)
{
this.current?.Leave();
this.current = next;
@@ -116,7 +116,6 @@ Point IPointPrivate.Go(string direction)
if (!this.targets.TryGetValue(direction, out Point target))
{
this.bus.Output($"You can't go {direction}.");
target = this;
}

return target;
@@ -224,5 +224,27 @@ public void ConnectToBadPoint()
.Which.ParamName.Should().Be("target");
}
}

[Fact]
public void ConnectRoomToItself()
{
MessageBus bus = new MessageBus();
List<string> messages = new List<string>();
bus.Subscribe<OutputMessage>(m => messages.Add(m.Text));
using (RoomMap map = new RoomMap(bus))
{
var p1 = map.Add(new TestRoom(bus));

p1.ConnectTo(p1, "north");
map.Start(p1);
bus.Send(new GoMessage("south"));
bus.Send(new GoMessage("north"));

messages.Should().Equal(
"You are in a test room.",
"You can't go south.",
"You are in a test room.");
}
}
}
}

0 comments on commit 16ea4b6

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