diff --git a/src/Analyzers/MSTest.Analyzers.CodeFixes/PreferTestCleanupOverDisposeFixer.cs b/src/Analyzers/MSTest.Analyzers.CodeFixes/PreferTestCleanupOverDisposeFixer.cs index b31908aa85..61b16518bf 100644 --- a/src/Analyzers/MSTest.Analyzers.CodeFixes/PreferTestCleanupOverDisposeFixer.cs +++ b/src/Analyzers/MSTest.Analyzers.CodeFixes/PreferTestCleanupOverDisposeFixer.cs @@ -49,7 +49,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) CodeAction.Create( CodeFixResources.ReplaceWithTestCleanuFix, c => ReplaceDisposeWithTestCleanupAsync(context.Document, methodDeclaration, c), - nameof(TestMethodShouldBeValidCodeFixProvider)), + nameof(PreferTestCleanupOverDisposeFixer)), diagnostic); } @@ -83,7 +83,9 @@ private static async Task ReplaceDisposeWithTestCleanupAsync(Document else { // If no interfaces left, remove the base list entirely + SyntaxTriviaList trailingTrivia = newParent.BaseList?.GetTrailingTrivia() ?? SyntaxTriviaList.Empty; newParent = newParent.WithBaseList(null); + newParent = newParent.WithIdentifier(newParent.Identifier.WithTrailingTrivia(trailingTrivia)); } editor.ReplaceNode(parentClass, newParent); diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs index 5111e4ed2a..278c0a417f 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/PreferTestCleanupOverDisposeAnalyzerTests.cs @@ -71,7 +71,8 @@ public class MyTestClass : IAsyncDisposable using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] - public class MyTestClass { + public class MyTestClass + { [TestCleanup] public ValueTask TestCleanup() {