public void MultipleMoveSequencesAreRun() { var game = new GameChallenge(Output.Object); game.Play(ValidSettings, "[[\"Rotate\"],[\"Rotate\"],[\"Rotate\"]]"); Output.Verify(x => x.Start(It.IsAny <int>()), Times.Exactly(3)); }
public void InvalidMovesOutputsAnError() { var game = new GameChallenge(Output.Object); game.Play(ValidSettings, "[[],[],[]]"); Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Error loading game moves from file, no moves defined"))), Times.Once); }
public void ValidSettingsRunASequence() { var game = new GameChallenge(Output.Object); game.Play(ValidSettings, ValidMoves); Output.Verify(x => x.Start(It.IsAny <int>()), Times.Once); }
public void InvalidSettingsOutputsAnError() { var game = new GameChallenge(Output.Object); game.Play("{}", ValidMoves); Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Settings contain invalid values"))), Times.Once); }
public void MalformedMovesJsonOutputsAnError() { var game = new GameChallenge(Output.Object); game.Play(ValidSettings, "abc"); Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Error loading game moves from file, please check they are in correct format"))), Times.Once); }
public void MalformedSettingsJsonOutputsAnError() { var game = new GameChallenge(Output.Object); game.Play("abc", ValidMoves); Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Could not load settings from file, please check that data is correct format"))), Times.Once); }
static void Main(string[] args) { if (args.Length != 2) { throw new ArgumentException("Game should have at 2 parameters: <settings> file and <moves> files.\nRun: TurtleChallengeCSharp.EXE <SettingsFileName> <MovesFileName>"); } if (!File.Exists(args[0])) { throw new FileNotFoundException("Settings file not found: " + args[0]); } if (!File.Exists(args[1])) { throw new FileNotFoundException("Moves file not found: " + args[1]); } var settingsJson = File.ReadAllText(args[0]); var movesJson = File.ReadAllText(args[1]); var game = new GameChallenge(); game.Play(settingsJson, movesJson); Console.WriteLine("Press any key..."); Console.ReadKey(); }
public void SuccessResult() { var game = new GameChallenge(Output.Object); var settings = new Settings { StartPosition = new Coordinates { X = 1, Y = 1 }, StartDirection = Direction.North, Exit = new Coordinates { X = 1, Y = 2 }, Height = 3, Width = 3, Mines = new List <Coordinates> { new Coordinates { X = 0, Y = 0 } } }; game.Play(JsonConvert.SerializeObject(settings), "[[\"Move\"]]"); Output.Verify(x => x.Won(), Times.Once); }
public void MoveUpdatesPosition(Direction startDirection, int expectedX, int expectedY) { var game = new GameChallenge(Output.Object); var settings = new Settings { StartPosition = new Coordinates { X = 1, Y = 1 }, StartDirection = startDirection, Exit = new Coordinates { X = 2, Y = 2 }, Height = 3, Width = 3, Mines = new List <Coordinates> { new Coordinates { X = 1, Y = 2 } } }; game.Play(JsonConvert.SerializeObject(settings), "[[\"Move\"]]"); Output.Verify(x => x.Moved(It.Is <Coordinates>(m => m.Y == expectedY && m.X == expectedX)), Times.Once); }
public void RoteUpdatesDirection(Direction startDirection, Direction expectedDirection) { var game = new GameChallenge(Output.Object); var settings = new Settings { StartPosition = new Coordinates { X = 1, Y = 1 }, StartDirection = startDirection, Exit = new Coordinates { X = 2, Y = 2 }, Height = 3, Width = 3, Mines = new List <Coordinates> { new Coordinates { X = 1, Y = 2 } } }; game.Play(JsonConvert.SerializeObject(settings), "[[\"Rotate\"]]"); Output.Verify(x => x.Rotated(It.Is <Direction>(m => m == expectedDirection)), Times.Once); }