Skip to content

Commit

Permalink
Add code coverage for LabelAccessibleObject (#11521)
Browse files Browse the repository at this point in the history
* Add code coverage for LabelAccessibleObject

* Update
  • Loading branch information
Olina-Zhang authored Jun 17, 2024
1 parent 630549e commit 8cbf7ea
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,44 @@ public void LabelAccessibleObject_TextChanged_AutomationPropertyChanged_Raised()
Assert.Equal(1, accessibilityObject.RaiseAutomationNotificationCallCount);
}

[WinFormsTheory]
[InlineData("&File", false, "&File")]
[InlineData("&File", true, "File")]
public void LabelAccessibleObject_Name_ReturnsExpected_WithUseMnemonic(string text, bool useMnemonic, string expectedName)
{
using Label label = new() { Text = text, UseMnemonic = useMnemonic };
LabelAccessibleObject accessibleObject = (LabelAccessibleObject)label.AccessibilityObject;

string name = accessibleObject.Name;

name.Should().Be(expectedName);
}

[WinFormsFact]
public void LabelAccessibleObject_ThrowsArgumentNullException_WhenOwnerIsNull()
{
Action action = () => new Label.LabelAccessibleObject(null);

action.Should().Throw<ArgumentNullException>();
}

[WinFormsTheory]
[InlineData("Test Accessible Name", "Test Accessible Name", false)]
[InlineData("Test Accessible Name", "Test Accessible Name", true)]
[InlineData("", null, false)]
[InlineData("", null, true)]
[InlineData(null, null, false)]
[InlineData(null, null, true)]
public void LabelAccessibleObject_Name_ReturnsExpected_WithVariousText(string labelText, string expectedName, bool useMnemonic)
{
using Label label = new() { Text = labelText, UseMnemonic = useMnemonic };
LabelAccessibleObject accessibleObject = (LabelAccessibleObject)label.AccessibilityObject;

string name = accessibleObject.Name;

name.Should().Be(expectedName);
}

private class LabelWithCustomAccessibleObject : Label
{
private readonly Func<UIA_PROPERTY_ID, VARIANT, bool> _checkRaisedEvent;
Expand Down

0 comments on commit 8cbf7ea

Please sign in to comment.