public void DefaultCursorSize_SetAndDrawn()
        {
            const int originalCursorSize    = 17;
            const int alternativeCursorSize = 23;
            var       api = new StubbedNativeCalls
            {
                GetCursorInfoConsoleOutputHandle = handle => (true, originalCursorSize, Point.Empty)
            };

            using var controller = new StubbedConsoleController();
            bool graphicsProvided = false;
            var  graphicsProvider = new StubbedGraphicsProvider();

            graphicsProvider.ProvideConsoleOutputHandleINativeCallsSizeFrameCharSets = (handle, calls, arg3, arg4) =>
            {
                graphicsProvided = true;
                return(graphicsProvider.Graphics);
            };
            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, graphicsProvider);
            var suti = (IControlContainer)sut;

            sut.DefaultCursorSize.Should().Be(originalCursorSize);
            suti.CursorSize.Should().Be(originalCursorSize);
            graphicsProvided = false;
            suti.CursorSize  = alternativeCursorSize;
            graphicsProvided.Should().BeTrue();
            sut.DefaultCursorSize.Should().Be(alternativeCursorSize);

            graphicsProvided = false;
            suti.CursorSize  = null;
            graphicsProvided.Should().BeFalse();
            sut.DefaultCursorSize.Should().Be(alternativeCursorSize);
        }
        public void DefaultForegroundColor_SetAndDrawn()
        {
            const ConsoleColor color = ConsoleColor.DarkMagenta;
            var api = new StubbedNativeCalls();

            using var controller = new StubbedConsoleController();
            bool graphicsProvided = false;
            var  graphicsProvider = new StubbedGraphicsProvider();

            graphicsProvider.ProvideConsoleOutputHandleINativeCallsSizeFrameCharSets = (handle, calls, arg3, arg4) =>
            {
                graphicsProvided = true;
                return(graphicsProvider.Graphics);
            };
            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, graphicsProvider);
            var suti = (IControlContainer)sut;

            sut.DefaultForegroundColor.Should().Be(ConsoleColor.Gray);
            suti.ForegroundColor.Should().Be(ConsoleColor.Gray);
            graphicsProvided     = false;
            suti.ForegroundColor = color;
            graphicsProvided.Should().BeTrue();
            sut.DefaultForegroundColor.Should().Be(color);

            graphicsProvided     = false;
            suti.ForegroundColor = null;
            graphicsProvided.Should().BeFalse();
            sut.DefaultForegroundColor.Should().Be(color);
        }
Beispiel #3
0
        public void FocusNext_Cousins_CorrectOrder()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            var c0 = new Panel(sut)
            {
                Parent = sut
            };
            var f00 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c0
            };
            var c1 = new Panel(sut)
            {
                Parent = sut
            };
            var f10 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c1
            };

            sut.FocusedControl.Should().BeNull();
            sut.FocusNext().Should().Be(f00);
            sut.FocusNext().Should().Be(f10);
            sut.FocusNext().Should().Be(f00);
            sut.FocusNext().Should().Be(f10);
        }
        public void ControlManagement_ControlAreaChanged_Redrawn()
        {
            var api = new StubbedNativeCalls();

            using var controller = new StubbedConsoleController();
            var  graphicsProvider = new StubbedGraphicsProvider();
            bool provided         = false;

            graphicsProvider.ProvideConsoleOutputHandleINativeCallsSizeFrameCharSets = (handle, calls, arg3, arg4) =>
            {
                provided = true;
                return(graphicsProvider.Graphics);
            };

            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, graphicsProvider);
            using var c   = new Panel(sut)
                  {
                      Area = (5, 5, 10, 10).Rect(), Parent = sut
                  };
            provided = false;
            c.Area   = (4, 4, 6, 6).Rect();
            provided.Should().BeTrue();

            sut.Controls.Remove(c);
            provided = false;
            c.Area   = (1, 2, 3, 4).Rect();
            provided.Should().BeFalse();
        }
    }
Beispiel #5
0
        public void FocusNext_Empty_Null()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            sut.FocusedControl.Should().BeNull();
            sut.FocusNext().Should().BeNull();
            sut.FocusNext().Should().BeNull();
        }
Beispiel #6
0
        public void FocusedControl_NonFocussableControl_InvalidOperationException()
        {
            var api = new StubbedNativeCalls();

            using var controller = new StubbedConsoleController();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, graphicsProvider);
            using var c   = new Panel(sut)
                  {
                      Parent = sut
                  };
            sut.Invoking(s => s.FocusedControl = c).Should().Throw <InvalidOperationException>();
        }
        public void ControlManagement_CursorUpdate_Updated()
        {
            bool  cursorVisible  = false;
            int   cursorSize     = 0;
            Point cursorPosition = Point.Empty;

            var api = new StubbedNativeCalls
            {
                SetCursorInfoConsoleOutputHandleBooleanInt32Point = (handle, visible, size, position) =>
                {
                    cursorVisible  = visible;
                    cursorSize     = size;
                    cursorPosition = position;
                }
            };

            using var controller = new StubbedConsoleController();
            var graphicsProvider = new StubbedGraphicsProvider();
            var textController   = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20,
                MaxLineLengthGet   = () => 20,
                EndCaretGet        = () => (20, 20).Pt(),
                GetLineLengthInt32 = l => 20
            };

            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, graphicsProvider);
            using var c   = new ConControls.Controls.TextBlock(sut, textController)
                  {
                      Area = (5, 5, 10, 10).Rect(), Parent = sut, CursorSize = 12, CursorVisible = false, CursorPosition = (1, 2).Pt()
                  };

            sut.FocusedControl = c;
            cursorVisible.Should().BeFalse();
            cursorSize.Should().Be(12);
            cursorPosition.Should().Be((6, 7).Pt());

            c.CursorPosition = (5, 6).Pt();
            cursorPosition.Should().Be((10, 11).Pt());

            c.CursorVisible = true;
            cursorVisible.Should().BeTrue();

            c.CursorSize = 23;
            cursorSize.Should().Be(23);
        }
Beispiel #8
0
        public void FocusNext_SingleThenDisabled_Null()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            var f0 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = sut
            };

            sut.FocusedControl.Should().BeNull();
            sut.FocusNext().Should().Be(f0);
            f0.Enabled = false;
            sut.FocusNext().Should().BeNull();
        }
Beispiel #9
0
        public void MouseEvents_MouseEventRaisedWithCorrectValues()
        {
            const ControlKeyStates controlKeys = ControlKeyStates.LEFT_ALT_PRESSED | ControlKeyStates.CAPSLOCK_ON;
            const int scroll = 123;
            const MouseButtonStates buttons = MouseButtonStates.LeftButtonPressed;
            Point position             = (3, 7).Pt();
            const MouseEventFlags kind = MouseEventFlags.Wheeled;

            var api = new StubbedNativeCalls();

            using var controller = new StubbedConsoleController();
            var graphicsProvider = new StubbedGraphicsProvider();

            var args = new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                ButtonState   = buttons,
                ControlKeys   = controlKeys,
                EventFlags    = kind,
                MousePosition = new COORD(position),
                Scroll        = scroll
            });

            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, graphicsProvider);
            bool raised = false;

            sut.MouseEvent += OnMouse;
            controller.MouseEventEvent(controller, args);
            raised.Should().BeTrue();
            raised          = false;
            sut.MouseEvent -= OnMouse;
            controller.MouseEventEvent(controller, args);
            raised.Should().BeFalse();

            void OnMouse(object sender, MouseEventArgs e)
            {
                sender.Should().Be(sut);
                e.ControlKeys.Should().Be(controlKeys);
                e.Scroll.Should().Be(scroll);
                e.ButtonState.Should().Be(buttons);
                e.Position.Should().Be(position);
                e.Kind.Should().Be(kind);
                raised = true;
            }
        }
Beispiel #10
0
        public void SetActiveScreen_SetsCorrectly()
        {
            var            api    = new StubbedNativeCalls();
            bool           active = false;
            IConsoleWindow?window = null;

            using var controller = new StubbedConsoleController
                  {
                      ActiveScreenSetBoolean = b =>
                      {
                          Assert.IsTrue(Monitor.IsEntered(window !.SynchronizationLock));
                          active = b;
                      }
                  };

            using var sut = new ConControls.Controls.ConsoleWindow(api, controller, new StubbedGraphicsProvider());
            window        = sut;
            active.Should().BeFalse();
            sut.ActiveScreen = true;
            active.Should().BeTrue();
            sut.ActiveScreen = false;
            active.Should().BeFalse();
        }
    }
Beispiel #11
0
        public void FocusPrevious_Single_Focused()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            var c0 = new Panel(sut)
            {
                Parent = sut
            };
            var f00 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c0
            };

            sut.Controls.Add(new Panel(sut));

            sut.FocusedControl.Should().BeNull();
            sut.FocusPrevious().Should().Be(f00);
            sut.FocusPrevious().Should().Be(f00);
            sut.FocusPrevious().Should().Be(f00);
        }
Beispiel #12
0
        public void FocusNext_MultipleTabOrder_CorrectSequence()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            var c0 = new Panel(sut)
            {
                TabOrder = 10
            };
            var f00 = new ConControls.Controls.TextBlock(sut)
            {
                TabOrder = 20
            };
            var f01 = new ConControls.Controls.TextBlock(sut)
            {
                TabOrder = 10
            };
            var c02 = new Panel(sut)
            {
                TabOrder = 15
            };
            var f020 = new ConControls.Controls.TextBlock(sut);
            var c021 = new ConControls.Controls.TextBlock(sut)
            {
                Enabled = false
            };
            var c1 = new Panel(sut)
            {
                TabOrder = 5
            };
            var f10  = new ConControls.Controls.TextBlock(sut);
            var f100 = new ConControls.Controls.TextBlock(sut)
            {
                TabOrder = 10
            };
            var f101 = new ConControls.Controls.TextBlock(sut)
            {
                TabOrder = 10
            };

            sut.Controls.AddRange(c0, c1);

            c0.Controls.AddRange(f00, f01, c02);
            c02.Controls.AddRange(f020, c021);

            c1.Controls.Add(f10);
            f10.Controls.AddRange(f100, f101);

            sut.FocusedControl.Should().BeNull();
            sut.FocusNext().Should().Be(f10);
            sut.FocusNext().Should().Be(f100);
            sut.FocusNext().Should().Be(f101);
            sut.FocusNext().Should().Be(f01);
            sut.FocusNext().Should().Be(f020);
            sut.FocusNext().Should().Be(f00);
            sut.FocusNext().Should().Be(f10);
            sut.FocusNext().Should().Be(f100);
            sut.FocusNext().Should().Be(f101);
            sut.FocusNext().Should().Be(f01);
            sut.FocusNext().Should().Be(f020);
            sut.FocusNext().Should().Be(f00);
        }
Beispiel #13
0
        public void FocusPrevious_MultipleTabOrder_CorrectSequence()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

            using var sut = new ConControls.Controls.ConsoleWindow(api, consoleController, graphicsProvider);

            var c0 = new Panel(sut)
            {
                Parent = sut, TabOrder = 10
            };
            var f00 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c0, TabOrder = 20
            };
            var f01 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c0, TabOrder = 10
            };
            var c02 = new Panel(sut)
            {
                Parent = c0, TabOrder = 15
            };
            var f020 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c02
            };

            c02.Controls.Add(new ConControls.Controls.TextBlock(sut)
            {
                Enabled = false
            });
            var c1 = new Panel(sut)
            {
                Parent = sut, TabOrder = 5
            };
            var f10 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = c1
            };
            var f100 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = f10, TabOrder = 10
            };
            var f101 = new ConControls.Controls.TextBlock(sut)
            {
                Parent = f10, TabOrder = 10
            };

            sut.FocusedControl.Should().BeNull();
            sut.FocusPrevious().Should().Be(f00);
            sut.FocusPrevious().Should().Be(f020);
            sut.FocusPrevious().Should().Be(f01);
            sut.FocusPrevious().Should().Be(f101);
            sut.FocusPrevious().Should().Be(f100);
            sut.FocusPrevious().Should().Be(f10);
            sut.FocusPrevious().Should().Be(f00);
            sut.FocusPrevious().Should().Be(f020);
            sut.FocusPrevious().Should().Be(f01);
            sut.FocusPrevious().Should().Be(f101);
            sut.FocusPrevious().Should().Be(f100);
            sut.FocusPrevious().Should().Be(f10);
        }