Пример #1
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
        }
Пример #2
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);
        }