Exemplo n.º 1
0
        public void PathAlreadyExistsAsDirectory()
        {
            string        path    = GetTestFilePath();
            DirectoryInfo testDir = Directory.CreateDirectory(path);

            Assert.True(Exists(IOServices.RemoveTrailingSlash(path)));
            Assert.True(Exists(IOServices.RemoveTrailingSlash(IOServices.RemoveTrailingSlash(path))));
            Assert.True(Exists(IOServices.RemoveTrailingSlash(IOServices.AddTrailingSlashIfNeeded(path))));
        }
        public void DotDotIsParentDirectory()
        {
            DirectoryInfo result = new DirectoryInfo(TestDirectory).CreateSubdirectory(Path.Combine(GetTestFileName(), ".."));

            Assert.Equal(IOServices.RemoveTrailingSlash(TestDirectory), result.FullName);

            result = new DirectoryInfo(TestDirectory).CreateSubdirectory(Path.Combine(GetTestFileName(), "..") + Path.DirectorySeparatorChar);
            Assert.Equal(IOServices.AddTrailingSlashIfNeeded(TestDirectory), result.FullName);
        }
Exemplo n.º 3
0
        public void DotIsCurrentDirectory()
        {
            string        path   = GetTestFilePath();
            DirectoryInfo result = Create(Path.Combine(path, "."));

            Assert.Equal(IOServices.RemoveTrailingSlash(path), result.FullName);

            result = Create(Path.Combine(path, ".") + Path.DirectorySeparatorChar);
            Assert.Equal(IOServices.AddTrailingSlashIfNeeded(path), result.FullName);
        }
Exemplo n.º 4
0
        [PlatformSpecific(TestPlatforms.Windows)]  // Extended path already exists as directory
        public void ExtendedPathAlreadyExistsAsDirectory()
        {
            string path = IOInputs.ExtendedPrefix + GetTestFilePath();

            Directory.CreateDirectory(path);

            Assert.True(Exists(IOServices.RemoveTrailingSlash(path)));
            Assert.True(Exists(IOServices.RemoveTrailingSlash(IOServices.RemoveTrailingSlash(path))));
            Assert.True(Exists(IOServices.RemoveTrailingSlash(IOServices.AddTrailingSlashIfNeeded(path))));
        }
Exemplo n.º 5
0
        public void PathAlreadyExistsAsFile()
        {
            string path = GetTestFilePath();

            File.Create(path).Dispose();

            Assert.True(Exists(IOServices.RemoveTrailingSlash(path)));
            Assert.True(Exists(IOServices.RemoveTrailingSlash(IOServices.RemoveTrailingSlash(path))));
            Assert.True(Exists(IOServices.RemoveTrailingSlash(IOServices.AddTrailingSlashIfNeeded(path))));
        }
Exemplo n.º 6
0
        public void PathAlreadyExistsAsFile()
        {
            string path = GetTestFilePath();

            File.Create(path).Dispose();

            Assert.Throws <IOException>(() => Create(path));
            Assert.Throws <IOException>(() => Create(IOServices.AddTrailingSlashIfNeeded(path)));
            Assert.Throws <IOException>(() => Create(IOServices.RemoveTrailingSlash(path)));
        }
Exemplo n.º 7
0
        [PlatformSpecific(TestPlatforms.Windows)]  // trailing slash
        public void ValidExtendedPathWithTrailingSlash(string component)
        {
            DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());

            string        path   = IOInputs.ExtendedPrefix + IOServices.AddTrailingSlashIfNeeded(Path.Combine(testDir.FullName, component));
            DirectoryInfo result = Create(path);

            Assert.Equal(path, result.FullName);
            Assert.True(result.Exists);
        }
Exemplo n.º 8
0
        [PlatformSpecific(TestPlatforms.Windows)]  // Extended path already exists as file
        public void ExtendedPathAlreadyExistsAsFile()
        {
            string path = IOInputs.ExtendedPrefix + GetTestFilePath();

            File.Create(path).Dispose();

            Assert.False(Exists(IOServices.RemoveTrailingSlash(path)));
            Assert.False(Exists(IOServices.RemoveTrailingSlash(IOServices.RemoveTrailingSlash(path))));
            Assert.False(Exists(IOServices.RemoveTrailingSlash(IOServices.AddTrailingSlashIfNeeded(path))));
        }
Exemplo n.º 9
0
        public void ValidPathWithTrailingSlash(string component)
        {
            DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());

            string        path   = IOServices.AddTrailingSlashIfNeeded(component);
            DirectoryInfo result = new DirectoryInfo(testDir.FullName).CreateSubdirectory(path);

            Assert.Equal(Path.Combine(testDir.FullName, path), result.FullName);
            Assert.True(Directory.Exists(result.FullName));
        }
Exemplo n.º 10
0
    public static void Exists_ExistingDirectoryWithTrailingSlashAsPath_ReturnsTrue()
    {
        using (TemporaryDirectory directory = new TemporaryDirectory())
        {
            string path = IOServices.AddTrailingSlashIfNeeded(directory.Path);

            bool result = Directory.Exists(path);

            Assert.True(result);
        }
    }
Exemplo n.º 11
0
    public static void Exists_FileWithTrailingSlashAsPath_ReturnsFalse()
    {
        using (TemporaryFile file = new TemporaryFile())
        {
            string path = IOServices.AddTrailingSlashIfNeeded(file.Path);

            bool result = Directory.Exists(path);

            Assert.False(result);
        }
    }
Exemplo n.º 12
0
    public static void CreateDirectory_FileWithTrailingSlashAsPath_ThrowsIOException()
    {
        using (TemporaryFile file = new TemporaryFile())
        {
            string path = IOServices.AddTrailingSlashIfNeeded(file.Path);

            Assert.Throws <IOException>(() =>
            {
                Directory.CreateDirectory(path);
            });
        }
    }
Exemplo n.º 13
0
    public static void CreateDirectory_ExistingDirectoryWithTrailingSlashAsPath_DoesNotThrow()
    {
        using (TemporaryDirectory directory = new TemporaryDirectory())
        {
            string path = IOServices.AddTrailingSlashIfNeeded(directory.Path);

            DirectoryInfo result = Directory.CreateDirectory(path);

            Assert.Equal(path, result.FullName);
            Assert.True(Directory.Exists(result.FullName));
        }
    }
Exemplo n.º 14
0
        public void ValidPathWithTrailingSlash()
        {
            DirectoryInfo testDir = Directory.CreateDirectory(GetTestFilePath());

            var components = IOInputs.GetValidPathComponentNames();

            Assert.All(components, (component) =>
            {
                string path          = IOServices.AddTrailingSlashIfNeeded(Path.Combine(testDir.FullName, component));
                DirectoryInfo result = Create(path);

                Assert.Equal(path, result.FullName);
                Assert.True(result.Exists);
            });
        }
Exemplo n.º 15
0
    public static void CreateDirectory_ValidPathWithTrailingSlash_CanBeCreated()
    {
        using (TemporaryDirectory directory = new TemporaryDirectory())
        {
            var components = IOInputs.GetValidPathComponentNames();

            foreach (var component in components)
            {
                string path = IOServices.AddTrailingSlashIfNeeded(Path.Combine(directory.Path, component));

                DirectoryInfo result = Directory.CreateDirectory(path);

                Assert.Equal(path, result.FullName);
                Assert.True(Directory.Exists(result.FullName));
            }
        }
    }
Exemplo n.º 16
0
 public void NonExistentFile()
 {
     Assert.Throws <FileNotFoundException>(() => Set(GetTestFilePath(), FileAttributes.Normal));
     Assert.Throws <FileNotFoundException>(() => Set(IOServices.AddTrailingSlashIfNeeded(GetTestFilePath()), FileAttributes.Normal));
     Assert.Throws <FileNotFoundException>(() => Set(IOServices.RemoveTrailingSlash(GetTestFilePath()), FileAttributes.Normal));
 }
Exemplo n.º 17
0
        public void PathAlreadyExistsAsFile()
        {
            string path = GetTestFileName();

            File.Create(Path.Combine(TestDirectory, path)).Dispose();

            Assert.Throws <IOException>(() => new DirectoryInfo(TestDirectory).CreateSubdirectory(path));
            Assert.Throws <IOException>(() => new DirectoryInfo(TestDirectory).CreateSubdirectory(IOServices.AddTrailingSlashIfNeeded(path)));
            Assert.Throws <IOException>(() => new DirectoryInfo(TestDirectory).CreateSubdirectory(IOServices.RemoveTrailingSlash(path)));
        }