Skip to content

Commit f78319c

Browse files
committed
Added test for generate properties for [INPC]
1 parent ee93385 commit f78319c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

UnitTests/UnitTests.NetCore/Mvvm/Test_INotifyPropertyChangedAttribute.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Collections.Generic;
56
using System.ComponentModel;
67
using System.Diagnostics.CodeAnalysis;
78
using System.Reflection;
@@ -75,5 +76,36 @@ public void Test_INotifyPropertyChanged_WithoutHelpers()
7576
public partial class SampleModelWithoutHelpers
7677
{
7778
}
79+
80+
[TestCategory("Mvvm")]
81+
[TestMethod]
82+
public void Test_INotifyPropertyChanged_WithGeneratedProperties()
83+
{
84+
Assert.IsTrue(typeof(INotifyPropertyChanged).IsAssignableFrom(typeof(SampleModelWithINPCAndObservableProperties)));
85+
Assert.IsFalse(typeof(INotifyPropertyChanging).IsAssignableFrom(typeof(SampleModelWithINPCAndObservableProperties)));
86+
87+
SampleModelWithINPCAndObservableProperties model = new();
88+
List<PropertyChangedEventArgs> eventArgs = new();
89+
90+
model.PropertyChanged += (s, e) => eventArgs.Add(e);
91+
92+
model.X = 42;
93+
model.Y = 66;
94+
95+
Assert.AreEqual(eventArgs.Count, 2);
96+
Assert.AreEqual(eventArgs[0].PropertyName, nameof(SampleModelWithINPCAndObservableProperties.X));
97+
Assert.AreEqual(eventArgs[1].PropertyName, nameof(SampleModelWithINPCAndObservableProperties.Y));
98+
}
99+
100+
// See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3665
101+
[INotifyPropertyChanged]
102+
public partial class SampleModelWithINPCAndObservableProperties
103+
{
104+
[ObservableProperty]
105+
private int x;
106+
107+
[ObservableProperty]
108+
private int y;
109+
}
78110
}
79111
}

0 commit comments

Comments
 (0)