feat: Phase 1 analyzer + code fix for parameterless MockFileSystem ctor#6
Merged
Conversation
Detect `new System.IO.Abstractions.TestingHelpers.MockFileSystem()` (parameterless) and rewrite the file's using directive to `Testably.Abstractions.Testing`, proving the analyzer → diagnostic → code fix → tests wiring end-to-end. The diagnostic carries a `pattern` property so later phases can layer in more rewrites under the same `TestablyAbstractionsMigration001` id. - Add `TestableIoSymbols` resolver in `Analyzers/Common` that bails when the TestingHelpers assembly is not referenced. - Replace the existing TestingHelpers using in place to preserve trivia / line endings; only append a new using when there is no existing one to repurpose. - Drop the global `using System.IO.Abstractions.TestingHelpers;` from the playground / Example.Tests so per-file usings remain rewritable. - Add a risk-#1 sentinel test that round-trips a rooted Unix-style path on Windows through both libraries via the parameterless constructor.
There was a problem hiding this comment.
Pull request overview
Wires up the first end-to-end slice of the migration tool: an analyzer that flags the parameterless new System.IO.Abstractions.TestingHelpers.MockFileSystem() and a code fix that rewrites the file's using directives to Testably.Abstractions.Testing. The diagnostic carries a pattern property so future phases can layer additional rewrites under the same diagnostic id.
Changes:
- Add
TestableIoSymbolsresolver +Patternsdiscriminator and register anObjectCreationoperation action inSystemIOAbstractionsAnalyzerthat reports only the zero-argumentMockFileSystemctor. - Implement
SystemIOAbstractionsCodeFixProvider.RewriteUsingsAsync, which replaces theTestingHelpersusing in place (preserving trivia), removes it when a Testably using already exists, or appends a new one. - Drop the global
using System.IO.Abstractions.TestingHelpers;from the playground and Example.Tests, add risk-#1 sentinel tests for Unix-style path round-tripping, and flesh out the analyzer / code-fix unit tests.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Source/Testably.Abstractions.Migration.Analyzers/SystemIOAbstractionsAnalyzer.cs | Registers compilation-start + operation actions to flag parameterless MockFileSystem ctor with a pattern property. |
| Source/Testably.Abstractions.Migration.Analyzers/Patterns.cs | New constants for the diagnostic pattern property key and Phase 1 value. |
| Source/Testably.Abstractions.Migration.Analyzers/Common/TestableIoSymbols.cs | New helper caching TestingHelpers type symbols; returns null when the assembly is not referenced. |
| Source/Testably.Abstractions.Migration.Analyzers.CodeFixers/SystemIOAbstractionsCodeFixProvider.cs | Implements pattern-dispatched code action that rewrites the file's TestingHelpers using to Testably.Abstractions.Testing. |
| Tests/Testably.Abstractions.Migration.Tests/SystemIOAbstractionsAnalyzerTests.cs | Adds analyzer tests for flagged/not-flagged ctor cases and no-op when assembly is missing. |
| Tests/Testably.Abstractions.Migration.Tests/SystemIOAbstractionsCodeFixProviderTests.cs | Adds code-fix tests for explicit and target-typed new MockFileSystem(). |
| Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/Usings.cs | Removes the global TestingHelpers using so per-file usings can be rewritten. |
| Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/UnixPathSmokeTest.cs | New smoke test exercising rooted Unix-style paths through the parameterless ctor. |
| Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/MockFileSystemSamples.cs | Adds a real Phase 1 call site for the analyzer/code fix to target. |
| Tests/Testably.Abstractions.Migration.Example.Tests/Usings.cs | Drops the global TestingHelpers using so per-file aliasing works. |
| Tests/Testably.Abstractions.Migration.Example.Tests/SystemIOAbstractionsMigrationExamples.cs | Adds risk-#1 sentinel theory comparing both libraries and a post-migration IFileSystem check. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Detect
new System.IO.Abstractions.TestingHelpers.MockFileSystem()(parameterless) and rewrite the file's using directive toTestably.Abstractions.Testing, proving the analyzer → diagnostic → code fix → tests wiring end-to-end. The diagnostic carries apatternproperty so later phases can layer in more rewrites under the sameTestablyAbstractionsMigration001id.TestableIoSymbolsresolver inAnalyzers/Commonthat bails when the TestingHelpers assembly is not referenced.using System.IO.Abstractions.TestingHelpers;from the playground / Example.Tests so per-file usings remain rewritable.