public void Requesting_Files_With_Search_Pattern_Should_Return_Matches_Only()
        {
            var results = testFolder.GetFiles("foo*").Select(f => f.MetaData);

            CheckResults(results, "foo.txt", "foobar.txt");

            results = testFolder.GetFiles("*bar.txt").Select(f => f.MetaData);
            CheckResults(results, "bar.txt", "foobar.txt");

            results = testFolder.GetFiles("*.t?t").Select(f => f.MetaData);
            CheckResults(results, testFolder.GetFiles("*.t?t").Select(fi => fi.MetaData.Name).ToArray());
        }
Пример #2
0
        public void WriteRootFolders()
        {
            VirtualFolder root = VirtualFolder.CreateRootFolder(Facade);

            foreach (var fileInfo in root.GetFiles("*.txt"))
            {
                var token = Facade.DownloadTransfers.RequestDownloadToken(fileInfo.MetaData.FullName, false);

                Func <long, StreamedDataBlock> func = n =>
                {
                    var db = Facade.DownloadTransfers.ReadBlockStreamed(token.TransferId, n);
                    return(db);
                };

                using (var s = new StreamedBlockInputStream(func, token.ResourceLength))
                {
                    StreamReader reader = new StreamReader(s);
                    var          text   = reader.ReadToEnd();
                    Console.Out.WriteLine("Read text:\n" + text);
                    Console.Out.WriteLine("");
                }


//        using(var stream = Facade.DownloadTransfers.ReadFile(fileInfo.MetaData.FullName))
//        {
//          StreamReader reader = new StreamReader(stream);
//          var text = reader.ReadToEnd();
//
//        }
            }
        }
Пример #3
0
    public void Overwriting_File_Without_Request_Should_Be_Blocked()
    {
      VirtualFile file;

      FileInfo sourceFile = rootDirectory.GetFiles().First();
      using (Stream stream = sourceFile.OpenRead())
      {
        file = root.AddFile("foobar.bin", stream, false, sourceFile.Length, ContentUtil.UnknownContentType);
        Assert.AreEqual("foobar.bin", file.MetaData.Name);
      }

      VirtualFileInfo original = file.MetaData;

      //overwrite file - this will not happen
      sourceFile = rootDirectory.GetFiles().Last();
      using (Stream stream = sourceFile.OpenRead())
      {
        try
        {
          root.AddFile("foobar.bin", stream, false, sourceFile.Length, ContentUtil.UnknownContentType);
          Assert.Fail("Could overwrite file.");
        }
        catch (ResourceOverwriteException e)
        {
          StringAssert.Contains("foobar.bin", e.Message);
        }
      }

      //make sure nothing changed
      var update = root.GetFiles("foobar.bin").Single();
      Assert.AreEqual(original.Length, update.MetaData.Length);
      Assert.AreEqual(original.LastWriteTime, update.MetaData.LastWriteTime);
    }
Пример #4
0
        public void Folders_Should_Indicate_Whether_They_Are_Empty_Or_Not()
        {
            VirtualFolder r       = VirtualFolder.CreateRootFolder(provider);
            var           folders = r.GetFolders();
            var           files   = r.GetFiles();

            bool testedEmpty     = false;
            bool testedPopulated = false;

            folders.Do(f =>
            {
                bool empty = f.GetFiles().Count() == 0 && f.GetFolders().Count() == 0;
                if (empty)
                {
                    testedEmpty = true;
                }
                else
                {
                    testedPopulated = true;
                }

                Assert.AreEqual(empty, f.MetaData.IsEmpty);
                files.First().Copy(provider.CreateFilePath(f.MetaData.FullName, "test.txt"));
                f.RefreshMetaData();
                Assert.IsFalse(f.MetaData.IsEmpty);
            });

            Assert.IsTrue(testedEmpty);
            Assert.IsTrue(testedPopulated);
        }
Пример #5
0
        public void Copied_Files_Should_Be_Equal()
        {
            var target     = source.Copy(targetPath);
            var sourceFile = source.GetFiles().First().MetaData.FullName;
            var targetFile = target.GetFiles().First().MetaData.FullName;

            var sourceToken = FileSystem.DownloadTransfers.RequestDownloadToken(sourceFile, true);
            var targetToken = FileSystem.DownloadTransfers.RequestDownloadToken(targetFile, true);

            FileSystem.DownloadTransfers.CancelTransfer(sourceToken.TransferId, AbortReason.ClientAbort);
            FileSystem.DownloadTransfers.CancelTransfer(targetToken.TransferId, AbortReason.ClientAbort);

            Assert.AreEqual(sourceToken.Md5FileHash, targetToken.Md5FileHash);
        }
Пример #6
0
        public void Querying_Files_Should_Return_Contents()
        {
            var files = testFolder.GetFiles()
                        .OrderBy(f => f.MetaData.Name)
                        .ToList();

            Assert.AreEqual(4, files.Count);

            Assert.AreEqual("file0.doc", files[0].MetaData.Name);
            Assert.AreEqual("file0.txt", files[1].MetaData.Name);
            Assert.AreEqual("file1.doc", files[2].MetaData.Name);
            Assert.AreEqual("file1.txt", files[3].MetaData.Name);

            files.Do(vf => Assert.AreEqual(testFolder.MetaData.FullName, vf.MetaData.ParentFolderPath));
        }
        public void Moved_Files_Should_Be_Equal()
        {
            //get download token for source file
            var sourceFile  = source.GetFiles().First().MetaData.FullName;
            var sourceToken = FileSystem.DownloadTransfers.RequestDownloadToken(sourceFile, true);

            FileSystem.DownloadTransfers.CancelTransfer(sourceToken.TransferId, AbortReason.ClientAbort);

            source.Move(targetPath);
            var target = VirtualFolder.Create(FileSystem, targetPath);

            //get download token for moved file
            var targetFile  = target.GetFiles().First().MetaData.FullName;
            var targetToken = FileSystem.DownloadTransfers.RequestDownloadToken(targetFile, true);

            FileSystem.DownloadTransfers.CancelTransfer(targetToken.TransferId, AbortReason.ClientAbort);

            Assert.AreEqual(sourceToken.Md5FileHash, targetToken.Md5FileHash);
        }
    private void BrowseFolder(VirtualFolder parentFolder, DirectoryInfo parentDir)
    {
      var contents = parentFolder.GetFolderContents();
      var folders = parentFolder.GetFolders();
      var files = parentFolder.GetFiles();

      Assert.AreEqual(contents.Folders.Count(), folders.Count());
      Assert.AreEqual(contents.Files.Count(), files.Count());


      Assert.AreEqual(parentDir.GetDirectories().Count(), contents.Folders.Count());
      Assert.AreEqual(parentDir.GetFiles().Count(), contents.Files.Count());

      foreach (var file in files)
      {
        //make sure contents matches the files collection
        VirtualFile virtualFile = file;
        Assert.AreEqual(contents.Files.Single(f => f.MetaData.FullName == virtualFile.MetaData.FullName).MetaData.Length, file.MetaData.Length);

        FileInfo fi = parentDir.GetFiles(file.MetaData.Name).Single();
        Assert.AreEqual(file.MetaData.Length, fi.Length);
      }

      foreach (var folder in contents.Folders)
      {
        //make sure contents matches the folders collection
        VirtualFolder virtualFolder = folder;
        Assert.AreEqual(contents.Folders.Single(f => f.MetaData.FullName == virtualFolder.MetaData.FullName).MetaData.Name, folder.MetaData.Name);


        DirectoryInfo dir = parentDir.GetDirectories(folder.MetaData.Name).Single();
        Assert.True(dir.Exists);

        //browse recursively
        BrowseFolder(folder, dir);
      }
    }
        private void BrowseFolder(VirtualFolder parentFolder, DirectoryInfo parentDir)
        {
            var contents = parentFolder.GetFolderContents();
            var folders  = parentFolder.GetFolders();
            var files    = parentFolder.GetFiles();

            Assert.AreEqual(contents.Folders.Count(), folders.Count());
            Assert.AreEqual(contents.Files.Count(), files.Count());


            Assert.AreEqual(parentDir.GetDirectories().Count(), contents.Folders.Count());
            Assert.AreEqual(parentDir.GetFiles().Count(), contents.Files.Count());

            foreach (var file in files)
            {
                //make sure contents matches the files collection
                VirtualFile virtualFile = file;
                Assert.AreEqual(contents.Files.Single(f => f.MetaData.FullName == virtualFile.MetaData.FullName).MetaData.Length, file.MetaData.Length);

                FileInfo fi = parentDir.GetFiles(file.MetaData.Name).Single();
                Assert.AreEqual(file.MetaData.Length, fi.Length);
            }

            foreach (var folder in contents.Folders)
            {
                //make sure contents matches the folders collection
                VirtualFolder virtualFolder = folder;
                Assert.AreEqual(contents.Folders.Single(f => f.MetaData.FullName == virtualFolder.MetaData.FullName).MetaData.Name, folder.MetaData.Name);


                DirectoryInfo dir = parentDir.GetDirectories(folder.MetaData.Name).Single();
                Assert.True(dir.Exists);

                //browse recursively
                BrowseFolder(folder, dir);
            }
        }