Skip to content
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

Add events on major events #168

Closed
zvirja opened this issue Aug 31, 2016 · 9 comments
Closed

Add events on major events #168

zvirja opened this issue Aug 31, 2016 · 9 comments
Labels
area: testinghelpers Issues that address the testing helpers state: needs discussion Issues that need further discussion state: stale type: enhancement Issues that propose new functionality

Comments

@zvirja
Copy link

zvirja commented Aug 31, 2016

Sometimes it's needed to test sequence of events with file system and currently it's impossible to do that with current implementation of MockFileSystem. Basically, we should add a couple of events, so we could subscribe on that events in our test. Moreover, this way we could simulate various situations (e.g. throw sharing violation exception when particular file is opened).

List of events:

  • File is being opened
  • File is being created
  • File is being deleted
  • File is being updated
  • File stream is opened
  • File stream is closed
  • Directory is being created
  • Directory is being deleted

I could implement that and create a PR for you. Will you approve such kind of PR?
Do you see some other ways to achieve the desired behavior?

@manne
Copy link
Contributor

manne commented Nov 27, 2016

@zvirja which kind of API do you have in your mind? and can you give example(s).

@zvirja
Copy link
Author

zvirja commented Nov 27, 2016

For instance, that could be a public property exposed directly from the MockFileSystem:

var fs = new MockFileSystem();
fs.Events.OnFileCreated += (sender, args) => {}
...

Basically, nothing special - any way it's convenient to implement. The only requirement is to be able to hook such events :)

Let me know if you want more input from me.

@manne
Copy link
Contributor

manne commented Dec 3, 2016

I think we need an API for the project TestingHelpers (MockFileSystem).
Some pull requests/issues indicate the need for this API.
see #189, #177 & #183

@ericnewton76
Copy link
Contributor

I wouldnt recommend events on the MockFileSystem at the moment.

You're basically then implementing a FileSystemWatcher instead. We should make sure the goal is parity with mscorlib.

@manne
Copy link
Contributor

manne commented Dec 5, 2016

I prefer to have a FileSystemWatcher.
@zvirja is a FileSystemWatcher sufficient for your purpose?

@zvirja
Copy link
Author

zvirja commented Dec 5, 2016

I'm not sure that watcher could cover my initial need why I fired this issue. Initially I wanted to have a way to throw exception when file is opened. That will not be achieved by watcher as it doesn't provide us with appropriate event.

Also FileSystemWatcher isn't synchronous by itself (if I'm not mistaken) which also makes it more difficult to simulate concurrency issues.

One more point is that watcher provides us with events after action is finished. That way we cannot simulate that action fails (e.g. deletion fails because file is used by other process).

Therefore, I'd prefer to have a special API inside the MockFileSystem to be able to intercept all such events.

@rkoeninger
Copy link
Contributor

rkoeninger commented Dec 5, 2018

I outlined an attempt to do this in #373 and it didn't go over well. It was agreed that this would be too involved for this library.

@fgreinacher @ericnewton76 I assume the same answer would apply to this issue?

@fgreinacher
Copy link
Contributor

In my opinion adding synchronous events like described here would enable quite some scenarios, so I would not reject a PR in this direction.

@fgreinacher fgreinacher added type: enhancement Issues that propose new functionality state: needs discussion Issues that need further discussion area: testinghelpers Issues that address the testing helpers labels Mar 24, 2019
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testinghelpers Issues that address the testing helpers state: needs discussion Issues that need further discussion state: stale type: enhancement Issues that propose new functionality
Projects
None yet
Development

No branches or pull requests

5 participants