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(); }
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(); }
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; } } }
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(); }
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(); }
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(); }
public void DisabledBorderColor_NotChanged_NoEvent() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderColorChanged).Should().Be(0); sut.DisabledBorderColor = sut.DisabledBorderColor; sut.DisabledBorderColor.Should().BeNull(); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderColorChanged).Should().Be(0); }
public void BorderStyle_NotChanged_NoEvent() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderStyleChanged).Should().Be(0); sut.BorderStyle = sut.BorderStyle; sut.BorderStyle.Should().Be(BorderStyle.None); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderStyleChanged).Should().Be(0); }
public void FocusedBackgroundColor_NotChanged_NoEvent() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.GetMethodCount(StubbedConsoleControl.MethodOnBackgroundColorChanged).Should().Be(0); sut.FocusedBackgroundColor = sut.FocusedBackgroundColor; sut.FocusedBackgroundColor.Should().BeNull(); sut.GetMethodCount(StubbedConsoleControl.MethodOnBackgroundColorChanged).Should().Be(0); }
public void Parent_SameNullParent_Nothing() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.GetMethodCount(StubbedConsoleControl.MethodOnParentChanged).Should().Be(0); sut.Parent.Should().BeNull(); sut.Parent = null; sut.GetMethodCount(StubbedConsoleControl.MethodOnParentChanged).Should().Be(0); sut.Parent.Should().BeNull(); }
public void BorderColor_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.BorderColor.Should().BeNull(); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderColorChanged).Should().Be(0); sut.BorderColor = ConsoleColor.DarkMagenta; sut.BorderColor.Should().Be(ConsoleColor.DarkMagenta); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderColorChanged).Should().Be(1); }
public void BorderStyle_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.BorderStyle.Should().Be(BorderStyle.None); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderStyleChanged).Should().Be(0); sut.BorderStyle = BorderStyle.DoubleLined; sut.BorderStyle.Should().Be(BorderStyle.DoubleLined); sut.GetMethodCount(StubbedConsoleControl.MethodOnBorderStyleChanged).Should().Be(1); }
public void DrawClientArea_ChildControlsDrawn() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow) { Area = new Rectangle(1, 2, 3, 4), Parent = stubbedWindow }; var child1 = new StubbedConsoleControl(stubbedWindow) { Parent = sut }; var child2 = new StubbedConsoleControl(stubbedWindow) { Parent = sut }; child1.ResetMethodCount(); child2.ResetMethodCount(); sut.DoDrawClientArea(new StubIConsoleGraphics()); child1.GetMethodCount(StubbedConsoleControl.MethodDrawBackground).Should().Be(1); child2.GetMethodCount(StubbedConsoleControl.MethodDrawBackground).Should().Be(1); }
public void Location_NotChanged_NoEvent() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); bool eventRaised = false; sut.AreaChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(0); sut.Location = sut.Location; sut.Location.Should().Be(Point.Empty); sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(0); eventRaised.Should().BeFalse(); }
public void CursorVisible_NotChanged_NoEvent() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); bool eventRaised = false; sut.CursorVisibleChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnCursorVisibleChanged).Should().Be(0); sut.CursorVisible = sut.CursorVisible; sut.CursorVisible.Should().BeFalse(); sut.GetMethodCount(StubbedConsoleControl.MethodOnCursorVisibleChanged).Should().Be(0); eventRaised.Should().BeFalse(); }
public void Name_Null_Default() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow) { Name = "different" }; bool eventRaised = false; sut.NameChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnNameChanged).Should().Be(1); sut.Name = null !; sut.Name.Should().Be(nameof(StubbedConsoleControl)); sut.GetMethodCount(StubbedConsoleControl.MethodOnNameChanged).Should().Be(2); eventRaised.Should().BeTrue(); }
public void Controls_ChildAreaChanged_Handled() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow) { Parent = stubbedWindow }; var child = new StubbedConsoleControl(stubbedWindow) { Parent = sut }; sut.ResetMethodCount(); child.Area = new Rectangle(1, 2, 3, 4); sut.GetMethodCount(StubbedConsoleControl.MethodDrawClientArea).Should().Be(1); sut.Controls.Remove(child); sut.ResetMethodCount(); child.Area = new Rectangle(2, 3, 4, 5); sut.GetMethodCount(StubbedConsoleControl.MethodDrawClientArea).Should().Be(0); }
public void CursorSize_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.CursorSize.Should().BeNull(); bool eventRaised = false; sut.CursorSizeChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnCursorSizeChanged).Should().Be(0); eventRaised.Should().BeFalse(); sut.CursorSize = 23; sut.CursorSize.Should().Be(23); sut.GetMethodCount(StubbedConsoleControl.MethodOnCursorSizeChanged).Should().Be(1); eventRaised.Should().BeTrue(); }
public void Name_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.Name.Should().Be(nameof(StubbedConsoleControl)); bool eventRaised = false; sut.NameChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnNameChanged).Should().Be(0); eventRaised.Should().BeFalse(); const string alt = "alt"; sut.Name = alt; sut.Name.Should().Be(alt); sut.GetMethodCount(StubbedConsoleControl.MethodOnNameChanged).Should().Be(1); eventRaised.Should().BeTrue(); }
public void Area_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.Area.Should().Be(Rectangle.Empty); bool eventRaised = false; sut.AreaChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(0); eventRaised.Should().BeFalse(); var rect = new Rectangle(1, 2, 3, 4); sut.Area = rect; sut.Area.Should().Be(rect); sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(1); eventRaised.Should().BeTrue(); }
public void Location_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.Location.Should().Be(Point.Empty); bool eventRaised = false; sut.AreaChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(0); eventRaised.Should().BeFalse(); var point = new Point(1, 2); sut.Location = point; sut.Location.Should().Be(point); sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(1); eventRaised.Should().BeTrue(); }
public void Size_Changed_ThreadSafeHandlerCall() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow); sut.Size.Should().Be(Size.Empty); bool eventRaised = false; sut.AreaChanged += (sender, e) => { sender.Should().Be(sut); eventRaised = true; }; sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(0); eventRaised.Should().BeFalse(); var size = new Size(1, 2); sut.Size = size; sut.Size.Should().Be(size); sut.GetMethodCount(StubbedConsoleControl.MethodOnAreaChanged).Should().Be(1); eventRaised.Should().BeTrue(); }
public void Parent_ValidParent_ControlCollectionsChanged() { var stubbedWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow) { Parent = stubbedWindow }; var differentParent = new StubbedConsoleControl(stubbedWindow) { Parent = stubbedWindow }; sut.Parent = differentParent; sut.Parent.Should().Be(differentParent); sut.GetMethodCount(StubbedConsoleControl.MethodOnParentChanged).Should().Be(2); stubbedWindow.Controls.Should().Equal(differentParent); differentParent.Controls.Should().Equal(sut); }
public void Parent_DifferentWindow_InvalidOperationException() { var stubbedWindow = new StubbedWindow(); var differentWindow = new StubbedWindow(); var sut = new StubbedConsoleControl(stubbedWindow) { Parent = stubbedWindow }; var differentParent = new StubbedConsoleControl(differentWindow) { Parent = differentWindow }; sut.Invoking(s => s.Parent = differentParent) .Should() .Throw <InvalidOperationException>(); sut.GetMethodCount(StubbedConsoleControl.MethodOnParentChanged).Should().Be(1); sut.Parent.Should().Be(stubbedWindow); }
public void DrawClientArea_DrawingInhibited_LoggedNotDrawn() { var stubbedWindow = new StubbedWindow { DrawingInhibitedGet = () => true }; bool inhibitLogged = false; var sut = new StubbedConsoleControl(stubbedWindow) { Parent = stubbedWindow }; var child1 = new StubbedConsoleControl(stubbedWindow) { Parent = sut }; var child2 = new StubbedConsoleControl(stubbedWindow) { Parent = sut }; child1.ResetMethodCount(); child2.ResetMethodCount(); using var logger = new TestLogger(CheckDrawLog); sut.DoDrawClientArea(new StubIConsoleGraphics()); inhibitLogged.Should().BeTrue(); child1.GetMethodCount(StubbedConsoleControl.MethodDrawBackground).Should().Be(0); child2.GetMethodCount(StubbedConsoleControl.MethodDrawBackground).Should().Be(0); void CheckDrawLog(string msg) { if (msg.Contains("drawing inhibited")) { inhibitLogged = true; } } }