Пример #1
0
        public void Execute_NoOpsForBlazorComponents()
        {
            // Arrange
            var properties   = new RazorSourceDocumentProperties(filePath: "ignored", relativePath: "Test.razor");
            var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", properties));

            codeDocument.SetFileKind(FileKinds.Component);

            var engine = CreateProjectEngine(b =>
            {
                PageDirective.Register(b);
            }).Engine;
            var irDocument = CreateIRDocument(engine, codeDocument);
            var pass       = new CreateNewOnMetadataUpdateAttributePass
            {
                Engine = engine
            };
            var documentClassifier = new DefaultDocumentClassifierPass {
                Engine = engine
            };

            // Act
            documentClassifier.Execute(codeDocument, irDocument);
            pass.Execute(codeDocument, irDocument);
            var visitor = new Visitor();

            visitor.Visit(irDocument);

            // Assert
            Assert.Empty(visitor.ExtensionNodes);
        }
Пример #2
0
        public void Execute_AddsAttributes()
        {
            // Arrange
            var properties   = new RazorSourceDocumentProperties(filePath: "ignored", relativePath: "Test.cshtml");
            var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", properties));

            var engine = CreateProjectEngine(b =>
            {
                PageDirective.Register(b);
            }).Engine;;
            var irDocument = CreateIRDocument(engine, codeDocument);
            var pass       = new CreateNewOnMetadataUpdateAttributePass
            {
                Engine = engine
            };
            var documentClassifier = new MvcViewDocumentClassifierPass {
                Engine = engine
            };

            // Act
            documentClassifier.Execute(codeDocument, irDocument);
            pass.Execute(codeDocument, irDocument);
            var visitor = new Visitor();

            visitor.Visit(irDocument);

            // Assert
            Assert.Collection(
                visitor.ExtensionNodes,
                node =>
            {
                var attributeNode = Assert.IsType <RazorCompiledItemMetadataAttributeIntermediateNode>(node);
                Assert.Equal("Identifier", attributeNode.Key);
                Assert.Equal("/Test.cshtml", attributeNode.Value);
            },
                node =>
            {
                Assert.IsType <CreateNewOnMetadataUpdateAttributePass.CreateNewOnMetadataUpdateAttributeIntermediateNode>(node);
            });
        }