Exemplo n.º 1
0
        public static void Register(RazorProjectEngineBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            InjectDirective.Register(builder);
            ModelDirective.Register(builder);
            NamespaceDirective.Register(builder);
            PageDirective.Register(builder);

            FunctionsDirective.Register(builder);
            InheritsDirective.Register(builder);
            SectionDirective.Register(builder);

            builder.Features.Add(new DefaultTagHelperDescriptorProvider());
            builder.Features.Add(new ViewComponentTagHelperDescriptorProvider());

            builder.AddTargetExtension(new ViewComponentTagHelperTargetExtension());
            builder.AddTargetExtension(new TemplateTargetExtension()
            {
                TemplateTypeName = "global::Microsoft.AspNetCore.Mvc.Razor.HelperResult",
            });

            builder.Features.Add(new ModelExpressionPass());
            builder.Features.Add(new PagesPropertyInjectionPass());
            builder.Features.Add(new ViewComponentTagHelperPass());
            builder.Features.Add(new RazorPageDocumentClassifierPass());
            builder.Features.Add(new MvcViewDocumentClassifierPass());
            builder.Features.Add(new AssemblyAttributeInjectionPass());
            builder.Features.Add(new InstrumentationPass());

            builder.SetImportFeature(new MvcImportProjectFeature());
        }
Exemplo n.º 2
0
        public void GetNamespace_IncompleteDirective_UsesEmptyNamespace()
        {
            // Arrange
            var source  = "c:\\foo\\bar\\bleh.cshtml";
            var imports = "c:\\foo\\baz\\bleh.cshtml";
            var node    = new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan(imports, 0, 0, 0, 0),
            };

            // Act
            var @namespace = NamespaceDirective.GetNamespace(source, node);

            // Assert
            Assert.Equal(string.Empty, @namespace);
        }
Exemplo n.º 3
0
        public void GetNamespace_ForRelatedFiles_ComputesNamespaceWithSuffix(string source, string imports, string expected)
        {
            // Arrange
            var node = new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan(imports, 0, 0, 0, 0),
            };

            node.Children.Add(new DirectiveTokenIntermediateNode()
            {
                Content = "Base"
            });

            // Act
            var @namespace = NamespaceDirective.GetNamespace(source, node);

            // Assert
            Assert.Equal(expected, @namespace);
        }
Exemplo n.º 4
0
        public void GetNamespace_ForNonRelatedFiles_UsesNamespaceVerbatim(string source, string imports)
        {
            // Arrange
            var node = new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan(imports, 0, 0, 0, 0),
            };

            node.Children.Add(new DirectiveTokenIntermediateNode()
            {
                Content = "Base"
            });

            // Act
            var @namespace = NamespaceDirective.GetNamespace(source, node);

            // Assert
            Assert.Equal("Base", @namespace);
        }
Exemplo n.º 5
0
        public void GetNamespace_EmptyDirective_UsesEmptyNamespace()
        {
            // Arrange
            var source  = "c:\\foo\\bar\\bleh.cshtml";
            var imports = "c:\\foo\\baz\\bleh.cshtml";
            var node    = new DirectiveIntermediateNode()
            {
                Directive = NamespaceDirective.Directive,
                Source    = new SourceSpan(imports, 0, 0, 0, 0),
            };

            node.Children.Add(new DirectiveTokenIntermediateNode()
            {
                Content = string.Empty
            });

            // Act
            var @namespace = NamespaceDirective.GetNamespace(source, node);

            // Assert
            Assert.Equal(string.Empty, @namespace);
        }