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 test coverage for ComboBox #11381

Merged
merged 5 commits into from
May 23, 2024
Merged
Changes from 2 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 @@ -285,6 +285,112 @@ public void ComboBox_BackColor_ShouldSerializeValue_Success()
Assert.False(property.ShouldSerializeValue(control));
}

[WinFormsFact]
public void TestAutoCompleteCustomSource()
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
AssertAutoCompleteCustomSource(new[] { "item1", "item2" }, false);
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
AssertAutoCompleteCustomSource(null, false);
AssertAutoCompleteCustomSource(new[] { "item3", "item4" }, false);
}

private void AssertAutoCompleteCustomSource(string[] items, bool isHandleCreated)
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
using ComboBox control = new();

if (items is object)
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
AutoCompleteStringCollection autoCompleteCustomSource = new();
autoCompleteCustomSource.AddRange(items);
control.AutoCompleteCustomSource = autoCompleteCustomSource;
control.AutoCompleteCustomSource.Should().BeEquivalentTo(autoCompleteCustomSource);
}
else
{
control.AutoCompleteCustomSource = null;
control.AutoCompleteCustomSource.Should().NotBeNull();
control.AutoCompleteCustomSource.Count.Should().Be(0);
}

control.IsHandleCreated.Should().Be(isHandleCreated);
}

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

using ComboBox control2 = new() { AutoCompleteSource = AutoCompleteSource.ListItems };
control2.BeginUpdate();
control2.EndUpdate();
control2.AutoCompleteMode.Should().Be(AutoCompleteMode.None);

using ComboBox control3 = new();
control3.BeginUpdate();
control3.CreateControl();
control3.EndUpdate();
control3.IsHandleCreated.Should().BeTrue();

using ComboBox control4 = new();
Exception exception = Record.Exception(() => control4.EndUpdate());
exception.Should().BeNull();
}

[WinFormsFact]
public void ComboBox_SelectedTextTests()
{
using ComboBox control = new();

if (!control.IsHandleCreated)
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
control.SelectedText.Should().BeEmpty();
}

control.CreateControl();
if (control.IsHandleCreated)
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
control.SelectedText.Should().BeEmpty();
}

control.DropDownStyle = ComboBoxStyle.DropDownList;
control.CreateControl();
if (control.DropDownStyle == ComboBoxStyle.DropDownList)
{
control.SelectedText.Should().BeEmpty();
}

// Test SetWithoutHandle
if (!control.IsHandleCreated)
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
control.SelectedText = "Test";
control.SelectedText.Should().BeEmpty();
}

// Test SetWithHandle
control.DropDownStyle = ComboBoxStyle.DropDown;
control.Text = "Initial";
control.SelectionStart = 0;
control.SelectionLength = 7;
control.CreateControl();
if (control.IsHandleCreated)
Nora-Zhou01 marked this conversation as resolved.
Show resolved Hide resolved
{
control.SelectedText = "Test";
control.Text.Should().Be("Test");
}

// Test SetWithDropDownListStyle
control.DropDownStyle = ComboBoxStyle.DropDownList;
control.CreateControl();
if (control.DropDownStyle == ComboBoxStyle.DropDownList)
{
control.SelectedText = "Test";
control.SelectedText.Should().BeEmpty();
}
}

[WinFormsTheory]
[CommonMemberData(typeof(CommonTestHelperEx), nameof(CommonTestHelperEx.GetImageTheoryData))]
public void ComboBox_BackgroundImage_Set_GetReturnsExpected(Image value)
Expand Down