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 comboBox #12038

Merged
merged 4 commits into from
Sep 9, 2024
Merged
Changes from 1 commit
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 @@ -305,6 +305,92 @@ public void ComboBox_BackColor_ShouldSerializeValue_Success()
Assert.False(property.ShouldSerializeValue(control));
}

[WinFormsFact]
public void ComboBox_MeasureItem_AddHandler()
{
using ComboBox control = new();
int initialItemHeight = control.ItemHeight;

MeasureItemEventHandler handler = (sender, e) => { };
control.MeasureItem += handler;

control.ItemHeight.Should().NotBe(initialItemHeight);
}

[WinFormsFact]
public void ComboBox_MeasureItem_RemoveHandler()
{
using ComboBox control = new();
int handlerCallCount = 0;
MeasureItemEventHandler handler = (sender, e) => { handlerCallCount++; };

control.MeasureItem += handler;
control.MeasureItem -= handler;

handlerCallCount.Should().Be(0, "The MeasureItem event handler was not removed as expected.");
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
}

[WinFormsFact]
public void ComboBox_MeasureItem_AddAndRemoveHandler()
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
using ComboBox control = new();

MeasureItemEventHandler handler = (sender, e) => { };
control.MeasureItem += handler;
control.MeasureItem -= handler;
}

public class TestableComboBox : ComboBox
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
public void InvokeOnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
}

[WinFormsFact]
public void ComboBox_Paint_AddHandler_ShouldSubscribeEvent()
{
using TestableComboBox comboBox = new();
int callCount = 0;

PaintEventHandler handler = (sender, e) => callCount++;

comboBox.Paint += handler;
comboBox.InvokeOnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), new Rectangle()));
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved

callCount.Should().Be(1);
}

[WinFormsFact]
public void ComboBox_Paint_RemoveHandler_ShouldUnsubscribeEvent()
{
using TestableComboBox comboBox = new();
int callCount = 0;

PaintEventHandler handler = (sender, e) => callCount++;

comboBox.Paint += handler;
comboBox.Paint -= handler;
comboBox.InvokeOnPaint(new PaintEventArgs(Graphics.FromHwnd(comboBox.Handle), new Rectangle()));

callCount.Should().Be(0);
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
}

[WinFormsFact]
public void ComboBox_Paint_EventHandlerCalledOnPaint()
{
using TestableComboBox comboBox = new();
Bitmap bitmap = new Bitmap(100, 100);
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
Graphics graphics = Graphics.FromImage(bitmap);
bool handlerCalled = false;

comboBox.Paint += (sender, e) => handlerCalled = true;
comboBox.InvokeOnPaint(new PaintEventArgs(graphics, new Rectangle(0, 0, 100, 100)));

handlerCalled.Should().BeTrue();
}

[WinFormsFact]
public void VerifyAutoCompleteEntries()
{
Expand Down