Exemplo n.º 1
0
        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"));
            }
        }
Exemplo n.º 2
0
        public void Parallel_CreateWriteReadFile()
        {
            using(var fs = new LocalFileSystem("L1"))
            {
              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)
                    {
                      Assert.AreEqual( "Hello, {0}".Args(i), file.ReadAllText());
                      file.Delete();
                    }
                    Assert.IsNull( session[fs.CombinePaths(LOCAL_ROOT, fn)] );

               });//Parallel.For

            }
        }
Exemplo n.º 3
0
        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());
              }
            }
        }
Exemplo n.º 4
0
        public void CreateWriteReadFile_1()
        {
            using(var fs = new LocalFileSystem("L1"))
            {

              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);

                Assert.AreEqual( "Hello!", rdr.ReadString());
                Assert.AreEqual( true,     rdr.ReadBoolean());
                Assert.AreEqual( 27.4d,    rdr.ReadDouble());
              }
            }
        }
Exemplo n.º 5
0
        public void CreateWriteCopyReadFile()
        {
            using(var fs = new LocalFileSystem("L1"))
            {
              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
              Assert.IsNotNull( dir.CreateFile(FN3, Path.Combine(LOCAL_ROOT, FN2), true) );

              using (var file = session[fs.CombinePaths(LOCAL_ROOT, FN3)] as FileSystemFile)
              {
                Assert.IsTrue( file.ReadOnly);
                Assert.IsTrue( file.IsReadOnly);

                var str = file.FileStream;

                var rdr = new BinaryReader(str);

                Assert.AreEqual( "Hello!", rdr.ReadString());
                Assert.AreEqual( true,     rdr.ReadBoolean());
                Assert.AreEqual( 27.4d,    rdr.ReadDouble());

                file.ReadOnly = false;

                Assert.IsFalse( file.ReadOnly);
                Assert.IsFalse( file.IsReadOnly);

              }
            }
        }
Exemplo n.º 6
0
        public void CreateDeleteFile()
        {
            using(var fs = new LocalFileSystem("L1"))
            {

              var session = fs.StartSession();

              var dir = session[LOCAL_ROOT] as FileSystemDirectory;

              var file = dir.CreateFile(FN1, 1500);

              Assert.AreEqual(FN1, file.Name);

              Assert.IsTrue( File.Exists(file.Path));
              Assert.AreEqual(1500, new FileInfo(file.Path).Length);
              Assert.AreEqual(1500, file.FileStream.Length);

              Assert.AreEqual(1500, file.Size);

              var file2 = session[fs.CombinePaths(LOCAL_ROOT, FN1)];
              Assert.IsNotNull( file2);
              Assert.IsTrue(file2 is FileSystemFile);
              Assert.AreEqual(FN1, ((FileSystemFile)file2).Name);

              file.Dispose();

              file2.Delete();
              Assert.IsFalse( File.Exists(file2.Path));
            }
        }