Skip to content
Merged
Show file tree
Hide file tree
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 @@ -25,7 +25,7 @@ public async Task AssemblyInitializeWithUnusedTestContext_DiagnosticIsSuppressed
public class SomeClass
{
[AssemblyInitialize]
public static void Initialize(TestContext [|context|])
public static void Initialize(TestContext {|#0:context|})
{
// TestContext parameter is unused but required by MSTest
}
Expand All @@ -36,12 +36,26 @@ public static void Initialize(TestContext [|context|])
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("context")
.WithIsSuppressed(false),
},
}.RunAsync();

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

Expand All @@ -55,7 +69,7 @@ public async Task ClassInitializeWithUnusedTestContext_DiagnosticIsSuppressed()
public class SomeClass
{
[ClassInitialize]
public static void Initialize(TestContext [|context|])
public static void Initialize(TestContext {|#0:context|})
{
// TestContext parameter is unused but required by MSTest
}
Expand All @@ -66,12 +80,26 @@ public static void Initialize(TestContext [|context|])
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("context")
.WithIsSuppressed(false),
},
}.RunAsync();

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

Expand All @@ -85,7 +113,7 @@ public async Task TestMethodWithUnusedParameter_DiagnosticIsNotSuppressed()
public class SomeClass
{
[TestMethod]
public void TestMethod(int [|unusedParam|])
public void TestMethod(int {|#0:unusedParam|})
{
// This should not be suppressed
}
Expand All @@ -96,12 +124,26 @@ public void TestMethod(int [|unusedParam|])
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForUnusedParameters.Rule)
.WithLocation(0)
.WithArguments("unusedParam")
.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("unusedParam")
.WithIsSuppressed(false),
},
}.RunAsync();
}

Expand All @@ -114,7 +156,7 @@ public async Task RegularMethodWithUnusedTestContext_DiagnosticIsNotSuppressed()
[TestClass]
public class SomeClass
{
public void RegularMethod(TestContext [|context|])
public void RegularMethod(TestContext {|#0:context|})
{
// This should not be suppressed as it's not AssemblyInitialize or ClassInitialize
}
Expand All @@ -125,12 +167,26 @@ public void RegularMethod(TestContext [|context|])
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,68 +26,108 @@ public async Task AsyncTestFixtureMethodsWithoutSuffix_DiagnosticIsSuppressed()
public class SomeClass
{
[AssemblyInitialize]
public static async Task [|AssemblyInitialize|]() { }
public static async Task {|#0:AssemblyInitialize|}() { }

[AssemblyCleanup]
public static async Task [|AssemblyCleanup|]() { }
public static async Task {|#1:AssemblyCleanup|}() { }

[ClassInitialize]
public static async Task [|ClassInitialize|]() { }
public static async Task {|#2:ClassInitialize|}() { }

[ClassCleanup]
public static async Task [|ClassCleanup|]() { }
public static async Task {|#3:ClassCleanup|}() { }

[TestInitialize]
public async Task [|TestInitialize|]() { }
public async Task {|#4:TestInitialize|}() { }

[TestCleanup]
public async Task [|TestCleanup|]() { }
public async Task {|#5:TestCleanup|}() { }
}
";

// Verify issues Are reported
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(0)
.WithIsSuppressed(false),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(1)
.WithIsSuppressed(false),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(2)
.WithIsSuppressed(false),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(3)
.WithIsSuppressed(false),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(4)
.WithIsSuppressed(false),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(5)
.WithIsSuppressed(false),
},
}.RunAsync();

await new TestWithSuppressor
{
TestState = { Sources = { code } },
ExpectedDiagnostics =
{
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(0)
.WithIsSuppressed(true),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(1)
.WithIsSuppressed(true),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(2)
.WithIsSuppressed(true),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(3)
.WithIsSuppressed(true),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(4)
.WithIsSuppressed(true),
VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule)
.WithLocation(5)
.WithIsSuppressed(true),
},
}.RunAsync();
}

[TestMethod]
public async Task AsyncTestMethodWithSuffix_NoDiagnostic()
{
string code = """
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class SomeClass
{
[AssemblyInitialize]
public static async Task AssemblyInitializeAsync() { }

[AssemblyCleanup]
public static async Task AssemblyCleanupAsync() { }
[TestClass]
public class SomeClass
{
[AssemblyInitialize]
public static async Task AssemblyInitializeAsync() { }

[ClassInitialize]
public static async Task ClassInitializeAsync() { }
[AssemblyCleanup]
public static async Task AssemblyCleanupAsync() { }

[ClassCleanup]
public static async Task ClassCleanupAsync() { }
[ClassInitialize]
public static async Task ClassInitializeAsync() { }

[TestInitialize]
public async Task TestInitializeAsync() { }
[ClassCleanup]
public static async Task ClassCleanupAsync() { }

[TestCleanup]
public async Task TestCleanupAsync() { }
}
[TestInitialize]
public async Task TestInitializeAsync() { }

""";
[TestCleanup]
public async Task TestCleanupAsync() { }
}
""";

await new VerifyCS.Test
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task AsyncTestMethodWithoutSuffix_DiagnosticIsSuppressed()
public class SomeClass
{
[TestMethod]
public async Task [|TestMethod|]() { }
public async Task {|#0:TestMethod|}() { }
}

""";
Expand All @@ -37,11 +37,13 @@ public class SomeClass
await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics = { VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule).WithLocation(0).WithIsSuppressed(false) },
}.RunAsync();

await new TestWithSuppressor
{
TestState = { Sources = { code } },
ExpectedDiagnostics = { VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule).WithLocation(0).WithIsSuppressed(true) },
}.RunAsync();
}

Expand All @@ -58,19 +60,21 @@ public async Task AsyncDataTestMethodWithoutSuffix_DiagnosticIsSuppressed()
public class SomeClass
{
[DataTestMethod, DataRow(0)]
public async Task [|TestMethod|](int arg) { }
public async Task {|#0:TestMethod|}(int arg) { }
}

""";

await new VerifyCS.Test
{
TestState = { Sources = { code } },
ExpectedDiagnostics = { VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule).WithLocation(0).WithIsSuppressed(false) },
}.RunAsync();

await new TestWithSuppressor
{
TestState = { Sources = { code } },
ExpectedDiagnostics = { VerifyCS.Diagnostic(WarnForMissingAsyncSuffix.Rule).WithLocation(0).WithIsSuppressed(true) },
}.RunAsync();
}

Expand Down