Exemple #1
0
        public void SimpleWrappers()
        {
            Assert.AreEqual(Path.Combine("test"), File.CombinePath("test"));
            Assert.AreEqual(Path.Combine("test", "1"), File.CombinePath("test", "1"));
            Assert.AreEqual(Path.Combine("test/", @"1\"), File.CombinePath("test/", @"1\"));

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

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

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

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

            Assert.AreEqual(Path.HasExtension(aFilePath), File.FileHasExtension(aFilePath));
            Assert.AreEqual(Path.HasExtension(aFileName), File.FileHasExtension(aFileName));
        }
Exemple #2
0
        public void Directory_ContentsRecursive()
        {
            var tmpSrc     = GetNewFileNameOnTempPath("");
            var tmpSrcInfo = File.DirectoryFromPath(tmpSrc);

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

            File.WriteText(newFile, "test");

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

            Directory.CreateDirectory(newDir);

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

            File.WriteText(newSubdirFile, "testSubdir");

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

            Assert.AreEqual(new[] { newFile, newSubdirFile }, contents["files"]);
            Assert.AreEqual(new[] { newDir }, contents["directories"]);
        }
Exemple #3
0
        public void Directory_Exists()
        {
            var tmp = GetNewFileNameOnTempPath("");

            Assert.IsFalse(File.DirectoryExists(tmp), "Directory hasn't been created yet.");
            Directory.CreateDirectory(tmp);
            Assert.IsTrue(File.DirectoryExists(tmp), "Directory has been created.");
        }
Exemple #4
0
        public void File_AbsolutePath_WithoutSession_ReturnsHintPath()
        {
            Assert.IsNull(ExecutionEvents.ActiveSession);
            var relativepath = @"excel\ascending.xlsx";
            var hintpath     = Path.Combine(TestDirectory, @"do not exist\no file.txt");

            Assert.AreEqual(hintpath, File.AbsolutePath(relativepath, hintpath));
        }
Exemple #5
0
        public void File_AbsolutePath_WithFullPathInput_ReturnsInput()
        {
            Assert.IsNull(ExecutionEvents.ActiveSession);
            string wspath       = Path.Combine(TestDirectory, @"core\files\dummy.dyn");
            var    relativepath = @"excel\ascending.xlsx";
            var    hintpath     = Path.Combine(TestDirectory, "core", relativepath);

            Assert.AreEqual(wspath, File.AbsolutePath(wspath, hintpath));
        }
Exemple #6
0
        public void FilePath_FileName()
        {
            const string aFilePath = @"hello\there.txt";

            Assert.AreEqual(Path.GetFileName(aFilePath), File.FileName(aFilePath));
            Assert.AreEqual(
                Path.GetFileNameWithoutExtension(aFilePath),
                File.FileName(aFilePath, withExtension: false));
        }
Exemple #7
0
        public void File_ReadText()
        {
            const string contents = "test";
            var          fn       = GetNewFileNameOnTempPath(".txt");

            System.IO.File.WriteAllText(fn, contents);
            var fnInfo = File.FromPath(fn);

            Assert.AreEqual(contents, File.ReadText(fnInfo));
        }
Exemple #8
0
        public void File_WriteText()
        {
            const string contents = "test";
            var          fn       = GetNewFileNameOnTempPath(".txt");

            Assert.IsFalse(System.IO.File.Exists(fn));
            File.WriteText(fn, contents);
            Assert.IsTrue(System.IO.File.Exists(fn));
            Assert.AreEqual(contents, System.IO.File.ReadAllText(fn));
        }
Exemple #9
0
        public void File_Delete()
        {
            const string contents = "test";
            var          fn       = GetNewFileNameOnTempPath(".txt");

            System.IO.File.WriteAllText(fn, contents);
            Assert.IsTrue(System.IO.File.Exists(fn));

            File.Delete(fn);
            Assert.IsFalse(System.IO.File.Exists(fn));
        }
Exemple #10
0
 public void Image_ReadFromFile()
 {
     foreach (var file in GetTestImageFiles())
     {
         Image.ReadFromFile(File.FromPath(file));
         Assert.DoesNotThrow(
             () =>
         {
             using (System.IO.File.OpenRead(file)) { }     //Check that it's not locked
         },
             "File is locked after being read!");
     }
 }
Exemple #11
0
        public void CSV_Read()
        {
            //Make a CSV file
            var data = Enumerable.Range(0, 10).Select(row => Enumerable.Range(0, 10).Select(col => row + col));
            var fn   = GetNewFileNameOnTempPath(".csv");

            System.IO.File.WriteAllText(fn, string.Join("\n", data.Select(row => string.Join(",", row))));

            //Now read it
            var fnInfo = File.FromPath(fn);

            Assert.AreEqual(data, CSV.ReadFromFile(fnInfo));
        }
Exemple #12
0
        public void CSV_Write()
        {
            //Write data to CSV
            var data =
                Enumerable.Range(0, 10)
                .Select(row => Enumerable.Range(0, 10).Select(col => row + col).Cast <object>().ToArray())
                .ToArray();
            var fn = GetNewFileNameOnTempPath(".csv");

            CSV.WriteToFile(fn, data);

            //Confirm it's correct
            Assert.AreEqual(data, CSV.ReadFromFile(File.FromPath(fn)));
        }
Exemple #13
0
        public void File_AbsolutePath_WithValidHintPath_ReturnsHintPath()
        {
            Assert.IsNull(ExecutionEvents.ActiveSession);
            string wspath = Path.Combine(TestDirectory, @"core\files\dummy.dyn");

            var session = new Mock <IExecutionSession>();

            session.Setup(s => s.CurrentWorkspacePath).Returns(wspath);
            SetActiveSession(session.Object);
            var relativepath = @"excel\ascending.xlsx";
            var hintpath     = Path.Combine(TestDirectory, "core", relativepath);

            Assert.AreEqual(hintpath, File.AbsolutePath(relativepath, hintpath));
            SetActiveSession(null);
        }
Exemple #14
0
        public void File_AbsolutePath_RelativePathDontExist()
        {
            Assert.IsNull(ExecutionEvents.ActiveSession);
            string wspath = Path.Combine(TestDirectory, @"core\files\dummy.dyn");

            var session = new Mock <IExecutionSession>();

            session.Setup(s => s.CurrentWorkspacePath).Returns(wspath);
            SetActiveSession(session.Object);
            var relativepath = @"do not exist\no file.txt";
            var expectedpath = Path.Combine(TestDirectory, @"core\files", relativepath);

            Assert.AreEqual(expectedpath, File.AbsolutePath(relativepath));
            SetActiveSession(null);
        }
Exemple #15
0
        public void File_Move()
        {
            const string contents = "test";
            var          fn       = GetNewFileNameOnTempPath(".txt");

            System.IO.File.WriteAllText(fn, contents);
            Assert.IsTrue(System.IO.File.Exists(fn));

            var dest     = GetNewFileNameOnTempPath(".txt");
            var destInfo = File.FromPath(dest);

            File.Move(fn, dest);
            Assert.IsTrue(System.IO.File.Exists(dest));
            Assert.IsFalse(System.IO.File.Exists(fn));
            Assert.AreEqual(contents, File.ReadText(destInfo));
        }
Exemple #16
0
        public void Directory_FromPath()
        {
            var tmp = GetNewFileNameOnTempPath("");

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

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

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

            Assert.AreEqual(tmp, info2.FullName);
            Assert.IsTrue(info2.Exists);
        }
Exemple #17
0
        public void Directory_Contents()
        {
            var          tmpSrc     = GetNewFileNameOnTempPath("");
            var          tmpSrcInfo = DSCore.IO.Directory.FromPath(tmpSrc);
            const string fileName   = @"temp.txt";
            var          newFile    = FilePath.Combine(tmpSrc, fileName);

            File.WriteText(newFile, "test");

            const string dirName = @"subDir";
            var          newDir  = FilePath.Combine(tmpSrc, dirName);

            Directory.CreateDirectory(newDir);

            var contents = DSCore.IO.Directory.Contents(tmpSrcInfo);

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

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

            File.WriteText(FilePath.Combine(tmpSrc, fileName), "test");

            Assert.Throws <IOException>(() => DSCore.IO.Directory.Delete(tmpSrc));
            DSCore.IO.Directory.Delete(tmpSrc, recursive: true);
            Assert.IsFalse(DSCore.IO.Directory.Exists(tmpSrc));

            var tmpSrc2 = GetNewFileNameOnTempPath("");

            Directory.CreateDirectory(tmpSrc2);
            DSCore.IO.Directory.Delete(tmpSrc2);
            Assert.IsFalse(DSCore.IO.Directory.Exists(tmpSrc2));
        }
Exemple #19
0
        public void Directory_Copy()
        {
            var          tmpSrc     = GetNewFileNameOnTempPath("");
            var          tmpSrcInfo = DSCore.IO.Directory.FromPath(tmpSrc);
            const string fileName   = @"temp.txt";

            File.WriteText(FilePath.Combine(tmpSrc, fileName), "test");

            var tmpDest = GetNewFileNameOnTempPath("");

            DSCore.IO.Directory.Copy(tmpSrcInfo, tmpDest);
            Assert.IsTrue(DSCore.IO.Directory.Exists(tmpSrc));
            Assert.IsTrue(DSCore.IO.Directory.Exists(tmpDest));

            var destFileName = FilePath.Combine(tmpDest, fileName);

            Assert.IsTrue(File.Exists(destFileName));
            Assert.AreEqual("test", File.ReadText(File.FromPath(destFileName)));
        }
Exemple #20
0
        public void Directory_Move()
        {
            var tmpSrc = GetNewFileNameOnTempPath("");

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

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

            var tmpDest = GetNewFileNameOnTempPath("");

            File.MoveDirectory(tmpSrc, tmpDest);
            Assert.IsFalse(File.DirectoryExists(tmpSrc));
            Assert.IsTrue(File.DirectoryExists(tmpDest));

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

            Assert.IsTrue(File.Exists(destFileName));
            Assert.AreEqual("test", File.ReadText(File.FromPath(destFileName)));
        }
Exemple #21
0
        public void File_FromPath()
        {
            var fn = GetNewFileNameOnTempPath(".txt");

            Assert.AreEqual(new FileInfo(fn).FullName, File.FromPath(fn).FullName);
        }