@@ -1672,6 +1672,30 @@ public partial class MyViewModel : ObservableObject
1672
1672
VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0035" ) ;
1673
1673
}
1674
1674
1675
+ // See https://github.com/CommunityToolkit/dotnet/issues/683
1676
+ [ TestMethod ]
1677
+ public void InvalidPropertyTargetedAttributeOnObservablePropertyField_InvalidExpression ( )
1678
+ {
1679
+ string source = """
1680
+ using System;
1681
+ using CommunityToolkit.Mvvm.ComponentModel;
1682
+
1683
+ public partial class MyViewModel : ObservableObject
1684
+ {
1685
+ [ObservableProperty]
1686
+ [property: Test(TestAttribute.M)]
1687
+ private int number;
1688
+ }
1689
+
1690
+ public class TestAttribute : Attribute
1691
+ {
1692
+ public static string M => "";
1693
+ }
1694
+ """ ;
1695
+
1696
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0037" ) ;
1697
+ }
1698
+
1675
1699
[ TestMethod ]
1676
1700
public void InvalidPropertyTargetedAttributeOnRelayCommandMethod_MissingUsingDirective ( )
1677
1701
{
@@ -1725,6 +1749,58 @@ private void Test()
1725
1749
VerifyGeneratedDiagnostics < RelayCommandGenerator > ( source , "MVVMTK0036" ) ;
1726
1750
}
1727
1751
1752
+ // See https://github.com/CommunityToolkit/dotnet/issues/683
1753
+ [ TestMethod ]
1754
+ public void InvalidPropertyTargetedAttributeOnRelayCommandMethod_InvalidExpressionOnFieldAttribute ( )
1755
+ {
1756
+ string source = """
1757
+ using System;
1758
+ using CommunityToolkit.Mvvm.Input;
1759
+
1760
+ public partial class MyViewModel
1761
+ {
1762
+ [RelayCommand]
1763
+ [field: Test(TestAttribute.M)]
1764
+ private void Test()
1765
+ {
1766
+ }
1767
+ }
1768
+
1769
+ public class TestAttribute : Attribute
1770
+ {
1771
+ public static string M => "";
1772
+ }
1773
+ """ ;
1774
+
1775
+ VerifyGeneratedDiagnostics < RelayCommandGenerator > ( source , "MVVMTK0038" ) ;
1776
+ }
1777
+
1778
+ // See https://github.com/CommunityToolkit/dotnet/issues/683
1779
+ [ TestMethod ]
1780
+ public void InvalidPropertyTargetedAttributeOnRelayCommandMethod_InvalidExpressionOnPropertyAttribute ( )
1781
+ {
1782
+ string source = """
1783
+ using System;
1784
+ using CommunityToolkit.Mvvm.Input;
1785
+
1786
+ public partial class MyViewModel
1787
+ {
1788
+ [RelayCommand]
1789
+ [property: Test(TestAttribute.M)]
1790
+ private void Test()
1791
+ {
1792
+ }
1793
+ }
1794
+
1795
+ public class TestAttribute : Attribute
1796
+ {
1797
+ public static string M => "";
1798
+ }
1799
+ """ ;
1800
+
1801
+ VerifyGeneratedDiagnostics < RelayCommandGenerator > ( source , "MVVMTK0038" ) ;
1802
+ }
1803
+
1728
1804
/// <summary>
1729
1805
/// Verifies the diagnostic errors for a given analyzer, and that all available source generators can run successfully with the input source (including subsequent compilation).
1730
1806
/// </summary>
0 commit comments