-
Notifications
You must be signed in to change notification settings - Fork 278
Fix MSTEST0020 codefix constructor placement - position after fields/static constructors #5944
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
base: main
Are you sure you want to change the base?
Conversation
…tors Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
test/UnitTests/MSTest.Analyzers.UnitTests/PreferConstructorOverTestInitializeAnalyzerTests.cs
Show resolved
Hide resolved
Co-authored-by: Youssef1313 <31348972+Youssef1313@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:
|
src/Analyzers/MSTest.Analyzers.CodeFixes/PreferConstructorOverTestInitializeFixer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/MSTest.Analyzers.CodeFixes/PreferConstructorOverTestInitializeFixer.cs
Outdated
Show resolved
Hide resolved
src/Analyzers/MSTest.Analyzers.CodeFixes/PreferConstructorOverTestInitializeFixer.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Youssef1313 <31348972+Youssef1313@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:
|
Co-authored-by: Youssef1313 <31348972+Youssef1313@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:
|
// Find appropriate position for the constructor | ||
// Place after last field or static constructor, but before any instance methods |
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.
Let's not do it this way, and always insert in the position of the existing TestInitialize.
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.
Simplified the constructor placement logic to always insert at the TestInitialize method position instead of trying to find the optimal position after fields/static constructors. Updated test expectations accordingly. Commit c8610a6.
…tion Co-authored-by: Youssef1313 <31348972+Youssef1313@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:
|
The MSTEST0020 codefix (PreferConstructorOverTestInitialize) was placing newly created constructors at the end of the class instead of following C# coding conventions.
Problem
When applying the codefix to convert a
[TestInitialize]
method to a constructor in a class that doesn't already have a constructor, the new constructor was added at the end of the class:Solution
Updated the codefix to place constructors at the appropriate position following C# conventions: after fields and static constructors, but before properties and methods.
Implementation
editor.AddMember()
with smart positioning logiceditor.InsertAfter()
to place the constructor at the appropriate locationTest Coverage
Fixes #5938.
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.25353.1.txt
(dns block)/home/REDACTED/work/testfx/testfx/.dotnet/dotnet build src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csproj --no-restore --verbosity normal
(dns block)/home/REDACTED/work/testfx/testfx/.dotnet/dotnet build test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj --no-restore --verbosity normal
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.