예제 #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 Directory_FromPath()
        {
            var tmp = GetNewFileNameOnTempPath("");

            Assert.IsFalse(Directory.Exists(tmp));
            var info = FileSystem.DirectoryFromPath(tmp);

            Assert.AreEqual(tmp, info.FullName);
            Assert.IsTrue(info.Exists);

            //Make again now that it already exists
            var info2 = FileSystem.DirectoryFromPath(tmp);

            Assert.AreEqual(tmp, info2.FullName);
            Assert.IsTrue(info2.Exists);
        }
예제 #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_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)));
        }