Example #1
0
    public void TraversingRootDirectoryWithDotDot_ReturnsSinkDirectory()
    {
        // Arrange
        var directory = ManifestDirectory.CreateRootDirectory(Array.Empty <ManifestEntry>());

        // Act
        var result = directory.Traverse("..");

        // Assert
        Assert.Equal(ManifestEntry.UnknownPath, result);
    }
Example #2
0
    public static EmbeddedFilesManifest Parse(Assembly assembly, string name)
    {
        if (assembly == null)
        {
            throw new ArgumentNullException(nameof(assembly));
        }

        if (name == null)
        {
            throw new ArgumentNullException(nameof(name));
        }

        var stream = assembly.GetManifestResourceStream(name);

        if (stream == null)
        {
            throw new InvalidOperationException($"Could not load the embedded file manifest " +
                                                $"'{name}' for assembly '{assembly.GetName().Name}'.");
        }

        var document = XDocument.Load(stream);

        var manifest        = EnsureElement(document, "Manifest");
        var manifestVersion = EnsureElement(manifest, "ManifestVersion");
        var version         = EnsureText(manifestVersion);

        if (!string.Equals("1.0", version, StringComparison.Ordinal))
        {
            throw new InvalidOperationException($"The embedded file manifest '{name}' for " +
                                                $"assembly '{assembly.GetName().Name}' specifies an unsupported file format" +
                                                $" version: '{version}'.");
        }
        var fileSystem = EnsureElement(manifest, "FileSystem");

        var entries     = fileSystem.Elements();
        var entriesList = new List <ManifestEntry>();

        foreach (var element in entries)
        {
            var entry = BuildEntry(element);
            entriesList.Add(entry);
        }

        ValidateEntries(entriesList);

        var rootDirectory = ManifestDirectory.CreateRootDirectory(entriesList.ToArray());

        return(new EmbeddedFilesManifest(rootDirectory));
    }
Example #3
0
    public void ScopingAFolderAndTryingToGetAScopedFile_ReturnsSinkDirectory()
    {
        // Arrange
        var directory = ManifestDirectory.CreateRootDirectory(new[] {
            ManifestDirectory.CreateDirectory("a",
                                              new[] { new ManifestFile("test1.txt", "text.txt") }),
            ManifestDirectory.CreateDirectory("b",
                                              new[] { new ManifestFile("test2.txt", "test2.txt") })
        });

        var newRoot = ((ManifestDirectory)directory.Traverse("a")).ToRootDirectory();

        // Act
        var result = newRoot.Traverse("../b/test.txt");

        // Assert
        Assert.Same(ManifestEntry.UnknownPath, result);
    }
    public void ResolveEntry_AllowsSingleDirectorySeparator(string path)
    {
        // Arrange
        var manifest = new EmbeddedFilesManifest(
            ManifestDirectory.CreateRootDirectory(
                new[]
        {
            ManifestDirectory.CreateDirectory("wwwroot",
                                              new[]
            {
                new ManifestFile("jquery.validate.js", "wwwroot.jquery.validate.js")
            })
        }));
        // Act
        var entry = manifest.ResolveEntry(path);

        // Assert
        Assert.NotNull(entry);
    }