public async Task WatchDoesNotCallCanExecuteWhenNoNewFileAppears()
        {
            //Fixture setup
            var  commandStub      = new Mock <ICommand>();
            bool canExecuteCalled = false;

            commandStub
            .Setup(command => command.CanExecute(It.IsAny <object>()))
            .Callback(() => canExecuteCalled = true);
            var sut = new CommandExecutingDirectoryWatcher(Config.WatchedPaths, commandStub.Object);
            //Exercise system
            var task = sut.Watch(1000);
            await Task.Delay(1000);

            await sut.Cancel();

            try
            {
                await task;
            }
            catch (OperationCanceledException)
            {
            }
            //Verify outcome
            Assert.False(canExecuteCalled);
        }
        public async Task WatchCallsCommandExecuteWhenNewFileAppearsAndOnlyWhenCanExecuteReturnsTrue(bool canExecute)
        {
            //Fixture setup
            var  commandStub   = new Mock <ICommand>();
            bool executeCalled = false;

            commandStub
            .Setup(command => command.CanExecute(It.IsAny <object>()))
            .Returns(canExecute);
            commandStub
            .Setup(command => command.ExecuteAsync(It.IsAny <object>()))
            .Returns(Task.CompletedTask)
            .Callback(() => executeCalled = true);
            commandStub
            .Setup(command => command.ExecuteAsync(It.IsAny <object>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask)
            .Callback(() => executeCalled = true);
            commandStub
            .Setup(command => command.Execute(It.IsAny <object>()))
            .Callback(() => executeCalled = true);
            var sut = new CommandExecutingDirectoryWatcher(Config.WatchedPaths, commandStub.Object);
            //Exercise system
            var task = sut.Watch(1000);

            using (new TestFileSource(Path.Combine(Config.WatchedPaths.First(), "test.mkv"),
                                      500 * 1024 * 1024))
            {
                await sut.Cancel();

                try
                {
                    await task;
                }
                catch (OperationCanceledException)
                {
                }
            }
            //Verify outcome
            if (canExecute)
            {
                Assert.True(executeCalled);
            }
            else
            {
                Assert.False(executeCalled);
            }
        }
        public async Task WatchTaskCancelledOnCancellationRequest()
        {
            //Fixture setup
            var commandStub = new Mock <ICommand>();

            commandStub
            .Setup(command => command.ExecuteAsync(It.IsAny <object>()))
            .Returns(Task.CompletedTask);
            var sut = new CommandExecutingDirectoryWatcher(Config.WatchedPaths, commandStub.Object);
            //Exercise system
            var task = sut.Watch(1000);
            await sut.Cancel().ConfigureAwait(true);

            //Verify outcome
            var e = await Assert.ThrowsAnyAsync <OperationCanceledException>(async() => await task);

            Assert.True(task.IsCanceled);
            //Teardown
        }