/// <summary> /// Initializes category choosing. /// </summary> /// <param name="game">Instance of <see cref="HangmanGame"/> class.</param> public override void Play(HangmanGame game) { var contentReader = new FolderContentReader(); string[] categoriesToList = contentReader.GetCategories(Globals.CategoriesPath, "*" + Globals.FileExtension); game.UI.Print(categoriesToList); game.UI.Print(Messages.EnterChoiceMessage, "NewLine"); string chosenCategory = game.UI.ReadLine(); bool categoryExists = this.CategoriesToLower(categoriesToList).Contains(chosenCategory.ToLower()); if (categoryExists) { game.WordSelect.FileName = "../../Words/" + chosenCategory + Globals.FileExtension; } else { game.UI.Print(Messages.WrongCommand, "NewLine"); this.Play(game); } game.State = new InitializeGameState(); game.State.Play(game); }
public void ExpectToReturnCathegoriesWhenWrightPathIsProvided() { var contentReader = new FolderContentReader(); var categoriesList = contentReader.GetCategories(@"..\..\..\HQC.Project.Hangman2.1\bin" + Globals.CategoriesPath, "*" + Globals.FileExtension); string[] allCategories = { "Animals", "CarManufacturers", "Countries", "EgyptianGods", "Fruits", "GreekMythology", "IT", "Philosophers", "Random", "Space", "Vegetables" }; Assert.AreEqual(allCategories.Length, categoriesList.Length); for (int i = 0; i < allCategories.Length; i++) { Assert.IsTrue(allCategories[i].Contains(categoriesList[i])); } }
public void ExpectToThrowWhenWrongPathToCathegoryListIsProvided() { var contentReader = new FolderContentReader(); var categoriesList = contentReader.GetCategories("wrong path" + Globals.CategoriesPath, "*" + Globals.FileExtension); }