Ejemplo n.º 1
0
        private void When_disposing_started_watcher_multiple_times_it_must_succeed()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";

            string pathToFileToUpdate = Path.Combine(directoryToWatch, "file.txt");

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingEmptyFile(pathToFileToUpdate)
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch);

            watcher.NotifyFilter        = TestNotifyFilters.All;
            watcher.EnableRaisingEvents = true;

            BlockUntilChangeProcessed(watcher, () =>
            {
                fileSystem.File.SetAttributes(pathToFileToUpdate, FileAttributes.ReadOnly);
            });

            // Act
            Action action = () =>
            {
                watcher.Dispose();
                watcher.Dispose();
            };

            // Assert
            action.Should().NotThrow();
        }
Ejemplo n.º 2
0
        private void When_disposing_unstarted_watcher_multiple_times_it_must_succeed()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingDirectory(directoryToWatch)
                                        .Build();

            // Act
            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch);

            // Act
            Action action = () =>
            {
                watcher.Dispose();
                watcher.Dispose();
            };

            // Assert
            action.Should().NotThrow();
        }
Ejemplo n.º 3
0
        private void When_setting_filter_on_disposed_watcher_it_must_succeed()
        {
            // Arrange
            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher();

            watcher.Dispose();

            // Act
            watcher.Filter = "*.txt";

            // Assert
            watcher.Filter.Should().Be("*.txt");
        }
Ejemplo n.º 4
0
        private void When_setting_InternalBufferSize_on_disposed_watcher_it_must_succeed()
        {
            // Arrange
            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher();

            watcher.Dispose();

            // Act
            watcher.InternalBufferSize = 4099;

            // Assert
            watcher.InternalBufferSize.Should().Be(4099);
        }
Ejemplo n.º 5
0
        private void When_setting_IncludeSubdirectories_on_disposed_watcher_it_must_succeed()
        {
            // Arrange
            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher();

            watcher.Dispose();

            // Act
            watcher.IncludeSubdirectories = true;

            // Assert
            watcher.IncludeSubdirectories.Should().BeTrue();
        }
        private void When_waiting_for_disposed_watcher_it_must_fail()
        {
            // Arrange
            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher();

            watcher.Dispose();

            // Act
            Action action = () => watcher.WaitForChanged(WatcherChangeTypes.All, MaxTestDurationInMilliseconds);

            // Assert
            action.Should().ThrowExactly <ObjectDisposedException>().WithMessage("Cannot access a disposed object.*")
            .And.ObjectName.Should().Be("FileSystemWatcher");
        }
Ejemplo n.º 7
0
        private void When_starting_disposed_watcher_it_must_fail()
        {
            // Arrange
            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher();

            watcher.Dispose();

            // Act
            Action action = () => watcher.EnableRaisingEvents = true;

            // Assert
            action.Should().ThrowExactly <ObjectDisposedException>().WithMessage("Cannot access a disposed object.*")
            .And.ObjectName.Should().Be("FileSystemWatcher");
        }
Ejemplo n.º 8
0
        private void When_setting_path_on_disposed_watcher_it_must_succeed()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingDirectory(directoryToWatch)
                                        .Build();

            FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher();

            watcher.Dispose();

            // Act
            watcher.Path = directoryToWatch;

            // Assert
            watcher.Path.Should().Be(directoryToWatch);
        }