@@ -72,6 +72,77 @@ public class SomeClass
7272 await VerifySingleSuppressionAsync ( code , isSuppressed : true ) ;
7373 }
7474
75+ [ TestMethod ]
76+ public async Task TestContextPropertyOnClassWithDerivedTestClassAttribute_DiagnosticIsSuppressed ( )
77+ {
78+ string code = @"
79+ #nullable enable
80+
81+ using System;
82+ using Microsoft.VisualStudio.TestTools.UnitTesting;
83+
84+ [AttributeUsage(AttributeTargets.Class)]
85+ public class DerivedTestClassAttribute : TestClassAttribute { }
86+
87+ [DerivedTestClass]
88+ public class SomeClass
89+ {
90+ public TestContext {|#0:TestContext|} { get; set; }
91+ }
92+ " ;
93+
94+ await VerifySingleSuppressionAsync ( code , isSuppressed : true ) ;
95+ }
96+
97+ [ TestMethod ]
98+ public async Task TestContextPropertyWithWrongTypeName_DiagnosticIsNotSuppressed ( )
99+ {
100+ string code = @"
101+ #nullable enable
102+
103+ using Microsoft.VisualStudio.TestTools.UnitTesting;
104+
105+ public class MyCustomContext { }
106+
107+ [TestClass]
108+ public class SomeClass
109+ {
110+ public MyCustomContext {|#0:TestContext|} { get; set; }
111+ }
112+ " ;
113+
114+ await VerifySingleSuppressionAsync ( code , isSuppressed : false ) ;
115+ }
116+
117+ [ TestMethod ]
118+ public async Task TestContextPropertyWithWrongPropertyName_DiagnosticIsNotSuppressed ( )
119+ {
120+ string code = @"
121+ #nullable enable
122+
123+ using Microsoft.VisualStudio.TestTools.UnitTesting;
124+
125+ [TestClass]
126+ public class SomeClass
127+ {
128+ public TestContext {|#0:MyContext|} { get; set; }
129+ }
130+ " ;
131+
132+ var test = new VerifyCS . Test
133+ {
134+ TestCode = code ,
135+ } ;
136+
137+ test . ExpectedDiagnostics . Add ( DiagnosticResult . CompilerError ( "CS8618" )
138+ . WithLocation ( 0 )
139+ . WithOptions ( DiagnosticOptions . IgnoreAdditionalLocations )
140+ . WithArguments ( "property" , "MyContext" )
141+ . WithIsSuppressed ( false ) ) ;
142+
143+ await test . RunAsync ( ) ;
144+ }
145+
75146 private Task VerifySingleSuppressionAsync ( string source , bool isSuppressed )
76147 => VerifyDiagnosticsAsync ( source , [ ( 0 , isSuppressed ) ] ) ;
77148
0 commit comments