Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage for toolstrip #11773

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7304,6 +7304,96 @@ public void ToolStrip_GetNextItem_ItemsBackwardExpected(ToolStripLayoutStyle too
Assert.False(toolStrip.IsHandleCreated);
}

[WinFormsTheory]
[InlineData(10, 10)]
[InlineData(0, 0)]
[InlineData(-10, -10)]
public void ToolStrip_GetChildAtPoint_WithoutSkipValue_Invoke_ReturnsExpected(int x, int y)
{
using ToolStrip toolStrip = new();
var child = toolStrip.GetChildAtPoint(new Point(x, y));

child.Should().BeNull();
}

[WinFormsTheory]
[InlineData(GetChildAtPointSkip.None)]
[InlineData(GetChildAtPointSkip.Disabled)]
[InlineData(GetChildAtPointSkip.Invisible)]
[InlineData(GetChildAtPointSkip.Transparent)]
public void ToolStrip_GetChildAtPoint_WithSkipValue_Invoke_ReturnsExpected(GetChildAtPointSkip skipValue)
{
using ToolStrip toolStrip = new();
var child = toolStrip.GetChildAtPoint(new Point(10, 10), skipValue);

child.Should().BeNull();
}

[WinFormsFact]
public void ToolStrip_ResetMinimumSize_Invoke_Success()
{
using ToolStrip toolStrip = new();
Size oldSize = toolStrip.MinimumSize;

toolStrip.ResetMinimumSize();

oldSize.Should().NotBe(toolStrip.MinimumSize);
toolStrip.MinimumSize.Should().Be(new Size(-1, -1));
}

[WinFormsFact]
public void ToolStrip_ResetGripMargin_SetsGripMarginToDefault()
{
using ToolStrip toolStrip = new();
var defaultMargin = toolStrip.Grip.DefaultMargin;
toolStrip.GripMargin = new Padding(10, 10, 10, 10);

toolStrip.TestAccessor().Dynamic.ResetGripMargin();

toolStrip.GripMargin.Should().Be(defaultMargin);
}

[WinFormsFact]
public void ToolStrip_SetAutoScrollMargin_Invoke_Success()
{
using var toolStrip = new ToolStrip() { AutoScrollMargin = new Size(10, 20) };

toolStrip.AutoScrollMargin.Should().Be(new Size(10, 20));
}

[WinFormsFact]
public void ToolStrip_ShouldSerializeLayoutStyle_Invoke_ReturnsExpected()
{
using ToolStrip toolStrip = new();
toolStrip.ShouldSerializeLayoutStyle().Should().BeFalse();

toolStrip.LayoutStyle = ToolStripLayoutStyle.Flow;
toolStrip.ShouldSerializeLayoutStyle().Should().BeTrue();

toolStrip.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
toolStrip.ShouldSerializeLayoutStyle().Should().BeTrue();

toolStrip.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow;
toolStrip.ShouldSerializeLayoutStyle().Should().BeTrue();

toolStrip.LayoutStyle = ToolStripLayoutStyle.Table;
toolStrip.ShouldSerializeLayoutStyle().Should().BeTrue();

toolStrip.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
toolStrip.ShouldSerializeLayoutStyle().Should().BeFalse();
}

[WinFormsFact]
public void ToolStrip_ShouldSerializeGripMargin_Invoke_ReturnsExpected()
{
using ToolStrip toolStrip = new() { GripMargin = new Padding(1) };
((bool)toolStrip.TestAccessor().Dynamic.ShouldSerializeGripMargin()).Should().BeTrue();

var defaultGripMargin = (Padding)toolStrip.TestAccessor().Dynamic.DefaultGripMargin;
toolStrip.GripMargin = defaultGripMargin;
((bool)toolStrip.TestAccessor().Dynamic.ShouldSerializeGripMargin()).Should().BeFalse();
}

private class SubAxHost : AxHost
{
public SubAxHost(string clsid) : base(clsid)
Expand Down