public void TestWhetherIsEmptylMethodReturnsFalseWhenThereAreScores() { IPersonalScore score = new PersonalScore("Ivan", 2); this.scoreBoardService.AddNewScore(score); var isEmpty = this.scoreBoardService.IsEmpty(); Assert.IsFalse(isEmpty); }
public void TestCapitalizeFormatter() { var player = new PersonalScore("pLaYer", 1); var formatter = new CapitalizeFormatter(); var result = formatter.Format(player); var expect = "Player ---> 1 mistake(s)!"; Assert.IsTrue(expect == result); }
public void TestIfAddNewScoreMethodAddsTheNumberOfScoresProvided(int count) { for (var i = 0; i < count; i++) { IPersonalScore score = new PersonalScore("ivan" + i, 2 + i); this.scoreBoardService.AddNewScore(score); } Assert.AreEqual(count, this.scoreBoard.Records.Count); }
public void TestFormat() { var player = new PersonalScore("pLaYer", 1); var formatter = new AllCapsFormatter(); var result = formatter.Format(player); var expect = "PLAYER ---> 1 MISTAKE(S)!"; Assert.IsTrue(expect == result); }
public void TestWhetherGetWorstScoreMethodProvidesLastResultWhenBelowMaxNumberOfScores() { IPersonalScore score = new PersonalScore("Ivan", 2); IPersonalScore secondScore = new PersonalScore("Georgi", 5); IPersonalScore thirdScore = new PersonalScore("Pesho", 3); this.scoreBoardService.AddNewScore(score); this.scoreBoardService.AddNewScore(secondScore); this.scoreBoardService.AddNewScore(thirdScore); this.scoreBoardService.SortScoreBoard(); var worstScore = this.scoreBoardService.GetWorstScore(5); Assert.AreEqual(5, worstScore); }
/// <summary> /// Reads the result from the database and restores them as a C# objects. /// </summary> /// <param name="scoreBoardService"> /// The current ScoreBoardService. /// </param> /// <param name="filePath"> /// The path to the file, which acts as a database. /// </param> public override void RestoreResults(IScoreBoardService scoreBoardService, string filePath) { IList<string> allResults = this.ReadAllResults(filePath); IList<IPersonalScore> restoredResults = new List<IPersonalScore>(); foreach (var result in allResults) { string[] record = result.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); string name = record[0]; int score = int.Parse(record[1]); IPersonalScore newRecord = new PersonalScore(name, score); restoredResults.Add(newRecord); } scoreBoardService.RestoreScores(restoredResults); }
public void TestWhetherIsFullMethodReturnsFalseWhenCountIsBelowMaxNumber() { IPersonalScore score = new PersonalScore("Ivan", 2); IPersonalScore secondScore = new PersonalScore("Georgi", 5); IPersonalScore thirdScore = new PersonalScore("Pesho", 3); this.scoreBoardService.AddNewScore(score); this.scoreBoardService.AddNewScore(secondScore); this.scoreBoardService.AddNewScore(thirdScore); this.scoreBoardService.SortScoreBoard(); var isFull = this.scoreBoardService.IsFull(5); Assert.IsFalse(isFull); }
public void TestWhetherSortScoreBoardMethodProperlySortsScores() { IPersonalScore score = new PersonalScore("Ivan", 2); IPersonalScore secondScore = new PersonalScore("Georgi", 5); IPersonalScore thirdScore = new PersonalScore("Pesho", 3); this.scoreBoardService.AddNewScore(score); this.scoreBoardService.AddNewScore(secondScore); this.scoreBoardService.AddNewScore(thirdScore); this.scoreBoardService.SortScoreBoard(); Assert.AreEqual(5, this.scoreBoard.Records.Last().Score); }
public void TestWhetherRemoveLastScoresMethodRemovesAllRecordsAfterTheProvidedLimit(int recordsToAdd, int maxNumberOfRecords) { for (var i = 0; i < recordsToAdd; i++) { IPersonalScore score = new PersonalScore("ivan" + i, 2 + i); this.scoreBoardService.AddNewScore(score); } this.scoreBoardService.RemoveLastScores(maxNumberOfRecords); Assert.AreEqual(maxNumberOfRecords - 1, this.scoreBoard.Records.Count); }
public void Init() { this.dataFileManager = DataFileManager.SingletonInstance; this.personalScore = new PersonalScore("Tester", 1); }
public void CleanUp() { this.dataFileManager = null; this.personalScore = null; }
/// <summary> /// Processes the result of the player. /// If player can enter high scores - saves the Player's result. /// </summary> /// <param name="playerCanEnterHighScores"> /// Boolean variable indicating if the player can enter high scores. /// </param> public void ProcessCurrentPlayerResult(bool playerCanEnterHighScores) { if (playerCanEnterHighScores) { string name = this.Player.Name; int mistakes = this.Player.Mistakes; IPersonalScore newRecord = new PersonalScore(name, mistakes); this.SaveResult(newRecord); bool isEmptyScoreBoard = this.ScoreBoardService.IsEmpty(); IList<IPersonalScore> topRecords = this.ScoreBoardService.GetTopScores(Constants.NumberOfScoresInScoreBoard); this.Renderer.ShowScoreBoardResults(isEmptyScoreBoard, topRecords); } else { string message = string.Format(Constants.LowScoreMessage, this.Player.Mistakes); this.Renderer.ShowMessage(message); } }