public void KeyEvents_NotFocused_Nothing() { 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, EndCaretGet = () => (0, 20).Pt(), GetLineLengthInt32 = l => 20 }; using var sut = new StubbedTextControl(stubbedWindow, stubbedController) { Area = (5, 5, 10, 10).Rect(), Parent = stubbedWindow, Caret = (10, 10).Pt() }; sut.Focused.Should().BeFalse(); var e = new KeyEventArgs(new ConsoleKeyEventArgs(new KEY_EVENT_RECORD { KeyDown = 1, VirtualKeyCode = VirtualKey.Up })); stubbedWindow.KeyEventEvent(stubbedWindow, e); sut.Caret.Should().Be((10, 10).Pt()); sut.Scroll.Should().Be(Point.Empty); e.Handled.Should().BeFalse(); }
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); }
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); }
public void OnKeyEvent_Disabled_Notthing() { ConControls.Controls.ConsoleControl?focused = null; using var stubbedWindow = new StubbedWindow { FocusedControlGet = () => focused, FocusedControlSetConsoleControl = c => focused = c }; using var sut = new ConControls.Controls.Button(stubbedWindow) { Size = (10, 3).Sz(), Parent = stubbedWindow, Enabled = false }; focused = sut; sut.Focused.Should().BeTrue(); bool clicked = false; sut.Click += (sender, ea) => clicked = true; var e = new KeyEventArgs(new ConsoleKeyEventArgs(new KEY_EVENT_RECORD { KeyDown = 1, ControlKeys = ControlKeyStates.NUMLOCK_ON, VirtualKeyCode = VirtualKey.Return })); stubbedWindow.KeyEventEvent(stubbedWindow, e); clicked.Should().BeFalse(); e.Handled.Should().BeFalse(); }
public void EffectiveBorderStyle_ExtraValues_CorrectValues() { ConControls.Controls.ConsoleControl?focused = null; var stubbedWindow = new StubbedWindow { GetGraphics = () => new StubIConsoleGraphics(), FocusedControlGet = () => focused, EnabledGet = () => true, FocusedControlSetConsoleControl = c => focused = c }; var sut = new StubbedConsoleControl(stubbedWindow) { Focusable = true, DisabledBorderStyle = BorderStyle.SingleLined, FocusedBorderStyle = BorderStyle.Bold, Parent = stubbedWindow }; sut.EffBorderStyle.Should().Be(BorderStyle.None); sut.Enabled = false; sut.EffBorderStyle.Should().Be(BorderStyle.SingleLined); sut.Focused = true; sut.EffBorderStyle.Should().Be(BorderStyle.SingleLined); sut.Enabled = true; sut.EffBorderStyle.Should().Be(BorderStyle.Bold); }
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); }
public void EffectiveBorderStyle_NoExtraValues_DefaultValues() { ConControls.Controls.ConsoleControl?focused = null; var stubbedWindow = new StubbedWindow { EnabledGet = () => true, FocusedControlGet = () => focused, FocusedControlSetConsoleControl = c => focused = c }; var sut = new StubbedConsoleControl(stubbedWindow) { Focusable = true }; sut.EffBorderStyle.Should().Be(BorderStyle.None); sut.Enabled = false; sut.EffBorderStyle.Should().Be(BorderStyle.None); sut.Focused = true; sut.EffBorderStyle.Should().Be(BorderStyle.None); sut.Enabled = true; sut.EffBorderStyle.Should().Be(BorderStyle.None); }
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(); } }