|
|
@@ -2,6 +2,8 @@
|
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
|
|
using System.Linq;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.Threading;
|
|
|
using System.Reflection;
|
|
|
using Microsoft.AspNetCore.Razor.Language;
|
|
|
using Microsoft.CodeAnalysis.CSharp;
|
|
|
@@ -25,7 +27,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|
|
context.SetCompilation(compilation);
|
|
|
context.ExcludeHidden = true;
|
|
|
|
|
|
- // Act
|
|
|
+ // Act
|
|
|
descriptorProvider.Execute(context);
|
|
|
|
|
|
// Assert
|
|
|
@@ -44,45 +46,15 @@ namespace Microsoft.CodeAnalysis.Razor
|
|
|
|
|
|
var context = TagHelperDescriptorProviderContext.Create();
|
|
|
|
|
|
- // Act
|
|
|
- descriptorProvider.Execute(context);
|
|
|
-
|
|
|
- // Assert
|
|
|
- Assert.Empty(context.Results);
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void Execute_WithFilterAssemblyDoesNotDiscoverTagHelpersFromReferences()
|
|
|
- {
|
|
|
- // Arrange
|
|
|
- var typeName = "TestAssembly.TestTagHelper";
|
|
|
- var csharp = @"
|
|
|
-using Microsoft.AspNetCore.Razor.TagHelpers;
|
|
|
-namespace TestAssembly
|
|
|
-{
|
|
|
- public class TestTagHelper : TagHelper
|
|
|
- {
|
|
|
- public override void Process(TagHelperContext context, TagHelperOutput output) {}
|
|
|
- }
|
|
|
-}";
|
|
|
- var compilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(csharp));
|
|
|
- var descriptorProvider = new DefaultTagHelperDescriptorProvider();
|
|
|
-
|
|
|
- var context = TagHelperDescriptorProviderContext.Create();
|
|
|
- context.SetCompilation(compilation);
|
|
|
- context.Items.SetTagHelperDiscoveryFilter(TagHelperDiscoveryFilter.CurrentCompilation);
|
|
|
-
|
|
|
// Act
|
|
|
descriptorProvider.Execute(context);
|
|
|
|
|
|
// Assert
|
|
|
- Assert.NotNull(compilation.GetTypeByMetadataName(typeName));
|
|
|
- var descriptor = Assert.Single(context.Results);
|
|
|
- Assert.Equal(typeName, descriptor.GetTypeName());
|
|
|
+ Assert.Empty(context.Results);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Execute_WithFilterReferenceDoesNotDiscoverTagHelpersFromAssembly()
|
|
|
+ public void Execute_WithDefaultDiscoversTagHelpersFromAssemblyAndReference()
|
|
|
{
|
|
|
// Arrange
|
|
|
var testTagHelper = "TestAssembly.TestTagHelper";
|
|
|
@@ -101,7 +73,6 @@ namespace TestAssembly
|
|
|
|
|
|
var context = TagHelperDescriptorProviderContext.Create();
|
|
|
context.SetCompilation(compilation);
|
|
|
- context.Items.SetTagHelperDiscoveryFilter(TagHelperDiscoveryFilter.ReferenceAssemblies);
|
|
|
|
|
|
// Act
|
|
|
descriptorProvider.Execute(context);
|
|
|
@@ -109,12 +80,12 @@ namespace TestAssembly
|
|
|
// Assert
|
|
|
Assert.NotNull(compilation.GetTypeByMetadataName(testTagHelper));
|
|
|
Assert.NotEmpty(context.Results);
|
|
|
- Assert.Empty(context.Results.Where(f => f.GetTypeName() == testTagHelper));
|
|
|
+ Assert.NotEmpty(context.Results.Where(f => f.GetTypeName() == testTagHelper));
|
|
|
Assert.NotEmpty(context.Results.Where(f => f.GetTypeName() == enumTagHelper));
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
- public void Execute_WithDefaultDiscoversTagHelpersFromAssemblyAndReference()
|
|
|
+ public void Execute_WithTargetMetadataReference_Works()
|
|
|
{
|
|
|
// Arrange
|
|
|
var testTagHelper = "TestAssembly.TestTagHelper";
|
|
|
@@ -133,7 +104,7 @@ namespace TestAssembly
|
|
|
|
|
|
var context = TagHelperDescriptorProviderContext.Create();
|
|
|
context.SetCompilation(compilation);
|
|
|
- context.Items.SetTagHelperDiscoveryFilter(TagHelperDiscoveryFilter.Default);
|
|
|
+ context.Items.SetTargetMetadataReference(compilation.References.First(r => r.Display.Contains("Microsoft.CodeAnalysis.Razor.Test.dll")));
|
|
|
|
|
|
// Act
|
|
|
descriptorProvider.Execute(context);
|
|
|
@@ -141,7 +112,7 @@ namespace TestAssembly
|
|
|
// Assert
|
|
|
Assert.NotNull(compilation.GetTypeByMetadataName(testTagHelper));
|
|
|
Assert.NotEmpty(context.Results);
|
|
|
- Assert.NotEmpty(context.Results.Where(f => f.GetTypeName() == testTagHelper));
|
|
|
+ Assert.Empty(context.Results.Where(f => f.GetTypeName() == testTagHelper));
|
|
|
Assert.NotEmpty(context.Results.Where(f => f.GetTypeName() == enumTagHelper));
|
|
|
}
|
|
|
}
|