public void Clear_Cleared() { using var stubbedWindow = new StubbedWindow(); bool cleared = false; var controller = new StubbedConsoleTextController { BufferLineCountGet = () => cleared ? 0 : 20, MaxLineLengthGet = () => cleared ? 0 : 20, GetLineLengthInt32 = l => cleared ? 0 : 20, ValidateCaretPoint = p => cleared ? Point.Empty : p, Clear = () => cleared = true }; using var sut = new StubbedTextControl(stubbedWindow, controller) { Size = (10, 10).Sz(), Caret = (3, 4).Pt(), Scroll = (2, 2).Pt() }; sut.Size.Should().Be((10, 10).Sz()); sut.Caret.Should().Be((3, 4).Pt()); sut.Scroll.Should().Be((2, 2).Pt()); sut.Clear(); cleared.Should().BeTrue(); sut.Caret.Should().Be(Point.Empty); sut.Scroll.Should().Be(Point.Empty); } }
public void OnMouseScroll_HorizontalScrollDisabled_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, Enabled = false }; var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD { EventFlags = MouseEventFlags.WheeledHorizontally, MousePosition = new COORD(5, 5), Scroll = 120 })); sut.CallOnMouseScroll(e); sut.Scroll.Should().Be(Point.Empty); e.Handled.Should().BeFalse(); }
public void Append_CaretNotAtEnd_DontScroll() { using var stubbedWindow = new StubbedWindow(); bool appended = false; const string text = "hello"; var endCaret = (5, 0).Pt(); 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), Text = text, Caret = (1, 0).Pt() }; sut.Append(text); appended.Should().BeTrue(); sut.Caret.Should().Be((1, 0).Pt()); sut.Scroll.Should().Be(Point.Empty); } }
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); }
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(); } }
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(); }
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(); }
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(); }
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); }
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)); }
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(); }
public void OnMouseClick_LeftClickedDisabled_Nothing() { 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(), Enabled = false }; var e = new MouseEventArgs(new ConsoleMouseEventArgs(new MOUSE_EVENT_RECORD { MousePosition = new COORD(10, 10), ButtonState = MouseButtonStates.LeftButtonPressed })); sut.CallOnMouseClick(e); sut.Caret.Should().Be(Point.Empty); sut.Focused.Should().BeFalse(); e.Handled.Should().BeFalse(); }
public void CanFocus_Set_EventOnlyOnChange() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController); int raised = 0; sut.CanFocusChanged += (sender, e) => raised++; sut.CanFocus = true; sut.CanFocus.Should().BeTrue(); raised.Should().Be(1); // base value is false before 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); }
public void CursorVisible_Set_EventOnlyOnChange() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController) { Size = (10, 10).Sz() }; int raised = 0; sut.CursorVisibleChanged += (sender, e) => raised++; sut.CursorVisible = true; sut.CursorVisible.Should().BeTrue(); raised.Should().Be(1); // base value is false sut.CursorVisible = true; sut.CursorVisible.Should().BeTrue(); raised.Should().Be(1); sut.CursorVisible = false; sut.CursorVisible.Should().BeFalse(); raised.Should().Be(2); sut.CursorVisible = false; sut.CursorVisible.Should().BeFalse(); raised.Should().Be(2); sut.CursorVisible = true; sut.CursorVisible.Should().BeTrue(); raised.Should().Be(3); }
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(); }
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>(); }
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>(); }
public void CanEdit_Get_False() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController); sut.CanEdit.Should().BeFalse(); }
public void CanFocus_Get_True() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.Button(stubbedWindow, textController); sut.CanFocus.Should().BeTrue(); }
public void TabStop_Get_True() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController); sut.TabStop.Should().BeTrue(); }
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); }
public void CursorVisible_Get_True() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController) { Size = new Size(10, 10) }; sut.CursorVisible.Should().BeTrue(); }
public void TabStop_InitiallyTrue() { using var stubbedWindow = new StubbedWindow(); var controller = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, controller); sut.TabStop.Should().BeTrue(); sut.TabStop = false; sut.TabStop.Should().BeFalse(); sut.TabStop = true; sut.TabStop.Should().BeTrue(); }
public void CanEdit_Set_NotSupportedException() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController(); using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController); sut.Invoking(s => s.CanEdit = true) .Should() .Throw <NotSupportedException>() .Where(e => e.Message.Contains(nameof(ConControls.Controls.TextBlock)) && e.Message.Contains(nameof(ConControls.Controls.TextBlock.CanEdit))); }
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); }
public void Text_EnclosedInParanthesis() { using var stubbedWindow = new StubbedWindow(); string text = string.Empty; var stubbedController = new StubbedConsoleTextController { TextGet = () => text, TextSetString = s => text = s }; using var sut = new ConControls.Controls.Button(stubbedWindow, stubbedController) { Text = "Hello World!" }; sut.Text.Should().Be("Hello World!"); text.Should().Be("[Hello World!]"); }
public void CursorVisible_CaretOutside_False() { using var stubbedWindow = new StubbedWindow(); var textController = new StubbedConsoleTextController { ValidateCaretPoint = p => p }; using var sut = new ConControls.Controls.TextBlock(stubbedWindow, textController) { Size = new Size(10, 10) }; sut.CursorVisible.Should().BeTrue(); sut.Caret = (11, 11).Pt(); sut.CaretVisible.Should().BeFalse(); sut.CursorVisible.Should().BeFalse(); }
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)); }
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(); }
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(); }