コード例 #1
0
    public void WriteCSharpExpressionAttributeValue_RendersCorrectly()
    {
        var writer         = new TagHelperHtmlAttributeRuntimeNodeWriter();
        var content        = "<input checked=\"hello-world @false\" />";
        var sourceDocument = TestRazorSourceDocument.Create(content);
        var codeDocument   = RazorCodeDocument.Create(sourceDocument);
        var documentNode   = Lower(codeDocument);
        var node           = documentNode.Children.OfType <HtmlAttributeIntermediateNode>().Single().Children[1] as CSharpExpressionAttributeValueIntermediateNode;

        var context = TestCodeRenderingContext.CreateRuntime();

        // Act
        writer.WriteCSharpExpressionAttributeValue(context, node);

        // Assert
        var csharp = context.CodeWriter.GenerateCode();

        Assert.Equal(
            @"
#nullable restore
#line (1,28)-(1,35) 31 ""test.cshtml""
AddHtmlAttributeValue("" "", 27, false, 28, 6, false);

#line default
#line hidden
#nullable disable
",
            csharp,
            ignoreLineEndingDifferences: true);
    }
コード例 #2
0
    public void WriteCSharpCodeAttributeValue_BuffersResult()
    {
        var writer = new TagHelperHtmlAttributeRuntimeNodeWriter();

        var content        = "<input checked=\"hello-world @if(@true){ }\" />";
        var sourceDocument = TestRazorSourceDocument.Create(content);
        var codeDocument   = RazorCodeDocument.Create(sourceDocument);
        var documentNode   = Lower(codeDocument);
        var node           = documentNode.Children.OfType <HtmlAttributeIntermediateNode>().Single().Children[1] as CSharpCodeAttributeValueIntermediateNode;

        var context = TestCodeRenderingContext.CreateRuntime(source: sourceDocument);

        // Act
        writer.WriteCSharpCodeAttributeValue(context, node);

        // Assert
        var csharp = context.CodeWriter.GenerateCode();

        Assert.Equal(
            @"AddHtmlAttributeValue("" "", 27, new Microsoft.AspNetCore.Mvc.Razor.HelperResult(async(__razor_attribute_value_writer) => {
    PushWriter(__razor_attribute_value_writer);
#nullable restore
#line 1 ""test.cshtml""
                             if(@true){ }

#line default
#line hidden
#nullable disable
    PopWriter();
}
), 28, 13, false);
",
            csharp,
            ignoreLineEndingDifferences: true);
    }
コード例 #3
0
    public void WriteHtmlAttributeValue_RendersCorrectly()
    {
        var writer = new TagHelperHtmlAttributeRuntimeNodeWriter();

        var content        = "<input checked=\"hello-world @false\" />";
        var sourceDocument = TestRazorSourceDocument.Create(content);
        var codeDocument   = RazorCodeDocument.Create(sourceDocument);
        var documentNode   = Lower(codeDocument);
        var node           = documentNode.Children.OfType <HtmlAttributeIntermediateNode>().Single().Children[0] as HtmlAttributeValueIntermediateNode;

        var context = TestCodeRenderingContext.CreateRuntime();

        // Act
        writer.WriteHtmlAttributeValue(context, node);

        // Assert
        var csharp = context.CodeWriter.GenerateCode();

        Assert.Equal(
            @"AddHtmlAttributeValue("""", 16, ""hello-world"", 16, 11, true);
",
            csharp,
            ignoreLineEndingDifferences: true);
    }