示例#1
0
        public void DrawClientArea_DrawingInhibited_NotDrawn()
        {
            const ConsoleColor foreColor = ConsoleColor.Cyan;
            const ConsoleColor backColor = ConsoleColor.Blue;
            bool drawn = false;

            using var stubbedWindow = new StubbedWindow
                  {
                      BackgroundColorGet  = () => backColor,
                      ForegroundColorGet  = () => foreColor,
                      DrawingInhibitedGet = () => true
                  };
            stubbedWindow.Graphics.CopyCharactersConsoleColorConsoleColorPointCharArraySize = (bg, fg, topLeft, characters, charsSize) => drawn = true;
            var stubbedController = new StubbedConsoleTextController
            {
                GetCharactersRectangle = rectangle => new char[10]
            };
            var size   = new Size(23, 42);
            var scroll = new Point(2, 3);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area        = new Rectangle(Point.Empty, size),
                      BorderStyle = BorderStyle.SingleLined,
                      Scroll      = scroll,
                      Parent      = stubbedWindow
                  };

            sut.CallDrawClientArea(stubbedWindow.Graphics);
            drawn.Should().BeFalse();
        }
示例#2
0
        public void KeyEvent_Handled_Ignored()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

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

            sut.KeyEvent += (sender, e) =>
            {
                sender.Should().Be(sut);
                raised    = true;
                e.Handled = true;
            };

            _ = new StubbedTextControl(sut);
            consoleController.KeyEventEvent(consoleController,
                                            new ConsoleKeyEventArgs(new KEY_EVENT_RECORD
            {
                ControlKeys = ControlKeyStates.None, KeyDown = 1, VirtualKeyCode = VirtualKey.Tab
            }));
            raised.Should().BeTrue();
            sut.FocusedControl.Should().BeNull();
        }
示例#3
0
        public void CanFocus_Set_EventOnlyOnChange()
        {
            using var sut = new StubbedTextControl();
            int raised = 0;

            sut.CanFocusChanged += OnCanFocusChanged;
            sut.CanFocus         = true;
            sut.CanFocus.Should().BeTrue();
            raised.Should().Be(1);
            sut.CanFocus = true;
            sut.CanFocus.Should().BeTrue();
            raised.Should().Be(1);
            sut.CanFocus = false;
            sut.CanFocus.Should().BeFalse();
            raised.Should().Be(2);
            sut.CanFocus = false;
            sut.CanFocus.Should().BeFalse();
            raised.Should().Be(2);
            sut.CanFocus = true;
            sut.CanFocus.Should().BeTrue();
            raised.Should().Be(3);

            sut.CanFocusChanged -= OnCanFocusChanged;
            sut.CanFocus         = false;
            raised.Should().Be(3);

            void OnCanFocusChanged(object sender, EventArgs e) => raised++;
        }
示例#4
0
        public void WrapMode_SetControllers_Value()
        {
            using var stubbedWindow = new StubbedWindow();
            WrapMode wrap       = WrapMode.NoWrap;
            int      called     = 0;
            var      controller = new StubbedConsoleTextController
            {
                WrapModeGet         = () => wrap,
                WrapModeSetWrapMode = b =>
                {
                    called += 1;
                    wrap    = b;
                }
            };

            using var sut = new StubbedTextControl(stubbedWindow, controller);

            sut.WrapMode.Should().Be(WrapMode.NoWrap);
            sut.WrapMode = WrapMode.SimpleWrap;
            called.Should().Be(1);
            wrap.Should().Be(WrapMode.SimpleWrap);
            sut.WrapMode = WrapMode.SimpleWrap;
            called.Should().Be(1);
            wrap.Should().Be(WrapMode.SimpleWrap);
            sut.WrapMode = WrapMode.NoWrap;
            called.Should().Be(2);
            wrap.Should().Be(WrapMode.NoWrap);
            sut.WrapMode = WrapMode.NoWrap;
            called.Should().Be(2);
            wrap.Should().Be(WrapMode.NoWrap);
        }
示例#5
0
        public void Append_Empty_SetTextAndCaret()
        {
            using var stubbedWindow = new StubbedWindow();
            bool         appended = false;
            const string text     = "hello";
            var          endCaret = Point.Empty;
            var          stubbedTextController = new StubbedConsoleTextController
            {
                AppendString = s =>
                {
                    s.Should().Be(text);
                    appended = true;
                    endCaret = new Point(17, 23);
                },
                ValidateCaretPoint = p => p,
                EndCaretGet        = () => endCaret
            };
            var size = new Size(10, 10);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedTextController)
                  {
                      Parent = stubbedWindow,
                      Area   = new Rectangle(Point.Empty, size)
                  };

            sut.Append(text);
            appended.Should().BeTrue();
            sut.Caret.Should().Be(endCaret);
            sut.Scroll.Should().Be(new Point(8, 14));
        }
示例#6
0
        public void Scroll_Scrolled()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedTextController = new StubbedConsoleTextController();
            var size = new Size(10, 10);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedTextController)
                  {
                      Parent = stubbedWindow,
                      Area   = new Rectangle(Point.Empty, size)
                  };

            sut.Scroll.Should().Be(Point.Empty);

            Point scroll = new Point(3, 4);
            bool  charactersRequestedCorrectly = false;

            stubbedTextController.GetCharactersRectangle = rectangle =>
            {
                rectangle.Should().Be(new Rectangle(scroll, size));
                charactersRequestedCorrectly = true;
                return(new char[100]);
            };

            sut.Scroll = scroll;
            charactersRequestedCorrectly.Should().BeTrue();
            sut.Scroll.Should().Be(scroll);
        }
示例#7
0
        public void Caret_SetAbove_ValidatedAndCursorInvisible()
        {
            using var stubbedWindow = new StubbedWindow();
            var   stubbedTextController = new StubbedConsoleTextController();
            var   size   = new Size(10, 10);
            Point scroll = new Point(3, 5);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedTextController)
                  {
                      Parent = stubbedWindow,
                      Area   = new Rectangle(Point.Empty, size),
                      Scroll = scroll
                  };

            sut.Caret.Should().Be(Point.Empty);
            bool  caretValidated = false;
            Point caret          = new Point(3, 1);

            stubbedTextController.ValidateCaretPoint = point =>
            {
                point.Should().Be(caret);
                caretValidated = true;
                return(caret);
            };

            sut.Caret = caret;
            caretValidated.Should().BeTrue();
            sut.Caret.Should().Be(caret);
            sut.CursorVisible.Should().BeFalse();
        }
示例#8
0
        public void Caret_SetInside_ValidatedAndCursorUpdatedAndCursorVisible()
        {
            using var stubbedWindow = new StubbedWindow();
            var   stubbedTextController = new StubbedConsoleTextController();
            var   size   = new Size(10, 10);
            Point scroll = new Point(3, 4);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedTextController)
                  {
                      Parent = stubbedWindow,
                      Area   = new Rectangle(Point.Empty, size),
                      Scroll = scroll
                  };

            sut.CursorVisible.Should().BeFalse();
            sut.CursorVisible = true;

            sut.Caret.Should().Be(Point.Empty);
            bool  caretValidated = false;
            Point caret          = new Point(7, 8);

            stubbedTextController.ValidateCaretPoint = point =>
            {
                point.Should().Be(caret);
                caretValidated = true;
                return(caret);
            };

            sut.Caret = caret;
            sut.Caret = caret; // just to cover this case
            caretValidated.Should().BeTrue();
            sut.Caret.Should().Be(caret);
            sut.CursorVisible.Should().BeTrue();
            sut.CursorPosition.Should().Be(new Point(4, 4));
        }
示例#9
0
        public void Text_Null_ArgumentNullException()
        {
            var stubbedWindow = new StubbedWindow();
            var sut           = new StubbedTextControl(stubbedWindow, new StubbedConsoleTextController());

            sut.Invoking(s => s.Text = null !).Should().Throw <ArgumentNullException>();
        }
示例#10
0
        public void CursorVisible_Dependency()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedTextController = new StubbedConsoleTextController
            {
                ValidateCaretPoint = p => p
            };
            var size = new Size(10, 10);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedTextController)
                  {
                      Parent = stubbedWindow,
                      Area   = new Rectangle(Point.Empty, size)
                  };

            sut.CursorVisible.Should().BeFalse();
            sut.CursorVisible = false;
            sut.CursorVisible.Should().BeFalse();

            sut.Scroll = new Point(0, 5);
            sut.CursorVisible.Should().BeFalse();
            sut.CursorVisible = true;
            sut.CursorVisible.Should().BeFalse();
            sut.Caret = new Point(1, 7);
            sut.CursorVisible.Should().BeTrue();
        }
示例#11
0
        public void DrawClientArea_Null_ArgumentNullException()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController();

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController);
            sut.Invoking(s => s.CallDrawClientArea()).Should().Throw <ArgumentNullException>();
        }
示例#12
0
        public void OnMouseScroll_Null_ArgumentNullException()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController();

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController);
            sut.Invoking(s => s.CallOnMouseScroll(null !)).Should().Throw <ArgumentNullException>();
        }
示例#13
0
        public void ConstructAndDispsoed_EventsWired_EventsUnwired()
        {
            using var window = new StubbedWindow();
            var textController = new StubbedConsoleTextController();

            using var sut = new StubbedTextControl(window, textController);
            sut.CursorVisible.Should().BeFalse();
            sut.CursorPosition.Should().Be(Point.Empty);
        }
示例#14
0
 public void CanEdit_Set_NotSupportedException()
 {
     using var sut = new StubbedTextControl();
     sut.Invoking(s => s.CanEdit = true)
     .Should()
     .Throw <NotSupportedException>()
     .Where(e =>
            e.Message.Contains(nameof(ConControls.Controls.TextControl)) &&
            e.Message.Contains(nameof(ConControls.Controls.TextControl.CanEdit)));
 }
示例#15
0
        public void WrapMode_GetControllers_Value()
        {
            using var stubbedWindow = new StubbedWindow();
            WrapMode wrap       = WrapMode.NoWrap;
            var      controller = new StubbedConsoleTextController
            {
                WrapModeGet = () => wrap
            };

            using var sut = new StubbedTextControl(stubbedWindow, controller);

            sut.WrapMode.Should().Be(WrapMode.NoWrap);
            wrap = WrapMode.SimpleWrap;
            sut.WrapMode.Should().Be(WrapMode.SimpleWrap);
        }
示例#16
0
        public void BorderStyleChanged_CursorUpdated()
        {
            var sut = new StubbedTextControl
            {
                Text = string.Empty.PadLeft(15, ' '),
                Size = new Size(10, 10)
            };

            sut.BorderStyle.Should().Be(BorderStyle.None);
            sut.Caret = new Point(9, 0);
            sut.CursorPosition.Should().Be(new Point(9, 0));
            sut.BorderStyle = BorderStyle.Bold;
            sut.BorderStyle.Should().Be(BorderStyle.Bold);
            sut.Caret.Should().Be(new Point(9, 0));
            sut.CursorVisible.Should().BeFalse();
        }
示例#17
0
        public void KeyEvent_UnhandledKeyUp_Ignored()
        {
            using var consoleController = new StubbedConsoleController();
            using var api = new StubbedNativeCalls();
            var graphicsProvider = new StubbedGraphicsProvider();

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

            _ = new StubbedTextControl(sut);
            consoleController.KeyEventEvent(consoleController,
                                            new ConsoleKeyEventArgs(new KEY_EVENT_RECORD
            {
                ControlKeys    = ControlKeyStates.None,
                KeyDown        = 0,
                VirtualKeyCode = VirtualKey.Tab
            }));
            sut.FocusedControl.Should().BeNull();
        }
示例#18
0
        public void DrawClientArea_DrawingAllowed_DrawnCorrectly()
        {
            const ConsoleColor foreColor = ConsoleColor.Cyan;
            const ConsoleColor backColor = ConsoleColor.Blue;

            using var stubbedWindow = new StubbedWindow
                  {
                      BackgroundColorGet = () => backColor,
                      ForegroundColorGet = () => foreColor
                  };
            var stubbedController = new StubbedConsoleTextController();
            var size   = new Size(23, 42);
            var scroll = new Point(2, 3);

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area        = new Rectangle(Point.Empty, size),
                      BorderStyle = BorderStyle.SingleLined,
                      Scroll      = scroll,
                      Parent      = stubbedWindow
                  };

            char[] expectedChars = new char[10];
            stubbedController.GetCharactersRectangle = rectangle =>
            {
                rectangle.Should().Be(new Rectangle(scroll.X, scroll.Y, size.Width - 2, size.Height - 2));
                return(expectedChars);
            };
            bool drawn = false;

            stubbedWindow.Graphics.CopyCharactersConsoleColorConsoleColorPointCharArraySize = (bg, fg, topLeft, characters, charsSize) =>
            {
                bg.Should().Be(backColor);
                fg.Should().Be(foreColor);
                topLeft.Should().Be(new Point(1, 1));
                characters.Should().BeSameAs(expectedChars);
                charsSize.Should().Be(new Size(size.Width - 2, size.Height - 2));
                drawn = true;
            };

            sut.Draw();
            drawn.Should().BeTrue();
        }
示例#19
0
        public void ScrollToCaret_CaretLeft_Changed()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                ValidateCaretPoint = p => p
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Size        = new Size(12, 12),
                      BorderStyle = BorderStyle.SingleLined
                  };

            sut.Scroll = new Point(10, 0);
            sut.Caret  = new Point(5, 7);
            sut.ScrollToCaret();
            sut.Scroll.Should().BeEquivalentTo(new Point(5, 0));
        }
示例#20
0
        public void AreaChanged_CursorUpdated()
        {
            var stubbedWindow = new StubbedWindow();
            var sut           = new StubbedTextControl(stubbedWindow)
            {
                Text  = new string(Enumerable.Repeat(' ', 1000).ToArray()),
                Size  = new Size(10, 10),
                Caret = new Point(9, 9)
            };

            sut.CursorVisible.Should().BeFalse();
            sut.CursorVisible = true;

            sut.Caret.Should().Be(new Point(9, 9));
            sut.CursorPosition.Should().Be(new Point(9, 9));
            sut.CursorVisible.Should().BeTrue();
            sut.Size.Should().Be(new Size(10, 10));

            sut.Size = new Size(5, 5);
            sut.Size.Should().Be(new Size(5, 5));
            sut.Caret.Should().Be(new Point(9, 9));
            sut.CursorVisible.Should().BeFalse();
        }
示例#21
0
        public void Text_NotNull_SetInControllerEventRaisedAndDrawn()
        {
            var stubbedWindow  = new StubbedWindow();
            var textController = new StubbedConsoleTextController();
            var sut            = new StubbedTextControl(stubbedWindow, textController)
            {
                Parent = stubbedWindow
            };

            const string expectedText    = "expected";
            string       controllerValue = string.Empty;

            textController.TextSetString = s => controllerValue = s;
            textController.TextGet       = () => controllerValue;
            int eventRaised = 0;

            sut.TextChanged += (sender, e) => eventRaised += 1;

            bool drawn = false;

            stubbedWindow.Graphics.CopyCharactersConsoleColorConsoleColorPointCharArraySize = (color, consoleColor, arg3, arg4, arg5) => drawn = true;

            sut.Text = expectedText;
            drawn.Should().BeTrue();
            controllerValue.Should().Be(expectedText);
            sut.Text.Should().Be(expectedText);
            eventRaised.Should().Be(1);

            // don't raise event twice
            drawn    = false;
            sut.Text = expectedText;
            controllerValue.Should().Be(expectedText);
            sut.Text.Should().Be(expectedText);
            eventRaised.Should().Be(1);
            drawn.Should().BeFalse();
        }
示例#22
0
 public void CanEdit_Get_False()
 {
     using var sut = new StubbedTextControl();
     sut.CanEdit.Should().BeFalse();
 }
示例#23
0
 public void CanFocus_Get_True()
 {
     using var sut = new StubbedTextControl();
     sut.CanFocus.Should().BeFalse();
 }