Exemplo n.º 1
0
        private void When_getting_directory_last_access_time_in_UTC_after_external_change_it_must_update_cache_on_refresh()
        {
            // Arrange
            const string path = @"c:\some\folder";

            var clock = new SystemClock(() => DefaultTimeUtc);

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            DateTime beforeTime = dirInfo.LastAccessTimeUtc;

            fileSystem.Directory.SetLastAccessTimeUtc(path, AlternateTimeUtc);

            // Act
            dirInfo.Refresh();

            // Assert
            DateTime afterTime = dirInfo.LastAccessTimeUtc;

            beforeTime.Should().Be(DefaultTimeUtc);
            afterTime.Should().Be(AlternateTimeUtc);
        }
Exemplo n.º 2
0
        private void When_getting_directory_creation_time_in_local_zone_after_external_change_it_must_update_cache_on_refresh()
        {
            // Arrange
            const string path = @"c:\some\folder";

            var clock = new SystemClock {
                UtcNow = () => DefaultTimeUtc
            };

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            DateTime beforeTime = dirInfo.CreationTime;

            fileSystem.Directory.SetCreationTime(path, AlternateTime);

            // Act
            dirInfo.Refresh();

            // Assert
            DateTime afterTime = dirInfo.CreationTime;

            beforeTime.Should().Be(DefaultTime);
            afterTime.Should().Be(AlternateTime);
        }
Exemplo n.º 3
0
        private void When_creating_subdirectory_for_relative_path_it_must_succeed()
        {
            // Arrange
            const string path       = @"d:\some";
            const string folderName = @"with\nested\subtree";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            IDirectoryInfo subdirInfo = dirInfo.CreateSubdirectory(folderName);

            // Assert
            const string completePath = path + @"\" + folderName;

            subdirInfo.FullName.Should().Be(completePath);
            subdirInfo.Exists.Should().BeTrue();

            IDirectoryInfo topDirectory = subdirInfo.Parent.ShouldNotBeNull().Parent.ShouldNotBeNull().Parent.ShouldNotBeNull();

            topDirectory.FullName.Should().Be(dirInfo.FullName);

            fileSystem.Directory.Exists(completePath).Should().BeTrue();
        }
Exemplo n.º 4
0
        private void When_getting_directory_last_write_time_in_local_zone_it_must_cache()
        {
            // Arrange
            const string path = @"c:\some\folder";

            var clock = new SystemClock {
                UtcNow = () => DefaultTimeUtc
            };

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            DateTime beforeTime = dirInfo.LastWriteTime;

            fileSystem.Directory.SetLastWriteTime(path, AlternateTime);

            // Act
            DateTime afterTime = dirInfo.LastWriteTime;

            // Assert
            beforeTime.Should().Be(DefaultTime);
            afterTime.Should().Be(DefaultTime);
        }
Exemplo n.º 5
0
        private void When_constructing_directory_info_for_missing_subdirectory_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\folder";

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

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be("folder");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(path);
            dirInfo.Exists.Should().BeFalse();
            dirInfo.Attributes.Should().Be(MissingEntryAttributes);

            dirInfo.CreationTime.Should().Be(ZeroFileTimeUtc.ToLocalTime());
            dirInfo.CreationTimeUtc.Should().Be(ZeroFileTimeUtc);
            dirInfo.LastAccessTime.Should().Be(ZeroFileTimeUtc.ToLocalTime());
            dirInfo.LastAccessTimeUtc.Should().Be(ZeroFileTimeUtc);
            dirInfo.LastWriteTime.Should().Be(ZeroFileTimeUtc.ToLocalTime());
            dirInfo.LastWriteTimeUtc.Should().Be(ZeroFileTimeUtc);

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

            parentInfo.FullName.Should().Be(@"c:\some");

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

            rootInfo.FullName.Should().Be(@"c:\");
        }
Exemplo n.º 6
0
        private void When_constructing_directory_info_for_root_of_drive_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\";

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

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

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be(@"c:\");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(path);
            dirInfo.Exists.Should().BeTrue();
            dirInfo.Attributes.Should().Be(FileAttributes.Hidden | FileAttributes.System | FileAttributes.Directory);

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

            dirInfo.Parent.Should().BeNull();
            dirInfo.Root.FullName.Should().Be(@"c:\");
        }
        private void When_changing_directory_last_access_time_in_UTC_it_must_refresh_automatically()
        {
            // Arrange
            const string path = @"c:\some\folder";

            var clock = new SystemClock {
                UtcNow = () => DefaultTimeUtc
            };

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            DateTime beforeTime = dirInfo.LastAccessTimeUtc;

            // Act
            dirInfo.LastAccessTimeUtc = AlternateTimeUtc;

            // Assert
            DateTime afterTime = dirInfo.LastAccessTimeUtc;

            beforeTime.Should().Be(DefaultTimeUtc);
            afterTime.Should().Be(AlternateTimeUtc);
        }
Exemplo n.º 8
0
        private void When_moving_directory_it_must_update_properties()
        {
            // Arrange
            const string sourcePath      = @"c:\some\folder";
            const string destinationPath = @"c:\other\folder";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(sourcePath);

            string beforeDirectoryName = dirInfo.Parent.ShouldNotBeNull().FullName;

            // Act
            dirInfo.MoveTo(destinationPath);

            // Assert
            beforeDirectoryName.Should().Be(@"c:\some");
            dirInfo.Exists.Should().BeTrue();
            dirInfo.Name.Should().Be("folder");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(destinationPath);
            dirInfo.ToString().Should().Be(destinationPath);

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

            parentInfo.FullName.Should().Be(@"c:\other");

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

            rootInfo.FullName.Should().Be(@"c:\");
        }
Exemplo n.º 9
0
        private void When_constructing_directory_info_for_directory_using_absolute_path_without_drive_letter_it_must_succeed()
        {
            // Arrange
            const string path = @"\some\folder";

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

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

            DateTime lastWriteTimeUtc = 18.March(2006).At(14, 03, 53).AsUtc();

            clock.UtcNow = () => lastWriteTimeUtc;

            fileSystem.File.WriteAllText(@"c:\some\folder" + @"\file.txt", "X");

            DateTime lastAccessTimeUtc = 19.March(2006).At(14, 03, 53).AsUtc();

            clock.UtcNow = () => lastAccessTimeUtc;

            fileSystem.Directory.GetFiles(@"c:\some\folder");

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

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be("folder");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(@"C:\some\folder");
            dirInfo.Exists.Should().BeTrue();
            dirInfo.Attributes.Should().Be(FileAttributes.Directory);

            dirInfo.CreationTime.Should().Be(creationTimeUtc.ToLocalTime());
            dirInfo.CreationTimeUtc.Should().Be(creationTimeUtc);
            dirInfo.LastAccessTime.Should().Be(lastAccessTimeUtc.ToLocalTime());
            dirInfo.LastAccessTimeUtc.Should().Be(lastAccessTimeUtc);
            dirInfo.LastWriteTime.Should().Be(lastWriteTimeUtc.ToLocalTime());
            dirInfo.LastWriteTimeUtc.Should().Be(lastWriteTimeUtc);

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

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

            parentInfo.Name.Should().Be("some");
            parentInfo.FullName.Should().Be(@"C:\some");
            parentInfo.ToString().Should().Be("some");

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

            rootInfo.Name.Should().Be(@"C:\");
            rootInfo.FullName.Should().Be(@"C:\");
            rootInfo.ToString().Should().Be(@"C:\");
        }
Exemplo n.º 10
0
        private void When_constructing_directory_info_for_existing_local_directory_with_different_casing_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(@"C:\some\FOLder", FileAttributes.Hidden)
                                     .Build();

            DateTime lastWriteTimeUtc = 18.March(2006).At(14, 03, 53).AsUtc();

            clock.UtcNow = () => lastWriteTimeUtc;

            fileSystem.File.WriteAllText(path + @"\file.txt", "X");

            DateTime lastAccessTimeUtc = 19.March(2006).At(14, 03, 53).AsUtc();

            clock.UtcNow = () => lastAccessTimeUtc;

            fileSystem.Directory.GetFiles(path);

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be("folDER");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(path);
            dirInfo.Exists.Should().BeTrue();
            dirInfo.Attributes.Should().Be(FileAttributes.Directory | FileAttributes.Hidden);

            dirInfo.CreationTime.Should().Be(creationTimeUtc.ToLocalTime());
            dirInfo.CreationTimeUtc.Should().Be(creationTimeUtc);
            dirInfo.LastAccessTime.Should().Be(lastAccessTimeUtc.ToLocalTime());
            dirInfo.LastAccessTimeUtc.Should().Be(lastAccessTimeUtc);
            dirInfo.LastWriteTime.Should().Be(lastWriteTimeUtc.ToLocalTime());
            dirInfo.LastWriteTimeUtc.Should().Be(lastWriteTimeUtc);

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

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

            parentInfo.Name.Should().Be("SOME");
            parentInfo.FullName.Should().Be(@"c:\SOME");
            parentInfo.ToString().Should().Be("SOME");

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

            rootInfo.Name.Should().Be(@"c:\");
            rootInfo.FullName.Should().Be(@"c:\");
            rootInfo.ToString().Should().Be(@"c:\");
        }
Exemplo n.º 11
0
        private void When_constructing_directory_info_for_whitespace_it_must_fail()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .Build();

            // Act
            Action action = () => fileSystem.ConstructDirectoryInfo(" ");

            // Assert
            action.Should().ThrowExactly <ArgumentException>().WithMessage("The path is not of a legal form.*");
        }
Exemplo n.º 12
0
        private void When_constructing_directory_info_for_reserved_name_it_must_fail()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .Build();

            // Act
            Action action = () => fileSystem.ConstructDirectoryInfo("COM1");

            // Assert
            action.Should().ThrowExactly <PlatformNotSupportedException>().WithMessage("Reserved names are not supported.");
        }
Exemplo n.º 13
0
        private void When_constructing_directory_info_for_wildcard_characters_it_must_fail()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .Build();

            // Act
            Action action = () => fileSystem.ConstructDirectoryInfo("some?.txt");

            // Assert
            action.Should().ThrowExactly <ArgumentException>().WithMessage("Illegal characters in path.*");
        }
Exemplo n.º 14
0
        private void When_constructing_directory_info_for_invalid_drive_it_must_fail()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .Build();

            // Act
            Action action = () => fileSystem.ConstructDirectoryInfo("_:");

            // Assert
            action.Should().ThrowExactly <NotSupportedException>().WithMessage("The given path's format is not supported.");
        }
Exemplo n.º 15
0
        private void When_constructing_directory_info_for_null_it_must_fail()
        {
            // Arrange
            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .Build();

            // Act
            // ReSharper disable once AssignNullToNotNullAttribute
            Action action = () => fileSystem.ConstructDirectoryInfo(null);

            // Assert
            action.Should().ThrowExactly <ArgumentNullException>();
        }
Exemplo n.º 16
0
        private void When_constructing_directory_info_for_existing_remote_directory_it_must_succeed()
        {
            // Arrange
            const string path = @"\\server\share\folder";

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

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

            DateTime lastWriteTimeUtc = 18.March(2006).At(14, 03, 53).AsUtc();

            clock.UtcNow = () => lastWriteTimeUtc;

            fileSystem.File.WriteAllText(path + @"\file.txt", "X");

            DateTime lastAccessTimeUtc = 19.March(2006).At(14, 03, 53).AsUtc();

            clock.UtcNow = () => lastAccessTimeUtc;

            fileSystem.Directory.GetFiles(path);

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be("folder");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(path);
            dirInfo.Exists.Should().BeTrue();
            dirInfo.Attributes.Should().Be(FileAttributes.Directory);

            dirInfo.CreationTime.Should().Be(creationTimeUtc.ToLocalTime());
            dirInfo.CreationTimeUtc.Should().Be(creationTimeUtc);
            dirInfo.LastAccessTime.Should().Be(lastAccessTimeUtc.ToLocalTime());
            dirInfo.LastAccessTimeUtc.Should().Be(lastAccessTimeUtc);
            dirInfo.LastWriteTime.Should().Be(lastWriteTimeUtc.ToLocalTime());
            dirInfo.LastWriteTimeUtc.Should().Be(lastWriteTimeUtc);

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

            parentInfo.FullName.Should().Be(@"\\server\share");

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

            rootInfo.FullName.Should().Be(@"\\server\share");
        }
Exemplo n.º 17
0
        private void When_constructing_directory_info_for_missing_network_share_it_must_succeed()
        {
            // Arrange
            const string path = @"\\server\share\folder";

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

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be("folder");
            dirInfo.Extension.Should().BeEmpty();
            dirInfo.FullName.Should().Be(path);
            dirInfo.Exists.Should().BeFalse();
            ActionFactory.IgnoreReturnValue(() => dirInfo.Attributes).Should().ThrowExactly <IOException>()
            .WithMessage("The network path was not found.");

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

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

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

            parentInfo.Name.Should().Be(@"\\server\share");
            parentInfo.FullName.Should().Be(@"\\server\share");
            parentInfo.ToString().Should().Be(@"share");

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

            rootInfo.Name.Should().Be(@"\\server\share");
            rootInfo.FullName.Should().Be(@"\\server\share");
            rootInfo.ToString().Should().Be(@"\\server\share");
        }
Exemplo n.º 18
0
        private void When_creating_directory_it_must_succeed()
        {
            // Arrange
            const string path = @"d:\some\folder\nested";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            dirInfo.Create();

            // Assert
            fileSystem.Directory.Exists(path).Should().BeTrue();
        }
        private void When_getting_directories_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\folder";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            IDirectoryInfo[] infos = dirInfo.GetDirectories();

            // Assert
            infos.Should().ContainSingle(x => x.FullName == @"c:\some\folder\sub");
        }
Exemplo n.º 20
0
        private void When_creating_subdirectory_for_invalid_root_it_must_fail()
        {
            // Arrange
            const string path = @"d:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            Action action = () => dirInfo.CreateSubdirectory("::");

            // Assert
            action.ShouldThrow <ArgumentException>().WithMessage("Second path fragment must not be a drive or UNC name.*");
        }
        private void When_deleting_directory_recursively_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\folder";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            dirInfo.Delete(true);

            // Assert
            fileSystem.Directory.Exists(path).Should().BeFalse();
        }
Exemplo n.º 22
0
        private void When_creating_subdirectory_for_invalid_characters_it_must_fail()
        {
            // Arrange
            const string path = @"d:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            Action action = () => dirInfo.CreateSubdirectory("sub?");

            // Assert
            action.ShouldThrow <ArgumentException>().WithMessage("Illegal characters in path.*");
        }
Exemplo n.º 23
0
        private void When_creating_subdirectory_for_too_many_parent_paths_below_directory_it_must_succeed()
        {
            // Arrange
            const string path = @"d:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            IDirectoryInfo subdirInfo = dirInfo.CreateSubdirectory(@"..\..\..\..\..\..\..\..\..\some\other");

            // Assert
            subdirInfo.FullName.Should().Be(@"d:\some\other");
        }
Exemplo n.º 24
0
        private void When_creating_subdirectory_for_empty_string_it_must_fail()
        {
            // Arrange
            const string path = @"d:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            Action action = () => dirInfo.CreateSubdirectory(string.Empty);

            // Assert
            action.ShouldThrow <ArgumentException>().WithMessage("Path cannot be the empty string or all whitespace.*");
        }
Exemplo n.º 25
0
        private void When_creating_subdirectory_for_whitespace_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            IDirectoryInfo resultDirInfo = dirInfo.CreateSubdirectory(" ");

            // Assert
            resultDirInfo.FullName.Should().Be(path);

            fileSystem.Directory.Exists(path).Should().BeTrue();
        }
Exemplo n.º 26
0
        private void When_creating_subdirectory_for_parent_path_next_to_directory_it_must_fail()
        {
            // Arrange
            const string path = @"d:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            Action action = () => dirInfo.CreateSubdirectory(@"..\some2\more");

            // Assert
            action.ShouldThrow <ArgumentException>()
            .WithMessage(@"The directory specified, '..\some2\more', is not a subdirectory of 'd:\some'.*");
        }
Exemplo n.º 27
0
        private void When_creating_subdirectory_for_null_it_must_fail()
        {
            // Arrange
            const string path = @"d:\some";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Act
            // ReSharper disable once AssignNullToNotNullAttribute
            Action action = () => dirInfo.CreateSubdirectory(null);

            // Assert
            action.ShouldThrow <ArgumentNullException>();
        }
        private void When_getting_directory_attributes_it_must_lazy_load()
        {
            // Arrange
            const string path = @"c:\some\folder";

            IFileSystem fileSystem = new FakeFileSystemBuilder()
                                     .IncludingDirectory(path, FileAttributes.Hidden)
                                     .Build();

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            fileSystem.File.SetAttributes(path, FileAttributes.ReadOnly);

            // Act
            FileAttributes attributes = dirInfo.Attributes;

            // Assert
            attributes.Should().Be(FileAttributes.Directory | FileAttributes.ReadOnly);
        }
        private void When_getting_directory_existence_it_must_lazy_load()
        {
            // Arrange
            const string path = @"c:\some\folder";

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

            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            fileSystem.Directory.CreateDirectory(path);

            // Act
            bool found = dirInfo.Exists;

            // Assert
            found.Should().BeTrue();
        }
Exemplo n.º 30
0
        private void When_constructing_directory_info_for_existing_local_file_it_must_succeed()
        {
            // Arrange
            const string path = @"c:\some\file.txt";

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

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

            // Act
            IDirectoryInfo dirInfo = fileSystem.ConstructDirectoryInfo(path);

            // Assert
            dirInfo.Name.Should().Be("file.txt");
            dirInfo.Extension.Should().Be(".txt");
            dirInfo.FullName.Should().Be(path);
            dirInfo.Exists.Should().BeFalse();
            dirInfo.Attributes.Should().Be(FileAttributes.Archive);

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

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

            IDirectoryInfo parentInfo = dirInfo.Parent.ShouldNotBeNull();

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

            IDirectoryInfo rootInfo = dirInfo.Root.ShouldNotBeNull();

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