|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Threading.Tasks; |
| 6 | +using CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers; |
| 7 | +using Microsoft.CodeAnalysis.Testing; |
| 8 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 9 | + |
| 10 | +namespace CommunityToolkit.GeneratedDependencyProperty.Tests; |
| 11 | + |
| 12 | +[TestClass] |
| 13 | +public class Test_DiagnosticSuppressors |
| 14 | +{ |
| 15 | + private static readonly DiagnosticResult CS0658 = DiagnosticResult.CompilerWarning("CS0658"); |
| 16 | + |
| 17 | + [TestMethod] |
| 18 | + [DataRow("get")] |
| 19 | + [DataRow("with")] |
| 20 | + [DataRow("readonly")] |
| 21 | + [DataRow("propdp")] |
| 22 | + public async Task StaticAttributeListTargetOnGeneratedDependencyPropertyDeclarationSuppressor_OtherTarget_NotSuppressed(string target) |
| 23 | + { |
| 24 | + await new CSharpSuppressorTest<StaticAttributeListTargetOnGeneratedDependencyPropertyDeclarationSuppressor>( |
| 25 | + $$""" |
| 26 | + using System; |
| 27 | + using CommunityToolkit.WinUI; |
| 28 | + using Windows.UI.Xaml; |
| 29 | +
|
| 30 | + public class MyObject : DependencyObject |
| 31 | + { |
| 32 | + [GeneratedDependencyProperty] |
| 33 | + [{{target}}: Test] |
| 34 | + public string? Name { get; set; } |
| 35 | + } |
| 36 | +
|
| 37 | + public class TestAttribute : Attribute; |
| 38 | + """) |
| 39 | + .WithSpecificDiagnostics(CS0658) |
| 40 | + .RunAsync(); |
| 41 | + } |
| 42 | + |
| 43 | + [TestMethod] |
| 44 | + public async Task StaticAttributeListTargetOnGeneratedDependencyPropertyDeclarationSuppressor_NoTriggerAttribute_NotSuppressed() |
| 45 | + { |
| 46 | + await new CSharpSuppressorTest<StaticAttributeListTargetOnGeneratedDependencyPropertyDeclarationSuppressor>( |
| 47 | + """ |
| 48 | + using System; |
| 49 | + using Windows.UI.Xaml; |
| 50 | +
|
| 51 | + public class MyObject : DependencyObject |
| 52 | + { |
| 53 | + [static: Test] |
| 54 | + public string? Name { get; set; } |
| 55 | + } |
| 56 | +
|
| 57 | + public class TestAttribute : Attribute; |
| 58 | + """) |
| 59 | + .WithSpecificDiagnostics(CS0658) |
| 60 | + .RunAsync(); |
| 61 | + } |
| 62 | + |
| 63 | + [TestMethod] |
| 64 | + public async Task StaticAttributeListTargetOnGeneratedDependencyPropertyDeclarationSuppressor_ValidUse_Suppressed() |
| 65 | + { |
| 66 | + await new CSharpSuppressorTest<StaticAttributeListTargetOnGeneratedDependencyPropertyDeclarationSuppressor>( |
| 67 | + """ |
| 68 | + using System; |
| 69 | + using CommunityToolkit.WinUI; |
| 70 | + using Windows.UI.Xaml; |
| 71 | +
|
| 72 | + public class MyObject : DependencyObject |
| 73 | + { |
| 74 | + [GeneratedDependencyProperty] |
| 75 | + [static: Test] |
| 76 | + public string? Name { get; set; } |
| 77 | + } |
| 78 | +
|
| 79 | + public class TestAttribute : Attribute; |
| 80 | + """) |
| 81 | + .WithSpecificDiagnostics(CS0658) |
| 82 | + .RunAsync(); |
| 83 | + } |
| 84 | +} |
0 commit comments