コード例 #1
0
    private static void ValidatePrerenderedContents_of_BlazorWasmApp0(string wwwrootDir, string homeTitle = "Home", string environment = "Prerendering", OutputStyle outputStyle = OutputStyle.AppendHtmlExtension)
    {
        var rootIndexHtmlPath  = Path.Combine(wwwrootDir, "index.html");
        var aboutIndexHtmlPath = outputStyle == OutputStyle.AppendHtmlExtension ?
                                 Path.Combine(wwwrootDir, "about.html") :
                                 Path.Combine(wwwrootDir, "about", "index.html");

        File.Exists(rootIndexHtmlPath).IsTrue();
        File.Exists(aboutIndexHtmlPath).IsTrue();

        var htmlParser = new HtmlParser();

        using var rootIndexHtml  = htmlParser.ParseDocument(File.ReadAllText(rootIndexHtmlPath));
        using var aboutIndexHtml = htmlParser.ParseDocument(File.ReadAllText(aboutIndexHtmlPath));

        // NOTICE: The document title was rendered by the <HeadOutlet> component of .NET 6.
        rootIndexHtml.Title.Is($"{homeTitle} | Blazor Wasm App 0");
        aboutIndexHtml.Title.Is("About | Blazor Wasm App 0");

        rootIndexHtml.QuerySelector("h1") !.TextContent.Is(homeTitle);
        aboutIndexHtml.QuerySelector("h1") !.TextContent.Is("About");

        rootIndexHtml.QuerySelector("a") !.TextContent.Is("about");
        (rootIndexHtml.QuerySelector("a") as IHtmlAnchorElement) !.Href.Is("about:///about");
        aboutIndexHtml.QuerySelector("a") !.TextContent.Is("home");
        (aboutIndexHtml.QuerySelector("a") as IHtmlAnchorElement) !.Href.Is("about:///");

        rootIndexHtml.QuerySelector(".environment") !.TextContent.Trim().Is($"Environment: {environment}");
    }