@@ -635,6 +635,179 @@ public partial class SampleViewModel : ObservableObject
635
635
VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0014" ) ;
636
636
}
637
637
638
+ [ TestMethod ]
639
+ public void AlsoNotifyChangeForInvalidTargetError_Null ( )
640
+ {
641
+ string source = @"
642
+ using System.ComponentModel.DataAnnotations;
643
+ using CommunityToolkit.Mvvm.ComponentModel;
644
+
645
+ namespace MyApp
646
+ {
647
+ public partial class SampleViewModel : ObservableObject
648
+ {
649
+ [ObservableProperty]
650
+ [AlsoNotifyChangeFor(null)]
651
+ private string Name;
652
+ }
653
+ }" ;
654
+
655
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0015" ) ;
656
+ }
657
+
658
+ [ TestMethod ]
659
+ public void AlsoNotifyChangeForInvalidTargetError_Missing ( )
660
+ {
661
+ string source = @"
662
+ using System.ComponentModel.DataAnnotations;
663
+ using CommunityToolkit.Mvvm.ComponentModel;
664
+
665
+ namespace MyApp
666
+ {
667
+ public partial class SampleViewModel : ObservableObject
668
+ {
669
+ [ObservableProperty]
670
+ [AlsoNotifyChangeFor(""FooBar"")]
671
+ private string Name;
672
+ }
673
+ }" ;
674
+
675
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0015" ) ;
676
+ }
677
+
678
+ [ TestMethod ]
679
+ public void AlsoNotifyChangeForInvalidTargetError_InvalidType ( )
680
+ {
681
+ string source = @"
682
+ using System.ComponentModel.DataAnnotations;
683
+ using CommunityToolkit.Mvvm.ComponentModel;
684
+
685
+ namespace MyApp
686
+ {
687
+ public partial class SampleViewModel : ObservableObject
688
+ {
689
+ [ObservableProperty]
690
+ [AlsoNotifyChangeFor(nameof(Foo))]
691
+ private string Name;
692
+
693
+ public void Foo()
694
+ {
695
+ }
696
+ }
697
+ }" ;
698
+
699
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0015" ) ;
700
+ }
701
+
702
+ [ TestMethod ]
703
+ public void AlsoNotifyCanExecuteForInvalidTargetError_Null ( )
704
+ {
705
+ string source = @"
706
+ using System.ComponentModel.DataAnnotations;
707
+ using CommunityToolkit.Mvvm.ComponentModel;
708
+
709
+ namespace MyApp
710
+ {
711
+ public partial class SampleViewModel : ObservableObject
712
+ {
713
+ [ObservableProperty]
714
+ [AlsoNotifyCanExecuteFor(null)]
715
+ private string Name;
716
+ }
717
+ }" ;
718
+
719
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0016" ) ;
720
+ }
721
+
722
+ [ TestMethod ]
723
+ public void AlsoNotifyCanExecuteForInvalidTargetError_Missing ( )
724
+ {
725
+ string source = @"
726
+ using System.ComponentModel.DataAnnotations;
727
+ using CommunityToolkit.Mvvm.ComponentModel;
728
+
729
+ namespace MyApp
730
+ {
731
+ public partial class SampleViewModel : ObservableObject
732
+ {
733
+ [ObservableProperty]
734
+ [AlsoNotifyCanExecuteFor(""FooBar"")]
735
+ private string Name;
736
+ }
737
+ }" ;
738
+
739
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0016" ) ;
740
+ }
741
+
742
+ [ TestMethod ]
743
+ public void AlsoNotifyCanExecuteForInvalidTargetError_InvalidMemberType ( )
744
+ {
745
+ string source = @"
746
+ using System.ComponentModel.DataAnnotations;
747
+ using CommunityToolkit.Mvvm.ComponentModel;
748
+
749
+ namespace MyApp
750
+ {
751
+ public partial class SampleViewModel : ObservableObject
752
+ {
753
+ [ObservableProperty]
754
+ [AlsoNotifyCanExecuteFor(nameof(Foo))]
755
+ private string Name;
756
+
757
+ public void Foo()
758
+ {
759
+ }
760
+ }
761
+ }" ;
762
+
763
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0016" ) ;
764
+ }
765
+
766
+ [ TestMethod ]
767
+ public void AlsoNotifyCanExecuteForInvalidTargetError_InvalidPropertyType ( )
768
+ {
769
+ string source = @"
770
+ using System.ComponentModel.DataAnnotations;
771
+ using CommunityToolkit.Mvvm.ComponentModel;
772
+
773
+ namespace MyApp
774
+ {
775
+ public partial class SampleViewModel : ObservableObject
776
+ {
777
+ [ObservableProperty]
778
+ [AlsoNotifyCanExecuteFor(nameof(Foo))]
779
+ private string Name;
780
+
781
+ public string Foo { get; }
782
+ }
783
+ }" ;
784
+
785
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0016" ) ;
786
+ }
787
+
788
+ [ TestMethod ]
789
+ public void AlsoNotifyCanExecuteForInvalidTargetError_InvalidCommandType ( )
790
+ {
791
+ string source = @"
792
+ using System.ComponentModel.DataAnnotations;
793
+ using CommunityToolkit.Mvvm.ComponentModel;
794
+ using CommunityToolkit.Mvvm.Input;
795
+
796
+ namespace MyApp
797
+ {
798
+ public partial class SampleViewModel : ObservableObject
799
+ {
800
+ [ObservableProperty]
801
+ [AlsoNotifyCanExecuteFor(nameof(FooCommand))]
802
+ private string Name;
803
+
804
+ public ICommand FooCommand { get; }
805
+ }
806
+ }" ;
807
+
808
+ VerifyGeneratedDiagnostics < ObservablePropertyGenerator > ( source , "MVVMTK0016" ) ;
809
+ }
810
+
638
811
/// <summary>
639
812
/// Verifies the output of a source generator.
640
813
/// </summary>
0 commit comments