From 0b756e4e7f3f09fbe20cb5c2f1c47249cb3171dc Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Sun, 9 Feb 2020 21:39:11 -0800 Subject: [PATCH] DirectoryWatcherBase - SubscribeNullFile --- .../DirectoryWatcherBase.cs | 5 +++++ .../DirectoryWatcherBaseTest.cs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/projects/DirectoryWatcherSample/DirectoryWatcherSample.Core/DirectoryWatcherBase.cs b/projects/DirectoryWatcherSample/DirectoryWatcherSample.Core/DirectoryWatcherBase.cs index 7001eaf..011de46 100644 --- a/projects/DirectoryWatcherSample/DirectoryWatcherSample.Core/DirectoryWatcherBase.cs +++ b/projects/DirectoryWatcherSample/DirectoryWatcherSample.Core/DirectoryWatcherBase.cs @@ -26,6 +26,11 @@ protected DirectoryWatcherBase(DirectoryInfo path) public IDisposable Subscribe(string file, Action 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 _); diff --git a/projects/DirectoryWatcherSample/DirectoryWatcherSample.Test/DirectoryWatcherBaseTest.cs b/projects/DirectoryWatcherSample/DirectoryWatcherSample.Test/DirectoryWatcherBaseTest.cs index ad52bdc..eceb401 100644 --- a/projects/DirectoryWatcherSample/DirectoryWatcherSample.Test/DirectoryWatcherBaseTest.cs +++ b/projects/DirectoryWatcherSample/DirectoryWatcherSample.Test/DirectoryWatcherBaseTest.cs @@ -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 onUpdate = f => { }; + string file = null; + + Action act = () => watcherBase.Subscribe(file, onUpdate); + + act.Should().Throw().Which.ParamName.Should().Be("file"); + } + private sealed class FakeDirectoryWatcher : DirectoryWatcherBase { public FakeDirectoryWatcher(DirectoryInfo path)