Example #1
0
        public void Run_All_Scenarios()
        {
            List <Type> scenarioClasses = Scenario.GetDerivedClasses <Scenario> ();

            Assert.NotEmpty(scenarioClasses);

            foreach (var scenarioClass in scenarioClasses)
            {
                // Setup some fake keypresses
                // Passing empty string will cause just a ctrl-q to be fired
                Console.MockKeyPresses.Clear();
                int stackSize  = CreateInput("");
                int iterations = 0;
                Application.Iteration = () => {
                    iterations++;
                    // Stop if we run out of control...
                    if (iterations > 10)
                    {
                        Application.RequestStop();
                    }
                };
                Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

                var ms         = 1000;
                var abortCount = 0;
                Func <MainLoop, bool> abortCallback = (MainLoop loop) => {
                    abortCount++;
                    Application.RequestStop();
                    return(false);
                };
                var token = Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(ms), abortCallback);

                var scenario = (Scenario)Activator.CreateInstance(scenarioClass);
                scenario.Init(Application.Top, Colors.Base);
                scenario.Setup();
                var rs = Application.Begin(Application.Top);
                scenario.Run();

                Application.End(rs);

                Assert.Equal(0, abortCount);
                // # of key up events should match # of iterations
                Assert.Equal(1, iterations);
                Assert.Equal(stackSize, iterations);
            }
#if DEBUG_IDISPOSABLE
            foreach (var inst in Responder.Instances)
            {
                Assert.True(inst.WasDisposed);
            }
            Responder.Instances.Clear();
#endif
        }
        public void AddIdle_Function_GetsCalled_OnIteration()
        {
            var ml = new MainLoop(new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var         functionCalled = 0;
            Func <bool> fn             = () => {
                functionCalled++;
                return(true);
            };

            ml.AddIdle(fn);
            ml.MainIteration();
            Assert.Equal(1, functionCalled);
        }
        public void RemoveIdle_Function_NotCalled()
        {
            var ml = new MainLoop(new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var         functionCalled = 0;
            Func <bool> fn             = () => {
                functionCalled++;
                return(true);
            };

            Assert.False(ml.RemoveIdle(fn));
            ml.MainIteration();
            Assert.Equal(0, functionCalled);
        }
Example #4
0
        public void Run_Generic()
        {
            List <Type> scenarioClasses = Scenario.GetDerivedClasses <Scenario> ();

            Assert.NotEmpty(scenarioClasses);

            var item          = scenarioClasses.FindIndex(t => Scenario.ScenarioMetadata.GetName(t).Equals("Generic", StringComparison.OrdinalIgnoreCase));
            var scenarioClass = scenarioClasses[item];
            // Setup some fake kepresses
            // Passing empty string will cause just a ctrl-q to be fired
            int stackSize = CreateInput("");

            int iterations = 0;

            Application.Iteration = () => {
                iterations++;
                // Stop if we run out of control...
                if (iterations == 10)
                {
                    Application.RequestStop();
                }
            };
            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            var ms         = 1000;
            var abortCount = 0;
            Func <MainLoop, bool> abortCallback = (MainLoop loop) => {
                abortCount++;
                Application.RequestStop();
                return(false);
            };
            var token = Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(ms), abortCallback);

            Application.Top.KeyPress += (View.KeyEventEventArgs args) => {
                Assert.Equal(Key.ControlQ, args.KeyEvent.Key);
            };

            var scenario = (Scenario)Activator.CreateInstance(scenarioClass);

            scenario.Init(Application.Top, Colors.Base);
            scenario.Setup();
            scenario.Run();

            Application.Shutdown();

            Assert.Equal(0, abortCount);
            // # of key up events should match # of iterations
            //Assert.Equal (1, iterations);
            Assert.Equal(stackSize, iterations);
        }
Example #5
0
        public void Init_Inits()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            driver.Init(() => { });

            Assert.Equal(80, Console.BufferWidth);
            Assert.Equal(25, Console.BufferHeight);

            // MockDriver is always 80x25
            Assert.Equal(Console.BufferWidth, driver.Cols);
            Assert.Equal(Console.BufferHeight, driver.Rows);
            driver.End();
        }
        public void IsSupported_Get()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            if (Clipboard.IsSupported)
            {
                Assert.True(Clipboard.IsSupported);
            }
            else
            {
                Assert.False(Clipboard.IsSupported);
            }

            Application.Shutdown();
        }
        public void HeightAsBuffer_Is_True_Top_Cannot_Be_Greater_Than_WindowHeight()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            Application.HeightAsBuffer = true;
            Assert.True(Application.HeightAsBuffer);

            driver.SetWindowPosition(80, 26);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            Application.Shutdown();
        }
Example #8
0
        public void PosCombine_Do_Not_Throws()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                X = Pos.Left(t) + 2,
                Y = Pos.Top(t) + 2
            };
            var f  = new FrameView("f");
            var v1 = new View("v1")
            {
                X = Pos.Left(w) + 2,
                Y = Pos.Top(w) + 2
            };
            var v2 = new View("v2")
            {
                X = Pos.Left(v1) + 2,
                Y = Pos.Top(v1) + 2
            };

            f.Add(v1, v2);
            w.Add(f);
            t.Add(w);

            f.X = Pos.X(t) + Pos.X(v2) - Pos.X(v1);
            f.Y = Pos.Y(t) + Pos.Y(v2) - Pos.Y(v1);

            t.Ready += () => {
                Assert.Equal(0, t.Frame.X);
                Assert.Equal(0, t.Frame.Y);
                Assert.Equal(2, w.Frame.X);
                Assert.Equal(2, w.Frame.Y);
                Assert.Equal(2, f.Frame.X);
                Assert.Equal(2, f.Frame.Y);
                Assert.Equal(4, v1.Frame.X);
                Assert.Equal(4, v1.Frame.Y);
                Assert.Equal(6, v2.Frame.X);
                Assert.Equal(6, v2.Frame.Y);
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Example #9
0
        public void DimCombine_Do_Not_Throws()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w")
            {
                Width  = Dim.Width(t) - 2,
                Height = Dim.Height(t) - 2
            };
            var f  = new FrameView("f");
            var v1 = new View("v1")
            {
                Width  = Dim.Width(w) - 2,
                Height = Dim.Height(w) - 2
            };
            var v2 = new View("v2")
            {
                Width  = Dim.Width(v1) - 2,
                Height = Dim.Height(v1) - 2
            };

            f.Add(v1, v2);
            w.Add(f);
            t.Add(w);

            f.Width  = Dim.Width(t) - Dim.Width(v2);
            f.Height = Dim.Height(t) - Dim.Height(v2);

            t.Ready += () => {
                Assert.Equal(80, t.Frame.Width);
                Assert.Equal(25, t.Frame.Height);
                Assert.Equal(78, w.Frame.Width);
                Assert.Equal(23, w.Frame.Height);
                Assert.Equal(6, f.Frame.Width);
                Assert.Equal(6, f.Frame.Height);
                Assert.Equal(76, v1.Frame.Width);
                Assert.Equal(21, v1.Frame.Height);
                Assert.Equal(74, v2.Frame.Width);
                Assert.Equal(19, v2.Frame.Height);
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
        public void HeightAsBuffer_Is_False_Left_And_Top_Is_Always_Zero()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            Assert.False(Application.HeightAsBuffer);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            driver.SetWindowPosition(5, 5);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            Application.Shutdown();
        }
        public void Contents_Gets_Sets()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var clipText = "This is a clipboard unit test.";

            Clipboard.Contents = clipText;

            Application.Iteration += () => Application.RequestStop();

            Application.Run();

            Assert.Equal(clipText, Clipboard.Contents);

            Application.Shutdown();
        }
Example #12
0
        public void Constuctors_Constuct()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            driver.Init(() => { });

            // Test parameterless constructor
            var attr = new Attribute();

            Assert.Equal(default(int), attr.Value);
            Assert.Equal(default(Color), attr.Foreground);
            Assert.Equal(default(Color), attr.Background);

            // Test value, foreground, background
            var value = 42;
            var fg    = new Color();

            fg = Color.Red;

            var bg = new Color();

            bg = Color.Blue;

            attr = new Attribute(value, fg, bg);

            Assert.Equal(value, attr.Value);
            Assert.Equal(fg, attr.Foreground);
            Assert.Equal(bg, attr.Background);

            // value, foreground, background
            attr = new Attribute(fg, bg);

            Assert.Equal(fg, attr.Foreground);
            Assert.Equal(bg, attr.Background);

            attr = new Attribute(fg);
            Assert.Equal(fg, attr.Foreground);
            Assert.Equal(fg, attr.Background);

            attr = new Attribute(bg);
            Assert.Equal(bg, attr.Foreground);
            Assert.Equal(bg, attr.Background);

            driver.End();
            Application.Shutdown();
        }
Example #13
0
        public void StatusBar_Contructor_Default()
        {
            var sb = new StatusBar();

            Assert.Empty(sb.Items);
            Assert.False(sb.CanFocus);
            Assert.Equal(Colors.Menu, sb.ColorScheme);
            Assert.Equal(0, sb.X);
            Assert.Equal(Dim.Fill(), sb.Width);
            Assert.Equal(1, sb.Height);

            Assert.Equal(0, sb.Y);

            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            sb = new StatusBar();

            driver.SetCursorVisibility(CursorVisibility.Default);
            driver.GetCursorVisibility(out CursorVisibility cv);
            Assert.Equal(CursorVisibility.Default, cv);
            Assert.True(FakeConsole.CursorVisible);

            Application.Iteration += () => {
                Assert.Equal(24, sb.Y);

                driver.SetWindowSize(driver.Cols, 15);

                Assert.Equal(14, sb.Y);

                sb.OnEnter(null);
                driver.GetCursorVisibility(out cv);
                Assert.Equal(CursorVisibility.Invisible, cv);
                Assert.False(FakeConsole.CursorVisible);

                Application.RequestStop();
            };

            Application.Top.Add(sb);

            Application.Run();

            Application.Shutdown();
        }
Example #14
0
        public void CanFocus_Faced_With_Container_After_Run()
        {
            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window("w");
            var f = new FrameView("f");
            var v = new View("v")
            {
                CanFocus = true
            };

            f.Add(v);
            w.Add(f);
            t.Add(w);

            t.Ready += () => {
                Assert.True(t.CanFocus);
                Assert.True(w.CanFocus);
                Assert.True(f.CanFocus);
                Assert.True(v.CanFocus);

                f.CanFocus = false;
                Assert.False(f.CanFocus);
                Assert.False(v.CanFocus);

                v.CanFocus = false;
                Assert.False(f.CanFocus);
                Assert.False(v.CanFocus);

                Assert.Throws <InvalidOperationException> (() => v.CanFocus = true);
                Assert.False(f.CanFocus);
                Assert.False(v.CanFocus);

                f.CanFocus = true;
                Assert.True(f.CanFocus);
                Assert.True(v.CanFocus);
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
        public void Init_Inits()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            driver.Init(() => { });

            Assert.Equal(80, Console.BufferWidth);
            Assert.Equal(25, Console.BufferHeight);

            // MockDriver is always 80x25
            Assert.Equal(Console.BufferWidth, driver.Cols);
            Assert.Equal(Console.BufferHeight, driver.Rows);
            driver.End();

            // Shutdown must be called to safely clean up Application if Init has been called
            Application.Shutdown();
        }
Example #16
0
        public ScrollBarViewTests()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var top = Application.Top;

            _hostView = new HostView()
            {
                Width  = Dim.Fill(),
                Height = Dim.Fill(),
                Top    = 0,
                Lines  = 30,
                Left   = 0,
                Cols   = 100
            };

            top.Add(_hostView);
        }
Example #17
0
        public void Navigation_With_Null_Focused_View()
        {
            // Non-regression test for #882 (NullReferenceException during keyboard navigation when Focused is null)

            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            Application.Top.Ready += () => {
                Assert.Null(Application.Top.Focused);
            };

            // Keyboard navigation with tab
            Console.MockKeyPresses.Push(new ConsoleKeyInfo('\t', ConsoleKey.Tab, false, false, false));

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Example #18
0
        public void AddTimer_Adds_Removes_NoFaults()
        {
            var ml = new MainLoop(new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            var ms = 100;

            var callbackCount = 0;
            Func <MainLoop, bool> callback = (MainLoop loop) => {
                callbackCount++;
                return(true);
            };

            var token = ml.AddTimeout(TimeSpan.FromMilliseconds(ms), callback);

            ml.RemoveTimeout(token);

            // BUGBUG: This should probably fault?
            ml.RemoveTimeout(token);
        }
        public void AddTimer_Run_Called()
        {
            var ml = new MainLoop(new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            var ms = 100;

            var callbackCount = 0;
            Func <MainLoop, bool> callback = (MainLoop loop) => {
                callbackCount++;
                ml.Stop();
                return(true);
            };

            var token = ml.AddTimeout(TimeSpan.FromMilliseconds(ms), callback);

            ml.Run();
            Assert.True(ml.RemoveTimeout(token));

            Assert.Equal(1, callbackCount);
        }
        public void Init_Shutdown_Cleans_Up()
        {
            // Verify initial state is per spec
            Pre_Init_State();

            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            // Verify post-Init state is correct
            Post_Init_State();

            // MockDriver is always 80x25
            Assert.Equal(80, Application.Driver.Cols);
            Assert.Equal(25, Application.Driver.Rows);

            Application.Shutdown();

            // Verify state is back to initial
            Pre_Init_State();
        }
        public void FakeDriver_MockKeyPresses()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var text  = "MockKeyPresses";
            var mKeys = new Stack <ConsoleKeyInfo> ();

            foreach (var r in text.Reverse())
            {
                var ck  = char.IsLetter(r) ? (ConsoleKey)char.ToUpper(r) : (ConsoleKey)r;
                var cki = new ConsoleKeyInfo(r, ck, false, false, false);
                mKeys.Push(cki);
            }
            FakeConsole.MockKeyPresses = mKeys;

            var top   = Application.Top;
            var view  = new View();
            var rText = "";
            var idx   = 0;

            view.KeyPress += (e) => {
                Assert.Equal(text [idx], (char)e.KeyEvent.Key);
                rText += (char)e.KeyEvent.Key;
                Assert.Equal(rText, text.Substring(0, idx + 1));
                e.Handled = true;
                idx++;
            };
            top.Add(view);

            Application.Iteration += () => {
                if (mKeys.Count == 0)
                {
                    Application.RequestStop();
                }
            };

            Application.Run();

            Assert.Equal("MockKeyPresses", rText);

            // Shutdown must be called to safely clean up Application if Init has been called
            Application.Shutdown();
        }
Example #22
0
        public void CanFocus_Container_Toggling_All_Subviews_To_Old_Value_When_Is_True()
        {
            Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w  = new Window("w");
            var f  = new FrameView("f");
            var v1 = new View("v1");
            var v2 = new View("v2")
            {
                CanFocus = true
            };

            f.Add(v1, v2);
            w.Add(f);
            t.Add(w);

            t.Ready += () => {
                Assert.True(t.CanFocus);
                Assert.True(w.CanFocus);
                Assert.True(f.CanFocus);
                Assert.False(v1.CanFocus);
                Assert.True(v2.CanFocus);

                w.CanFocus = false;
                Assert.True(w.CanFocus);
                Assert.False(f.CanFocus);
                Assert.False(v1.CanFocus);
                Assert.False(v2.CanFocus);

                w.CanFocus = true;
                Assert.True(w.CanFocus);
                Assert.True(f.CanFocus);
                Assert.False(v1.CanFocus);
                Assert.True(v2.CanFocus);
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Example #23
0
        public void HeightAsBuffer_Is_True_Top_Cannot_Be_Greater_Than_BufferHeight_Minus_WindowHeight()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            Application.HeightAsBuffer = true;
            Assert.True(Application.HeightAsBuffer);

            driver.SetWindowPosition(80, 26);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            // MockDriver will now be sets to 80x40
            driver.SetBufferSize(80, 40);
            Assert.Equal(80, Application.Driver.Cols);
            Assert.Equal(40, Application.Driver.Rows);
            Assert.Equal(80, Console.BufferWidth);
            Assert.Equal(40, Console.BufferHeight);
            Assert.Equal(80, Console.WindowWidth);
            Assert.Equal(25, Console.WindowHeight);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);
            driver.SetWindowPosition(80, 40);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(15, Console.WindowTop);

            driver.SetWindowSize(80, 20);
            Assert.Equal(80, Application.Driver.Cols);
            Assert.Equal(40, Application.Driver.Rows);
            Assert.Equal(80, Console.BufferWidth);
            Assert.Equal(40, Console.BufferHeight);
            Assert.Equal(80, Console.WindowWidth);
            Assert.Equal(20, Console.WindowHeight);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(15, Console.WindowTop);
            driver.SetWindowPosition(80, 41);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(20, Console.WindowTop);

            Application.Shutdown();
        }
        public void Run_Runs_Idle_Stop_Stops_Idle()
        {
            var ml = new MainLoop(new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var         functionCalled = 0;
            Func <bool> fn             = () => {
                functionCalled++;
                if (functionCalled == 10)
                {
                    ml.Stop();
                }
                return(true);
            };

            ml.AddIdle(fn);
            ml.Run();
            Assert.True(ml.RemoveIdle(fn));

            Assert.Equal(10, functionCalled);
        }
Example #25
0
        public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Null()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            var t = Application.Top;

            var w = new Window(new Rect(1, 2, 4, 5), "w");

            t.Add(w);

            t.Ready += () => {
                Assert.Equal(2, w.X = 2);
                Assert.Equal(2, w.Y = 2);
            };

            Application.Iteration += () => Application.RequestStop();

            Application.Run();
            Application.Shutdown();
        }
Example #26
0
        public void SetColors_Changes_Colors()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            driver.Init(() => { });
            Assert.Equal(ConsoleColor.Gray, Console.ForegroundColor);
            Assert.Equal(ConsoleColor.Black, Console.BackgroundColor);

            Console.ForegroundColor = ConsoleColor.Red;
            Assert.Equal(ConsoleColor.Red, Console.ForegroundColor);

            Console.BackgroundColor = ConsoleColor.Green;
            Assert.Equal(ConsoleColor.Green, Console.BackgroundColor);

            Console.ResetColor();
            Assert.Equal(ConsoleColor.Gray, Console.ForegroundColor);
            Assert.Equal(ConsoleColor.Black, Console.BackgroundColor);
            driver.End();
        }
        public void TerminalResized_Simulation()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            var wasTerminalResized = false;

            Application.Resized = (e) => {
                wasTerminalResized = true;
                Assert.Equal(120, e.Cols);
                Assert.Equal(40, e.Rows);
            };

            Assert.Equal(80, Console.BufferWidth);
            Assert.Equal(25, Console.BufferHeight);

            // MockDriver is by default 80x25
            Assert.Equal(Console.BufferWidth, driver.Cols);
            Assert.Equal(Console.BufferHeight, driver.Rows);
            Assert.False(wasTerminalResized);

            // MockDriver will now be sets to 120x40
            driver.SetBufferSize(120, 40);
            Assert.Equal(120, Application.Driver.Cols);
            Assert.Equal(40, Application.Driver.Rows);
            Assert.True(wasTerminalResized);

            // MockDriver will still be 120x40
            wasTerminalResized         = false;
            Application.HeightAsBuffer = true;
            driver.SetWindowSize(40, 20);
            Assert.Equal(120, Application.Driver.Cols);
            Assert.Equal(40, Application.Driver.Rows);
            Assert.Equal(120, Console.BufferWidth);
            Assert.Equal(40, Console.BufferHeight);
            Assert.Equal(40, Console.WindowWidth);
            Assert.Equal(20, Console.WindowHeight);
            Assert.True(wasTerminalResized);

            Application.Shutdown();
        }
Example #28
0
        public TextViewTests()
        {
            Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            //                   1         2         3
            //         01234567890123456789012345678901=32 (Length)
            var txt  = "TAB to jump between text fields.";
            var buff = new byte [txt.Length];

            for (int i = 0; i < txt.Length; i++)
            {
                buff [i] = (byte)txt [i];
            }
            var ms = new System.IO.MemoryStream(buff).ToArray();

            _textView = new TextView()
            {
                Width = 30, Height = 10
            };
            _textView.Text = ms;
        }
Example #29
0
        public void End_Cleans_Up()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));
            driver.Init(() => { });

            FakeConsole.ForegroundColor = ConsoleColor.Red;
            Assert.Equal(ConsoleColor.Red, Console.ForegroundColor);

            FakeConsole.BackgroundColor = ConsoleColor.Green;
            Assert.Equal(ConsoleColor.Green, Console.BackgroundColor);
            driver.Move(2, 3);
            Assert.Equal(2, Console.CursorLeft);
            Assert.Equal(3, Console.CursorTop);

            driver.End();
            Assert.Equal(0, Console.CursorLeft);
            Assert.Equal(0, Console.CursorTop);
            Assert.Equal(ConsoleColor.Gray, Console.ForegroundColor);
            Assert.Equal(ConsoleColor.Black, Console.BackgroundColor);
        }
        public void HeightAsBuffer_Is_True_Left_Cannot_Be_Greater_Than_BufferWidth_Minus_WindowWidth()
        {
            var driver = new FakeDriver();

            Application.Init(driver, new FakeMainLoop(() => FakeConsole.ReadKey(true)));

            Application.HeightAsBuffer = true;
            Assert.True(Application.HeightAsBuffer);

            driver.SetWindowPosition(81, 25);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            // MockDriver will now be sets to 120x25
            driver.SetBufferSize(120, 25);
            Assert.Equal(120, Application.Driver.Cols);
            Assert.Equal(25, Application.Driver.Rows);
            Assert.Equal(120, Console.BufferWidth);
            Assert.Equal(25, Console.BufferHeight);
            Assert.Equal(120, Console.WindowWidth);
            Assert.Equal(25, Console.WindowHeight);
            driver.SetWindowPosition(121, 25);
            Assert.Equal(0, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            driver.SetWindowSize(90, 25);
            Assert.Equal(120, Application.Driver.Cols);
            Assert.Equal(25, Application.Driver.Rows);
            Assert.Equal(120, Console.BufferWidth);
            Assert.Equal(25, Console.BufferHeight);
            Assert.Equal(90, Console.WindowWidth);
            Assert.Equal(25, Console.WindowHeight);
            driver.SetWindowPosition(121, 25);
            Assert.Equal(30, Console.WindowLeft);
            Assert.Equal(0, Console.WindowTop);

            Application.Shutdown();
        }