public void ConnectTwice() { MessageBus bus = new MessageBus(); using (RoomMap map = new RoomMap(bus)) { RoomMap.Point p1 = map.Add(new TestRoom(bus)); RoomMap.Point p2 = map.Add(new TestRoom(bus)); p1.ConnectTo(p2, "east"); Action act = () => p1.ConnectTo(p2, "east"); act.Should().Throw <InvalidOperationException>("There is already a connection for 'east'."); } }
public void GoBetweenFourRoomsBothDirections() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); using (RoomMap map = new RoomMap(bus)) { RoomMap.Point nw = map.Add(new TestRoom(bus, "NW")); RoomMap.Point ne = map.Add(new TestRoom(bus, "NE")); RoomMap.Point sw = map.Add(new TestRoom(bus, "SW")); RoomMap.Point se = map.Add(new TestRoom(bus, "SE")); nw.ConnectTo(ne, "east"); nw.ConnectTo(sw, "south"); ne.ConnectTo(nw, "west"); ne.ConnectTo(se, "south"); sw.ConnectTo(se, "east"); sw.ConnectTo(nw, "north"); se.ConnectTo(sw, "west"); se.ConnectTo(ne, "north"); map.Start(nw); bus.Send(new GoMessage("east")); bus.Send(new GoMessage("south")); bus.Send(new GoMessage("west")); bus.Send(new GoMessage("north")); bus.Send(new GoMessage("south")); bus.Send(new GoMessage("east")); bus.Send(new GoMessage("north")); bus.Send(new GoMessage("west")); messages.Should().Equal( "You are in a NW test room.", "You are in a NE test room.", "You are in a SE test room.", "You are in a SW test room.", "You are in a NW test room.", "You are in a SW test room.", "You are in a SE test room.", "You are in a NE test room.", "You are in a NW test room."); } }
public void ConnectTwoRoomsOneDirection() { MessageBus bus = new MessageBus(); using (RoomMap map = new RoomMap(bus)) { RoomMap.Point p1 = map.Add(new TestRoom(bus)); RoomMap.Point p2 = map.Add(new TestRoom(bus)); Action act = () => p1.ConnectTo(p2, "east"); act.Should().NotThrow(); } }
public void GoBetweenTwoRooms() { MessageBus bus = new MessageBus(); List <string> messages = new List <string>(); bus.Subscribe <OutputMessage>(m => messages.Add(m.Text)); using (RoomMap map = new RoomMap(bus)) { RoomMap.Point p1 = map.Add(new TestRoom(bus, "red")); RoomMap.Point p2 = map.Add(new TestRoom(bus, "green")); p1.ConnectTo(p2, "east"); p2.ConnectTo(p1, "west"); map.Start(p1); bus.Send(new GoMessage("east")); bus.Send(new GoMessage("west")); messages.Should().Equal( "You are in a red test room.", "You are in a green test room.", "You are in a red test room."); } }