public void ProgramLoop_WhenUserSelectsFirstPuzzleAndEnterSearchWordOfABAndExit_OuputContainsFileListAndGridAndMenuOptionsAndSolution() { //arrange Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.Black; string expected = $"---- Word Search ----{Environment.NewLine}{Environment.NewLine}(1) wordsearch.txt{Environment.NewLine}(2) wordsearch2.txt{Environment.NewLine}{Environment.NewLine}Select puzzle number: 1{Environment.NewLine}{Environment.NewLine}AD,IE{Environment.NewLine}{Environment.NewLine}A B C {Environment.NewLine}D E F {Environment.NewLine}G H I {Environment.NewLine}{Environment.NewLine}(1) Show solution{Environment.NewLine}(2) Enter a search word{Environment.NewLine}(3) Select another puzzle{Environment.NewLine}(4) Exit{Environment.NewLine}{Environment.NewLine}Enter selection: 2{Environment.NewLine}AD,IE{Environment.NewLine}{Environment.NewLine}A B C {Environment.NewLine}D E F {Environment.NewLine}G H I {Environment.NewLine}{Environment.NewLine}Enter a search word to find in puzzle or hit <enter> to return to the menu{Environment.NewLine}{Environment.NewLine}Search word: AB{Environment.NewLine}AD,IE{Environment.NewLine}{Environment.NewLine}AB: (0,0),(1,0){Environment.NewLine}{Environment.NewLine}<fg:Black><bg:Gray>A<fg:Gray><bg:Black> <fg:Black><bg:Gray>B<fg:Gray><bg:Black> C {Environment.NewLine}D E F {Environment.NewLine}G H I {Environment.NewLine}{Environment.NewLine}Enter a search word to find in puzzle or hit <enter> to return to the menu{Environment.NewLine}{Environment.NewLine}Search word: {Environment.NewLine}{Environment.NewLine}(1) Show solution{Environment.NewLine}(2) Enter a search word{Environment.NewLine}(3) Select another puzzle{Environment.NewLine}(4) Exit{Environment.NewLine}{Environment.NewLine}Enter selection: 4{Environment.NewLine}"; IConsoleWrapper consoleWrapper = new ConsoleWrapperMock(); ((ConsoleWrapperMock)consoleWrapper).ReadKeyChars = new List <char>() { '1', '2', '4' }; ((ConsoleWrapperMock)consoleWrapper).ReadLineResults = new List <string>() { "AB", "" }; WordSearchProgram wordSearchProgram = new WordSearchProgram(consoleWrapper, _fileOperations, _wordFinder, _searchOrientationManager); //act wordSearchProgram.ProgramLoop(TestUtilities.TEST_PUZZLES_DIRECTORY); string output = _consoleOuput.ToString(); //assert Assert.Equal(expected, output); }
public void ProgramLoop_WhenPuzzleDirectoryDoesNotExist_ThrowsArgumentException(string directory) { //arrange string fullPath = $"{_fileOperations.ApplicationBasePath("WordSearch")}{Path.DirectorySeparatorChar}{directory}"; string expectedMessage = $"directory does not exist: {fullPath}"; WordSearchProgram wordSearchProgram = new WordSearchProgram(_consoleWrapper, _fileOperations, _wordFinder, _searchOrientationManager); //act & assert var exception = Assert.Throws <ArgumentException>(() => wordSearchProgram.ProgramLoop(directory)); Assert.Equal(expectedMessage, exception.Message); }
public void ProgramLoop_WhenPuzzleDirectoryIsEmpty_ThrowsArgumentException() { //arrange string directory = TestUtilities.EMPTY_DIRECTORY; string fullPath = $"{_fileOperations.ApplicationBasePath("WordSearch")}{Path.DirectorySeparatorChar}{directory}"; _testUtilities.CreateEmptyDirectory(fullPath); string expectedMessage = $"puzzle directory contains no files: {fullPath}"; WordSearchProgram wordSearchProgram = new WordSearchProgram(_consoleWrapper, _fileOperations, _wordFinder, _searchOrientationManager); //act & assert var exception = Assert.Throws <ArgumentException>(() => wordSearchProgram.ProgramLoop(directory)); Assert.Equal(expectedMessage, exception.Message); }