public void Render_GenericComponent_WithChildContent() { // Arrange AdditionalSyntaxTrees.Add(GenericContextComponent); var component = CompileToComponent(@" <GenericContext TItem=int Items=""@(new List<int>() { 1, 2, })""> <div>@(context.Item * context.Index)</div> </GenericContext>"); // Act var frames = GetRenderTree(component); // Assert var genericComponentType = component.GetType().Assembly.DefinedTypes .Where(t => t.Name == "GenericContext`1") .Single() .MakeGenericType(typeof(int)); Assert.Collection( frames, frame => AssertFrame.Component(frame, genericComponentType.FullName, 3, 0), frame => AssertFrame.Attribute(frame, "Items", typeof(List <int>), 1), frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 2), frame => AssertFrame.MarkupWhitespace(frame, 3), frame => AssertFrame.Element(frame, "div", 2, 4), frame => AssertFrame.Text(frame, "0", 5), frame => AssertFrame.MarkupWhitespace(frame, 6), frame => AssertFrame.MarkupWhitespace(frame, 3), frame => AssertFrame.Element(frame, "div", 2, 4), frame => AssertFrame.Text(frame, "2", 5), frame => AssertFrame.MarkupWhitespace(frame, 6)); }
public void Render_BodyChildContent_Recursive() { // Arrange AdditionalSyntaxTrees.Add(RenderChildContentComponent); var component = CompileToComponent(@" <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, "ChildContent", 1), frame => AssertFrame.MarkupWhitespace(frame, 2), frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 3), frame => AssertFrame.Attribute(frame, "ChildContent", 4), frame => AssertFrame.MarkupWhitespace(frame, 6), frame => AssertFrame.Markup(frame, "\n <div></div>\n ", 5)); }
[Fact] // Additional coverage of OrphanTagHelperLoweringPass public void Render_BindToElementFallback_SpecifiesValueAndChangeEvent_BodyContent() { // Arrange var component = CompileToComponent(@" <div @bind-value=""@ParentValue"" @bind-value:event=""onchange""> <span>@(42.ToString())</span> </div> @code { public int ParentValue { get; set; } = 42; }"); // Act var frames = GetRenderTree(component); // Assert Assert.Collection( frames, frame => AssertFrame.Element(frame, "div", 7, 0), frame => AssertFrame.Attribute(frame, "value", "42", 1), frame => AssertFrame.Attribute(frame, "onchange", typeof(EventCallback), 2), frame => AssertFrame.MarkupWhitespace(frame, 3), frame => AssertFrame.Element(frame, "span", 2, 4), frame => AssertFrame.Text(frame, "42", 5), frame => AssertFrame.MarkupWhitespace(frame, 6)); }
public void SupportsCSharpExpressions() { // Arrange/Act var component = CompileToComponent(@" @(""Hello"") @((object)null) @(123) @(new object()) "); // Assert var frames = GetRenderTree(component); Assert.Collection(frames, frame => AssertFrame.Text(frame, "Hello", 0), frame => AssertFrame.MarkupWhitespace(frame, 1), frame => AssertFrame.TextWhitespace(frame, 2), // @((object)null) frame => AssertFrame.MarkupWhitespace(frame, 3), frame => AssertFrame.Text(frame, "123", 4), frame => AssertFrame.MarkupWhitespace(frame, 5), frame => AssertFrame.Text(frame, new object().ToString(), 6)); }
public void Render_BodyChildContent_Generic() { // Arrange AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); var component = CompileToComponent(@" <RenderChildContentString Value=""HI""> <div>@context.ToLowerInvariant()</div> </RenderChildContentString>"); // Act var frames = GetRenderTree(component); // Assert Assert.Collection( frames, frame => AssertFrame.Component(frame, "Test.RenderChildContentString", 3, 0), frame => AssertFrame.Attribute(frame, "Value", "HI", 1), frame => AssertFrame.Attribute(frame, "ChildContent", 2), frame => AssertFrame.MarkupWhitespace(frame, 3), frame => AssertFrame.Element(frame, "div", 2, 4), frame => AssertFrame.Text(frame, "hi", 5), frame => AssertFrame.MarkupWhitespace(frame, 6)); }
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)); }