Ejemplo n.º 1
0
        public void CanAddElementReferenceCaptureInsideElement()
        {
            // Arrange
            var builder = new RenderTreeBuilder(new TestRenderer());
            Action <ElementRef> referenceCaptureAction = elementRef => { };

            // Act
            builder.OpenElement(0, "myelement");                           //  0: <myelement
            builder.AddAttribute(1, "attribute2", 123);                    //  1:     attribute2=intExpression123>
            builder.AddElementReferenceCapture(2, referenceCaptureAction); //  2:     # capture: referenceCaptureAction
            builder.AddContent(3, "some text");                            //  3:     some text
            builder.CloseElement();                                        //     </myelement>

            // Assert
            Assert.Collection(builder.GetFrames(),
                              frame => AssertFrame.Element(frame, "myelement", 4, 0),
                              frame => AssertFrame.Attribute(frame, "attribute2", "123", 1),
                              frame => AssertFrame.ElementReferenceCapture(frame, referenceCaptureAction, 2),
                              frame => AssertFrame.Text(frame, "some text", 3));
        }
Ejemplo n.º 2
0
        public void CanAddMultipleReferenceCapturesToSameElement()
        {
            // There won't be any way of doing this from Razor because there's no known use
            // case for it. However it's harder to *not* support it than to support it, and
            // there's no known reason to prevent it, so here's test coverage to show it
            // just works.

            // Arrange
            var builder = new RenderTreeBuilder(new TestRenderer());
            Action <ElementRef> referenceCaptureAction1 = elementRef => { };
            Action <ElementRef> referenceCaptureAction2 = elementRef => { };

            // Act
            builder.OpenElement(0, "myelement");
            builder.AddElementReferenceCapture(0, referenceCaptureAction1);
            builder.AddElementReferenceCapture(0, referenceCaptureAction2);
            builder.CloseElement();

            // Assert
            Assert.Collection(builder.GetFrames(),
                              frame => AssertFrame.Element(frame, "myelement", 3),
                              frame => AssertFrame.ElementReferenceCapture(frame, referenceCaptureAction1),
                              frame => AssertFrame.ElementReferenceCapture(frame, referenceCaptureAction2));
        }