Esempio n. 1
0
        public void TestRedrawOnChangeProps()
        {
            // <PropsChangeTestComponent Id="1">
            // </PropsChangeTestComponent>

            const string id = "1";

            var rootBlueprint = ComponentBlueprint.From <PropsChangeTestComponent, PropsChangeTestComponentProps>(new PropsChangeTestComponentProps
            {
                Id = id,
            });

            var document   = new TestHtmlDocument();
            var renderer   = new DomRenderer(document);
            var renderNode = renderer.Mount(rootBlueprint);

            var expected = "<div id=\"1\"></div>";

            Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);

            var childrenString = "";

            for (var i = 0; i < 10; i += 1)
            {
                PropsChangeTestComponent.IncreaseLength(id);

                childrenString += $"<div id=\"1-{i + 1}\"></div>";
                expected        = $"<div id=\"1\">{childrenString}</div>";
                Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);
            }
        }
Esempio n. 2
0
        public void TestMethod1()
        {
            // <div style="1">
            //   <div style="2"></div>
            // </div>

            var rootBlueprint = ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
            {
                Style    = "1",
                Children = new Blueprint[]
                {
                    ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
                    {
                        Style = "2"
                    }),
                },
            });

            var document    = new TestHtmlDocument();
            var renderer    = new DomRenderer(document);
            var htmlElement = renderer.Mount(rootBlueprint).RootNodes[0];

            var expected = "<div style=\"1\"><div style=\"2\"></div></div>";

            Assert.AreEqual(htmlElement.ToString(), expected);
        }
Esempio n. 3
0
        public void TestTextNodeChild()
        {
            // <div>"abc"</div>

            var rootBlueprint = ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
            {
                Children = new Blueprint[]
                {
                    new ValueBlueprint("abc"),
                },
            });

            var document    = new TestHtmlDocument();
            var renderer    = new DomRenderer(document);
            var htmlElement = renderer.Mount(rootBlueprint).RootNodes[0];

            var expected = @"<div>abc</div>";

            Assert.AreEqual(htmlElement.ToString(), expected);
        }
Esempio n. 4
0
        public void TestRedrawOnChangeState()
        {
            // <MyComponent style="1" id="first">
            //   <MyComponent style="2" id="second"></MyComponent>
            // </MyComponent>

            // <div style="1">
            //   <div style="2"></div>
            // </div>

            var rootBlueprint = ComponentBlueprint.From <MyComponent, MyComponentProps>(new MyComponentProps
            {
                Style    = "1",
                Id       = "first",
                Children = new Blueprint[]
                {
                    ComponentBlueprint.From <MyComponent, MyComponentProps>(new MyComponentProps
                    {
                        Style = "2",
                        Id    = "second",
                    }),
                },
            });


            var document   = new TestHtmlDocument();
            var renderer   = new DomRenderer(document);
            var renderNode = renderer.Mount(rootBlueprint);

            var expected = "<div style=\"1\"><div style=\"2\"></div></div>";

            Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);

            MyComponent.Click("first");

            expected = "<div style=\"1 clicked\"><div style=\"2\"></div></div>";
            Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);
        }
Esempio n. 5
0
        public void TestBraceNodeChild_float()
        {
            var children = SyntaxFactory.List(new CsxNodeSyntax[]
            {
                SyntaxFactory.CsxBraceNode(SyntaxFactory.ParseExpression("123.456")),
            });

            var parent = SyntaxFactory.CsxOpenCloseTagElement(
                SyntaxFactory.Identifier("DivComponent"),
                SyntaxFactory.List <CsxAttributeSyntax>(),
                children,
                SyntaxFactory.CsxCloseTag("DivComponent"));

            var csxCodeBlock = @"<DivComponent>{123.456}</DivComponent>";

            Assert.AreEqual(csxCodeBlock, parent.ToFullString());

            var tree     = CSharpSyntaxTree.ParseText(RoslynTestHelper.GenerateCodeForExpression(csxCodeBlock));
            var root     = (CompilationUnitSyntax)tree.GetRoot();
            var rewriter = new CsxRewriter();
            var result   = rewriter.Visit(root);

            var expectedCsCode = RoslynTestHelper.GenerateCodeForExpression(@"ComponentBlueprint.From<DivComponent, DivComponentProps>(new DivComponentProps {Children=new Blueprint[]{123.456}})");

            Assert.AreEqual(expectedCsCode, result.ToFullString());

            var rootBlueprint = RoslynTestHelper.GetGeneratedExpressionCodeReturnValue <ComponentBlueprint>(expectedCsCode);

            var document    = new TestHtmlDocument();
            var renderer    = new DomRenderer(document);
            var htmlElement = renderer.Mount(rootBlueprint).RootNodes[0];

            var expected = @"<div>123.456</div>";

            Assert.AreEqual(htmlElement.ToString(), expected);
        }