예제 #1
0
        public void CanEnumerateFilesRecursivelyWithinZipArchives()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    var nested = zip.CreateEntry("archive.zip");
                    using (var nestedZip = new ZipArchive(nested.Open(), ZipArchiveMode.Create))
                    {
                        nestedZip.CreateEntry("nestedA");
                        nestedZip.CreateEntry("nestedB");
                    }
                    zip.CreateEntry("outerA");
                    zip.CreateEntry("outerB");
                }

                using (var buffer = new TemporaryDirectory())
                {
                    var hierarchy = new ZipFileSystemHierarchy(new DirectoryInfo(temporaryDirectory.FullPath), buffer, suppressZipExtensions: false, caseSensitive: false);
                    var matcher   = new GlobMatchEnumerator(new GlobParser().Parse("test*/**/*A"));

                    var results = matcher.EnumerateMatches(hierarchy).ToArray();

                    Assert.That(results, Has.Length.EqualTo(2));
                    Assert.That(results.Select(r => r.Item.Exists), Has.All.True);
                }
            }
        }
예제 #2
0
        public void SuppressedZipExtensionsAreNotMatched()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    var nested = zip.CreateEntry("archive.zip");
                    using (var nestedZip = new ZipArchive(nested.Open(), ZipArchiveMode.Create))
                    {
                        nestedZip.CreateEntry("nestedA");
                        nestedZip.CreateEntry("nestedB");
                    }
                    zip.CreateEntry("outerA");
                    zip.CreateEntry("outerB");
                }

                using (var buffer = new TemporaryDirectory())
                {
                    var hierarchy = new ZipFileSystemHierarchy(new DirectoryInfo(temporaryDirectory.FullPath), buffer, suppressZipExtensions: true, caseSensitive: false);
                    var matcher   = new GlobMatchEnumerator(new GlobParser().Parse("test*/*.zip/*A"));

                    var results = matcher.EnumerateMatches(hierarchy).ToArray();

                    Assert.That(results, Is.Empty);
                }
            }
        }
예제 #3
0
        public void CanUseZipFileAsHierarchyRoot()
        {
            using (var temporaryDirectory = new TemporaryDirectory())
            {
                using (var zip = new ZipArchive(File.OpenWrite(temporaryDirectory.GetPath("test.zip")), ZipArchiveMode.Create))
                {
                    var nested = zip.CreateEntry("inside/archive.zip");
                    using (var nestedZip = new ZipArchive(nested.Open(), ZipArchiveMode.Create))
                    {
                        nestedZip.CreateEntry("directory/nestedFile.txt");
                    }
                }

                using (var buffer = new TemporaryDirectory())
                {
                    var hierarchy = new ZipFileSystemHierarchy(new FileInfo(temporaryDirectory.GetPath("test.zip")), buffer, suppressZipExtensions: false, caseSensitive: false);
                    var matcher   = new GlobMatchEnumerator(new GlobParser().Parse("**/*.txt"));

                    var results = matcher.EnumerateMatches(hierarchy).ToArray();

                    Assume.That(results, Has.Length.EqualTo(1));
                    Assert.That(results.Single().Details.GetPathSegments(), Is.EqualTo(new [] { "inside", "archive.zip", "directory", "nestedFile.txt" }));
                }
            }
        }