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 ToolStripPanelControlCollection_XYComparer #12711

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
@@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Drawing;

namespace System.Windows.Forms.Tests;

public class ToolStripPanel_ToolStripPanelControlCollection_XYComparerTests
{
private readonly ToolStripPanel.ToolStripPanelControlCollection.XYComparer _comparer = new();
private readonly Control _control1 = new() { Bounds = new Rectangle(10, 20, 100, 100) };
Zheng-Li01 marked this conversation as resolved.
Show resolved Hide resolved
private readonly Control _control2 = new() { Bounds = new Rectangle(10, 10, 100, 100) };

public void Dispose()
{
_control1.Dispose();
_control2.Dispose();
}

[WinFormsFact]
public void Compare_FirstControlNull_ReturnsNegativeOne() =>
_comparer.Compare(null, _control1).Should().Be(-1);

[WinFormsFact]
public void Compare_SecondControlNull_ReturnsOne() =>
_comparer.Compare(_control1, null).Should().Be(1);

[WinFormsFact]
public void Compare_BothControlsNull_ReturnsZero() =>
_comparer.Compare(null, null).Should().Be(0);

[WinFormsTheory]
[InlineData(10, 10, 20, 10, -1)]
[InlineData(10, 10, 10, 20, -1)]
[InlineData(10, 20, 10, 10, 1)]
[InlineData(20, 10, 10, 10, 1)]
public void Compare_VariousBounds_ReturnsExpected(int x1, int y1, int x2, int y2, int expected)
{
_control1.Bounds = new Rectangle(x1, y1, 100, 100);
_control2.Bounds = new Rectangle(x2, y2, 100, 100);

_comparer.Compare(_control1, _control2).Should().Be(expected);
}
}