Skip to content

DirectoryMock.Move doesn't raise FileSystemWatcher.Renamed if NotifyFilters.DirectoryName is set #865

@stogle

Description

@stogle

Hi. If I have a mock FileSystemWatcherMock with NotifyFilters = NotifyFilters.DirectoryName, and I call DirectoryMock.Move to rename a folder inside the watched location, then the Renamed event isn't raised. It is only raised if I have NotifyFilters = NotifyFilters.FileName set, which is wrong.

I believe this is due to https://github.com/Testably/Testably.Abstractions/blob/main/Source/Testably.Abstractions.Testing/Storage/InMemoryStorage.cs#L1031:

			ChangeDescription fileSystemChange =
				_fileSystem.ChangeHandler.NotifyPendingChange(WatcherChangeTypes.Renamed,
					container.Type,
					NotifyFilters.FileName,
					destination,
					source);

Here NotifyFilters.FileName is hard-coded, whereas other calls use ToNotifyFilters(container.Type).


In a slightly different scenario, if I call DirectoryMock.Move to move a folder out of the watched location, then no event is raised. It should raise the Deleted event in this case. This doesn't seem to be related to NotifyFilters though. It's because FileSystemWatcherMock.MatchesFilter only considers the new path, not the old path:

else if (!string.Equals(
_fileSystem.Execute.Path.GetDirectoryName(changeDescription.Path),
fullPath,
_fileSystem.Execute.StringComparisonMode))
{
return false;
}
I don't know if it's just a matter of considering both old and new paths, or it's more complicated than that. Let me know if I should create a separate issue for this.

Thanks again for your efforts.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions