Ejemplo n.º 1
0
        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);
        }
    }
Ejemplo n.º 2
0
        public void PointToClient_WithBorders_CorrectResult()
        {
            var stubbedWindow = new StubbedWindow
            {
                PointToClientPoint  = p => p,
                PointToConsolePoint = p => p
            };

            var l1 = new Point(12, 34);
            var l2 = new Point(23, 42);

            var sut1 = new Panel(stubbedWindow)
            {
                Location    = l1,
                BorderStyle = BorderStyle.SingleLined
            };
            var sut2 = new Panel(stubbedWindow)
            {
                Location = l2
            };

            sut1.Controls.Add(sut2);
            stubbedWindow.Controls.Add(sut1);

            var consolePoint = new Point(123, 456);

            sut2.PointToClient(consolePoint)
            .Should()
            .Be(new Point(
                    consolePoint.X - l1.X - l2.X - 1,
                    consolePoint.Y - l1.Y - l2.Y - 1));
        }
Ejemplo n.º 3
0
        public void AddRange_Mutliple_EventFired()
        {
            var stubbedWindow = new StubbedWindow();

            var sut      = new ConControls.Controls.ControlCollection(stubbedWindow);
            var control1 = new StubbedConsoleControl(stubbedWindow);
            var control2 = new StubbedConsoleControl(stubbedWindow);
            var control3 = new StubbedConsoleControl(stubbedWindow);
            var control4 = new StubbedConsoleControl(stubbedWindow);

            int fired = 0;

            sut.ControlCollectionChanged += (sender, e) =>
            {
                fired++;
                if (fired == 1)
                {
                    e.AddedControls.Should().Equal(control1, control2);
                    return;
                }

                fired.Should().Be(2);
                e.AddedControls.Should().Equal(control3, control4);
            };
            sut.AddRange(control1, null !, control2);
            fired.Should().Be(1);
            sut.AddRange(control3, null !, control2, control4);
            fired.Should().Be(2);
        }
Ejemplo n.º 4
0
        public void Draw_DrawingInhibited_LoggedNotDrawn()
        {
            var stubbedWindow = new StubbedWindow
            {
                DrawingInhibitedGet = () => true
            };
            bool inhibitLogged = false;
            var  sut           = new StubbedConsoleControl(stubbedWindow);

            using var logger = new TestLogger(CheckDrawLog);
            sut.ResetMethodCount();
            sut.Draw();
            inhibitLogged.Should().BeTrue();
            sut.GetMethodCount(StubbedConsoleControl.MethodDrawBackground).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodDrawBorder).Should().Be(0);
            sut.GetMethodCount(StubbedConsoleControl.MethodDrawClientArea).Should().Be(0);

            void CheckDrawLog(string msg)
            {
                if (msg.Contains("drawing inhibited"))
                {
                    inhibitLogged = true;
                }
            }
        }
Ejemplo n.º 5
0
        public void EffectiveForegroundColor_ExtraValues_CorrectValues()
        {
            ConControls.Controls.ConsoleControl?focused = null;
            var stubbedWindow = new StubbedWindow
            {
                DefaultForegroundColorGet = () => ConsoleColor.Cyan,
                DefaultBackgroundColorGet = () => ConsoleColor.DarkRed,
                DefaultBorderColorGet     = () => ConsoleColor.DarkYellow,
                FocusedControlGet         = () => focused,
                EnabledGet = () => true,
                FocusedControlSetConsoleControl = c => focused = c
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Focusable = true,
                DisabledForegroundColor = ConsoleColor.Blue,
                FocusedForegroundColor  = ConsoleColor.Green,
                Parent = stubbedWindow
            };

            sut.EffForeColor.Should().Be(ConsoleColor.Cyan);
            sut.Enabled = false;
            sut.EffForeColor.Should().Be(ConsoleColor.Blue);
            sut.Focused = true;
            sut.EffForeColor.Should().Be(ConsoleColor.Blue);
            sut.Enabled = true;
            sut.EffForeColor.Should().Be(ConsoleColor.Green);
        }
Ejemplo n.º 6
0
        public void Visible_Changed_ThreadSafeHandlerCall()
        {
            var stubbedWindow = new StubbedWindow
            {
                VisibleGet = () => true
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Parent = stubbedWindow
            };

            sut.Visible.Should().BeTrue();
            bool eventRaised = false;

            sut.VisibleChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                eventRaised = true;
            };

            sut.GetMethodCount(StubbedConsoleControl.MethodOnVisibleChanged).Should().Be(0);
            eventRaised.Should().BeFalse();
            sut.Visible = false;
            sut.Visible.Should().BeFalse();
            sut.GetMethodCount(StubbedConsoleControl.MethodOnVisibleChanged).Should().Be(1);
            eventRaised.Should().BeTrue();
        }
Ejemplo n.º 7
0
        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);
        }
    }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        public void DrawBackground_BackgroundDrawn()
        {
            const ConsoleColor Color = ConsoleColor.DarkBlue;
            var stubbedWindow        = new StubbedWindow
            {
                BackgroundColorGet = () => Color
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Area   = new Rectangle(1, 2, 3, 4),
                Parent = stubbedWindow
            };

            bool backgroundDrawn = false;
            var  graphics        = new StubIConsoleGraphics
            {
                DrawBackgroundConsoleColorRectangle = (color, rect) =>
                {
                    color.Should().Be(Color);
                    rect.Should().Be(sut.Area);
                    backgroundDrawn = true;
                }
            };

            sut.DoDrawBackground(graphics);
            backgroundDrawn.Should().BeTrue();
        }
Ejemplo n.º 11
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();
        }
Ejemplo n.º 12
0
        public void DrawBackground_DrawingInhibited_LoggedNotDrawn()
        {
            var stubbedWindow = new StubbedWindow
            {
                DrawingInhibitedGet = () => true
            };
            bool backgroundDrawn = false;
            var  graphics        = new StubIConsoleGraphics
            {
                DrawBackgroundConsoleColorRectangle = (color, rect) => backgroundDrawn = true
            };
            bool inhibitLogged = false;
            var  sut           = new StubbedConsoleControl(stubbedWindow);

            using var logger = new TestLogger(CheckDrawLog);
            sut.DoDrawBackground(graphics);
            inhibitLogged.Should().BeTrue();
            backgroundDrawn.Should().BeFalse();

            void CheckDrawLog(string msg)
            {
                if (msg.Contains("drawing inhibited"))
                {
                    inhibitLogged = true;
                }
            }
        }
Ejemplo n.º 13
0
        public void Focused_CanFocus_SetFocus()
        {
            ConControls.Controls.ConsoleControl?focusedControl = null;
            var stubbedWindow = new StubbedWindow
            {
                FocusedControlGet = () => focusedControl,
                FocusedControlSetConsoleControl = ctrl => focusedControl = ctrl
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Focusable = true
            };

            sut.Focused.Should().BeFalse();
            bool eventRaised = false;

            sut.FocusedChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                eventRaised = true;
            };

            sut.GetMethodCount(StubbedConsoleControl.MethodOnFocusedChanged).Should().Be(0);
            eventRaised.Should().BeFalse();
            sut.Focused = true;
            sut.Focused.Should().BeTrue();
            focusedControl.Should().Be(sut);
            sut.GetMethodCount(StubbedConsoleControl.MethodOnFocusedChanged).Should().Be(1);
            eventRaised.Should().BeTrue();
        }
Ejemplo n.º 14
0
        public void Focused_CannotFocus_InvalidOperationException()
        {
            ConControls.Controls.ConsoleControl?focusedControl = null;
            var stubbedWindow = new StubbedWindow
            {
                FocusedControlGet = () => focusedControl,
                FocusedControlSetConsoleControl = ctrl => focusedControl = ctrl
            };
            var sut = new StubbedConsoleControl(stubbedWindow);

            sut.Focused.Should().BeFalse();
            sut.CanFocus.Should().BeFalse();
            bool eventRaised = false;

            sut.FocusedChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                eventRaised = true;
            };

            sut.GetMethodCount(StubbedConsoleControl.MethodOnFocusedChanged).Should().Be(0);
            eventRaised.Should().BeFalse();
            sut.Invoking(s => s.Focused = true)
            .Should()
            .Throw <InvalidOperationException>();
            sut.Focused.Should().BeFalse();
            sut.GetMethodCount(StubbedConsoleControl.MethodOnFocusedChanged).Should().Be(0);
            eventRaised.Should().BeFalse();
        }
Ejemplo n.º 15
0
        public void DrawBorder_BorderDrawn()
        {
            var stubbedWindow = new StubbedWindow
            {
                BackgroundColorGet = () => ConsoleColor.DarkMagenta,
                BorderColorGet     = () => ConsoleColor.Cyan
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Area   = new Rectangle(1, 2, 3, 4),
                Parent = stubbedWindow
            };

            bool borderDrawn = false;
            var  graphics    = new StubIConsoleGraphics
            {
                DrawBorderConsoleColorConsoleColorBorderStyleRectangle = (bg, fg, style, rect) =>
                {
                    fg.Should().Be(ConsoleColor.Cyan);
                    bg.Should().Be(ConsoleColor.DarkMagenta);
                    style.Should().Be(BorderStyle.None);
                    rect.Should().Be(sut.Area);
                    borderDrawn = true;
                }
            };

            sut.DoDrawBorder(graphics);
            borderDrawn.Should().BeTrue();
        }
Ejemplo n.º 16
0
        public void Enabled_NotChanged_NoEvent()
        {
            var stubbedWindow = new StubbedWindow
            {
                EnabledGet = () => true
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Parent = stubbedWindow
            };
            bool eventRaised = false;

            sut.EnabledChanged += (sender, e) =>
            {
                sender.Should().Be(sut);
                eventRaised = true;
            };

            sut.GetMethodCount(StubbedConsoleControl.MethodOnEnabledChanged).Should().Be(0);
            sut.Enabled = sut.Enabled;
            sut.Enabled.Should().BeTrue();
            sut.GetMethodCount(StubbedConsoleControl.MethodOnEnabledChanged).Should().Be(0);
            eventRaised.Should().BeFalse();
        }
Ejemplo n.º 17
0
        public void Remove_ForeignControl_Nothing()
        {
            using var stubbedWindow = new StubbedWindow();
            var control3 = new StubbedConsoleControl(stubbedWindow)
            {
                Parent = stubbedWindow
            };

            stubbedWindow.Controls.Remove(control3);
            bool called = false;
            // ReSharper disable once UnusedVariable
            var control1 = new StubbedConsoleControl(stubbedWindow)
            {
                Parent = stubbedWindow
            };
            // ReSharper disable once UnusedVariable
            var control2 = new StubbedConsoleControl(stubbedWindow)
            {
                Parent = stubbedWindow
            };

            stubbedWindow.Controls.ControlCollectionChanged += (sender, e) =>
            {
                called = true;
                Assert.Fail();
            };
            stubbedWindow.Controls.Remove(control3);
            stubbedWindow.Controls.Count.Should().Be(2);
            called.Should().BeFalse();
        }
Ejemplo n.º 18
0
        public void ConsoleControl_CompletelyInitialized_NoParentYet()
        {
            var stubbedWindow = new StubbedWindow
            {
                VisibleGet = () => true
            };

            var sut = new StubbedConsoleControl(stubbedWindow);

            sut.Visible.Should().BeFalse();
            sut.Enabled.Should().BeFalse();
            sut.CanFocus.Should().BeFalse();
            sut.Name.Should().Be(nameof(StubbedConsoleControl));
            sut.Parent.Should().BeNull();

            sut.Parent = stubbedWindow;
            stubbedWindow.KeyEventEvent.Should().NotBeNull();
            stubbedWindow.MouseEventEvent.Should().NotBeNull();
            stubbedWindow.Controls.Should().Contain(sut);

            sut.Dispose();
            stubbedWindow.KeyEventEvent.Should().BeNull();
            stubbedWindow.MouseEventEvent.Should().BeNull();
            sut.Dispose(); // should not throw
        }
Ejemplo n.º 19
0
        public void EffectiveBorderColor_NoExtraValues_DefaultValues()
        {
            ConControls.Controls.ConsoleControl?focused = null;
            var stubbedWindow = new StubbedWindow
            {
                DefaultForegroundColorGet = () => ConsoleColor.DarkYellow,
                DefaultBackgroundColorGet = () => ConsoleColor.DarkRed,
                DefaultBorderColorGet     = () => ConsoleColor.Cyan,
                EnabledGet        = () => true,
                GetGraphics       = () => new StubIConsoleGraphics(),
                FocusedControlGet = () => focused,
                FocusedControlSetConsoleControl = c => focused = c
            };

            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Focusable = true
            };

            sut.EffBorderColor.Should().Be(ConsoleColor.Cyan);
            sut.Enabled = false;
            sut.EffBorderColor.Should().Be(ConsoleColor.Cyan);
            sut.Focused = true;
            sut.EffBorderColor.Should().Be(ConsoleColor.Cyan);
            sut.Enabled = true;
            sut.EffBorderColor.Should().Be(ConsoleColor.Cyan);
        }
Ejemplo n.º 20
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>();
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        public void Draw_WithGraphics_AllPartsDrawnNotFlushed()
        {
            bool flushed  = false;
            var  graphics = new StubIConsoleGraphics
            {
                Flush = () => flushed = true
            };
            var stubbedWindow = new StubbedWindow
            {
                GetGraphics = () => graphics
            };
            var sut = new StubbedConsoleControl(stubbedWindow)
            {
                Parent = stubbedWindow
            };

            flushed = false;
            stubbedWindow.GetGraphics = () => null;
            sut.ResetMethodCount();
            sut.Draw(graphics);
            sut.GetMethodCount(StubbedConsoleControl.MethodDrawBackground).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodDrawBorder).Should().Be(1);
            sut.GetMethodCount(StubbedConsoleControl.MethodDrawClientArea).Should().Be(1);
            flushed.Should().BeFalse();
        }
Ejemplo n.º 24
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);
        }
    }
Ejemplo n.º 25
0
        public void CheckDisposed_NotDisposed_Nothing()
        {
            var stubbedWindow = new StubbedWindow();
            var sut           = new StubbedConsoleControl(stubbedWindow);

            sut.DoCheckDisposed();
        }
Ejemplo n.º 26
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);
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
        public void DrawBorder_DrawingInhibited_LoggedNotDrawn()
        {
            var stubbedWindow = new StubbedWindow
            {
                DrawingInhibitedGet = () => true,
                BackgroundColorGet  = () => ConsoleColor.DarkMagenta,
                BorderColorGet      = () => ConsoleColor.Cyan
            };

            bool borderDrawn = false;
            var  graphics    = new StubIConsoleGraphics
            {
                DrawBorderConsoleColorConsoleColorBorderStyleRectangle = (bg, fg, style, rect) => borderDrawn = true
            };
            bool inhibitLogged = false;
            var  sut           = new StubbedConsoleControl(stubbedWindow);

            using var logger = new TestLogger(CheckDrawLog);
            sut.DoDrawBorder(graphics);
            inhibitLogged.Should().BeTrue();
            borderDrawn.Should().BeFalse();

            void CheckDrawLog(string msg)
            {
                if (msg.Contains("drawing inhibited"))
                {
                    inhibitLogged = true;
                }
            }
        }
Ejemplo n.º 29
0
        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();
        }
Ejemplo n.º 30
0
        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();
        }