public void Parallel_CreateWriteReadFile() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) { System.Threading.Tasks.Parallel.For(PARALLEL_FROM, PARALLEL_TO, (i) => { var fn = FN_PARALLEL_MASK.Args(i); var session = fs.StartSession(); var dir = session[LOCAL_ROOT] as FileSystemDirectory; using (var file = dir.CreateFile(fn)) { file.WriteAllText("Hello, {0}".Args(i)); } using (var file = session[fs.CombinePaths(LOCAL_ROOT, fn)] as FileSystemFile) { Aver.AreEqual("Hello, {0}".Args(i), file.ReadAllText()); file.Delete(); } Aver.IsNull(session[fs.CombinePaths(LOCAL_ROOT, fn)]); });//Parallel.For } }
public void CreateWriteReadFile_1() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) { var session = fs.StartSession(); var dir = session[LOCAL_ROOT] as FileSystemDirectory; using (var file = dir.CreateFile(FN2)) { var str = file.FileStream; var wri = new BinaryWriter(str); wri.Write("Hello!"); wri.Write(true); wri.Write(27.4d); wri.Close(); } using (var file = session[fs.CombinePaths(LOCAL_ROOT, FN2)] as FileSystemFile) { var str = file.FileStream; var rdr = new BinaryReader(str); Aver.AreEqual("Hello!", rdr.ReadString()); Aver.AreEqual(true, rdr.ReadBoolean()); Aver.AreEqual(27.4d, rdr.ReadDouble()); } } }
public void CreateDeleteFile() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) { var session = fs.StartSession(); var dir = session[LOCAL_ROOT] as FileSystemDirectory; var file = dir.CreateFile(FN1, 1500); Aver.AreEqual(FN1, file.Name); Aver.IsTrue(File.Exists(file.Path)); Aver.AreEqual(1500, new FileInfo(file.Path).Length); Aver.AreEqual(1500, file.FileStream.Length); Aver.IsTrue(1500 == file.Size); var file2 = session[fs.CombinePaths(LOCAL_ROOT, FN1)]; Aver.IsNotNull(file2); Aver.IsTrue(file2 is FileSystemFile); Aver.AreEqual(FN1, ((FileSystemFile)file2).Name); file.Dispose(); file2.Delete(); Aver.IsFalse(File.Exists(file2.Path)); } }
public void CreateWriteCopyReadFile() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) { var session = fs.StartSession(); var dir = session[LOCAL_ROOT] as FileSystemDirectory; using (var file = dir.CreateFile(FN2)) { var str = file.FileStream; var wri = new BinaryWriter(str); wri.Write("Hello!"); wri.Write(true); wri.Write(27.4d); wri.Close(); } //FN3 copied from FN2 and made readonly Aver.IsNotNull(dir.CreateFile(FN3, Path.Combine(LOCAL_ROOT, FN2), true)); using (var file = session[fs.CombinePaths(LOCAL_ROOT, FN3)] as FileSystemFile) { Aver.IsTrue(file.ReadOnly); Aver.IsTrue(file.IsReadOnly); var str = file.FileStream; var rdr = new BinaryReader(str); Aver.AreEqual("Hello!", rdr.ReadString()); Aver.AreEqual(true, rdr.ReadBoolean()); Aver.AreEqual(27.4d, rdr.ReadDouble()); file.ReadOnly = false; Aver.IsFalse(file.ReadOnly); Aver.IsFalse(file.IsReadOnly); } } }
public void CreateWriteReadFile_2() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) { var session = fs.StartSession(); var dir = session[LOCAL_ROOT] as FileSystemDirectory; using (var file = dir.CreateFile(FN4)) { file.WriteAllText("This is what it takes!"); } using (var file = session[fs.CombinePaths(LOCAL_ROOT, FN4)] as FileSystemFile) { Aver.AreEqual("This is what it takes!", file.ReadAllText()); } } }
public void CreateWriteReadFile_3() { using (var fs = new LocalFileSystem("L1")) { var session = fs.StartSession(); var dir = session[LOCAL_ROOT] as FileSystemDirectory; using (var file = dir.CreateFile(FN4)) { file.WriteAllText("Hello,"); file.WriteAllText("this will overwrite"); } using (var file = session[fs.CombinePaths(LOCAL_ROOT, FN4)] as FileSystemFile) { Assert.AreEqual("this will overwrite", file.ReadAllText()); } } }
public void CombinePaths() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) { Aver.AreEqual(@"c:\a.txt", fs.CombinePaths(@"c:\", @"a.txt")); Aver.AreEqual(@"c:\a.txt", fs.CombinePaths(@"c:\", @"\a.txt")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books", @"fiction", "saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books", @"\fiction", "saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books", @"\fiction", @"saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books", @"\fiction", @"\saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books", @"fiction", @"\saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books\", @"fiction", "saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books\", @"\fiction", "saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books\", @"\fiction", @"saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books\", @"\fiction", @"\saga.pdf")); Aver.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books\", @"fiction", @"\saga.pdf")); Aver.AreEqual(@"\books\fiction\saga.pdf", fs.CombinePaths("", @"books", @"fiction", @"\saga.pdf")); } }
public void CombinePaths() { using (var fs = new LocalFileSystem("L1")) { Assert.AreEqual(@"c:\a.txt", fs.CombinePaths(@"c:\", @"a.txt")); Assert.AreEqual(@"c:\a.txt", fs.CombinePaths(@"c:\", @"\a.txt")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books", @"fiction", "saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books", @"\fiction", "saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books", @"\fiction", @"saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books", @"\fiction", @"\saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books", @"fiction", @"\saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books\", @"fiction", "saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books\", @"\fiction", "saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books\", @"\fiction", @"saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"\books\", @"\fiction", @"\saga.pdf")); Assert.AreEqual(@"c:\books\fiction\saga.pdf", fs.CombinePaths(@"c:\", @"books\", @"fiction", @"\saga.pdf")); Assert.AreEqual(@"\books\fiction\saga.pdf", fs.CombinePaths("", @"books", @"fiction", @"\saga.pdf")); } }