-
Notifications
You must be signed in to change notification settings - Fork 265
feat: Add support for event-driven behaviours in MockFileSystem. #1313
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
Draft
mistial-dev
wants to merge
4
commits into
TestableIO:main
Choose a base branch
from
mistial-dev:feat-805
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
src/TestableIO.System.IO.Abstractions.TestingHelpers/Events/FileOperation.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace System.IO.Abstractions.TestingHelpers.Events; | ||
|
||
/// <summary> | ||
/// Represents the type of file system operation. | ||
/// </summary> | ||
public enum FileOperation | ||
{ | ||
/// <summary> | ||
/// File or directory creation operation. | ||
/// </summary> | ||
Create, | ||
|
||
/// <summary> | ||
/// File open operation. | ||
/// </summary> | ||
Open, | ||
|
||
/// <summary> | ||
/// File write operation. | ||
/// </summary> | ||
Write, | ||
|
||
/// <summary> | ||
/// File read operation. | ||
/// </summary> | ||
Read, | ||
|
||
/// <summary> | ||
/// File or directory deletion operation. | ||
/// </summary> | ||
Delete, | ||
|
||
/// <summary> | ||
/// File or directory move operation. | ||
/// </summary> | ||
Move, | ||
|
||
/// <summary> | ||
/// File or directory copy operation. | ||
/// </summary> | ||
Copy, | ||
|
||
/// <summary> | ||
/// Set attributes operation. | ||
/// </summary> | ||
SetAttributes, | ||
|
||
/// <summary> | ||
/// Set file times operation. | ||
/// </summary> | ||
SetTimes, | ||
|
||
/// <summary> | ||
/// Set permissions operation. | ||
/// </summary> | ||
SetPermissions | ||
} |
68 changes: 68 additions & 0 deletions
68
src/TestableIO.System.IO.Abstractions.TestingHelpers/Events/FileSystemOperationEventArgs.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
namespace System.IO.Abstractions.TestingHelpers.Events; | ||
|
||
/// <summary> | ||
/// Provides data for file system operation events. | ||
/// </summary> | ||
public class FileSystemOperationEventArgs : EventArgs | ||
{ | ||
private OperationResponse response; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="FileSystemOperationEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="path">The path of the resource being operated on.</param> | ||
/// <param name="operation">The type of operation.</param> | ||
/// <param name="resourceType">The type of resource.</param> | ||
/// <param name="phase">The phase of the operation.</param> | ||
public FileSystemOperationEventArgs( | ||
string path, | ||
FileOperation operation, | ||
ResourceType resourceType, | ||
OperationPhase phase) | ||
{ | ||
Path = path ?? throw new ArgumentNullException(nameof(path)); | ||
Operation = operation; | ||
ResourceType = resourceType; | ||
Phase = phase; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the path of the resource being operated on. | ||
/// </summary> | ||
public string Path { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of operation being performed. | ||
/// </summary> | ||
public FileOperation Operation { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of resource being operated on. | ||
/// </summary> | ||
public ResourceType ResourceType { get; } | ||
|
||
/// <summary> | ||
/// Gets the phase of the operation. | ||
/// </summary> | ||
public OperationPhase Phase { get; } | ||
|
||
/// <summary> | ||
/// Sets a response for the operation. Only valid for Before phase events. | ||
/// </summary> | ||
/// <param name="response">The response to set.</param> | ||
/// <exception cref="InvalidOperationException">Thrown when called on an After phase event.</exception> | ||
public void SetResponse(OperationResponse response) | ||
{ | ||
if (Phase != OperationPhase.Before) | ||
{ | ||
throw new InvalidOperationException("Response can only be set for Before phase events."); | ||
} | ||
|
||
this.response = response ?? throw new ArgumentNullException(nameof(response)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the response set for this operation, if any. | ||
/// </summary> | ||
internal OperationResponse GetResponse() => response; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
It would help to have a list of operations on the file system in the XML-Comment, that trigger the corresponding
FileOperation
s.