public void IsValidCompilation_ReturnsFalseIfSystemStringCannotBeFound()
        {
            // Arrange
            var references = new[]
            {
                MetadataReference.CreateFromFile(typeof(ITagHelper).Assembly.Location),
            };
            var compilation = CSharpCompilation.Create("Test", references: references);

            // Act
            var result = CompilationTagHelperFeature.IsValidCompilation(compilation);

            // Assert
            Assert.False(result);
        }
        public void IsValidCompilation_ReturnsTrueIfWellKnownTypesAreFound()
        {
            // Arrange
            var references = new[]
            {
                MetadataReference.CreateFromFile(typeof(string).Assembly.Location),
                MetadataReference.CreateFromFile(typeof(ITagHelper).Assembly.Location),
            };
            var compilation = CSharpCompilation.Create("Test", references: references);

            // Act
            var result = CompilationTagHelperFeature.IsValidCompilation(compilation);

            // Assert
            Assert.True(result);
        }
Beispiel #3
0
        protected virtual async Task <TagHelperResolutionResult> GetTagHelpersAsync(ProjectSnapshot project, RazorProjectEngine engine)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }

            if (project.WorkspaceProject == null)
            {
                return(TagHelperResolutionResult.Empty);
            }

            var providers = engine.Engine.Features.OfType <ITagHelperDescriptorProvider>().ToArray();

            if (providers.Length == 0)
            {
                return(TagHelperResolutionResult.Empty);
            }

            var results = new List <TagHelperDescriptor>();
            var context = TagHelperDescriptorProviderContext.Create(results);

            context.ExcludeHidden        = true;
            context.IncludeDocumentation = true;

            var compilation = await project.WorkspaceProject.GetCompilationAsync().ConfigureAwait(false);

            if (CompilationTagHelperFeature.IsValidCompilation(compilation))
            {
                context.SetCompilation(compilation);
            }

            for (var i = 0; i < providers.Length; i++)
            {
                var provider = providers[i];
                provider.Execute(context);
            }

            return(new TagHelperResolutionResult(results, Array.Empty <RazorDiagnostic>()));
        }