public void TestProcessInputCommandInvalid() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(closedLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "ninja"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); StringBuilder expectedString = new StringBuilder(); expectedString.Append("Invalid command"); expectedString.Append(Environment.NewLine); expectedString.Append("\nEnter your move (L=left, R=right, U=up, D=down):"); expectedString.Append("Good Bye!"); expectedString.Append(Environment.NewLine); string expected = expectedString.ToString(); string output = sw.ToString(); output = output.Substring(output.Length - 77); Assert.AreEqual<string>(expected, output); } }
public Engine() { labyrinth = new LabyrinthBoard(); topScores = new TopScores(); flagContinue = true; enterMove = "\nEnter your move (L=left, R=right, U=up, D=down):"; welcome = "Welcome to “Labirinth” game. Your goal is to escape. \nUse 'top' to view the top scoreboard, \n'restart' to start a new game \nand 'exit' to quit the game.\n"; }
public void TestCheckIdScoreIsHighEnoughHighScore() { scores = new TopScores(); scores.EnterTopScore("ninja", 6); scores.EnterTopScore("ganio", 4); scores.EnterTopScore("ganio", 4); scores.EnterTopScore("sando", 5); scores.EnterTopScore("ninja", 5); bool isTrue = scores.CheckIdScoreIsHighEnough(3); Assert.AreEqual(true, isTrue); }
public void TestEnterTopScoreEmptyName() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); scores = new TopScores(); scores.EnterTopScore("", 0); scores.ShowTopScores(); string expected = "1 - 0\r\n"; string output = sw.ToString(); Assert.AreEqual<string>(expected, output); } }
public void TestProcessInputCommandExit() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(closedLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "exit"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); StringBuilder expectedString = new StringBuilder(); expectedString.Append("Good Bye!"); expectedString.Append(Environment.NewLine); string expected = expectedString.ToString(); string output = sw.ToString(); output = output.Substring(output.Length - 11); Assert.AreEqual<string>(expected, output); } }
public void TestProcessInputCommandRestart() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(closedLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "restart"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); string expected = testBoard.ToString(); string output = testEngine.Labyrinth.ToString(); Assert.AreNotEqual<string>(expected, output); } }
public void TestWalkInLabirinth() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(mockLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "L"; userInterface.SimulateWin = true; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); StringBuilder expectedString = new StringBuilder(); expectedString.Append("Congratulations! You escaped in 3 moves."); expectedString.Append(Environment.NewLine); expectedString.Append("Please, enter your name:"); string expected = expectedString.ToString(); string output = sw.ToString(); output = output.Substring(output.Length - 395,66); Assert.AreEqual<string>(expected, output); } }
public void TestStartMethodForCorrectOutput() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(mockLabyrinth); MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "exit"; testEngine = new Engine(testBoard,scores,userInterface); testEngine.Start(); string welcomeString = "Welcome to “Labirinth” game. Your goal is to escape. \nUse 'top' to view the top scoreboard, \n'restart' to start a new game \nand 'exit' to quit the game.\n"; string boardString = testBoard.ToString(); string enterMoveString = "\nEnter your move (L=left, R=right, U=up, D=down):"; StringBuilder startMethodOutput = new StringBuilder(); startMethodOutput.Append(welcomeString); startMethodOutput.Append(Environment.NewLine); startMethodOutput.Append(boardString); startMethodOutput.Append(enterMoveString); startMethodOutput.Append("Good Bye!"); startMethodOutput.Append(Environment.NewLine); string expected = startMethodOutput.ToString(); string output = sw.ToString(); Assert.AreEqual<string>(expected, output); } }
public void TestProcessInputDirectionUp() { TopScores scores = new TopScores(); MockLabyrinthBoard testBoard = new MockLabyrinthBoard(mockLabyrinth); int positionY = testBoard.PiecePositionRow; MockingUserInterface userInterface = new MockingUserInterface(); userInterface.FakeInput = "U"; testEngine = new Engine(testBoard, scores, userInterface); testEngine.Start(); Assert.AreEqual<int>(positionY - 1, testEngine.Labyrinth.PiecePositionRow); }
public Engine(LabyrinthBoard labyrinthBoard, TopScores scores, UserInput userInterface) { this.Labyrinth = labyrinthBoard; this.TopScores = scores; this.UserInterface = userInterface; }
public void TestEnterTopScoreNotHighEnough() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); scores = new TopScores(); scores.EnterTopScore("", 3); scores.EnterTopScore("", 4); scores.EnterTopScore("", 4); scores.EnterTopScore("", 4); scores.EnterTopScore("", 4); string caught = ""; try { scores.EnterTopScore("", 4); } catch (InvalidOperationException ioe) { caught = "exception caught"; } string expected = "exception caught"; Assert.AreEqual<string>(expected, caught); } }
public void TestDefaultConstructorForExceptions() { scores = new TopScores(); // Checking for exceptions. }
public void TestShowTopScoresEmpty() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); scores = new TopScores(); scores.ShowTopScores(); string expected = "The scoreboard is empty.\r\n"; string output = sw.ToString(); Assert.AreEqual<string>(expected, output); } }
public void TestShowTopScoresCorrect() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); scores = new TopScores(); scores.EnterTopScore("ninja", 6); scores.EnterTopScore("ganio", 4); scores.EnterTopScore("ganio", 4); scores.EnterTopScore("sando", 5); scores.EnterTopScore("ninja", 5); scores.EnterTopScore("sando", 3); scores.ShowTopScores(); StringBuilder sBuild = new StringBuilder(); sBuild.Append("1 - sando 3\r\n"); sBuild.Append("2 - ganio 4\r\n"); sBuild.Append("3 - ganio 4\r\n"); sBuild.Append("4 - sando 5\r\n"); sBuild.Append("5 - ninja 5\r\n"); string expected = sBuild.ToString(); string output = sw.ToString(); Assert.AreEqual<string>(expected, output); } }