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 }
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); }
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); }
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)); }
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(); }