Skip to content

Commit ec9c1d9

Browse files
committed
Add unit tests for lowercase command names
1 parent c3f2df1 commit ec9c1d9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,25 @@ public void Test_ObservableProperty_WithExplicitAttributeForProperty()
946946
Assert.AreEqual(testAttribute2.Animal, (Animal)67);
947947
}
948948

949+
// See https://github.com/CommunityToolkit/dotnet/issues/446
950+
[TestMethod]
951+
public void Test_ObservableProperty_CommandNamesThatCantBeLowered()
952+
{
953+
ModelWithCommandNamesThatCantBeLowered model = new();
954+
955+
// Just ensures this builds
956+
_ = model.中文Command;
957+
_ = model.c中文Command;
958+
959+
FieldInfo? fieldInfo = typeof(ModelWithCommandNamesThatCantBeLowered).GetField($"_{nameof(ModelWithCommandNamesThatCantBeLowered.中文)}Command", BindingFlags.Instance | BindingFlags.NonPublic);
960+
961+
Assert.AreSame(model.中文Command, fieldInfo.GetValue(model));
962+
963+
fieldInfo = typeof(ModelWithCommandNamesThatCantBeLowered).GetField($"_{nameof(ModelWithCommandNamesThatCantBeLowered.c中文)}Command", BindingFlags.Instance | BindingFlags.NonPublic);
964+
965+
Assert.AreSame(model.c中文Command, fieldInfo.GetValue(model));
966+
}
967+
949968
public abstract partial class BaseViewModel : ObservableObject
950969
{
951970
public string? Content { get; set; }
@@ -1517,4 +1536,17 @@ public PropertyInfoAttribute(object? o, Type t, bool flag, double d, string[] na
15171536

15181537
public Animal Animal { get; set; }
15191538
}
1539+
1540+
private sealed partial class ModelWithCommandNamesThatCantBeLowered
1541+
{
1542+
[RelayCommand]
1543+
public void 中文()
1544+
{
1545+
}
1546+
1547+
[RelayCommand]
1548+
public void c中文()
1549+
{
1550+
}
1551+
}
15201552
}

0 commit comments

Comments
 (0)