public void CheckIfActionsControllerReadActionMethodReturnsFalseWhenExitCommandCommandIsCalled() { var data = new Data(); var mockednumberGenerator = new Mock<INumberGenerator>(); var mockedScoreboard = new Mock<IScoreboard>(); var mockedActionsReader = new Mock<IActionsReader>(); mockedActionsReader.Setup(x => x.Read()) .Returns("exit"); var mockedNotifier = new Mock<INotifier>(); mockedNotifier.Setup(x => x.Notify( It.IsAny<string>())) .Verifiable(); var mockedCommandsFactory = new Mock<ICommandsFactory>(); mockedCommandsFactory.Setup(x => x.GetCommand( It.IsAny<string>())) .Returns(new EmptyCommand()); var controller = new ActionsController(data, mockedNotifier.Object, mockednumberGenerator.Object, mockedScoreboard.Object, mockedCommandsFactory.Object, mockedActionsReader.Object); controller.Run(); Assert.AreEqual(false, controller.IsRunning); }
public void DisplayMessageCommandShouldCallNotifier() { var mockedNotifier = new Mock<INotifier>(); IDataState data = new Data(); ICommand displayMessage = new DisplayMessageCommand(mockedNotifier.Object, true, ""); displayMessage.Execute(); mockedNotifier.Verify(m => m.Notify(""), Times.Once); }
public void DisplayCommandsListCommandShouldCallNotifier() { var mockedNotifier = new Mock<INotifier>(); IDataState data = new Data(); ICommand displayCommandsList = new DisplayCommandsListCommand(mockedNotifier.Object); displayCommandsList.Execute(); mockedNotifier.Verify(m => m.Notify(It.IsAny<string>()), Times.Once); }
public void QuitGameCommandShouldCallNotifier() { var mockedNotifier = new Mock<INotifier>(); IDataState data = new Data(); ICommand quitGameCommand = new QuitGameCommand(mockedNotifier.Object); quitGameCommand.Execute(); mockedNotifier.Verify(m => m.Notify(It.IsAny<string>()), Times.Once); }
public void WinGameCommandShouldCallNotifier() { var mockedNotifier = new Mock<INotifier>(); var mockedScoreboard = new Mock<IScoreboard>(); IDataState data = new Data(); ICommand winGameCommand = new WinGameCommand(mockedNotifier.Object, mockedScoreboard.Object, data); winGameCommand.Execute(); mockedNotifier.Verify(m => m.Notify(It.IsAny<string>()), Times.Once); }
public void GetCommandShouldCreateEmptyCommandWhenStringIsEmpty() { IDataState data = new Data(); INotifier notifier = new ConsoleNotifier(); INumberGenerator numberGenerator = new RandomNumberGenerator(); var mockedScoreboard = new Mock<IScoreboard>(); var commandsFactory = new CommandsFactory(data, notifier, numberGenerator, mockedScoreboard.Object); var result = (commandsFactory.GetCommand("empty")).ToString(); Assert.AreEqual(result, "BullsAndCows.Helpers.Commands.EmptyCommand"); }
public void GetCommandShouldCreateDisplayMessageCommandWhenStringIsGuessed() { IDataState data = new Data(); data.NumberToGuess = "1234"; INotifier notifier = new ConsoleNotifier(); INumberGenerator numberGenerator = new RandomNumberGenerator(); var mockedScoreboard = new Mock<IScoreboard>(); var commandsFactory = new CommandsFactory(data, notifier, numberGenerator, mockedScoreboard.Object); var result = (commandsFactory.GetCommand("1234")).ToString(); Assert.AreEqual(result, "BullsAndCows.Helpers.Commands.WinGameCommand"); }
public void CheatCommandExecuteShouldUpdateHasCheated() { IDataState data = new Data(); data.NumberToGuess = "1234"; data.CheatHelper = "XXXX"; INotifier notifier = new ConsoleNotifier(); INumberGenerator numberGenerator = new RandomNumberGenerator(); CheatCommand cheatCommand = new CheatCommand(data, notifier, numberGenerator); cheatCommand.Execute(); Assert.AreEqual(true, data.HasCheated); }
public void WinGameCommandShouldCallScoreboardIfNotHasCheated() { INotifier notifier = new ConsoleNotifier(); var mockedScoreboard = new Mock<IScoreboard>(); var data = new Data(); data.HasCheated = false; data.PlayTime = 7; data.GuessAttempts = 3; ICommand winGameCommand = new WinGameCommand(notifier, mockedScoreboard.Object, data); winGameCommand.Execute(); mockedScoreboard.Verify(m => m.AddToScoreboard(data.GuessAttempts, data.PlayTime), Times.Once); }
public void CheatCommandShouldUpdateCheatHelper() { var mockednumberGenerator = new Mock<INumberGenerator>(); mockednumberGenerator.Setup(d => d.Next(0, 4)).Returns(1); IDataState data = new Data(); data.NumberToGuess = "1234"; data.CheatHelper = "XXXX"; INotifier notifier = new ConsoleNotifier(); CheatCommand cheatCommand = new CheatCommand(data, notifier, mockednumberGenerator.Object); cheatCommand.Execute(); Assert.AreEqual("X2XX", data.CheatHelper); }