From e7070a95ce56f1e099e515664fec73aeea2b8f37 Mon Sep 17 00:00:00 2001 From: Matt Chaulklin Date: Wed, 21 Aug 2024 12:51:59 -0400 Subject: [PATCH 1/3] Added new message --- .../CodeFixTest`1.cs | 12 ++++++++++-- .../CodeRefactoringTest`1.cs | 6 +++++- .../MissingCodeFixMarkupTests.cs | 4 ++-- .../MissingCodeFixTests.cs | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs index f42dcd6f2..fb138788c 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs @@ -692,7 +692,11 @@ private async Task VerifyProjectAsync(ProjectState newState, Project project, IV try { - if (expectedNumberOfIterations >= 0) + if (expectedNumberOfIterations == 0 && numberOfIterations <= 0) + { + verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, "No code fixes were expected, but a fix was offered that made no changes to the code."); + } + else if (expectedNumberOfIterations >= 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, $"Expected '{expectedNumberOfIterations}' iterations but found '{expectedNumberOfIterations - numberOfIterations}' iterations."); } @@ -862,7 +866,11 @@ private async Task VerifyProjectAsync(ProjectState newState, Project project, IV try { - if (expectedNumberOfIterations >= 0) + if (expectedNumberOfIterations == 0 && numberOfIterations <= 0) + { + verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, "No code fixes were expected, but a fix was offered that made no changes to the code."); + } + else if (expectedNumberOfIterations >= 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, $"Expected '{expectedNumberOfIterations}' iterations but found '{expectedNumberOfIterations - numberOfIterations}' iterations."); } diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs index f765544fe..1ffbbf996 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs @@ -302,7 +302,11 @@ private async Task VerifyProjectAsync(ProjectState newState, Project project, IV try { - if (expectedNumberOfIterations >= 0) + if (expectedNumberOfIterations == 0 && numberOfIterations <= 0) + { + verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, "No code fixes were expected, but a fix was offered that made no changes to the code."); + } + else if (expectedNumberOfIterations >= 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, $"Expected '{expectedNumberOfIterations}' iterations but found '{expectedNumberOfIterations - numberOfIterations}' iterations."); } diff --git a/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixMarkupTests.cs b/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixMarkupTests.cs index 422f8491d..9978ed059 100644 --- a/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixMarkupTests.cs +++ b/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixMarkupTests.cs @@ -78,7 +78,7 @@ namespace MyNamespace {|Brace:{|} Assert.Equal( """ Context: Iterative code fix application - Expected '0' iterations but found '1' iterations. + No code fixes were expected, but a fix was offered that made no changes to the code. """.ReplaceLineEndings(), exception.Message); @@ -91,7 +91,7 @@ namespace MyNamespace {|Brace:{|} Assert.Equal( """ Context: Iterative code fix application - Expected '0' iterations but found '1' iterations. + No code fixes were expected, but a fix was offered that made no changes to the code. """.ReplaceLineEndings(), exception.Message); } diff --git a/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixTests.cs b/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixTests.cs index 2f9776330..704b94d69 100644 --- a/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixTests.cs +++ b/tests/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing.UnitTests/MissingCodeFixTests.cs @@ -82,7 +82,7 @@ namespace MyNamespace { Assert.Equal( """ Context: Iterative code fix application - Expected '0' iterations but found '1' iterations. + No code fixes were expected, but a fix was offered that made no changes to the code. """.ReplaceLineEndings(), exception.Message); @@ -95,7 +95,7 @@ namespace MyNamespace { Assert.Equal( """ Context: Iterative code fix application - Expected '0' iterations but found '1' iterations. + No code fixes were expected, but a fix was offered that made no changes to the code. """.ReplaceLineEndings(), exception.Message); } From 875d29a34d1ae03947e48631aaa310271ecacb41 Mon Sep 17 00:00:00 2001 From: Matt Chaulklin Date: Wed, 21 Aug 2024 13:14:21 -0400 Subject: [PATCH 2/3] code cleanup --- .../CodeRefactoringTest`1.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs index 1ffbbf996..f765544fe 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeRefactoring.Testing/CodeRefactoringTest`1.cs @@ -302,11 +302,7 @@ private async Task VerifyProjectAsync(ProjectState newState, Project project, IV try { - if (expectedNumberOfIterations == 0 && numberOfIterations <= 0) - { - verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, "No code fixes were expected, but a fix was offered that made no changes to the code."); - } - else if (expectedNumberOfIterations >= 0) + if (expectedNumberOfIterations >= 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, $"Expected '{expectedNumberOfIterations}' iterations but found '{expectedNumberOfIterations - numberOfIterations}' iterations."); } From e401620ce9ca90bb784cda3f1499ca4a018b84a4 Mon Sep 17 00:00:00 2001 From: Matt Chaulklin Date: Mon, 26 Aug 2024 09:53:10 -0400 Subject: [PATCH 3/3] Applied code changes and tested --- .../CodeFixTest`1.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs index fb138788c..be3411585 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.CodeFix.Testing/CodeFixTest`1.cs @@ -692,11 +692,11 @@ private async Task VerifyProjectAsync(ProjectState newState, Project project, IV try { - if (expectedNumberOfIterations == 0 && numberOfIterations <= 0) + if (expectedNumberOfIterations == 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, "No code fixes were expected, but a fix was offered that made no changes to the code."); } - else if (expectedNumberOfIterations >= 0) + else if (expectedNumberOfIterations > 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, $"Expected '{expectedNumberOfIterations}' iterations but found '{expectedNumberOfIterations - numberOfIterations}' iterations."); } @@ -866,11 +866,11 @@ private async Task VerifyProjectAsync(ProjectState newState, Project project, IV try { - if (expectedNumberOfIterations == 0 && numberOfIterations <= 0) + if (expectedNumberOfIterations == 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, "No code fixes were expected, but a fix was offered that made no changes to the code."); } - else if (expectedNumberOfIterations >= 0) + else if (expectedNumberOfIterations > 0) { verifier.Equal(expectedNumberOfIterations, expectedNumberOfIterations - numberOfIterations, $"Expected '{expectedNumberOfIterations}' iterations but found '{expectedNumberOfIterations - numberOfIterations}' iterations."); }