Example #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);
        }
Example #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);
        }
Example #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))));
        }
Example #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))));
        }
Example #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)));
        }
Example #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);
        }
Example #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))));
        }
Example #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));
        }
Example #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);
        }
    }
Example #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);
        }
    }
Example #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);
            });
        }
    }
Example #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));
        }
    }
Example #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);
            });
        }
Example #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));
            }
        }
    }
Example #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));
 }
Example #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)));
        }