Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,96 @@ public void RegularMethod(TestContext {|#0:context|})
}.RunAsync();
}

[TestMethod]
public async Task TestMethodWithUnusedTestContext_DiagnosticIsNotSuppressed()
{
// [TestMethod] is not in the suppressor's fixture-attribute list, so even a TestContext
// parameter should not be suppressed.
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class SomeClass
{
[TestMethod]
public void TestMethod(TestContext {|#0:context|})
{
}
}
""";

// Verify issue is reported without suppressor
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("context")
.WithIsSuppressed(false),
},
}.RunAsync();

// Verify issue is still reported with suppressor (not suppressed)
await new TestWithSuppressor
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("context")
.WithIsSuppressed(false),
},
}.RunAsync();
}

[TestMethod]
public async Task AssemblyInitializeWithUnusedNonTestContextParameter_DiagnosticIsNotSuppressed()
{
// The suppressor only suppresses TestContext parameters; a non-TestContext parameter in a
// fixture method (e.g. [AssemblyInitialize]) should not be suppressed.
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class SomeClass
{
[AssemblyInitialize]
public static void Initialize(string {|#0:message|})
{
}
}
""";

// Verify issue is reported without suppressor
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("message")
.WithIsSuppressed(false),
},
}.RunAsync();

// Verify issue is still reported with suppressor (not suppressed)
await new TestWithSuppressor
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("message")
.WithIsSuppressed(false),
},
}.RunAsync();
}

[DiagnosticAnalyzer(LanguageNames.CSharp)]
[SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1038:Compiler extensions should be implemented in assemblies with compiler-provided references", Justification = "For suppression test only.")]
[SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1036:Specify analyzer banned API enforcement setting", Justification = "For suppression test only.")]
Expand Down
Loading