Skip to content

Commit 8857555

Browse files
committed
Add runtime unit tests for new dependency generation
1 parent 8e6afab commit 8857555

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/CommunityToolkit.Mvvm.UnitTests/Test_ObservablePropertyAttribute.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,39 @@ public void Test_ObservableProperty_ModelWithObservablePropertyWithUnderscoreAnd
10401040
Assert.IsTrue(model.IsReadOnly);
10411041
}
10421042

1043+
// See https://github.com/CommunityToolkit/dotnet/issues/711
1044+
[TestMethod]
1045+
public void Test_ObservableProperty_ModelWithDependentPropertyAndPropertyChanging()
1046+
{
1047+
ModelWithDependentPropertyAndPropertyChanging model = new();
1048+
1049+
List<string> changingArgs = new();
1050+
List<string> changedArgs = new();
1051+
1052+
model.PropertyChanging += (s, e) => changingArgs.Add(e.PropertyName);
1053+
model.PropertyChanged += (s, e) => changedArgs.Add(e.PropertyName);
1054+
1055+
model.Name = "Bob";
1056+
1057+
CollectionAssert.AreEqual(new[] { nameof(ModelWithDependentPropertyAndPropertyChanging.Name), nameof(ModelWithDependentPropertyAndPropertyChanging.FullName) }, changingArgs);
1058+
CollectionAssert.AreEqual(new[] { nameof(ModelWithDependentPropertyAndPropertyChanging.Name), nameof(ModelWithDependentPropertyAndPropertyChanging.FullName) }, changedArgs);
1059+
}
1060+
1061+
// See https://github.com/CommunityToolkit/dotnet/issues/711
1062+
[TestMethod]
1063+
public void Test_ObservableProperty_ModelWithDependentPropertyAndNoPropertyChanging()
1064+
{
1065+
ModelWithDependentPropertyAndNoPropertyChanging model = new();
1066+
1067+
List<string> changedArgs = new();
1068+
1069+
model.PropertyChanged += (s, e) => changedArgs.Add(e.PropertyName);
1070+
1071+
model.Name = "Alice";
1072+
1073+
CollectionAssert.AreEqual(new[] { nameof(ModelWithDependentPropertyAndNoPropertyChanging.Name), nameof(ModelWithDependentPropertyAndNoPropertyChanging.FullName) }, changedArgs);
1074+
}
1075+
10431076
#if NET6_0_OR_GREATER
10441077
[TestMethod]
10451078
public void Test_ObservableProperty_MemberNotNullAttributeIsPresent()
@@ -1745,4 +1778,23 @@ public enum NegativeEnum
17451778
Problem = -1,
17461779
OK = 0
17471780
}
1781+
1782+
private sealed partial class ModelWithDependentPropertyAndPropertyChanging : ObservableObject
1783+
{
1784+
[ObservableProperty]
1785+
[NotifyPropertyChangedFor(nameof(FullName))]
1786+
private string? name;
1787+
1788+
public string? FullName => "";
1789+
}
1790+
1791+
[INotifyPropertyChanged(IncludeAdditionalHelperMethods = false)]
1792+
private sealed partial class ModelWithDependentPropertyAndNoPropertyChanging
1793+
{
1794+
[ObservableProperty]
1795+
[NotifyPropertyChangedFor(nameof(FullName))]
1796+
private string? name;
1797+
1798+
public string? FullName => "";
1799+
}
17481800
}

0 commit comments

Comments
 (0)