示例#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"]);
        }
示例#2
0
        public void File_WriteText()
        {
            const string contents = "test";
            var          fn       = GetNewFileNameOnTempPath(".txt");

            Assert.IsFalse(System.IO.File.Exists(fn));
            FileSystem.WriteText(fn, contents);
            Assert.IsTrue(System.IO.File.Exists(fn));
            Assert.AreEqual(contents, System.IO.File.ReadAllText(fn));
        }
示例#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"]);
        }
示例#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));
        }
示例#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)));
        }