public void CanAddRegions() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); // Act builder.OpenElement(10, "parent"); // 0: <parent> builder.OpenRegion(11); // 1: [region builder.AddText(3, "Hello"); // 2: Hello builder.OpenRegion(4); // 3: [region builder.OpenElement(3, "another"); // 4: <another> builder.CloseElement(); // </another> builder.CloseRegion(); // ] builder.AddText(6, "Goodbye"); // 5: Goodbye builder.CloseRegion(); // ] builder.CloseElement(); // </parent> // Assert Assert.Collection(builder.GetFrames(), frame => AssertFrame.Element(frame, "parent", 6, 10), frame => AssertFrame.Region(frame, 5, 11), frame => AssertFrame.Text(frame, "Hello", 3), frame => AssertFrame.Region(frame, 2, 4), frame => AssertFrame.Element(frame, "another", 1, 3), frame => AssertFrame.Text(frame, "Goodbye", 6)); }
public void CanClear() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); // Act builder.AddText(0, "some text"); builder.OpenElement(1, "elem"); builder.AddText(2, "more text"); builder.CloseElement(); builder.Clear(); // Assert Assert.Empty(builder.GetFrames()); }
public void CanAddAttributes() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); UIEventHandler eventHandler = eventInfo => { }; // Act builder.OpenElement(0, "myelement"); // 0: <myelement builder.AddAttribute(0, "attribute1", "value 1"); // 1: attribute1="value 1" builder.AddAttribute(0, "attribute2", 123); // 2: attribute2=intExpression123> builder.OpenElement(0, "child"); // 3: <child builder.AddAttribute(0, "childevent", eventHandler); // 4: childevent=eventHandler> builder.AddText(0, "some text"); // 5: some text builder.CloseElement(); // </child> builder.CloseElement(); // </myelement> // Assert Assert.Collection(builder.GetFrames(), frame => AssertFrame.Element(frame, "myelement", 6), frame => AssertFrame.Attribute(frame, "attribute1", "value 1"), frame => AssertFrame.Attribute(frame, "attribute2", "123"), frame => AssertFrame.Element(frame, "child", 3), frame => AssertFrame.Attribute(frame, "childevent", eventHandler), frame => AssertFrame.Text(frame, "some text")); }
public void CanAddNonStringValueAsText() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); var nullObject = (object)null; // Act builder.AddText(0, 1234); builder.AddText(0, nullObject); // Assert var frames = builder.GetFrames(); Assert.Collection(frames, frame => AssertFrame.Text(frame, "1234"), frame => AssertFrame.Text(frame, string.Empty)); }
public void ClosedElementsHaveCorrectSubtreeLength() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); // Act builder.OpenElement(0, "my element"); builder.AddText(0, "child 1"); builder.AddText(0, "child 2"); builder.CloseElement(); builder.AddText(0, "unrelated item"); // Assert var frames = builder.GetFrames(); Assert.Equal(4, frames.Count); AssertFrame.Element(frames.Array[0], "my element", 3); }
public void BuildRenderTree(RenderTreeBuilder builder) { builder.OpenElement(0, "h1"); builder.AddText(1, "Hello from RenderTree"); builder.CloseElement(); builder.OpenElement(2, "ul"); builder.OpenElement(3, "li"); builder.AddText(4, "First item"); builder.CloseElement(); builder.OpenElement(5, "li"); builder.AddText(6, "Second item"); builder.CloseElement(); builder.CloseElement(); }
public void CanAddText() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); var nullString = (string)null; // Act builder.AddText(0, "First item"); builder.AddText(0, nullString); builder.AddText(0, "Second item"); // Assert var frames = builder.GetFrames(); Assert.Collection(frames, frame => AssertFrame.Text(frame, "First item"), frame => AssertFrame.Text(frame, string.Empty), frame => AssertFrame.Text(frame, "Second item")); }
protected override void BuildRenderTree(RenderTreeBuilder builder) { if (_isFirstTime) // Don't want an infinite loop { _isFirstTime = false; Parent.TriggerRender(); } builder.AddText(0, "Child is here"); }
public void CannotAddEventHandlerAttributeToText() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); // Act/Assert Assert.Throws <InvalidOperationException>(() => { builder.OpenElement(0, "some element"); builder.AddText(1, "hello"); builder.AddAttribute(2, "name", eventInfo => { }); }); }
public void ClosedEmptyElementsHaveSubtreeLengthOne() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); // Act builder.AddText(0, "some frame so that the element isn't at position zero"); builder.OpenElement(0, "my element"); builder.CloseElement(); // Assert var frames = builder.GetFrames(); Assert.Equal(2, frames.Count); AssertFrame.Element(frames.Array[1], "my element", 1); }
public void BuildRenderTree(RenderTreeBuilder builder) { builder.AddText(0, "Parent here"); if (IncludeChild) { builder.OpenComponent <T>(1); if (ChildParameters != null) { var sequence = 2; foreach (var kvp in ChildParameters) { builder.AddAttribute(sequence++, kvp.Key, kvp.Value); } } builder.CloseComponent(); } }
public void CanNestElements() { // Arrange var builder = new RenderTreeBuilder(new TestRenderer()); // Act builder.AddText(0, "standalone text 1"); // 0: standalone text 1 builder.OpenElement(0, "root"); // 1: <root> builder.AddText(0, "root text 1"); // 2: root text 1 builder.AddText(0, "root text 2"); // 3: root text 2 builder.OpenElement(0, "child"); // 4: <child> builder.AddText(0, "child text"); // 5: child text builder.OpenElement(0, "grandchild"); // 6: <grandchild> builder.AddText(0, "grandchild text 1"); // 7: grandchild text 1 builder.AddText(0, "grandchild text 2"); // 8: grandchild text 2 builder.CloseElement(); // </grandchild> builder.CloseElement(); // </child> builder.AddText(0, "root text 3"); // 9: root text 3 builder.OpenElement(0, "child 2"); // 10: <child 2> builder.CloseElement(); // </child 2> builder.CloseElement(); // </root> builder.AddText(0, "standalone text 2"); // 11: standalone text 2 // Assert Assert.Collection(builder.GetFrames(), frame => AssertFrame.Text(frame, "standalone text 1"), frame => AssertFrame.Element(frame, "root", 10), frame => AssertFrame.Text(frame, "root text 1"), frame => AssertFrame.Text(frame, "root text 2"), frame => AssertFrame.Element(frame, "child", 5), frame => AssertFrame.Text(frame, "child text"), frame => AssertFrame.Element(frame, "grandchild", 3), frame => AssertFrame.Text(frame, "grandchild text 1"), frame => AssertFrame.Text(frame, "grandchild text 2"), frame => AssertFrame.Text(frame, "root text 3"), frame => AssertFrame.Element(frame, "child 2", 1), frame => AssertFrame.Text(frame, "standalone text 2")); }
public void BuildRenderTree(RenderTreeBuilder builder) { builder.AddText(0, $"Notifications: {NotificationsCount}"); }
public void BuildRenderTree(RenderTreeBuilder builder) { builder.AddText(100, $"Hello from {nameof(FakeComponent2)}"); }
public void RecognizesNewItemsBeingInserted() { // Arrange oldTree.AddText(0, "text0"); oldTree.AddText(2, "text2"); newTree.AddText(0, "text0"); newTree.AddText(1, "text1"); newTree.AddText(2, "text2"); // Act var result = GetSingleUpdatedComponent(); // Assert Assert.Collection(result.Edits, entry => { AssertEdit(entry, RenderTreeEditType.PrependFrame, 1); Assert.Equal(0, entry.ReferenceFrameIndex); AssertFrame.Text(result.ReferenceFrames.Array[0], "text1", 1); }); }
protected override void BuildRenderTree(RenderTreeBuilder builder) { builder.AddText(0, Message); }
public void BuildRenderTree(RenderTreeBuilder builder) { builder.AddText(0, $"Hello from {nameof(TestComponent)}"); }
public void BuildRenderTree(RenderTreeBuilder builder) { builder.AddText(0, Message); }