public void JoinGameShouldSubscribeItselfToTheGame() { var game = new Mock<IGame>(); game.Setup(x => x.Subscribe(It.IsAny<IPlayer>())).Verifiable(); var player = new ComputerPlayer(PlayerName, Mark.Cross); player.Join(game.Object); game.Verify(x => x.Subscribe(player), Times.Once()); }
public void DisposeShouldLeaveTheGame() { var trigger = new ManualResetEvent(false); var ticket = new Mock<IDisposable>(); ticket.Setup(x => x.Dispose()) .Callback(() => trigger.Set()); var game = new Mock<IGame>(); game.Setup(x => x.Subscribe(It.IsAny<IPlayer>())) .Returns(ticket.Object); using (var player = new ComputerPlayer(PlayerName, Mark.Cross)) { player.Join(game.Object); } trigger.WaitOne(); ticket.Verify(x => x.Dispose(), Times.Once()); }