public void Render_BodyChildContent_Recursive()
        {
            // Arrange
            AdditionalSyntaxTrees.Add(RenderChildContentComponent);

            var component = CompileToComponent(@"
@addTagHelper *, TestAssembly
<RenderChildContent>
  <RenderChildContent>
    <div></div>
  </RenderChildContent>
</RenderChildContent>");

            // Act
            var frames = GetRenderTree(component);

            // Assert
            Assert.Collection(
                frames,
                frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0),
                frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1),
                frame => AssertFrame.Whitespace(frame, 2),
                frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 3),
                frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 4),
                frame => AssertFrame.Whitespace(frame, 6),
                frame => AssertFrame.Markup(frame, "\n    <div></div>\n  ", 5));
        }
        public void SupportsElementsAsStaticBlock()
        {
            // Arrange/Act
            var component = CompileToComponent("<myelem>Hello</myelem>");

            // Assert
            Assert.Collection(GetRenderTree(component),
                              frame => AssertFrame.Markup(frame, "<myelem>Hello</myelem>", 0));
        }
        public void SupportsVoidHtmlElements()
        {
            // Arrange/Act
            var component = CompileToComponent("Some text so elem isn't at position 0 <img>");

            // Assert
            Assert.Collection(
                GetRenderTree(component),
                frame => AssertFrame.Markup(frame, "Some text so elem isn't at position 0 <img>", 0));
        }
        public void SupportsSelfClosingElementsAsStaticBlock()
        {
            // Arrange/Act
            var component = CompileToComponent("Some text so elem isn't at position 0 <input attr='123' />");

            // Assert
            Assert.Collection(
                GetRenderTree(component),
                frame => AssertFrame.Markup(frame, "Some text so elem isn't at position 0 <input attr=\"123\">", 0));
        }
        public void SupportsComments()
        {
            // Arrange/Act
            var component = CompileToComponent("Start<!-- My comment -->End");
            var frames    = GetRenderTree(component);

            // Assert
            Assert.Collection(
                frames,
                frame => AssertFrame.Markup(frame, "StartEnd", 0));
        }
        public void RendersMarkupStringAsMarkupFrame()
        {
            // Arrange/Act
            var component = CompileToComponent(
                "@{ var someMarkup = new MarkupString(\"<div>Hello</div>\"); }"
                + "<p>@someMarkup</p>");

            // Assert
            Assert.Collection(GetRenderTree(component),
                              frame => AssertFrame.Element(frame, "p", 2, 0),
                              frame => AssertFrame.Markup(frame, "<div>Hello</div>", 1));
        }
Example #7
0
        public void Render_Component_HtmlBlockEncoded()
        {
            // Arrange
            var component = CompileToComponent(@"<div>&lt;span&gt;Hi&lt/span&gt;</div>");

            // Act
            var frames = GetRenderTree(component);

            // Assert
            Assert.Collection(
                frames,
                frame => AssertFrame.Markup(frame, "<div>&lt;span&gt;Hi&lt/span&gt;</div>"));
        }
        [Fact] // In this case, onclick is just a normal HTML attribute
        public void SupportsEventHandlerWithString()
        {
            // Arrange
            var component = CompileToComponent(@"
<button onclick=""function(){console.log('hello');};"" />");

            // Act
            var frames = GetRenderTree(component);

            // Assert
            Assert.Collection(frames,
                              frame => AssertFrame.Markup(frame, "<button onclick=\"function(){console.log('hello');};\"></button>", 0));
        }
Example #9
0
        public void CanAddNullMarkup()
        {
            // Arrange
            var builder = new RenderTreeBuilder(new TestRenderer());

            // Act
            builder.AddMarkupContent(0, null);

            // Assert
            var frames = builder.GetFrames();

            Assert.Collection(frames,
                              frame => AssertFrame.Markup(frame, string.Empty));
        }
Example #10
0
        public void CanAddMarkupViaMarkupString()
        {
            // This represents putting @someMarkupString into the component,
            // as opposed to calling builder.AddMarkupContent directly.

            // Arrange
            var builder = new RenderTreeBuilder(new TestRenderer());

            // Act - can use either constructor or cast
            builder.AddContent(0, (MarkupString)"Some markup");
            builder.AddContent(1, new MarkupString(null));

            // Assert
            var frames = builder.GetFrames();

            Assert.Collection(frames,
                              frame => AssertFrame.Markup(frame, "Some markup"),
                              frame => AssertFrame.Markup(frame, string.Empty));
        }
Example #11
0
        public void CanAddMarkup()
        {
            // Arrange
            var builder = new RenderTreeBuilder(new TestRenderer());

            // Act
            builder.OpenElement(0, "some elem");
            builder.AddMarkupContent(1, "Blah");
            builder.AddMarkupContent(2, string.Empty);
            builder.CloseElement();

            // Assert
            var frames = builder.GetFrames();

            Assert.Collection(frames,
                              frame => AssertFrame.Element(frame, "some elem", 3),
                              frame => AssertFrame.Markup(frame, "Blah"),
                              frame => AssertFrame.Markup(frame, string.Empty));
        }
Example #12
0
        public void Render_BodyChildContent()
        {
            // Arrange
            AdditionalSyntaxTrees.Add(RenderChildContentComponent);

            var component = CompileToComponent(@"
<RenderChildContent>
  <div></div>
</RenderChildContent>");

            // Act
            var frames = GetRenderTree(component);

            // Assert
            Assert.Collection(
                frames,
                frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0),
                frame => AssertFrame.Attribute(frame, "ChildContent", 1),
                frame => AssertFrame.Markup(frame, "\n  <div></div>\n", 2));
        }
        public void CreatesSeparateMarkupFrameForEachTopLevelStaticElement()
        {
            // The JavaScript-side rendering code does not rely on this behavior. It supports
            // inserting markup frames with arbitrary markup (e.g., multiple top-level elements
            // or none). This test exists only as an observation of the current behavior rather
            // than a promise that we never want to change it.

            // Arrange/Act
            var component = CompileToComponent(
                "<root>@(\"Hi\") <child1>a</child1> <child2><another>b</another></child2> </root>");

            // Assert
            Assert.Collection(GetRenderTree(component),
                              frame => AssertFrame.Element(frame, "root", 7, 0),
                              frame => AssertFrame.Text(frame, "Hi", 1),
                              frame => AssertFrame.Text(frame, " ", 2),
                              frame => AssertFrame.Markup(frame, "<child1>a</child1>", 3),
                              frame => AssertFrame.Text(frame, " ", 4),
                              frame => AssertFrame.Markup(frame, "<child2><another>b</another></child2>", 5),
                              frame => AssertFrame.Text(frame, " ", 6));
        }
Example #14
0
        public void Render_HtmlBlock_Integration()
        {
            // Arrange
            AdditionalSyntaxTrees.Add(Parse(@"
using Microsoft.AspNetCore.Components;
namespace Test
{
    public class MyComponent : ComponentBase
    {
        [Parameter]
        public RenderFragment ChildContent { get; set; }
    }
}
"));

            var component = CompileToComponent(@"
<html>
  <head><meta><meta></head>
  <body>
    <MyComponent>
      <div><span></span><span></span></div>
      <div>@(""hi"")</div>
      <div><span></span><span></span></div>
      <div></div>
      <div>@(""hi"")</div>
      <div></div>
  </MyComponent>
  </body>
</html>");

            // Act
            var frames = GetRenderTree(component);

            // Assert: component frames are correct
            Assert.Collection(
                frames,
                frame => AssertFrame.Element(frame, "html", 9, 0),
                frame => AssertFrame.MarkupWhitespace(frame, 1),
                frame => AssertFrame.Markup(frame, "<head><meta><meta></head>\n  ", 2),
                frame => AssertFrame.Element(frame, "body", 5, 3),
                frame => AssertFrame.MarkupWhitespace(frame, 4),
                frame => AssertFrame.Component(frame, "Test.MyComponent", 2, 5),
                frame => AssertFrame.Attribute(frame, "ChildContent", 6),
                frame => AssertFrame.MarkupWhitespace(frame, 16),
                frame => AssertFrame.MarkupWhitespace(frame, 17));

            // Assert: Captured ChildContent frames are correct
            var childFrames = GetFrames((RenderFragment)frames[6].AttributeValue);

            Assert.Collection(
                childFrames.AsEnumerable(),
                frame => AssertFrame.MarkupWhitespace(frame, 7),
                frame => AssertFrame.Markup(frame, "<div><span></span><span></span></div>\n      ", 8),
                frame => AssertFrame.Element(frame, "div", 2, 9),
                frame => AssertFrame.Text(frame, "hi", 10),
                frame => AssertFrame.MarkupWhitespace(frame, 11),
                frame => AssertFrame.Markup(frame, "<div><span></span><span></span></div>\n      <div></div>\n      ", 12),
                frame => AssertFrame.Element(frame, "div", 2, 13),
                frame => AssertFrame.Text(frame, "hi", 14),
                frame => AssertFrame.Markup(frame, "\n      <div></div>\n  ", 15));
        }