Beispiel #1
0
        public void DescriptorProvider_WithCurrentCompilationFilter_FindsDescriptorFromCurrentCompilation()
        {
            // Arrange
            var code = @"
        public class StringParameterViewComponent
        {
            public string Invoke(string foo, string bar) => null;
        }
";

            var compilation = MvcShim.BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));

            var context = TagHelperDescriptorProviderContext.Create();

            context.SetCompilation(compilation);
            context.Items.SetTagHelperDiscoveryFilter(TagHelperDiscoveryFilter.CurrentCompilation);

            var provider = new ViewComponentTagHelperDescriptorProvider()
            {
                Engine = RazorProjectEngine.CreateEmpty().Engine,
            };

            // Act
            provider.Execute(context);

            // Assert
            Assert.Single(context.Results);
        }
Beispiel #2
0
        public void DescriptorProvider_FindsVCTH()
        {
            // Arrange
            var code = @"
        public class StringParameterViewComponent
        {
            public string Invoke(string foo, string bar) => null;
        }
";

            var testCompilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(code));

            var context = TagHelperDescriptorProviderContext.Create();

            context.SetCompilation(testCompilation);

            var provider = new ViewComponentTagHelperDescriptorProvider()
            {
                Engine       = RazorEngine.CreateEmpty(b => { }),
                ForceEnabled = true,
            };

            var expectedDescriptor = TagHelperDescriptorBuilder.Create(
                ViewComponentTagHelperConventions.Kind,
                "__Generated__StringParameterViewComponentTagHelper",
                TestCompilation.AssemblyName)
                                     .TypeName("__Generated__StringParameterViewComponentTagHelper")
                                     .DisplayName("StringParameterViewComponentTagHelper")
                                     .TagMatchingRuleDescriptor(rule =>
                                                                rule
                                                                .RequireTagName("vc:string-parameter")
                                                                .RequireAttributeDescriptor(attribute => attribute.Name("foo"))
                                                                .RequireAttributeDescriptor(attribute => attribute.Name("bar")))
                                     .BoundAttributeDescriptor(attribute =>
                                                               attribute
                                                               .Name("foo")
                                                               .PropertyName("foo")
                                                               .TypeName(typeof(string).FullName)
                                                               .DisplayName("string StringParameterViewComponentTagHelper.foo"))
                                     .BoundAttributeDescriptor(attribute =>
                                                               attribute
                                                               .Name("bar")
                                                               .PropertyName("bar")
                                                               .TypeName(typeof(string).FullName)
                                                               .DisplayName("string StringParameterViewComponentTagHelper.bar"))
                                     .AddMetadata(ViewComponentTagHelperMetadata.Name, "StringParameter")
                                     .Build();

            // Act
            provider.Execute(context);

            // Assert
            var descriptor = context.Results.FirstOrDefault(d => TagHelperDescriptorComparer.CaseSensitive.Equals(d, expectedDescriptor));

            Assert.NotNull(descriptor);
        }
Beispiel #3
0
        public void DescriptorProvider_FindsVCTH()
        {
            // Arrange
            var code = @"
        public class StringParameterViewComponent
        {
            public string Invoke(string foo, string bar) => null;
        }
";

            var compilation = MvcShim.BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));

            var context = TagHelperDescriptorProviderContext.Create();

            context.SetCompilation(compilation);

            var provider = new ViewComponentTagHelperDescriptorProvider()
            {
                Engine = RazorProjectEngine.CreateEmpty().Engine,
            };

            var expectedDescriptor = TagHelperDescriptorBuilder.Create(
                ViewComponentTagHelperConventions.Kind,
                "__Generated__StringParameterViewComponentTagHelper",
                TestCompilation.AssemblyName)
                                     .TypeName("__Generated__StringParameterViewComponentTagHelper")
                                     .DisplayName("StringParameterViewComponentTagHelper")
                                     .TagMatchingRuleDescriptor(rule =>
                                                                rule
                                                                .RequireTagName("vc:string-parameter")
                                                                .RequireAttributeDescriptor(attribute => attribute.Name("foo"))
                                                                .RequireAttributeDescriptor(attribute => attribute.Name("bar")))
                                     .BoundAttributeDescriptor(attribute =>
                                                               attribute
                                                               .Name("foo")
                                                               .PropertyName("foo")
                                                               .TypeName(typeof(string).FullName)
                                                               .DisplayName("string StringParameterViewComponentTagHelper.foo"))
                                     .BoundAttributeDescriptor(attribute =>
                                                               attribute
                                                               .Name("bar")
                                                               .PropertyName("bar")
                                                               .TypeName(typeof(string).FullName)
                                                               .DisplayName("string StringParameterViewComponentTagHelper.bar"))
                                     .AddMetadata(ViewComponentTagHelperMetadata.Name, "StringParameter")
                                     .Build();

            // Act
            provider.Execute(context);

            // Assert
            Assert.Single(context.Results, d => TagHelperDescriptorComparer.Default.Equals(d, expectedDescriptor));
        }