Exemplo n.º 1
0
        public void PromptForExit_ShouldRequestInputAgain_If_NotSpecifiedKey_IsPressed(char keyChar, ConsoleKey consoleKey)
        {
            //Arange
            MockConsoleMethods console    = new MockConsoleMethods();
            Validation         gateKeeper = new Validation();
            InputHelper        input      = new InputHelper(console, gateKeeper);

            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo(keyChar, consoleKey, false, false, false);

            void ExitInfiniteLoop()
            {
                console.readKeyInput = new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false);
            }

            new Thread(() =>
            {
                Thread.Sleep(70);
                ExitInfiniteLoop();
            }).Start();

            console.readKeyInput = keyInfo;
            int expected_moreThan = 1;

            //Act
            input.PromptForExit();
            int actual = console.timesInputed;

            //Assert
            Assert.True(actual > expected_moreThan);
        }
Exemplo n.º 2
0
        public void GenerateAir_ShouldGenerate_EqualAmountOfAirBlocks_ToPyramidHeight()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);
            int height   = 5;
            int expected = 5;

            string airBlocks = pyramid.GenerateAir(height);
            int    actual    = airBlocks.Length;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 3
0
        public void DrawPyramid_TopLineShouldContain_TwoHashtags()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);
            int expected = 2;

            pyramid.DrawPyramid(5);
            string[] floorsArray = Utility.SplitThisBy(console.writeLineString, "\n");
            string   topFloor    = floorsArray[0];
            int      actual      = Utility.CountInstances(topFloor, '#');

            Assert.Equal(expected, actual);
        }
Exemplo n.º 4
0
        public void DrawPyramid_ShouldGenerate_PyramidOfHeight_EqualToInputHeight()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);
            int height   = 7;
            int expected = 7;

            pyramid.DrawPyramid(height);
            string[] floorsArray = Utility.SplitThisBy(console.writeLineString, "\n");
            int      actual      = floorsArray.Length;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 5
0
        public void DrawPyramid_ShouldDrawPyramidOfWidth_1GreaterThanHeight()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);
            int height   = 12;
            int expected = height + 1;

            pyramid.DrawPyramid(height);
            string[] floorsArray = Utility.SplitThisBy(console.writeLineString, "\n");

            int actual = floorsArray[0].Length; //since we tested before that every line is of the same length, then I need only 1 test

            Assert.Equal(expected, actual);
        }
Exemplo n.º 6
0
        public void DrawPyramid_ShouldDecrease_TheAmountofAirBlocks_By1_everySubsequentLine()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);

            pyramid.DrawPyramid(5);
            string[] floorsArray = Utility.SplitThisBy(console.writeLineString, "\n");

            for (int i = 0; i < floorsArray.Length - 1; i++)
            {
                int hashCountAbove  = Utility.CountInstances(floorsArray[i], ' ');
                int hashCountBellow = Utility.CountInstances(floorsArray[i + 1], ' ');

                Assert.True(hashCountBellow < hashCountAbove);
            }
        }
Exemplo n.º 7
0
        public void DrawPyramid_SumLengthOf_PyramidAndAirBlocks_ShouldRemainConstant()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);

            pyramid.DrawPyramid(5);
            string[] floorsArray = Utility.SplitThisBy(console.writeLineString, "\n");

            int expected = floorsArray[0].Length;

            for (int i = 1; i < floorsArray.Length; i++)
            {
                int actual = floorsArray[i].Length;


                Assert.Equal(expected, actual);
            }
        }
Exemplo n.º 8
0
        public void PromptForExit_ShouldReturn_False_When_N_IsPressed()
        {
            //Arange
            MockConsoleMethods console    = new MockConsoleMethods();
            Validation         gateKeeper = new Validation();
            InputHelper        input      = new InputHelper(console, gateKeeper);

            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false);

            console.readKeyInput = keyInfo;
            bool expected = false;

            //Act
            bool actual = input.PromptForExit();

            //Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 9
0
        public void PromptForExit_ShouldReturn_True_When_Y_IsPressed()
        {
            //Arange

            MockConsoleMethods console    = new MockConsoleMethods();
            Validation         gateKeeper = new Validation();
            InputHelper        input      = new InputHelper(console, gateKeeper);

            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo('y', ConsoleKey.Y, false, false, false);    //no need to check for alt, shift, ctrl because I'm extacting only the console key out of all this other available informations

            console.readKeyInput = keyInfo;
            bool expected = true;

            //Act

            bool actual = input.PromptForExit();

            //Assert

            Assert.Equal(expected, actual);
        }
Exemplo n.º 10
0
        public void DrawPyramid_ShouldDraw_HashtagsToTheRightOfSpaces()
        {
            MockConsoleMethods console = new MockConsoleMethods();
            PyramidHelper      pyramid = new PyramidHelper(console);

            pyramid.DrawPyramid(8);
            string[] floorsArray = Utility.SplitThisBy(console.writeLineString, "\n");

            for (int i = 1; i < floorsArray.Length; i++)
            {
                int    indexHash = floorsArray[i].IndexOf('#');
                string left      = floorsArray[i].Substring(0, indexHash);
                string right     = floorsArray[i].Substring(indexHash);

                foreach (char c in left)
                {
                    Assert.Equal(' ', c);
                }                                                 //every symbol has to be space
                foreach (char c in right)
                {
                    Assert.Equal('#', c);
                }                                                   //every symbol has to be hashtag
            }
        }