feat: Phase 5.4 migrate MockFileSystem.AddDrive to WithDrive#13
Merged
Conversation
Rewrites `fs.AddDrive(name, new MockDriveData { TotalSize = X, IsReady = Y, ... })`
to `fs.WithDrive(name, d => d.SetTotalSize(X).SetIsReady(Y)...)`.
Mappable initializer properties (1:1 with IStorageDrive setters):
- TotalSize -> SetTotalSize
- IsReady -> SetIsReady
- DriveFormat -> SetDriveFormat
- DriveType -> SetDriveType
AvailableFreeSpace, TotalFreeSpace and VolumeLabel have no IStorageDrive
setter equivalent — the rewrite bails for any initializer that touches
them so the user can address them by hand.
Gating:
- Receiver must be the concrete TestableIO MockFileSystem (the rewrite
emits WithDrive, which is Testably-only).
- Second argument must be a `new MockDriveData()` (explicit or target-
typed `new()`) with no ctor arguments — the copy ctor and captured
references fall through to manual review.
Other notes:
- Empty initializer collapses to the single-argument `fs.WithDrive(name)`
overload (no lambda).
- Lambda parameter name is chosen fresh from ["d", "drive", "driveBuilder",
d1, d2, ...] to avoid shadowing identifiers in the initializer RHS.
- The fix swaps the using directive to Testably.Abstractions.Testing,
matching the constructor-fix pattern, because WithDrive doesn't exist
on TestableIO.
Playground gains two AddDrive parity samples; analyzer + code-fix tests
cover empty/single/multi-property/target-typed rewrites and the four
HasNoFix cases (interface receiver, non-literal data, unsupported
initializer property, copy ctor).
There was a problem hiding this comment.
Pull request overview
This PR adds analyzer/code-fix support for migrating MockFileSystem.AddDrive usages from System.IO.Abstractions.TestingHelpers to Testably’s WithDrive API.
Changes:
- Adds a new
MockFileSystem.AddDriveanalyzer pattern. - Implements a code fix that rewrites supported
MockDriveDatainitializers intoWithDrivecalls and swaps the testing namespace. - Adds analyzer, code-fix, and playground coverage for supported and unsupported AddDrive migration cases.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
Source/Testably.Abstractions.Migration.Analyzers/SystemIOAbstractionsAnalyzer.cs |
Flags AddDrive invocations for migration. |
Source/Testably.Abstractions.Migration.Analyzers/Patterns.cs |
Adds the AddDrive migration pattern constant. |
Source/Testably.Abstractions.Migration.Analyzers.CodeFixers/SystemIOAbstractionsCodeFixProvider.cs |
Adds the AddDrive-to-WithDrive rewrite logic. |
Tests/Testably.Abstractions.Migration.Tests/SystemIOAbstractionsAnalyzerTests.cs |
Adds analyzer coverage for AddDrive detection. |
Tests/Testably.Abstractions.Migration.Tests/SystemIOAbstractionsCodeFixProviderTests.AccessorMethodTests.cs |
Adds code-fix coverage for supported rewrites and no-fix cases. |
Tests/Testably.Abstractions.Migration.SystemIOAbstractionsPlayground/AccessorMethodTests.cs |
Adds playground AddDrive samples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The Phase 5.4 gate only checked the receiver's semantic type, so the fix was still offered when the receiver's declared type syntax was alias- or fully-qualified — e.g. `System.IO.Abstractions.TestingHelpers.MockFileSystem fs` or `using TestableIo = ...; TestableIo.MockFileSystem fs`. In those cases the using-swap leaves the declaration untouched, so after the rewrite `fs` still binds to TestableIO MockFileSystem and `fs.WithDrive(...)` fails to compile. Add a syntactic gate IsRetargetableMockFileSystemReceiver that inspects the declaration of the receiver symbol (local, parameter, field, property or method return type) and only accepts unqualified type syntax (IdentifierNameSyntax, optionally wrapped in NullableTypeSyntax). Direct constructions reuse the existing HasUnqualifiedMockFileSystemTypeName gate. Anything else (qualified, alias-qualified, missing source declaration) falls through to manual review. Tests added for the fully-qualified and alias-qualified receiver shapes.
|
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.



Rewrites
fs.AddDrive(name, new MockDriveData { TotalSize = X, IsReady = Y, ... })tofs.WithDrive(name, d => d.SetTotalSize(X).SetIsReady(Y)...).Mappable initializer properties (1:1 with IStorageDrive setters):
AvailableFreeSpace, TotalFreeSpace and VolumeLabel have no IStorageDrive setter equivalent — the rewrite bails for any initializer that touches them so the user can address them by hand.
Gating:
new MockDriveData()(explicit or target- typednew()) with no ctor arguments — the copy ctor and captured references fall through to manual review.Other notes:
fs.WithDrive(name)overload (no lambda).Playground gains two AddDrive parity samples; analyzer + code-fix tests cover empty/single/multi-property/target-typed rewrites and the four HasNoFix cases (interface receiver, non-literal data, unsupported initializer property, copy ctor).