Skip to content

Commit

Permalink
Add code coverage for ToolStripPanelControlCollection_XYComparer (#12711
Browse files Browse the repository at this point in the history
)

related #10453

Proposed changes
Add unit tests for ToolStripPanelControlCollectionXYComparer.cs to test its methods
  • Loading branch information
Zheng-Li01 authored Jan 7, 2025
1 parent ba481ce commit a3da2c9
Showing 1 changed file with 46 additions and 0 deletions.
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) };
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);
}
}

0 comments on commit a3da2c9

Please sign in to comment.