Пример #1
0
        public void OnWindowMouseEvent_MoveInsideAndOutside_EnterMoveAndLeave()
        {
            ConControls.Controls.ConsoleControl?focused = null;
            using var stubbedWindow = new StubbedWindow
                  {
                      FocusedControlGet = () => focused,
                      FocusedControlSetConsoleControl = c => focused = c
                  };
            using var sut = new StubbedConsoleControl(stubbedWindow)
                  {
                      Area        = (5, 5, 10, 10).Rect(),
                      BorderStyle = BorderStyle.DoubleLined,
                      Parent      = stubbedWindow,
                      Focusable   = true
                  };
            var enterArgs = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.Moved,
                MousePosition = new COORD(6, 6),
                ButtonState   = MouseButtonStates.None
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, enterArgs);

            sut.Focused.Should().BeFalse();
            enterArgs.Handled.Should().BeTrue();

            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseEnter).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseLeave).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseMove).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseDoubleClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseScroll).Should().Be(0);

            var leaveArgs = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.Moved,
                MousePosition = new COORD(4, 4),
                ButtonState   = MouseButtonStates.None
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, leaveArgs);

            sut.Focused.Should().BeFalse();
            leaveArgs.Handled.Should().BeTrue();

            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseEnter).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseLeave).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseMove).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseDoubleClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseScroll).Should().Be(0);
        }
Пример #2
0
        public void OnWindowMouseEvent_Disabled_Nothing()
        {
            ConControls.Controls.ConsoleControl?focused = null;
            using var stubbedWindow = new StubbedWindow
                  {
                      FocusedControlGet = () => focused,
                      FocusedControlSetConsoleControl = c => focused = c
                  };
            using var sut = new StubbedConsoleControl(stubbedWindow)
                  {
                      Area        = (5, 5, 10, 10).Rect(),
                      BorderStyle = BorderStyle.DoubleLined,
                      Parent      = stubbedWindow,
                      Focusable   = true,
                      Enabled     = false
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                MousePosition = new COORD(12, 12),
                ButtonState   = MouseButtonStates.LeftButtonPressed
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);

            sut.Focused.Should().BeFalse();
            e.Handled.Should().BeFalse();

            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseEnter).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseLeave).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseMove).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseDoubleClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseScroll).Should().Be(0);
        }
Пример #3
0
        public void OnWindowMouseEvent_MouseWheeledHorizontally_OnMouseScrollCalled()
        {
            using var stubbedWindow = new StubbedWindow();
            using var sut           = new StubbedConsoleControl(stubbedWindow)
                  {
                      Area        = (5, 5, 10, 10).Rect(),
                      BorderStyle = BorderStyle.DoubleLined,
                      Parent      = stubbedWindow
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.WheeledHorizontally,
                MousePosition = new COORD(12, 12)
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);

            e.Handled.Should().BeTrue();
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseEnter).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseLeave).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseMove).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseDoubleClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseScroll).Should().Be(1);
        }
    }
Пример #4
0
        public void OnWindowMouseEvent_RightClickedInside_ClickCalledButNotFocused()
        {
            ConControls.Controls.ConsoleControl?focused = null;
            using var stubbedWindow = new StubbedWindow
                  {
                      FocusedControlGet = () => focused,
                      FocusedControlSetConsoleControl = c => focused = c
                  };
            using var sut = new StubbedConsoleControl(stubbedWindow)
                  {
                      Area        = (5, 5, 10, 10).Rect(),
                      BorderStyle = BorderStyle.DoubleLined,
                      Parent      = stubbedWindow,
                      Focusable   = true
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.None,
                MousePosition = new COORD(12, 12),
                ButtonState   = MouseButtonStates.RightButtonPressed
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);

            sut.Focused.Should().BeFalse();
            e.Handled.Should().BeTrue($"{nameof(StubbedConsoleControl)} should always set handled flag");

            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseEnter).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseLeave).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseMove).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseClick).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseDoubleClick).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnMouseScroll).Should().Be(0);
        }
Пример #5
0
        public void OnMouseScroll_VerticalScrollTooLow_Bottom()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area   = (5, 5, 10, 10).Rect(),
                      Parent = stubbedWindow,
                      Scroll = (0, 17).Pt()
                  };

            sut.Scroll.Should().Be((0, 17).Pt());
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.Wheeled,
                MousePosition = new COORD(5, 5),
                Scroll        = -480
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Scroll.Should().Be((0, 19).Pt());
            e.Handled.Should().BeTrue();
        }
    }
Пример #6
0
        public void OnMouseScroll_VerticalScrollInvisible_NotScrolled()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area    = (5, 5, 10, 10).Rect(),
                      Parent  = stubbedWindow,
                      Visible = false
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.Wheeled,
                MousePosition = new COORD(5, 5),
                Scroll        = 120
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Scroll.Should().Be(Point.Empty);
            e.Handled.Should().BeFalse();
        }
Пример #7
0
        public void OnMouseScroll_HorizontalScrollOutsideArea_NotScrolled()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20,
                MaxLineLengthGet   = () => 20,
                WidthGet           = () => 20,
                GetLineLengthInt32 = l => 20
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area   = (5, 5, 10, 10).Rect(),
                      Parent = stubbedWindow
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.WheeledHorizontally,
                MousePosition = new COORD(4, 4),
                Scroll        = 120
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Scroll.Should().Be(Point.Empty);
            e.Handled.Should().BeFalse();
        }
Пример #8
0
        public void OnMouseScroll_HorizontalScrollTooRight_Right()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20,
                MaxLineLengthGet   = () => 25,
                WidthGet           = () => 20,
                GetLineLengthInt32 = l => 20
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area   = (5, 5, 10, 10).Rect(),
                      Parent = stubbedWindow,
                      Scroll = (22, 0).Pt()
                  };

            sut.Scroll.Should().Be((22, 0).Pt());
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.WheeledHorizontally,
                MousePosition = new COORD(5, 5),
                Scroll        = -480
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Scroll.Should().Be((24, 0).Pt());
            e.Handled.Should().BeTrue();
        }
Пример #9
0
        public void OnMouseClick_LeftClickedOutsideArea_Notthing()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20,
                MaxLineLengthGet   = () => 20,
                WidthGet           = () => 20,
                GetLineLengthInt32 = l => 20
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area   = (5, 5, 10, 10).Rect(),
                      Parent = stubbedWindow,
                      Scroll = (3, 3).Pt()
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                MousePosition = new COORD(4, 4),
                ButtonState   = MouseButtonStates.LeftButtonPressed
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Caret.Should().Be(Point.Empty);
            sut.Focused.Should().BeFalse();
            e.Handled.Should().BeFalse();
        }
Пример #10
0
        public void OnMouseScroll_VerticalScrollDown_ScrolledDown()
        {
            using var stubbedWindow = new StubbedWindow();
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20,
                GetLineLengthInt32 = _ => 20,
                MaxLineLengthGet   = () => 20,
                ValidateCaretPoint = p => p
            };

            using var sut = new StubbedTextControl(stubbedWindow, stubbedController)
                  {
                      Area          = (5, 5, 10, 10).Rect(),
                      Parent        = stubbedWindow,
                      Scroll        = (0, 5).Pt(),
                      Caret         = (5, 6).Pt(),
                      CursorVisible = true,
                      CanFocus      = true,
                      Focused       = true
                  };

            sut.Scroll.Should().Be((0, 5).Pt());
            sut.Caret.Should().Be((5, 6).Pt());
            sut.CursorVisible.Should().BeTrue();
            sut.CursorPosition.Should().Be((5, 1).Pt());
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                EventFlags    = MouseEventFlags.Wheeled,
                MousePosition = new COORD(5, 5),
                Scroll        = -360
            }));
            bool changed = false;

            sut.CursorVisibleChanged += (sender, e1) => changed = true;
            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Scroll.Should().Be((0, 8).Pt());
            sut.CursorVisible.Should().BeFalse();
            changed.Should().BeTrue();
            sut.Caret.Should().Be((5, 6).Pt());
            e.Handled.Should().BeTrue();
        }
Пример #11
0
        public void OnMouseClick_RightClicked_Nothing()
        {
            using var stubbedWindow = new StubbedWindow();
            using var sut           = new ConControls.Controls.Button(stubbedWindow)
                  {
                      Size   = (10, 3).Sz(),
                      Parent = stubbedWindow
                  };
            bool clicked = false;

            sut.Click += (sender, ea) => clicked = true;
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                MousePosition = new COORD(1, 1),
                ButtonState   = MouseButtonStates.RightButtonPressed
            }));

            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            clicked.Should().BeFalse();
            e.Handled.Should().BeFalse();
        }
Пример #12
0
        public void OnMouseClick_LeftClicked_FocusedAndCaretSet()
        {
            ConControls.Controls.ConsoleControl?focused = null;
            using var stubbedWindow = new StubbedWindow
                  {
                      FocusedControlGet = () => focused,
                      FocusedControlSetConsoleControl = c => focused = c
                  };
            var stubbedController = new StubbedConsoleTextController
            {
                BufferLineCountGet = () => 20,
                MaxLineLengthGet   = () => 20,
                WidthGet           = () => 20,
                GetLineLengthInt32 = l => 20
            };

            using var sut = new ConControls.Controls.TextBlock(stubbedWindow, stubbedController)
                  {
                      Area   = (5, 5, 10, 10).Rect(),
                      Parent = stubbedWindow,
                      Scroll = (3, 2).Pt()
                  };
            var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD
            {
                MousePosition = new COORD(10, 10),
                ButtonState   = MouseButtonStates.LeftButtonPressed
            }));

            sut.Focused.Should().BeFalse();
            focused.Should().BeNull();
            stubbedWindow.MouseEventEvent(stubbedWindow, e);
            sut.Caret.Should().Be(new Point(8, 7));
            sut.Focused.Should().BeTrue();
            focused.Should().Be(sut);
            e.Handled.Should().BeTrue();
        }
    }
Пример #13
0
 public void OnWindowMouseEvent_EventArgsNull_ArgumentNullException()
 {
     using var stubbedWindow = new StubbedWindow();
     using var sut           = new StubbedConsoleControl(stubbedWindow);
     sut.Invoking(s => stubbedWindow.MouseEventEvent(stubbedWindow, null !)).Should().Throw <ArgumentNullException>();
 }