Example #1
0
        public void Directory_ContentsRecursive()
        {
            var tmpSrc     = GetNewFileNameOnTempPath("");
            var tmpSrcInfo = FileSystem.DirectoryFromPath(tmpSrc);

            // make test file
            const string fileName = @"temp.txt";
            var          newFile  = FileSystem.CombinePath(tmpSrc, fileName);

            FileSystem.WriteText(newFile, "test");

            // make subdirectory
            const string dirName = @"subDir";
            var          newDir  = FileSystem.CombinePath(tmpSrc, dirName);

            Directory.CreateDirectory(newDir);

            // make another test file in subdirectory
            const string subdirFileName = @"tempSubdir.txt";
            var          newSubdirFile  = FileSystem.CombinePath(newDir, subdirFileName);

            FileSystem.WriteText(newSubdirFile, "testSubdir");

            var contents = FileSystem.GetDirectoryContents(tmpSrcInfo, "*.*", true);

            Assert.AreEqual(new[] { newFile, newSubdirFile }, contents["files"]);
            Assert.AreEqual(new[] { newDir }, contents["directories"]);
        }
Example #2
0
        public void SimpleWrappers()
        {
            Assert.AreEqual(Path.Combine("test"), FileSystem.CombinePath("test"));
            Assert.AreEqual(Path.Combine("test", "1"), FileSystem.CombinePath("test", "1"));
            Assert.AreEqual(Path.Combine("test/", @"1\"), FileSystem.CombinePath("test/", @"1\"));

            const string aFilePath = @"hello\there.txt";
            const string aFileName = "hello";

            Assert.AreEqual(Path.GetExtension(aFilePath), FileSystem.FileExtension(aFilePath));
            Assert.AreEqual(Path.GetExtension(aFileName), FileSystem.FileExtension(aFileName));

            Assert.AreEqual(
                Path.ChangeExtension(aFilePath, ".png"),
                FileSystem.ChangePathExtension(aFilePath, ".png"));
            Assert.AreEqual(
                Path.ChangeExtension(aFileName, ".txt"),
                FileSystem.ChangePathExtension(aFileName, ".txt"));

            Assert.AreEqual(Path.GetDirectoryName(aFilePath), FileSystem.DirectoryName(aFilePath));
            Assert.AreEqual(Path.GetDirectoryName(aFileName), FileSystem.DirectoryName(aFileName));

            Assert.AreEqual(Path.HasExtension(aFilePath), FileSystem.FileHasExtension(aFilePath));
            Assert.AreEqual(Path.HasExtension(aFileName), FileSystem.FileHasExtension(aFileName));
        }
Example #3
0
        public void Directory_Contents()
        {
            var          tmpSrc     = GetNewFileNameOnTempPath("");
            var          tmpSrcInfo = FileSystem.DirectoryFromPath(tmpSrc);
            const string fileName   = @"temp.txt";
            var          newFile    = FileSystem.CombinePath(tmpSrc, fileName);

            FileSystem.WriteText(newFile, "test");

            const string dirName = @"subDir";
            var          newDir  = FileSystem.CombinePath(tmpSrc, dirName);

            Directory.CreateDirectory(newDir);

            var contents = FileSystem.GetDirectoryContents(tmpSrcInfo);

            Assert.AreEqual(new[] { newFile }, contents["files"]);
            Assert.AreEqual(new[] { newDir }, contents["directories"]);
        }
Example #4
0
        public void Directory_Delete()
        {
            var tmpSrc = GetNewFileNameOnTempPath("");

            Directory.CreateDirectory(tmpSrc);
            const string fileName = @"temp.txt";

            FileSystem.WriteText(FileSystem.CombinePath(tmpSrc, fileName), "test");

            Assert.Throws <IOException>(() => FileSystem.DeleteDirectory(tmpSrc));
            FileSystem.DeleteDirectory(tmpSrc, recursive: true);
            Assert.IsFalse(FileSystem.DirectoryExists(tmpSrc));

            var tmpSrc2 = GetNewFileNameOnTempPath("");

            Directory.CreateDirectory(tmpSrc2);
            FileSystem.DeleteDirectory(tmpSrc2);
            Assert.IsFalse(FileSystem.DirectoryExists(tmpSrc2));
        }
Example #5
0
        public void Directory_Copy()
        {
            var          tmpSrc     = GetNewFileNameOnTempPath("");
            var          tmpSrcInfo = FileSystem.DirectoryFromPath(tmpSrc);
            const string fileName   = @"temp.txt";

            FileSystem.WriteText(FileSystem.CombinePath(tmpSrc, fileName), "test");

            var tmpDest = GetNewFileNameOnTempPath("");

            FileSystem.CopyDirectory(tmpSrcInfo, tmpDest);
            Assert.IsTrue(FileSystem.DirectoryExists(tmpSrc));
            Assert.IsTrue(FileSystem.DirectoryExists(tmpDest));

            var destFileName = FileSystem.CombinePath(tmpDest, fileName);

            Assert.IsTrue(FileSystem.FileExists(destFileName));
            Assert.AreEqual("test", FileSystem.ReadText(FileSystem.FileFromPath(destFileName)));
        }