Skip to content

Add unit test for ArrayElementGridEntry.cs file #13537

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

Merged
merged 2 commits into from
Jun 16, 2025
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,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Windows.Forms.PropertyGridInternal.Tests;

public class ArrayElementGridEntryTests
{
private class TestGridEntry : GridEntry
{
public TestGridEntry(PropertyGrid ownerGrid, GridEntry? parent = null)
: base(ownerGrid, parent)
{
PropertyValue = new int[] { 1, 2, 3 };
}

public override GridItemType GridItemType => GridItemType.Property;
public override bool IsValueEditable => true;
public override string PropertyLabel => "Test";
public override Type? PropertyType => typeof(int[]);
public override object? PropertyValue { get; set; }
public override bool ShouldRenderReadOnly => false;
}

private static PropertyGrid CreatePropertyGrid() => new();

[WinFormsFact]
public void ArrayElementGridEntry_ConstructorAndProperties()
{
using PropertyGrid grid = CreatePropertyGrid();
TestGridEntry parent = new(grid);
ArrayElementGridEntry entry = new(grid, parent, 2);

entry.Should().NotBeNull();
entry.PropertyLabel.Should().Be("[2]");
entry.GridItemType.Should().Be(GridItemType.ArrayValue);
entry.IsValueEditable.Should().BeTrue();
entry.PropertyType.Should().Be(typeof(int));
entry.ShouldRenderReadOnly.Should().BeFalse();
entry.PropertyValue.Should().Be(3);

entry.PropertyValue = 10;
entry.PropertyValue.Should().Be(10);
}
}