Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            DisplayBorder mainBorder   = new DisplayBorder('#', 1, ConsoleColor.Cyan);
            DisplayBorder sideBorder   = new DisplayBorder('#', 1, ConsoleColor.Red);
            DisplayBorder bottomBorder = new DisplayBorder('#', 1, ConsoleColor.Yellow);
            DisplayBox    mainBox      = new DisplayBox("MainBox", 0, 0, 80, 30, mainBorder);
            DisplayBox    sideBox      = new DisplayBox("SideBox", mainBox.DisplayWidth, 0, 30, 30, sideBorder);
            DisplayBox    bottomBox    = new DisplayBox("BottomBox", 0, mainBox.DisplayHeight, mainBox.DisplayWidth + sideBox.DisplayWidth, 10, bottomBorder);
            DisplayScreen screen       = new DisplayScreen(150, 50);

            screen.Add(mainBox);
            screen.Add(sideBox);
            screen.Add(bottomBox);
            screen.LoadBorders();

            screen.WriteString("MainBox", "Hello World", ConsoleColor.White, ConsoleColor.Black, 15, 35);
            screen.WriteString("MainBox", "How are you today?", ConsoleColor.Red, ConsoleColor.Black, 16, 31);
            //screen.WriteString("SideBox", "Side box", ConsoleColor.White, ConsoleColor.Black, 15, 12);
            screen.WriteString("SideBox", "Welcome ", ConsoleColor.White, ConsoleColor.Black, 2, 2);
            screen.WriteString("SideBox", "Unnar", ConsoleColor.Yellow, ConsoleColor.Black, 2, 10);
            screen.WriteString("SideBox", "Today is: ", ConsoleColor.White, ConsoleColor.Black, 4, 2);
            screen.WriteString("SideBox", "Monday", ConsoleColor.Yellow, ConsoleColor.Black, 4, 12);
            screen.WriteString("SideBox", "New messages: ", ConsoleColor.White, ConsoleColor.Black, 6, 2);
            screen.WriteString("SideBox", "2", ConsoleColor.Yellow, ConsoleColor.Black, 6, 16);
            screen.WriteString("BottomBox", " 21.3.2021 14:23 - Some event has been logged", ConsoleColor.White, ConsoleColor.Black, 2, 1);
            screen.WriteString("BottomBox", " 21.3.2021 14:42 - Some event has been logged", ConsoleColor.White, ConsoleColor.Black, 3, 1);
            screen.WriteString("BottomBox", " 21.3.2021 17:42 - Some event has been logged", ConsoleColor.White, ConsoleColor.Black, 4, 1);
            //StringWriter sw = new StringWriter();
            //Console.SetOut(sw);
            screen.PrintScreen();
            Console.CursorVisible = true;
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public void Clear_DisplayBoxGetsCleared()
        {
            //Set up
            int           boxLines = 10;
            int           boxCols  = 10;
            DisplayBorder border1  = new DisplayBorder('#', 1);
            DisplayBorder border2  = new DisplayBorder('#', 1);
            DisplayBox    box1     = new DisplayBox("Box1", 0, 0, boxCols, boxLines, border1);
            DisplayBox    box2     = new DisplayBox("Box2", 0, boxLines, boxCols, boxLines, border2);
            DisplayScreen screen   = new DisplayScreen(10, 20);

            screen.Add(box1);
            screen.Add(box2);
            screen.LoadBorders();
            screen.WriteString("Box1", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0);
            screen.WriteString("Box2", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0);
            string expectedString1 = string.Concat(Enumerable.Repeat(new string(' ', 10) + Environment.NewLine, 10));

            //Action
            screen.Clear("Box1");
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            int    splitPtr      = (boxCols + 2) * boxLines;
            string actualString1 = sw.ToString().Substring(0, splitPtr);
            string actualString2 = sw.ToString().Substring(splitPtr);

            //Assertion
            Assert.Equal(expectedString1, actualString1);       // Box1 should be cleared
            Assert.NotEqual(expectedString1, actualString2);    // but not Box2
        }
Ejemplo n.º 3
0
        public void Add_OverlappingBoxesThrowsException(int box1X, int box1Y, int box1Width, int box1Height, int box2X, int box2Y, int box2Width, int box2Height)
        {
            //Set up
            DisplayBox    box1   = new DisplayBox("Box1", box1X, box1Y, box1Width, box1Height);
            DisplayBox    box2   = new DisplayBox("Box2", box2X, box2Y, box2Width, box2Height);
            DisplayScreen screen = new DisplayScreen(150, 50);

            screen.Add(box1);

            //Assertion
            Assert.Throws <DisplayBoxOverlapException>(() => screen.Add(box2));
        }
Ejemplo n.º 4
0
        public void Add_NewBoxGetsAddedToNonEmptyList(int box1X, int box1Y, int box1Width, int box1Height, int box2X, int box2Y, int box2Width, int box2Height)
        {
            //Set up
            DisplayBox    box1   = new DisplayBox("Box1", box1X, box1Y, box1Width, box1Height);
            DisplayBox    box2   = new DisplayBox("Box2", box2X, box2Y, box2Width, box2Height);
            DisplayScreen screen = new DisplayScreen(150, 50);

            screen.Add(box1);
            screen.Add(box2);

            //No assert needed as test succeeds if no exception is thrown
        }
Ejemplo n.º 5
0
        public void Add_BoxNameAlreadyExistsThrowsException()
        {
            //Set up
            string        boxName = "MyBox";
            DisplayScreen screen  = new DisplayScreen(150, 50);
            DisplayBox    box1    = new DisplayBox(boxName, 0, 0, 80, 30);
            DisplayBox    box2    = new DisplayBox(boxName, 0, 0, 80, 30);

            //Action
            screen.Add(box1);

            //Assert
            Assert.Throws <DisplayBoxExistsException>(() => screen.Add(box2));
        }
Ejemplo n.º 6
0
        public void LoadBorders_BordersDisplayedCorrectly(char borderChar, int borderThickness_left, int borderThickness_top, int borderThickness_right, int borderThickness_bottom, int boxWidth, int boxHeight,
                                                          int checkLine, string expectedString)
        {
            //Set up
            DisplayScreen screen = new DisplayScreen(150, 50);
            DisplayBorder border = new DisplayBorder(borderChar);

            border.Thickness[DisplayBorder.LEFT]   = borderThickness_left;
            border.Thickness[DisplayBorder.TOP]    = borderThickness_top;
            border.Thickness[DisplayBorder.RIGHT]  = borderThickness_right;
            border.Thickness[DisplayBorder.BOTTOM] = borderThickness_bottom;
            DisplayBox box = new DisplayBox("MyBox", 0, 0, boxWidth, boxHeight, border);

            screen.Add(box);

            //Action
            screen.LoadBorders();
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            string targetString = sw.ToString().Substring(checkLine * 150 + (checkLine * 2), boxWidth);

            //Assert
            Assert.True(targetString == expectedString);
        }
Ejemplo n.º 7
0
        public void Clear_OutputGetsCleared()
        {
            //Set up
            int           lines  = 10;
            int           cols   = 10;
            DisplayBorder border = new DisplayBorder('#', 1);
            DisplayBox    box    = new DisplayBox("MyBox", 0, 0, cols, lines, border);
            DisplayScreen screen = new DisplayScreen(cols, lines);

            screen.Add(box);
            screen.LoadBorders();
            screen.WriteString("MyBox", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0);
            string expectedString = string.Concat(Enumerable.Repeat(new string(' ', 10) + Environment.NewLine, 10));

            //Action
            screen.Clear();
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            string actualString = sw.ToString();

            //Assertion
            Assert.True(expectedString == actualString);
        }
Ejemplo n.º 8
0
        public void PrintScreen_TextDisplayedCorrectly(string text, int line, int column, string expectedString)
        {
            //Set up
            int           displayWidth  = 150;
            int           displayHeight = 50;
            int           boxX          = 0;
            int           boxY          = 0;
            int           boxWidth      = 80;
            int           boxHeight     = 30;
            DisplayBox    box           = new DisplayBox("MyBox", boxX, boxY, boxWidth, boxHeight);
            DisplayScreen screen        = new DisplayScreen(displayWidth, displayHeight);

            screen.Add(box);
            int stringBufferPtr = displayWidth * line + (line * 2) + column;

            //Action
            screen.WriteString("MyBox", text, ConsoleColor.White, ConsoleColor.Black, line, column);
            StringWriter sw = new StringWriter();

            Console.SetOut(sw);
            screen.PrintScreen();
            string targetString = sw.ToString().Substring(stringBufferPtr, expectedString.Length);

            //Assert
            Assert.True(targetString == expectedString);
        }
Ejemplo n.º 9
0
        public void WriteString_InvalidBoxNameExceptionThrown()
        {
            //Set up
            DisplayBox    box    = new DisplayBox("MyBox", 0, 0, 80, 30);
            DisplayScreen screen = new DisplayScreen(150, 50);

            screen.Add(box);

            //Action - assert
            Assert.Throws <ArgumentException>(() => screen.WriteString("BogusName", "SomeText", ConsoleColor.Black, ConsoleColor.White, 0, 0));
        }
Ejemplo n.º 10
0
        public void Add_NewBoxGetsAddedCorrectly(string name, int x, int y, int width, int height, int screenWidth, int screenHeight)
        {
            //Set up
            DisplayScreen screen = new DisplayScreen(screenWidth, screenHeight);
            DisplayBox    box    = new DisplayBox(name, x, y, width, height);

            //Action
            screen.Add(box);
            List <DisplayBox> boxList = screen.GetDisplayBoxes();

            //Assert
            Assert.True(boxList.Count > 0);
            Assert.True(boxList[0].Name == name);
            Assert.True(boxList[0].DisplayX == x);
            Assert.True(boxList[0].DisplayY == y);
            Assert.True(boxList[0].DisplayWidth == width);
            Assert.True(boxList[0].DisplayHeight == height);
        }