Skip to content

Commit 914f31d

Browse files
committed
Add unit tests for blocked generated properties
1 parent 780b596 commit 914f31d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/CommunityToolkit.Mvvm.SourceGenerators.UnitTests/Test_SourceGeneratorsDiagnostics.cs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,89 @@ private void GreetUser(object value)
11051105
VerifyGeneratedDiagnostics<ICommandGenerator>(source, "MVVMTK0023");
11061106
}
11071107

1108+
[TestMethod]
1109+
public void InvalidObservablePropertyError_Object()
1110+
{
1111+
string source = @"
1112+
using CommunityToolkit.Mvvm.ComponentModel;
1113+
1114+
namespace MyApp
1115+
{
1116+
public partial class MyViewModel : ObservableObject
1117+
{
1118+
[ObservableProperty]
1119+
public object property;
1120+
}
1121+
}";
1122+
1123+
VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
1124+
}
1125+
1126+
[TestMethod]
1127+
public void InvalidObservablePropertyError_PropertyChangingEventArgs()
1128+
{
1129+
string source = @"
1130+
using System.ComponentModel;
1131+
using CommunityToolkit.Mvvm.ComponentModel;
1132+
1133+
namespace MyApp
1134+
{
1135+
public partial class MyViewModel : ObservableObject
1136+
{
1137+
[ObservableProperty]
1138+
public PropertyChangingEventArgs property;
1139+
}
1140+
}";
1141+
1142+
VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
1143+
}
1144+
1145+
[TestMethod]
1146+
public void InvalidObservablePropertyError_PropertyChangedEventArgs()
1147+
{
1148+
string source = @"
1149+
using System.ComponentModel;
1150+
using CommunityToolkit.Mvvm.ComponentModel;
1151+
1152+
namespace MyApp
1153+
{
1154+
public partial class MyViewModel : ObservableObject
1155+
{
1156+
[ObservableProperty]
1157+
public PropertyChangedEventArgs property;
1158+
}
1159+
}";
1160+
1161+
VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
1162+
}
1163+
1164+
[TestMethod]
1165+
public void InvalidObservablePropertyError_CustomTypeDerivedFromPropertyChangedEventArgs()
1166+
{
1167+
string source = @"
1168+
using System.ComponentModel;
1169+
using CommunityToolkit.Mvvm.ComponentModel;
1170+
1171+
namespace MyApp
1172+
{
1173+
public class MyPropertyChangedEventArgs : PropertyChangedEventArgs
1174+
{
1175+
public MyPropertyChangedEventArgs(string propertyName)
1176+
: base(propertyName)
1177+
{
1178+
}
1179+
}
1180+
1181+
public partial class MyViewModel : ObservableObject
1182+
{
1183+
[ObservableProperty]
1184+
public MyPropertyChangedEventArgs property;
1185+
}
1186+
}";
1187+
1188+
VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
1189+
}
1190+
11081191
/// <summary>
11091192
/// Verifies the output of a source generator.
11101193
/// </summary>

0 commit comments

Comments
 (0)