public void WinOutputsValidMessages() { var frontEnd = new ConsoleUI(); var moves = 10; var output = new StringBuilder(); string nameInput = "myName is UnitTest also"; RankListRecord reccord = null; var writer = new StringWriter(output); using (writer) { Console.SetOut(writer); var nameReader = new StringReader(nameInput); using (nameReader) { Console.SetIn(nameReader); reccord = frontEnd.Win(moves); } } var outputAsString = output.ToString(); string actualFirstLine = null; var reader = new StringReader(outputAsString); using (reader) { actualFirstLine = reader.ReadLine(); } var expectedFirstLine = "Congratulations! You completed the game in 10 moves."; Assert.AreEqual(expectedFirstLine, actualFirstLine); }
public void CompareToEqualResult() { var record1 = new RankListRecord(10, "pesho"); var record2 = new RankListRecord(10, "gosho"); int result = record1.CompareTo(record2); Assert.AreEqual(result, 0); }
public void CompareToHigherResult() { var recordWithHigherScore = new RankListRecord(10, "pesho"); var recordWithLowerScore = new RankListRecord(3, "gosho"); int result = recordWithHigherScore.CompareTo(recordWithLowerScore); Assert.AreEqual(result, 1); }
public void RankListReccordToFormattedString() { var reccord = new RankListRecord(15, "A happy name"); var actual = reccord.ToFormattedString(); var expected = ". A happy name - 15 moves."; Assert.AreEqual(expected, actual); }
public void RankListReccordToString() { var reccord = new RankListRecord(15, "A happy name"); var actual = reccord.ToString(); var expected = "A happy name, 15"; Assert.AreEqual(expected, actual); }
/// <summary> /// Informs the user that the game is over. /// Prompts the user to enter their name /// </summary> /// <param name="movesCount"></param> /// <returns>A RankListReccord with the user's name and movesCount</returns> public RankListRecord Win(int movesCount) { Console.WriteLine("Congratulations! You completed the game in {0} moves.", movesCount); string playerName = string.Empty; do { Console.Write("Enter your name(between 3 and 30 characters): "); playerName = Console.ReadLine(); }while (playerName.Length < 3 || playerName.Length > 30); // TO PUT THIS IN A BETTER POSITION! //// Console.WriteLine("\nNEW GAME!\n"); var newReccord = new RankListRecord(movesCount, playerName); return(newReccord); }
public void WinResturnsValidReccord() { var frontEnd = new ConsoleUI(); var moves = 10; string input = "myName is UnitTest"; RankListRecord reccord = null; var reader = new StringReader(input); using (reader) { Console.SetIn(reader); reccord = frontEnd.Win(moves); } bool movesCorrect = (moves == reccord.Value); bool nameCorrect = (input == reccord.Name); Assert.IsTrue(movesCorrect && nameCorrect); }
public void RankListRecordCreateWithInvalidName() { var record = new RankListRecord(6, " "); }
public void RankListRecordCreateWithInvalidValue() { var record = new RankListRecord(0, "pesho"); }