public void ExpectSaveToFileToCreateFileIfTheFileDoesntExist() { var fileName = "testFile.txt"; var scoreHandler = new ScoresHandler(); scoreHandler.SaveToFile(fileName); Assert.True(File.Exists(fileName)); File.Delete(fileName); }
/// <summary> /// Method that loads the records from a file, and displays them /// </summary> /// <param name="commandInfo">HIGHSCORE Command needed</param> public override void Execute(ICommandInfo commandInfo) { var scoresHandler = new ScoresHandler(); scoresHandler.LoadFromFile(GlobalErrorMessages.SaveRecordstFileName); List<IPlayer> records = (List<IPlayer>)scoresHandler.Reccords; foreach (var record in records) { var recordToString = string.Format("{0} - {1}", record.Nickname, record.Score); this.Printer.PrintLine(recordToString); } Navigation.ReturnExitNavigation(this.engine, new SecondMenuOptions()); }
public void ScoresHandlerRecordsListIsUpdatedWhenAddingRecords(int count) { ScoresHandler scoresHandler = new ScoresHandler(); int expectedListLength = scoresHandler.Reccords.Count + count; for (int i = 0; i < count; i++) { Player player = new Player(string.Format("Petkan{0}", i), i); scoresHandler.AddReccord(player); } int newListLength = scoresHandler.Reccords.Count; Assert.AreEqual(expectedListLength, newListLength, "List of Records are not updated!"); }
public void ExpectLoadFromFileToLoadCorrectList() { var fileName = "testFile.txt"; var scoreHandler = new ScoresHandler(); var playerA = new Player("TestPlayerA", 1); var playerB = new Player("TestPlayerB", 2); scoreHandler.AddReccord(playerA); scoreHandler.AddReccord(playerB); scoreHandler.SaveToFile(fileName); scoreHandler.LoadFromFile(fileName); Assert.AreEqual(2, scoreHandler.Reccords.Count, "The loaded scores are {0}, which is incorect value", scoreHandler.Reccords.Count); File.Delete(fileName); }
/// <summary> /// Method to add you score to the highscore table /// </summary> private void EnterScoreRecordHandler() { Console.Write("Enter your nickname: "); var nickname = Console.ReadLine(); try { var playerProxy = new PlayerProxy(nickname, this.Player.Score); var scoresHandler = new ScoresHandler(); scoresHandler.LoadFromFile(GlobalErrorMessages.SaveRecordstFileName); scoresHandler.AddReccord(playerProxy); scoresHandler.SaveToFile(GlobalErrorMessages.SaveRecordstFileName); Console.WriteLine("Press any key to continiue.."); Console.ReadKey(); MainMenu.PrintMenu(this.engine); } catch (ArgumentOutOfRangeException) { Console.WriteLine("The name should be between 2 and 10 characters"); this.EnterScoreRecordHandler(); } }