public async Task ExtractZipJobQueue_Test()
        {
            var    fs   = new PhysicalFileSystem();
            var    temp = Path.GetTempPath();
            string test = Path.GetRandomFileName();
            var    pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var    dir  = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/"));

            var    dirToCopy    = new DirectoryInfo(temp).CreateSubdirectory(Path.GetRandomFileName());
            var    subDirToCopy = dirToCopy.CreateSubdirectory(Path.GetRandomFileName());
            string fileName;

            using (var file = System.IO.File.Create(Path.Combine(subDirToCopy.FullName, Path.GetRandomFileName())))
            {
                fileName = Path.GetFileName(file.Name);
                await file.WriteAsync(Data, 0, Data.Length);
            }

            var subSubDirToCopy = subDirToCopy
                                  .CreateSubdirectory(Path.GetRandomFileName());

            string zipFile = Path.GetTempFileName();

            System.IO.File.Delete(zipFile); // hack to get around file existing.
            ZipFile.CreateFromDirectory(dirToCopy.FullName, zipFile, CompressionLevel.Fastest, true);

            var tq    = new AsyncJobQueue <TaskResult <IFile> >();
            var token = await tq.QueueJob(EmitZipResult(zipFile, dir));

            await foreach (var res in tq.AsEnumerable(token))
            {
                var val = await res;
                if (res.Error != null)
                {
                    throw res.Error.InnerException;
                }
            }


            Assert.True(dir.ContainsDirectory(dirToCopy.Name), "Did not extract parent successfully");
            Assert.True(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully");
            using (var file = dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).OpenFile(fileName).OpenStream()) {
                Assert.Equal(Data.Length, file.Length);
            }
            Assert.True(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsDirectory(subSubDirToCopy.Name), "Did not copy nested folder successfully");

            dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).OpenFile(fileName).Delete();
            Assert.False(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not cleanup file successfully");

            try
            {
                // nothing to do with tests here if this fails
                System.IO.File.Delete(zipFile);
            } catch
            {
            }
        }
示例#2
0
        public async Task CopyDirectoryJobQueue_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var    dirToCopy    = new DirectoryInfo(temp).CreateSubdirectory(Path.GetRandomFileName());
            var    subDirToCopy = dirToCopy.CreateSubdirectory(Path.GetRandomFileName());
            string fileName;

            using (var file = System.IO.File.Create(Path.Combine(subDirToCopy.FullName, Path.GetRandomFileName())))
            {
                fileName = Path.GetFileName(file.Name);
                await file.WriteAsync(Data, 0, Data.Length);

                file.Close();
            }

            var subSubDirToCopy = subDirToCopy
                                  .CreateSubdirectory(Path.GetRandomFileName());

            var tq    = new AsyncJobQueue <TaskResult <IFile> >();
            var token = await tq.QueueJob(EmitCopyDirResult(dirToCopy, dir));

            await foreach (var x in  tq.AsEnumerable(token))
            {
            }

            Assert.True(dir.ContainsDirectory(subDirToCopy.Name), "Did not copy parent successfully");
            Assert.True(dir.OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully");

            using (var file = dir.OpenDirectory(subDirToCopy.Name).OpenFile(fileName).OpenStream())
            {
                Assert.Equal(Data.Length, file.Length);
            }

            Assert.True(dir.OpenDirectory(subDirToCopy.Name).ContainsDirectory(subSubDirToCopy.Name), "Did not copy nested folder successfully");

            dir.OpenDirectory(subDirToCopy.Name).OpenFile(fileName).Delete();
            Assert.False(dir.OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully");
        }
示例#3
0
        public async Task CopyDirectory_Test()
        {
            var fs = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/"));

            var dirToCopy = new DirectoryInfo(temp).CreateSubdirectory(Path.GetRandomFileName());
            var subDirToCopy = dirToCopy.CreateSubdirectory(Path.GetRandomFileName());
            string fileName;
            using (var file = System.IO.File.Create(Path.Combine(subDirToCopy.FullName, Path.GetRandomFileName())))
            {
                fileName = Path.GetFileName(file.Name);
                await file.WriteAsync(Data, 0, Data.Length);
                file.Close();
            }

            var subSubDirToCopy = subDirToCopy
                .CreateSubdirectory(Path.GetRandomFileName());

            // Execute the results.
            await foreach (var res in EmitCopyDirResult(dirToCopy, dir))
            {
                Assert.Equal(await res.Description, $"Copied {(await res).Name} to directory {dir.Name}");
                Assert.Equal(await res.Description, $"Copied {(await res).Name} to directory {dir.Name}");
            }

            Assert.True(dir.ContainsDirectory(subDirToCopy.Name), "Did not copy parent successfully");
            Assert.True(dir.OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully");

            using (var file = dir.OpenDirectory(subDirToCopy.Name).OpenFile(fileName).OpenStream())
            {
                Assert.Equal(Data.Length, file.Length);
            }

            Assert.True(dir.OpenDirectory(subDirToCopy.Name).ContainsDirectory(subSubDirToCopy.Name), "Did not copy nested folder successfully");

            dir.OpenDirectory(subDirToCopy.Name).OpenFile(fileName).Delete();
            Assert.False(dir.OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully");

        }