Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void DefaultConsoleReader_ValidPassword()
        {
            string             password = "******";
            ConsoleWrapperMock console  = new ConsoleWrapperMock();

            console.PasswordOutput = password;
            DefaultPasswordReader reader = new DefaultPasswordReader(console);

            SecureString sstr = reader.GetSecurePassword('*');

            Assert.IsTrue(console.Output == "************");
            Assert.IsTrue(sstr.Length == password.Length);
        }
Esempio n. 3
0
        public void WriteTitle_ClearsConsoleAndWritesTitle()
        {
            //arrange
            string                  expected                = $"<clear>---- Word Search ----{Environment.NewLine}{Environment.NewLine}";
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock(true);
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            //act
            wordSearchProgramHelper.WriteTitle();
            string output = _consoleOuput.ToString();

            //assert
            Assert.Equal(expected, output);
        }
        public void ConsolificationEngine_PropertyJobNotAJob()
        {
            string[] args = new string[2];
            args[0] = "/A";
            args[1] = "123456ABCDEF";

            ConsolificationEngine <BadJobDataMock> engine = new ConsolificationEngine <BadJobDataMock>();
            ConsoleWrapperMock console = new ConsoleWrapperMock();

            engine.Console = console;

            int result = engine.Start(args);

            Assert.IsTrue(result == engine.ResultCannotParseArguments);
            Assert.IsTrue(console.Output.Contains("does not implement the Consolification.Core.IJob interface."));
        }
Esempio n. 5
0
        public void ReadFileNumber_WhenUserFirstEntersInvalidNumber_UserIsPromptedToEnterAgain(int numFiles, string userInput, string expected)
        {
            //arrange
            expected = expected.Replace("{Environment.NewLine}", Environment.NewLine);
            IConsoleWrapper consoleWrapper = new ConsoleWrapperMock();

            ((ConsoleWrapperMock)consoleWrapper).ReadKeyChars = userInput.ToCharArray().ToList();

            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            //act
            var    userSelection = wordSearchProgramHelper.ReadFileNumberFromConsole(numFiles);
            string output        = _consoleOuput.ToString();

            //assert
            Assert.Equal(expected, output);
            Assert.Equal(userInput.Substring(userInput.Length - 1), userSelection.ToString());
        }
Esempio n. 6
0
        public void PromptForMenuSelection_WhenUserSelectsNumberedOptionOutOfRange_RetryMessageDisplayed(string menuSelection, string expectedOutput, MenuSelection expectedMenuSelection)
        {
            //arrange
            expectedOutput = expectedOutput.Replace("{Environment.NewLine}", Environment.NewLine);
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            ((ConsoleWrapperMock)consoleWrapper).ReadKeyChars = menuSelection.ToCharArray().ToList();
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;

            //act
            MenuSelection actualMenuSelection = wordSearchProgramHelper.PromptForMenuSelection();
            string        output = _consoleOuput.ToString();

            //assert
            Assert.Equal(expectedMenuSelection, actualMenuSelection);
            Assert.Equal(expectedOutput, output);
        }
Esempio n. 7
0
        public void PromptForMenuSelection_WhenUserSelectsNumberedOptionInRange_CorrectNumberReturned(MenuSelection menuSelection)
        {
            //arrange
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            ((ConsoleWrapperMock)consoleWrapper).ReadKeyChar = ((int)menuSelection).ToString().ToCharArray().First();
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;
            string expected = $"(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: {(int)menuSelection}{Environment.NewLine}";

            //act
            MenuSelection actualMenuSelection = wordSearchProgramHelper.PromptForMenuSelection();
            string        output = _consoleOuput.ToString();

            //assert
            Assert.Equal(menuSelection, actualMenuSelection);
            Assert.Equal(expected, output);
        }
Esempio n. 8
0
        public async Task Run(IEnumerable <TypedValue> expecteds, string value)
        {
            ConsoleWrapperMock.Setup(x => x.ReadLine(It.IsAny <string>()))
            .Returns <string>(x => value);

            TaskWrapperMock.Setup(x => x.Delay(It.IsAny <int>()))
            .Returns <int>(x => Task.CompletedTask);

            await MainFlow.Run();

            var count = expecteds.Count();

            TaskWrapperMock.Verify(x => x.Delay(It.IsAny <int>()), Times.Exactly(count));
            ConsoleWrapperMock.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(count));

            foreach (var e in expecteds)
            {
                ConsoleWrapperMock.Verify(x => x.WriteLine(e.ToString()), Times.Once);
            }
        }
Esempio n. 9
0
        public void WriteGridToConsole_WhenGridArrayAndHighlightCoordinatesPassedIn_WritesArrayContentsToConsoleWithColorChanges(string gridSource, int xcoord, int ycoord, string expected)
        {
            //arrange
            expected       = expected.Replace("{Environment.NewLine}", Environment.NewLine);
            string[,] grid = _testUtilities.StringToGrid(gridSource);
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;

            //act
            wordSearchProgramHelper.WriteGridToConsole(grid, ConsoleColor.Gray, ConsoleColor.Black, new PointList()
            {
                new Point(xcoord, ycoord)
            });
            var output = _consoleOuput.ToString();

            //assert
            Assert.Equal(expected, output);
        }
Esempio n. 10
0
        public void SetConsoleColors_WhenOnlyForegroundColorsIsDifferentToCurrentColor_OnlyForegroundColorChanged()
        {
            //arrange
            var    fg       = Console.ForegroundColor;
            var    bg       = Console.BackgroundColor;
            string expected = "<fg:Cyan>";

            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.ForegroundColor = ConsoleColor.Blue;
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            //act
            wordSearchProgramHelper.SetConsoleColors(ConsoleColor.Cyan, ConsoleColor.DarkBlue);
            string output = _consoleOuput.ToString();

            //assert
            Assert.Equal(expected, output);

            Console.ForegroundColor = fg;
            Console.BackgroundColor = bg;
        }
Esempio n. 11
0
        public void SetConsoleColors_WhenColorsAreSameAsCurrentColors_ColorsAreNotChanged()
        {
            //arrange
            var    fg       = Console.ForegroundColor;
            var    bg       = Console.BackgroundColor;
            string expected = "";

            Console.BackgroundColor = ConsoleColor.DarkBlue;
            Console.ForegroundColor = ConsoleColor.Blue;
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            //act
            wordSearchProgramHelper.SetConsoleColors(ConsoleColor.Blue, ConsoleColor.DarkBlue);
            string output = _consoleOuput.ToString();

            //assert
            Assert.Equal(expected, output);

            Console.ForegroundColor = fg;
            Console.BackgroundColor = bg;
        }
Esempio n. 12
0
        public void PromptForSearchWord_WhenUserEntersWord_PromptDisplayedAndWordReturned(string searchWord)
        {
            //arrange
            string                  expected                = $"Enter a search word to find in puzzle or hit <enter> to return to the menu{Environment.NewLine}{Environment.NewLine}Search word: {searchWord}{Environment.NewLine}";
            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, null, null, null);

            ((ConsoleWrapperMock)consoleWrapper).ReadLineResults = new List <string>()
            {
                searchWord
            };
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;

            //act
            string searchWordOut = wordSearchProgramHelper.PromptForSearchWord();
            string output        = _consoleOuput.ToString();

            //assert
            Assert.Equal(searchWord, searchWordOut);
            Assert.Equal(expected, output);
        }
        public void WriteSolvedPuzzleCoordinatesToConsole_WhenSearchWordFound_CoordinatesWrittenToConsole(string searchWords, string fileRowsDelimeteredArray, string puzzleFileName, string expected)
        {
            //arrange
            expected = expected.Replace("{Environment.NewLine}", Environment.NewLine);
            string workingDir = $"{_fileOperations.ApplicationBasePath(TestUtilities.APPLICATION_DIRECTORY)}{Path.DirectorySeparatorChar}{TEST_DIRECTORY}";

            CreatePuzzleFile(workingDir, searchWords, fileRowsDelimeteredArray, puzzleFileName);

            IConsoleWrapper         consoleWrapper          = new ConsoleWrapperMock();
            WordSearchProgramHelper wordSearchProgramHelper = new WordSearchProgramHelper(consoleWrapper, _fileOperations, _wordFinder, _searchOrientationManager);

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.BackgroundColor = ConsoleColor.Black;

            //act
            var(searchString, grid) = wordSearchProgramHelper.ConvertPuzzleFileToSearchWordsAndGrid($"{workingDir}{Path.DirectorySeparatorChar}{puzzleFileName}");
            IGridManager gridManager = new GridManager(grid);

            wordSearchProgramHelper.WriteSolvedPuzzleCoordinatesToConsole(searchString, gridManager);
            var output = _consoleOuput.ToString();

            //assert
            Assert.True(expected == _consoleOuput.ToString());
        }