-
-
Notifications
You must be signed in to change notification settings - Fork 10
fix(FileSystem): When creating chained sym links of different types MockFileSystem in windows doesn't throw #833
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
…erent file types on windows
…inks of different types
|
@vbreuss The tests currently fail, because of the Edit: To add I currently do not consider |
You could write it as follows: await That(() => dirSymLink.ResolveLinkTarget(true))
.Throws<IOException>()
.WithMessage($"*{dirSymLink.FullName}*").AsWildcard();but that would hide the fact, that the actually thrown exception message is
I needed the |
I created aweXpect/aweXpect#710 for the error with |
I'll rewrite it to use the working example in the issue and check the type with |
aweXpect v2.21.2 just got released with this fix. So you could update the version in Directory.Packages.props and use the syntax you originally wanted. |
I think |
|
One problem I've is that the exception for |
|
@vbreuss I've noticed that the actual HResult is Edit: Link to Code Testably.Abstractions/Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs Line 355 in 31a3aba
Edit: Test failure message: |
|
I also noticed that the exception message in Win32Marshal.GetExceptionForWin32Error was changed (EDIT: The message now ends with a dot). Since we don't have a different nuget for .NET 8 and .NET 9 should I use the newer version or the older one? |
I can't remember why I had to add this, but if you remove the catch-block I am sure there will be a failing test that explains the scenario under which the exception was incorrect. Unfortunately I won't be able to go into more detail before the weekend... |
I expect the behavior of .NET9 to also apply to .NET10, so this will be more relevant in future. You could
|
…low an optional dot in the exception message
I've removed it and executed the tests that reference it locally, pushed it to also verify it works here. Can revert it later on if that works for you |
|
I think I found the missing piece. In The failing tests now succeed on my machine (they also failed by me, I haven't executed the tests for @vbreuss is my assumption correct or was the catch needed for something not tested? |
Used the pre-processor to concate the dot and used Regex for the message, making the dot optional, so allows specifically the optional dot and nothing more after |
I remember adding this catch block due to a failing test. It is an ugly solution, so if you found a better way and the tests succeed I am more than happy with it 😀 |
Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs
Outdated
Show resolved
Hide resolved
How did you solve this issue? Is there something we can do in the test suite? |
I haven't so far. I see it as a fine detail and I wanted everything to work before I get to it. Mostly those translated messages come from somewhere internal of private lib, runtime or interop. So it's rather tricky to get them. |
…annotBeResolved with a wrong HResult
|
So I looked some more into the translating message 'The directory name was invalid.' and it came from the PInvoke error 267. I used |
|
Ready to merge if no comments |
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.
I really like that you got rid of the try/catch block in FileSystemInfoMock and the overall direction of the change looks great.
Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs
Outdated
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ResolveLinkTargetTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ResolveLinkTargetTests.cs
Show resolved
Hide resolved
Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ResolveLinkTargetTests.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs
Outdated
Show resolved
Hide resolved
Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs
Outdated
Show resolved
Hide resolved
…ssDenied and removed pre-processor statement
|
Your request should now all be applied, please check that I've haven't forgotten some (did some weird git locally) |
vbreuss
left a comment
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.
The change looks really good. I have one small issue with the scope of an IDisposable. Could you have a quick look and then we can finish the PR...
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.
Pull Request Overview
This PR fixes a bug where MockFileSystem on Windows doesn't properly throw exceptions when creating chained symbolic links of different types (file vs directory), making the behavior consistent with the real Windows file system.
- Adds proper type checking for symbolic link chains to throw appropriate exceptions on Windows
- Updates test cases to verify the new behavior with proper platform-specific exception handling
- Simplifies exception handling by consolidating access denied logic
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
Tests/Testably.Abstractions.Tests/FileSystem/FileInfo/ResolveLinkTargetTests.cs |
Added new test for cross-type symbolic links and improved existing tests with proper error validation |
Tests/Testably.Abstractions.Tests/FileSystem/DirectoryInfo/ResolveLinkTargetTests.cs |
Added new test for cross-type symbolic links and improved existing tests with proper error validation |
Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs |
Implemented type checking logic to throw proper exceptions when resolving mixed-type symbolic link chains |
Source/Testably.Abstractions.Testing/Storage/InMemoryContainer.cs |
Updated to use consolidated access denied exception method |
Source/Testably.Abstractions.Testing/Helpers/ExceptionFactory.cs |
Consolidated access denied exception creation and removed platform-specific restriction |
Source/Testably.Abstractions.Testing/FileSystem/FileSystemInfoMock.cs |
Simplified exception handling by removing redundant try-catch block |
Directory.Packages.props |
Updated aweXpect package version from 2.21.0 to 2.21.1 |
| { | ||
| throw ExceptionFactory.FileNameCannotBeResolved( | ||
| originalLocation.FullPath); | ||
| originalLocation.FullPath, _fileSystem.Execute.IsWindows ? -2147022975 : -2146232800 |
Copilot
AI
Aug 15, 2025
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.
The hardcoded HResult values (-2147022975 and -2146232800) should be defined as named constants to improve readability and maintainability. Consider creating constants like WINDOWS_TOO_MANY_LINKS_HRESULT and UNIX_TOO_MANY_LINKS_HRESULT.
| await That(() => link.ResolveLinkTarget(true)).Throws<IOException>(); | ||
| await That(Act).Throws<IOException>() | ||
| .WithHResult(Test.RunsOnWindows ? -2147022975 : -2146232800).And | ||
| .WithMessageContaining($"'{fileInfo.FullName}'"); |
Copilot
AI
Aug 15, 2025
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.
The hardcoded HResult values (-2147022975 and -2146232800) are duplicated across test files. Consider defining these as shared constants in a test utilities class to ensure consistency and easier maintenance.
|
|
||
| await That(() => link.ResolveLinkTarget(true)).Throws<IOException>(); | ||
| await That(Act).Throws<IOException>() | ||
| .WithHResult(Test.RunsOnWindows ? -2147022975 : -2146232800).And |
Copilot
AI
Aug 15, 2025
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.
The hardcoded HResult values (-2147022975 and -2146232800) are duplicated across test files. Consider defining these as shared constants in a test utilities class to ensure consistency and easier maintenance.
| .WithHResult(Test.RunsOnWindows ? -2147022975 : -2146232800).And | |
| .WithHResult(Test.RunsOnWindows ? TestConstants.HResultTooManySymbolicLinksWindows : TestConstants.HResultTooManySymbolicLinksNonWindows).And |
|
This is addressed in release v4.3.2. |
Closes #818