Skip to content

Commit ef22336

Browse files
committed
Add unit test for consistent compilation diagnostic
1 parent 3533b97 commit ef22336

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ namespace MyApp
468468
{
469469
public partial class SampleViewModel : ObservableObject
470470
{
471-
[{|MVVMTK0051:ObservableProperty|}]
471+
[{|MVVMTK0051:ObservableProperty|}]
472472
private string {|MVVMTK0045:name|};
473473
}
474474
}
@@ -480,6 +480,58 @@ await CSharpAnalyzerWithLanguageVersionTest<WinRTObservablePropertyOnFieldsIsNot
480480
editorconfig: [("_MvvmToolkitIsUsingWindowsRuntimePack", true), ("CsWinRTAotOptimizerEnabled", "auto")]);
481481
}
482482

483+
[TestMethod]
484+
public async Task WinRTObservablePropertyOnFieldsIsNotAotCompatibleAnalyzer_TargetingWindows_CsWinRTAotOptimizerEnabled_Auto_NotCSharpPreview_MultipleFields_Warns_WithCompilationWarning_ConsistentLocation()
485+
{
486+
const string source = """
487+
using CommunityToolkit.Mvvm.ComponentModel;
488+
489+
namespace MyApp
490+
{
491+
public partial class SampleViewModel : ObservableObject
492+
{
493+
[{|MVVMTK0051:ObservableProperty|}]
494+
private string {|MVVMTK0045:f1|};
495+
496+
[ObservableProperty]
497+
private string {|MVVMTK0045:f2|};
498+
499+
[ObservableProperty]
500+
private string {|MVVMTK0045:f3|};
501+
}
502+
503+
public partial class OtherViewModel : ObservableObject
504+
{
505+
[ObservableProperty]
506+
private string {|MVVMTK0045:f1|};
507+
508+
[ObservableProperty]
509+
private string {|MVVMTK0045:f2|};
510+
511+
[ObservableProperty]
512+
private string {|MVVMTK0045:f3|};
513+
}
514+
}
515+
516+
namespace OtherNamespace
517+
{
518+
public partial class YetAnotherViewModel : ObservableObject
519+
{
520+
[ObservableProperty]
521+
private string {|MVVMTK0045:f1|};
522+
523+
[ObservableProperty]
524+
private string {|MVVMTK0045:f2|};
525+
}
526+
}
527+
""";
528+
529+
await CSharpAnalyzerWithLanguageVersionTest<WinRTObservablePropertyOnFieldsIsNotAotCompatibleAnalyzer>.VerifyAnalyzerAsync(
530+
source,
531+
LanguageVersion.CSharp12,
532+
editorconfig: [("_MvvmToolkitIsUsingWindowsRuntimePack", true), ("CsWinRTAotOptimizerEnabled", "auto")]);
533+
}
534+
483535
[TestMethod]
484536
public async Task WinRTObservablePropertyOnFieldsIsNotAotCompatibleAnalyzer_TargetingWindows_CsWinRTAotOptimizerEnabled_True_NoXaml_Level1_DoesNotWarn()
485537
{

0 commit comments

Comments
 (0)