public void IsViewComponent_GenericViewComponent_ReturnsFalse() { // Arrange var testVisitor = new ViewComponentTypeVisitor( TestViewComponentAttributeSymbol, TestNonViewComponentAttributeSymbol, new List <INamedTypeSymbol>()); var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Invalid_GenericViewComponent <>).FullName); // Act var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); // Assert Assert.False(isViewComponent); }
public void IsViewComponent_DecoratedViewComponent_ReturnsTrue() { // Arrange var testVisitor = new ViewComponentTypeVisitor( TestViewComponentAttributeSymbol, TestNonViewComponentAttributeSymbol, new List <INamedTypeSymbol>()); var tagHelperSymbol = Compilation.GetTypeByMetadataName(typeof(Valid_DecoratedVC).FullName); // Act var isViewComponent = testVisitor.IsViewComponent(tagHelperSymbol); // Assert Assert.True(isViewComponent); }
public void Execute(TagHelperDescriptorProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var compilation = context.GetCompilation(); if (compilation == null) { // No compilation, nothing to do. return; } var types = new List <INamedTypeSymbol>(); var visitor = ViewComponentTypeVisitor.Create(compilation, types); // We always visit the global namespace. visitor.Visit(compilation.Assembly.GlobalNamespace); foreach (var reference in compilation.References) { if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly) { if (IsTagHelperAssembly(assembly)) { visitor.Visit(assembly.GlobalNamespace); } } } var factory = new ViewComponentTagHelperDescriptorFactory(compilation); for (var i = 0; i < types.Count; i++) { var descriptor = factory.CreateDescriptor(types[i]); if (descriptor != null) { context.Results.Add(descriptor); } } }