Beispiel #1
0
        private void When_getting_entries_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\folder";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingDirectory(@"c:\some\folder\sub")
                                     .IncludingEmptyFile(@"c:\some\folder\file.txt")
                                     .Build();

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            IFileSystemInfo[] infos = dirInfo.GetFileSystemInfos();

            // Assert
            IFileSystemInfo[] array = infos.Should().HaveCount(2).And.Subject.ToArray();
            array[0].FullName.Should().Be(@"c:\some\folder\file.txt");
            array[1].FullName.Should().Be(@"c:\some\folder\sub");
        }
        private void When_creating_file_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingDirectory(@"c:\some")
                                     .Build();

            IFileInfo fileInfo = fileSystem.ConstructFileInfo(path);

            // Act
            using (fileInfo.Create())
            {
            }

            // Assert
            fileSystem.File.Exists(path).Should().BeTrue();
            fileSystem.File.ReadAllText(path).Should().Be(string.Empty);
        }
        private void When_overwriting_file_it_must_succeed()
        {
            // Arrange
            const string path = @"C:\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingVolume("C:", new FakeVolumeInfoBuilder()
                                                      .OfCapacity(8192)
                                                      .WithFreeSpace(4096))
                                     .IncludingBinaryFile(path, BufferFactory.Create(1024))
                                     .Build();

            // Act
            fileSystem.File.WriteAllBytes(path, BufferFactory.Create(4000));

            // Assert
            IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:");

            driveInfo.AvailableFreeSpace.Should().Be(96);
        }
        private void When_renaming_directory_it_must_succeed()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingVolume("C:", new FakeVolumeInfoBuilder()
                                                      .OfCapacity(8192)
                                                      .WithFreeSpace(4096))
                                     .IncludingBinaryFile(@"c:\source\src.txt", BufferFactory.Create(64))
                                     .IncludingBinaryFile(@"c:\source\nested\src.txt", BufferFactory.Create(256))
                                     .IncludingDirectory(@"c:\source\subfolder")
                                     .Build();

            // Act
            fileSystem.Directory.Move(@"C:\source", @"C:\target");

            // Assert
            IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:");

            driveInfo.AvailableFreeSpace.Should().Be(3776);
        }
        private void When_decrypting_file_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(path)
                                     .Build();

            fileSystem.File.Encrypt(path);

            IFileInfo fileInfo = fileSystem.ConstructFileInfo(path);

            // Act
            fileInfo.Decrypt();

            // Assert
            fileInfo.Attributes.Should().NotHaveFlag(FileAttributes.Encrypted);
            fileSystem.File.GetAttributes(path).Should().NotHaveFlag(FileAttributes.Encrypted);
        }
        private void When_writing_to_file_it_must_fail()
        {
            // Arrange
            const string path = @"C:\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingVolume("C:", new FakeVolumeInfoBuilder()
                                                      .OfCapacity(8192)
                                                      .WithFreeSpace(512))
                                     .Build();

            // Act
            Action action = () => fileSystem.File.WriteAllBytes(path, BufferFactory.Create(1024));

            // Assert
            action.Should().ThrowExactly <IOException>().WithMessage("There is not enough space on the disk.");

            AssertFileSize(fileSystem, path, 0);
            AssertFreeSpaceOnDrive(fileSystem, "C:", 512);
        }
Beispiel #7
0
        private void When_setting_position_to_negative_it_must_fail()
        {
            // Arrange
            const string path = @"C:\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingTextFile(path, "ABC")
                                     .Build();

            using (IFileStream stream = fileSystem.File.Open(path, FileMode.Open))
            {
                // Act
                // ReSharper disable once AccessToDisposedClosure
                Action action = () => stream.Position = -1;

                // Assert
                action.ShouldThrow <ArgumentOutOfRangeException>()
                .WithMessage("Specified argument was out of the range of valid values.*");
            }
        }
        private void When_moving_file_to_subdirectory_it_must_succeed()
        {
            // Arrange
            const string sourcePath      = @"C:\some\file.txt";
            const string destinationPath = @"C:\some\sub\newname.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(sourcePath)
                                     .IncludingDirectory(@"c:\some\sub")
                                     .Build();

            fileSystem.File.WriteAllText(sourcePath, "ABC");

            // Act
            fileSystem.File.Move(sourcePath, destinationPath);

            // Assert
            fileSystem.File.Exists(sourcePath).Should().BeFalse();
            fileSystem.File.Exists(destinationPath).Should().BeTrue();
        }
Beispiel #9
0
        private void When_setting_path_to_missing_remote_directory_it_must_fail()
        {
            // Arrange
            const string path = @"\\server\share\MissingFolder";

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingDirectory(@"\\server\share")
                                        .Build();

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher())
            {
                // Act
                // ReSharper disable once AccessToDisposedClosure
                Action action = () => watcher.Path = path;

                // Assert
                action.Should().ThrowExactly <ArgumentException>().WithMessage(
                    @"The directory name \\server\share\MissingFolder is invalid.");
            }
        }
Beispiel #10
0
        private void When_setting_path_to_local_parent_directory_that_exists_as_file_it_must_fail()
        {
            // Arrange
            const string path = @"c:\some\file.txt";

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

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher())
            {
                // Act
                // ReSharper disable once AccessToDisposedClosure
                Action action = () => watcher.Path = path + @"\nested";

                // Assert
                action.Should().ThrowExactly <ArgumentException>().WithMessage(
                    @"The directory name c:\some\file.txt\nested is invalid.");
            }
        }
Beispiel #11
0
        private void When_setting_path_to_null_it_must_fail()
        {
            // Arrange
            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .Build();

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher())
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                watcher.Path = null;

                // Act
                // ReSharper disable once AccessToDisposedClosure
                Action action = () => watcher.EnableRaisingEvents = true;

                // Assert
                watcher.Path.Should().Be(string.Empty);
                action.Should().ThrowExactly <FileNotFoundException>().WithMessage("Error reading the  directory.");
            }
        }
Beispiel #12
0
        private void When_moving_directory_it_must_succeed()
        {
            // Arrange
            const string sourcePath      = @"c:\some\folder";
            const string destinationPath = @"c:\other\renamed";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingTextFile(@"c:\some\folder\file.txt", DefaultContents, attributes: FileAttributes.ReadOnly)
                                     .IncludingDirectory(@"c:\other")
                                     .Build();

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(sourcePath);

            // Act
            dirInfo.MoveTo(destinationPath);

            // Assert
            fileSystem.Directory.Exists(sourcePath).Should().BeFalse();
            fileSystem.Directory.Exists(destinationPath).Should().BeTrue();
        }
Beispiel #13
0
        private void When_creating_directory_it_must_not_update_properties()
        {
            // Arrange
            const string path = @"d:\some\folder\nested";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingDirectory(@"d:\")
                                     .Build();

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            bool beforeExists = dirInfo.Exists;

            // Act
            dirInfo.Create();

            // Assert
            beforeExists.Should().BeFalse();
            dirInfo.Exists.Should().BeFalse();
        }
        private void When_including_existing_local_binary_file_it_must_overwrite()
        {
            // Arrange
            const string path = @"d:\path\to\folder\readme.txt";

            FakeFileSystemBuilder builder = new FakeFileSystemBuilder()
                                            .IncludingBinaryFile(path, LongerContents);

            // Act
            IFileSystem fileSystem = builder
                                     .IncludingBinaryFile(path, DefaultContents)
                                     .Build();

            // Assert
            fileSystem.File.Exists(path).Should().BeTrue();

            IFileInfo info = fileSystem.ConstructFileInfo(path);

            info.Length.Should().Be(DefaultContents.Length);
        }
        private void When_deleting_local_file_that_is_in_use_it_must_fail()
        {
            // Arrange
            const string path = @"C:\some\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(path)
                                     .Build();

            using (fileSystem.File.Open(path, FileMode.Open, FileAccess.Read))
            {
                // Act
                Action action = () => fileSystem.File.Delete(path);

                // Assert
                action.ShouldThrow <IOException>()
                .WithMessage(
                    @"The process cannot access the file 'C:\some\file.txt' because it is being used by another process.");
            }
        }
        private void When_enumerating_entries_recursively_for_name_pattern_it_must_match()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(@"C:\base\one.txt")
                                     .IncludingDirectory(@"C:\base\deep\two.txt")
                                     .IncludingEmptyFile(@"C:\base\more\nested\three.txt")
                                     .IncludingEmptyFile(@"C:\base\more\nested\four.txt")
                                     .Build();

            // Act
            IEnumerable <string> entries =
                fileSystem.Directory.EnumerateFileSystemEntries(@"c:\base", "*o*.txt", SearchOption.AllDirectories);

            // Assert
            string[] entryArray = entries.Should().HaveCount(3).And.Subject.ToArray();
            entryArray[0].Should().Be(@"c:\base\one.txt");
            entryArray[1].Should().Be(@"c:\base\deep\two.txt");
            entryArray[2].Should().Be(@"c:\base\more\nested\four.txt");
        }
        private void When_including_local_binary_file_it_must_succeed()
        {
            // Arrange
            const string path = @"d:\path\to\folder\readme.txt";

            var builder = new FakeFileSystemBuilder();

            // Act
            IFileSystem fileSystem = builder
                                     .IncludingBinaryFile(path, DefaultContents)
                                     .Build();

            // Assert
            fileSystem.File.Exists(path).Should().BeTrue();
            fileSystem.File.GetAttributes(path).Should().Be(FileAttributes.Archive);

            IFileInfo info = fileSystem.ConstructFileInfo(path);

            info.Length.Should().Be(DefaultContents.Length);
        }
Beispiel #18
0
        private void When_setting_last_write_time_in_UTC_using_absolute_path_without_drive_letter_it_must_succeed()
        {
            // Arrange
            var clock = new SystemClock {
                UtcNow = () => DefaultTimeUtc
            };

            IFileSystem fileSystem = new FakeFileSystemBuilder(clock)
                                     .IncludingDirectory(@"c:\some")
                                     .IncludingEmptyFile(@"C:\file.txt")
                                     .Build();

            fileSystem.Directory.SetCurrentDirectory(@"C:\some");

            // Act
            fileSystem.File.SetLastWriteTimeUtc(@"\file.txt", DefaultTimeUtc);

            // Assert
            fileSystem.File.GetLastWriteTimeUtc(@"c:\file.txt").Should().Be(DefaultTimeUtc);
        }
Beispiel #19
0
        private void When_getting_last_write_time_in_local_zone_using_absolute_path_without_drive_letter_it_must_succeed()
        {
            // Arrange
            var clock = new SystemClock {
                UtcNow = () => DefaultTimeUtc
            };

            IFileSystem fileSystem = new FakeFileSystemBuilder(clock)
                                     .IncludingDirectory(@"c:\some")
                                     .IncludingDirectory(@"C:\folder")
                                     .Build();

            fileSystem.Directory.SetCurrentDirectory(@"C:\some");

            // Act
            DateTime time = fileSystem.Directory.GetLastWriteTime(@"\folder");

            // Assert
            time.Should().Be(DefaultTime);
        }
        private void When_including_existing_remote_empty_file_it_must_overwrite()
        {
            // Arrange
            const string path = @"\\server\share\folder\file.txt";

            FakeFileSystemBuilder builder = new FakeFileSystemBuilder()
                                            .IncludingTextFile(path, "XYZ");

            // Act
            IFileSystem fileSystem = builder
                                     .IncludingEmptyFile(path)
                                     .Build();

            // Assert
            fileSystem.File.Exists(path).Should().BeTrue();

            IFileInfo info = fileSystem.ConstructFileInfo(path);

            info.Length.Should().Be(0);
        }
        private void When_copying_file_to_relative_path_it_must_succeed()
        {
            // Arrange
            const string sourcePath      = @"C:\some\file.txt";
            const string destinationPath = @"D:\other\folder\newname.doc";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(sourcePath)
                                     .IncludingDirectory(@"D:\other\folder")
                                     .Build();

            fileSystem.Directory.SetCurrentDirectory(@"D:\other");

            // Act
            fileSystem.File.Copy(sourcePath, @"folder\newname.doc");

            // Assert
            fileSystem.File.Exists(sourcePath).Should().BeTrue();
            fileSystem.File.Exists(destinationPath).Should().BeTrue();
        }
        private void When_waiting_for_changes_with_negative_timeout_it_must_fail()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";

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

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch))
            {
                // Act
                // ReSharper disable once AccessToDisposedClosure
                Action action = () => watcher.WaitForChanged(WatcherChangeTypes.All, -5);

                // Assert
                action.Should().ThrowExactly <ArgumentOutOfRangeException>().WithMessage(
                    "Specified argument was out of the range of valid values.*");
            }
        }
Beispiel #23
0
        private void When_moving_directory_from_directory_that_exists_as_open_file_it_must_fail()
        {
            // Arrange
            const string sourcePath      = @"C:\some\file.txt";
            const string destinationPath = @"C:\some\other.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingEmptyFile(sourcePath)
                                     .Build();

            using (fileSystem.File.Open(sourcePath, FileMode.Open, FileAccess.Read))
            {
                // Act
                Action action = () => fileSystem.Directory.Move(sourcePath, destinationPath);

                // Assert
                action.Should().ThrowExactly <IOException>().WithMessage(
                    "The process cannot access the file because it is being used by another process.");
            }
        }
Beispiel #24
0
        private void When_moving_directory_to_relative_path_it_must_succeed()
        {
            // Arrange
            const string sourcePath      = @"d:\some\folder";
            const string destinationPath = @"D:\other\node\newname";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingDirectory(sourcePath)
                                     .IncludingDirectory(@"D:\other\node")
                                     .Build();

            fileSystem.Directory.SetCurrentDirectory(@"D:\other");

            // Act
            fileSystem.Directory.Move(sourcePath, @"node\newname");

            // Assert
            fileSystem.Directory.Exists(sourcePath).Should().BeFalse();
            fileSystem.Directory.Exists(destinationPath).Should().BeTrue();
        }
Beispiel #25
0
        When_replacing_file_with_different_name_in_same_directory_without_backup_and_existing_temporary_directory_it_must_fail()
        {
            // Arrange
            const string sourcePath = @"C:\some\source.txt";
            const string targetPath = @"C:\some\target.txt";

            var clock = new SystemClock(() => 1.January(2000));

            IFileSystem fileSystem = new FakeFileSystemBuilder(clock)
                                     .IncludingTextFile(sourcePath, "SourceText")
                                     .IncludingTextFile(targetPath, "TargetText")
                                     .IncludingDirectory(@"C:\some\target.txt~RFbe6312.TMP")
                                     .Build();

            // Act
            Action action = () => fileSystem.File.Replace(sourcePath, targetPath, null);

            // Assert
            action.Should().ThrowExactly <IOException>().WithMessage("Unable to remove the file to be replaced.");
        }
        private void When_filtering_directory_tree_with_asterisk_dot_pattern_it_must_not_raise_events()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";

            string pathToFileToUpdate1      = Path.Combine(directoryToWatch, "RootFile");
            string pathToFileToUpdate2      = Path.Combine(directoryToWatch, "SubFolder", "SubFile");
            string pathToDirectoryToUpdate1 = Path.Combine(directoryToWatch, "RootFolder");
            string pathToDirectoryToUpdate2 = Path.Combine(directoryToWatch, "SubFolder", "Nested");

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingEmptyFile(pathToFileToUpdate1)
                                        .IncludingEmptyFile(pathToFileToUpdate2)
                                        .IncludingDirectory(pathToDirectoryToUpdate1)
                                        .IncludingDirectory(pathToDirectoryToUpdate2)
                                        .Build();

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch))
            {
                watcher.NotifyFilter          = TestNotifyFilters.All;
                watcher.IncludeSubdirectories = true;
                watcher.Filter = "*.";

                using (var listener = new FileSystemWatcherEventListener(watcher))
                {
                    // Act
                    fileSystem.File.SetAttributes(pathToFileToUpdate1, FileAttributes.Hidden);
                    fileSystem.File.SetAttributes(pathToFileToUpdate2, FileAttributes.Hidden);
                    fileSystem.File.SetAttributes(pathToDirectoryToUpdate1, FileAttributes.Hidden);
                    fileSystem.File.SetAttributes(pathToDirectoryToUpdate2, FileAttributes.Hidden);

                    watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds);

                    // Assert
                    watcher.Filter.Should().Be("*.");

                    string text = string.Join(Environment.NewLine, listener.GetEventsCollectedAsText());
                    text.Should().BeEmpty();
                }
            }
        }
Beispiel #27
0
        private void When_constructing_file_info_for_missing_network_share_it_must_fail()
        {
            // Arrange
            const string path = @"\\server\share\file.txt";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .Build();

            // Act
            IFileInfo fileInfo = fileSystem.ConstructFileInfo(path);

            // Assert
            fileInfo.Name.Should().Be("file.txt");
            fileInfo.Extension.Should().Be(".txt");
            fileInfo.FullName.Should().Be(@"\\server\share\file.txt");
            fileInfo.DirectoryName.Should().Be(@"\\server\share");
            fileInfo.Exists.Should().BeFalse();
            ActionFactory.IgnoreReturnValue(() => fileInfo.Length)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.IsReadOnly)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.Attributes)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");

            ActionFactory.IgnoreReturnValue(() => fileInfo.CreationTime)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.CreationTimeUtc)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.LastAccessTime)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.LastAccessTimeUtc)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.LastWriteTime)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");
            ActionFactory.IgnoreReturnValue(() => fileInfo.LastWriteTimeUtc)
            .ShouldThrow <IOException>().WithMessage("The network path was not found");

            IDirectoryInfo directoryInfo = fileInfo.Directory.ShouldNotBeNull();

            directoryInfo.FullName.Should().Be(@"\\server\share");
        }
        private void When_waiting_for_change_it_must_apply_filters()
        {
            // Arrange
            const string directoryToWatch = @"c:\some";

            string pathToMismatchingFile      = Path.Combine(directoryToWatch, "OtherName.txt");
            string pathToMismatchingDirectory = Path.Combine(directoryToWatch, "SomeFolderIgnored");
            string pathToMatchingFile         = Path.Combine(directoryToWatch, "Subfolder", "SomeFile.txt");

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingEmptyFile(pathToMismatchingFile)
                                        .IncludingDirectory(Path.Combine(directoryToWatch, "Subfolder"))
                                        .IncludingEmptyFile(pathToMatchingFile)
                                        .Build();

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch))
            {
                watcher.NotifyFilter          = NotifyFilters.FileName | NotifyFilters.Size;
                watcher.IncludeSubdirectories = true;
                watcher.Filter = "Some*";

                Task.Run(() =>
                {
                    // ReSharper disable once AccessToDisposedClosure
                    BlockUntilStarted(watcher);

                    fileSystem.Directory.CreateDirectory(pathToMismatchingDirectory);
                    fileSystem.File.AppendAllText(pathToMismatchingFile, "IgnoreMe");
                    fileSystem.File.AppendAllText(pathToMatchingFile, "NotifyForMe");
                });

                // Act
                WaitForChangedResult result = watcher.WaitForChanged(WatcherChangeTypes.All, MaxTestDurationInMilliseconds);

                // Assert
                result.TimedOut.Should().BeFalse();
                result.ChangeType.Should().Be(WatcherChangeTypes.Changed);
                result.Name.Should().Be(@"Subfolder\SomeFile.txt");
                result.OldName.Should().BeNull();
            }
        }
Beispiel #29
0
        private void When_moving_directory_tree_to_subdirectory_it_must_raise_events(NotifyFilters filters,
                                                                                     [NotNull] string expectedText)
        {
            // Arrange
            const string directoryToWatch         = @"c:\some";
            const string containerDirectoryName   = "Container";
            const string sourceDirectoryName      = "MoveSource";
            const string destinationDirectoryName = @"MoveTarget\NewMoveSource";

            string pathToContainerDirectory   = Path.Combine(directoryToWatch, containerDirectoryName);
            string pathToSourceDirectory      = Path.Combine(pathToContainerDirectory, sourceDirectoryName);
            string pathToDestinationDirectory = Path.Combine(pathToContainerDirectory, destinationDirectoryName);

            FakeFileSystem fileSystem = new FakeFileSystemBuilder()
                                        .IncludingDirectory(Path.Combine(pathToSourceDirectory, @"FolderA\SubFolderA"))
                                        .IncludingEmptyFile(Path.Combine(pathToSourceDirectory, @"FolderA\FileInA.txt"))
                                        .IncludingEmptyFile(Path.Combine(pathToSourceDirectory, @"FolderB\FileInB.txt"))
                                        .IncludingEmptyFile(Path.Combine(pathToSourceDirectory, @"FolderC\SubFolderC\FileInSubFolderC.txt"))
                                        .IncludingEmptyFile(Path.Combine(pathToSourceDirectory, @"FileInRoot2.txt"))
                                        .IncludingEmptyFile(Path.Combine(pathToSourceDirectory, @"FileInRoot1.txt"))
                                        .IncludingDirectory(Path.Combine(pathToContainerDirectory, "MoveTarget"))
                                        .Build();

            using (FakeFileSystemWatcher watcher = fileSystem.ConstructFileSystemWatcher(directoryToWatch))
            {
                watcher.NotifyFilter          = filters;
                watcher.IncludeSubdirectories = true;

                using (var listener = new FileSystemWatcherEventListener(watcher))
                {
                    // Act
                    fileSystem.Directory.Move(pathToSourceDirectory, pathToDestinationDirectory);

                    watcher.FinishAndWaitForFlushed(MaxTestDurationInMilliseconds);

                    // Assert
                    string text = string.Join(Environment.NewLine, listener.GetEventsCollectedAsText());
                    text.Should().Be(expectedText);
                }
            }
        }
        private void When_constructing_file_info_for_existing_local_directory_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\folder";

            DateTime creationTimeUtc = 17.March(2006).At(14, 03, 53).AsUtc();
            var      clock           = new SystemClock(() => creationTimeUtc);

            IFileSystem fileSystem = new FakeFileSystemBuilder(clock)
                                     .IncludingDirectory(path)
                                     .Build();

            // Act
            IFileInfo fileInfo = fileSystem.ConstructFileInfo(path);

            // Assert
            fileInfo.Name.Should().Be("folder");
            fileInfo.Extension.Should().Be(string.Empty);
            fileInfo.FullName.Should().Be(path);
            fileInfo.DirectoryName.Should().Be(@"c:\some");
            fileInfo.Exists.Should().BeFalse();
            ActionFactory.IgnoreReturnValue(() => fileInfo.Length).Should().ThrowExactly <FileNotFoundException>()
            .WithMessage(@"Could not find file 'c:\some\folder'.");
            fileInfo.IsReadOnly.Should().BeFalse();
            fileInfo.Attributes.Should().Be(FileAttributes.Directory);

            fileInfo.CreationTime.Should().Be(creationTimeUtc.ToLocalTime());
            fileInfo.CreationTimeUtc.Should().Be(creationTimeUtc);
            fileInfo.LastAccessTime.Should().Be(creationTimeUtc.ToLocalTime());
            fileInfo.LastAccessTimeUtc.Should().Be(creationTimeUtc);
            fileInfo.LastWriteTime.Should().Be(creationTimeUtc.ToLocalTime());
            fileInfo.LastWriteTimeUtc.Should().Be(creationTimeUtc);

            fileInfo.ToString().Should().Be(path);

            IDirectoryInfo directoryInfo = fileInfo.Directory.ShouldNotBeNull();

            directoryInfo.Name.Should().Be("some");
            directoryInfo.FullName.Should().Be(@"c:\some");
            directoryInfo.ToString().Should().Be(@"c:\some");
        }