Skip to content

Commit

Permalink
DirectoryWatcherBase - SubscribeNullCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Feb 10, 2020
1 parent 0b756e4 commit 1dd3fff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Expand Up @@ -31,6 +31,11 @@ public IDisposable Subscribe(string file, Action<FileInfo> onUpdate)
throw new ArgumentNullException(nameof(file));
}

if (onUpdate == null)
{
throw new ArgumentNullException(nameof(onUpdate));
}

FileInfo fullPath = new FileInfo(Path.Combine(this.path, file));
string key = fullPath.FullName;
Action onDispose = () => this.subscriptions.TryRemove(key, out _);
Expand Down
Expand Up @@ -189,6 +189,17 @@ public void SubscribeNullFile()
act.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("file");
}

[TestMethod]
public void SubscribeNullCallback()
{
DirectoryWatcherBase watcherBase = new FakeDirectoryWatcher(new DirectoryInfo(@"X:\root"));
Action<FileInfo> onUpdate = null;

Action act = () => watcherBase.Subscribe("file1.txt", onUpdate);

act.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("onUpdate");
}

private sealed class FakeDirectoryWatcher : DirectoryWatcherBase
{
public FakeDirectoryWatcher(DirectoryInfo path)
Expand Down

0 comments on commit 1dd3fff

Please sign in to comment.