Skip to content
Permalink
Browse files

DirectoryWatcherBase - SubscribeEmptyFileName

  • Loading branch information
bobbymcr committed Feb 10, 2020
1 parent ea619a0 commit b868dc1fa7c9e09ec8585437233b6ca7b19a8333
@@ -36,6 +36,11 @@ public IDisposable Subscribe(string file, Action<FileInfo> onUpdate)
throw new ArgumentNullException(nameof(onUpdate));
}

if (file.Length == 0)
{
throw new ArgumentException("File name cannot be empty.", nameof(file));
}

if (file.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
{
throw new ArgumentException($"Invalid file name '{file}'.", nameof(file));
@@ -213,6 +213,19 @@ public void SubscribeBadFileName()
ae.ParamName.Should().Be("file");
}

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

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

ArgumentException ae = act.Should().Throw<ArgumentException>().Which;
ae.Message.Should().Contain("File name cannot be empty");
ae.ParamName.Should().Be("file");
}

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

0 comments on commit b868dc1

Please sign in to comment.
You can’t perform that action at this time.