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"]); }
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)); }
public void Directory_Exists() { var tmp = GetNewFileNameOnTempPath(""); Assert.IsFalse(FileSystem.DirectoryExists(tmp), "Directory hasn't been created yet."); Directory.CreateDirectory(tmp); Assert.IsTrue(FileSystem.DirectoryExists(tmp), "Directory has been created."); }
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, FileSystem.AbsolutePath(relativepath, hintpath)); }
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, FileSystem.AbsolutePath(wspath, hintpath)); }
public void FilePath_FileName() { const string aFilePath = @"hello\there.txt"; Assert.AreEqual(Path.GetFileName(aFilePath), FileSystem.FileName(aFilePath)); Assert.AreEqual( Path.GetFileNameWithoutExtension(aFilePath), FileSystem.FileName(aFilePath, withExtension: false)); }
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)); }
public void File_ReadText() { const string contents = "test"; var fn = GetNewFileNameOnTempPath(".txt"); System.IO.File.WriteAllText(fn, contents); var fnInfo = FileSystem.FileFromPath(fn); Assert.AreEqual(contents, FileSystem.ReadText(fnInfo)); }
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)); FileSystem.DeleteFile(fn); Assert.IsFalse(System.IO.File.Exists(fn)); }
public void Image_ReadFromFile() { foreach (var file in GetTestImageFiles()) { Image.ReadFromFile(FileSystem.FileFromPath(file)); Assert.DoesNotThrow( () => { using (System.IO.File.OpenRead(file)) { } //Check that it's not locked }, "File is locked after being read!"); } }
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, FileSystem.AbsolutePath(relativepath)); SetActiveSession(null); }
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, FileSystem.AbsolutePath(relativepath, hintpath)); SetActiveSession(null); }
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 = FileSystem.FileFromPath(dest); FileSystem.MoveFile(fn, dest); Assert.IsTrue(System.IO.File.Exists(dest)); Assert.IsFalse(System.IO.File.Exists(fn)); Assert.AreEqual(contents, FileSystem.ReadText(destInfo)); }
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); }
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))); }
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"]); }
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)); }
public void File_FromPath() { var fn = GetNewFileNameOnTempPath(".txt"); Assert.AreEqual(new FileInfo(fn).FullName, FileSystem.FileFromPath(fn).FullName); }