-
Notifications
You must be signed in to change notification settings - Fork 278
Add analyzer and code fix to migrate from StringAssert to Assert APIs #5792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't update the existing analyzer. Add a new one.
…sting analyzer Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Created a new StringAssertToAssertAnalyzer (MSTEST0045) instead of extending the existing UseProperAssertMethodsAnalyzer. The changes to the original analyzer have been reverted and the StringAssert functionality is now in a separate analyzer with its own code fixer and tests. Commit: 05f98b9 Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
# Conflicts: # src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.Designer.cs # src/Analyzers/MSTest.Analyzers.CodeFixes/CodeFixResources.resx # src/Analyzers/MSTest.Analyzers.CodeFixes/PublicAPI.Unshipped.txt # src/Analyzers/MSTest.Analyzers/AnalyzerReleases.Unshipped.md # src/Analyzers/MSTest.Analyzers/Helpers/DiagnosticIds.cs # src/Analyzers/MSTest.Analyzers/Resources.Designer.cs
src/Analyzers/MSTest.Analyzers.CodeFixes/StringAssertToAssertFixer.cs
Outdated
Show resolved
Hide resolved
...IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/MSTest.Analyzers.CodeFixes/StringAssertToAssertFixer.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR implements an analyzer and code fix to help migrate from
StringAssert
APIs to equivalentAssert
APIs with swapped parameter order.Changes Made
1. Added Missing Assert Methods
Created
Assert.StringMethods.cs
with new methods that have swapped parameter order compared to StringAssert:All methods include comprehensive overloads supporting:
2. Extended UseProperAssertMethodsAnalyzer
CodeFixModeSwapArguments
for the new transformation pattern3. Extended UseProperAssertMethodsFixer
FixAssertMethodForSwapArgumentsModeAsync
method to handle the transformationStringAssert
toAssert
4. Added Comprehensive Tests
Added test cases covering:
Example Transformation
The analyzer reports this as an info-level diagnostic (MSTEST0037) with the message:
"Use 'Assert.Contains' instead of 'StringAssert.Contains'"
This helps developers migrate to the more consistent Assert API where the expected value comes first, matching the pattern used in other Assert methods like
Assert.AreEqual(expected, actual)
.Fixes #5791.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cflvsblobprodcus383.vsblob.vsassets.io
/home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25313.2.txt
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.