@@ -1040,6 +1040,39 @@ public void Test_ObservableProperty_ModelWithObservablePropertyWithUnderscoreAnd
1040
1040
Assert . IsTrue ( model . IsReadOnly ) ;
1041
1041
}
1042
1042
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
+
1043
1076
#if NET6_0_OR_GREATER
1044
1077
[ TestMethod ]
1045
1078
public void Test_ObservableProperty_MemberNotNullAttributeIsPresent ( )
@@ -1745,4 +1778,23 @@ public enum NegativeEnum
1745
1778
Problem = - 1 ,
1746
1779
OK = 0
1747
1780
}
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
+ }
1748
1800
}
0 commit comments