Skip to content

Commit

Permalink
DirectoryWatcherBase - SubscribeNullFile
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Feb 10, 2020
1 parent eab1aea commit 0b756e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -26,6 +26,11 @@ protected DirectoryWatcherBase(DirectoryInfo path)

public IDisposable Subscribe(string file, Action<FileInfo> onUpdate)
{
if (file == null)
{
throw new ArgumentNullException(nameof(file));
}

FileInfo fullPath = new FileInfo(Path.Combine(this.path, file));
string key = fullPath.FullName;
Action onDispose = () => this.subscriptions.TryRemove(key, out _);
Expand Down
Expand Up @@ -177,6 +177,18 @@ public void SubscribeSameFileTwiceDifferentCase()
.WithMessage(@"A subscription for 'X:\root\FILE1.txt' already exists.");
}

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

Action act = () => watcherBase.Subscribe(file, onUpdate);

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

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

0 comments on commit 0b756e4

Please sign in to comment.