Skip to content

Commit

Permalink
Add unit tests for blocked generated properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed May 9, 2022
1 parent 780b596 commit 914f31d
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,89 @@ private void GreetUser(object value)
VerifyGeneratedDiagnostics<ICommandGenerator>(source, "MVVMTK0023");
}

[TestMethod]
public void InvalidObservablePropertyError_Object()
{
string source = @"
using CommunityToolkit.Mvvm.ComponentModel;
namespace MyApp
{
public partial class MyViewModel : ObservableObject
{
[ObservableProperty]
public object property;
}
}";

VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
}

[TestMethod]
public void InvalidObservablePropertyError_PropertyChangingEventArgs()
{
string source = @"
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace MyApp
{
public partial class MyViewModel : ObservableObject
{
[ObservableProperty]
public PropertyChangingEventArgs property;
}
}";

VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
}

[TestMethod]
public void InvalidObservablePropertyError_PropertyChangedEventArgs()
{
string source = @"
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace MyApp
{
public partial class MyViewModel : ObservableObject
{
[ObservableProperty]
public PropertyChangedEventArgs property;
}
}";

VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
}

[TestMethod]
public void InvalidObservablePropertyError_CustomTypeDerivedFromPropertyChangedEventArgs()
{
string source = @"
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace MyApp
{
public class MyPropertyChangedEventArgs : PropertyChangedEventArgs
{
public MyPropertyChangedEventArgs(string propertyName)
: base(propertyName)
{
}
}
public partial class MyViewModel : ObservableObject
{
[ObservableProperty]
public MyPropertyChangedEventArgs property;
}
}";

VerifyGeneratedDiagnostics<ObservablePropertyGenerator>(source, "MVVMTK0024");
}

/// <summary>
/// Verifies the output of a source generator.
/// </summary>
Expand Down

0 comments on commit 914f31d

Please sign in to comment.