Merge branch 'rel/vs15.7' into dev
This commit is contained in:
commit
2f79b90af5
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.Language.Extensions;
|
||||
using Microsoft.CodeAnalysis.Razor;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
||||
{
|
||||
|
|
@ -22,6 +23,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
FunctionsDirective.Register(builder);
|
||||
InheritsDirective.Register(builder);
|
||||
|
||||
builder.Features.Add(new DefaultTagHelperDescriptorProvider());
|
||||
|
||||
// Register section directive with the 1.x compatible target extension.
|
||||
builder.AddDirective(SectionDirective.Directive);
|
||||
builder.Features.Add(new SectionDirectivePass());
|
||||
|
|
@ -67,6 +70,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
FunctionsDirective.Register(builder);
|
||||
InheritsDirective.Register(builder);
|
||||
|
||||
builder.Features.Add(new DefaultTagHelperDescriptorProvider());
|
||||
|
||||
// Register section directive with the 1.x compatible target extension.
|
||||
builder.AddDirective(SectionDirective.Directive);
|
||||
builder.Features.Add(new SectionDirectivePass());
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
{
|
||||
public sealed class ViewComponentTagHelperDescriptorProvider : RazorEngineFeatureBase, ITagHelperDescriptorProvider
|
||||
{
|
||||
// Hack for testability. The visitor will normally just no op if we're not referencing
|
||||
// an appropriate version of MVC.
|
||||
internal bool ForceEnabled { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
|
||||
public void Execute(TagHelperDescriptorProviderContext context)
|
||||
|
|
@ -33,10 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
|
||||
var types = new List<INamedTypeSymbol>();
|
||||
var visitor = ViewComponentTypeVisitor.Create(compilation, types);
|
||||
if (ForceEnabled)
|
||||
{
|
||||
visitor.Enabled = true;
|
||||
}
|
||||
|
||||
// We always visit the global namespace.
|
||||
visitor.Visit(compilation.Assembly.GlobalNamespace);
|
||||
|
|
|
|||
|
|
@ -18,22 +18,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
|
||||
public static ViewComponentTypeVisitor Create(Compilation compilation, List<INamedTypeSymbol> results)
|
||||
{
|
||||
var enabled = false;
|
||||
foreach (var reference in compilation.References)
|
||||
{
|
||||
var symbol = compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
|
||||
if (symbol != null)
|
||||
{
|
||||
if (string.Equals(symbol.Identity.Name, ViewComponentTypes.Assembly, StringComparison.Ordinal))
|
||||
{
|
||||
enabled = symbol.Identity.Version >= ViewComponentTypes.AssemblyVersion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var vcAttribute = enabled ? compilation.GetTypeByMetadataName(ViewComponentTypes.ViewComponentAttribute) : null;
|
||||
var nonVCAttribute = enabled ? compilation.GetTypeByMetadataName(ViewComponentTypes.NonViewComponentAttribute) : null;
|
||||
var vcAttribute = compilation.GetTypeByMetadataName(ViewComponentTypes.ViewComponentAttribute);
|
||||
var nonVCAttribute = compilation.GetTypeByMetadataName(ViewComponentTypes.NonViewComponentAttribute);
|
||||
return new ViewComponentTypeVisitor(vcAttribute, nonVCAttribute, results);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.Language.Extensions;
|
||||
using Microsoft.CodeAnalysis.Razor;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||
{
|
||||
|
|
@ -25,6 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
InheritsDirective.Register(builder);
|
||||
SectionDirective.Register(builder);
|
||||
|
||||
builder.Features.Add(new DefaultTagHelperDescriptorProvider());
|
||||
builder.Features.Add(new ViewComponentTagHelperDescriptorProvider());
|
||||
|
||||
builder.AddTargetExtension(new ViewComponentTagHelperTargetExtension());
|
||||
|
|
@ -61,6 +63,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
InheritsDirective.Register(builder);
|
||||
SectionDirective.Register(builder);
|
||||
|
||||
builder.Features.Add(new DefaultTagHelperDescriptorProvider());
|
||||
builder.Features.Add(new ViewComponentTagHelperDescriptorProvider());
|
||||
|
||||
builder.AddTargetExtension(new ViewComponentTagHelperTargetExtension());
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
{
|
||||
public sealed class ViewComponentTagHelperDescriptorProvider : RazorEngineFeatureBase, ITagHelperDescriptorProvider
|
||||
{
|
||||
// Hack for testability. The visitor will normally just no op if we're not referencing
|
||||
// an appropriate version of MVC.
|
||||
internal bool ForceEnabled { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
|
||||
public void Execute(TagHelperDescriptorProviderContext context)
|
||||
|
|
@ -33,10 +29,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
|
||||
var types = new List<INamedTypeSymbol>();
|
||||
var visitor = ViewComponentTypeVisitor.Create(compilation, types);
|
||||
if (ForceEnabled)
|
||||
{
|
||||
visitor.Enabled = true;
|
||||
}
|
||||
|
||||
// We always visit the global namespace.
|
||||
visitor.Visit(compilation.Assembly.GlobalNamespace);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
|
@ -29,12 +28,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
_viewComponentAttribute = viewComponentAttribute;
|
||||
_nonViewComponentAttribute = nonViewComponentAttribute;
|
||||
_results = results;
|
||||
|
||||
Enabled = _viewComponentAttribute != null;
|
||||
}
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public override void VisitNamedType(INamedTypeSymbol symbol)
|
||||
{
|
||||
if (IsViewComponent(symbol))
|
||||
|
|
@ -63,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
|
||||
internal bool IsViewComponent(INamedTypeSymbol symbol)
|
||||
{
|
||||
if (!Enabled)
|
||||
if (_viewComponentAttribute == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
{
|
||||
public abstract class TagHelperDescriptorProviderContext
|
||||
{
|
||||
public virtual bool ExcludeHidden { get; set; }
|
||||
|
||||
public virtual bool IncludeDocumentation { get; set; }
|
||||
|
||||
public abstract ItemCollection Items { get; }
|
||||
|
||||
public abstract ICollection<TagHelperDescriptor> Results { get; }
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
|
||||
var results = new List<TagHelperDescriptor>();
|
||||
var context = TagHelperDescriptorProviderContext.Create(results);
|
||||
context.ExcludeHidden = true;
|
||||
context.IncludeDocumentation = true;
|
||||
|
||||
var compilation = await project.WorkspaceProject.GetCompilationAsync().ConfigureAwait(false);
|
||||
context.SetCompilation(compilation);
|
||||
|
|
|
|||
|
|
@ -28,9 +28,11 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Omitted)
|
||||
.WithMiscellaneousOptions(SymbolDisplayFormat.FullyQualifiedFormat.MiscellaneousOptions & (~SymbolDisplayMiscellaneousOptions.UseSpecialTypes));
|
||||
|
||||
public DefaultTagHelperDescriptorFactory(Compilation compilation, bool designTime)
|
||||
public DefaultTagHelperDescriptorFactory(Compilation compilation, bool includeDocumentation, bool excludeHidden)
|
||||
{
|
||||
DesignTime = designTime;
|
||||
IncludeDocumentation = includeDocumentation;
|
||||
ExcludeHidden = excludeHidden;
|
||||
|
||||
_htmlAttributeNameAttributeSymbol = compilation.GetTypeByMetadataName(TagHelperTypes.HtmlAttributeNameAttribute);
|
||||
_htmlAttributeNotBoundAttributeSymbol = compilation.GetTypeByMetadataName(TagHelperTypes.HtmlAttributeNotBoundAttribute);
|
||||
_htmlTargetElementAttributeSymbol = compilation.GetTypeByMetadataName(TagHelperTypes.HtmlTargetElementAttribute);
|
||||
|
|
@ -40,7 +42,9 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
_iDictionarySymbol = compilation.GetTypeByMetadataName(TagHelperTypes.IDictionary);
|
||||
}
|
||||
|
||||
protected bool DesignTime { get; }
|
||||
protected bool ExcludeHidden { get; }
|
||||
|
||||
protected bool IncludeDocumentation { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual TagHelperDescriptor CreateDescriptor(INamedTypeSymbol type)
|
||||
|
|
@ -154,7 +158,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
|
||||
private void AddDocumentation(INamedTypeSymbol type, TagHelperDescriptorBuilder builder)
|
||||
{
|
||||
if (!DesignTime)
|
||||
if (!IncludeDocumentation)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -169,10 +173,6 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
|
||||
private void AddTagOutputHint(INamedTypeSymbol type, TagHelperDescriptorBuilder builder)
|
||||
{
|
||||
if (!DesignTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string outputElementHint = null;
|
||||
var outputElementHintAttribute = type.GetAttributes().Where(a => a.AttributeClass == _outputElementHintAttributeSymbol).FirstOrDefault();
|
||||
if (outputElementHintAttribute != null)
|
||||
|
|
@ -221,7 +221,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
builder.IsEnum = true;
|
||||
}
|
||||
|
||||
if (DesignTime)
|
||||
if (IncludeDocumentation)
|
||||
{
|
||||
var xml = property.GetDocumentationCommentXml();
|
||||
|
||||
|
|
@ -416,7 +416,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
|
||||
private bool ShouldSkipDescriptorCreation(ISymbol symbol)
|
||||
{
|
||||
if (DesignTime)
|
||||
if (ExcludeHidden)
|
||||
{
|
||||
var editorBrowsableAttribute = symbol.GetAttributes().Where(a => a.AttributeClass == _editorBrowsableAttributeSymbol).FirstOrDefault();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
{
|
||||
public sealed class DefaultTagHelperDescriptorProvider : RazorEngineFeatureBase, ITagHelperDescriptorProvider
|
||||
{
|
||||
[Obsolete(
|
||||
"This property is obsolete will not be honored. Documentation will be included if " +
|
||||
"TagHelperDescriptorProviderContext.IncludeDocumentation is set to true. Hidden tag helpers will" +
|
||||
"be excluded from the results if TagHelperDescriptorProviderContext.ExcludeHidden is set to true.")]
|
||||
public bool DesignTime { get; set; }
|
||||
|
||||
public int Order { get; set; }
|
||||
|
|
@ -44,7 +48,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
}
|
||||
}
|
||||
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, DesignTime);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, context.IncludeDocumentation, context.ExcludeHidden);
|
||||
for (var i = 0; i < types.Count; i++)
|
||||
{
|
||||
var descriptor = factory.CreateDescriptor(types[i]);
|
||||
|
|
|
|||
|
|
@ -53,11 +53,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
//
|
||||
// Most notably, we are going to find the Tag Helpers using a compilation, and we have
|
||||
// no editor settings.
|
||||
Action<RazorProjectEngineBuilder> configure = (b) =>
|
||||
{
|
||||
b.Features.Add(new DefaultTagHelperDescriptorProvider() { DesignTime = true });
|
||||
};
|
||||
|
||||
//
|
||||
// The default configuration currently matches MVC-2.0. Beyond MVC-2.0 we added SDK support for
|
||||
// properly detecting project versions, so that's a good version to assume when we can't find a
|
||||
// configuration.
|
||||
|
|
@ -68,7 +64,7 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
// This will stop a crash from happening in this case (misconfigured project), but will still make
|
||||
// it obvious to the user that something is wrong.
|
||||
var factory = CreateFactory(configuration, factoryTypeName) ?? _fallbackFactory;
|
||||
return factory.Create(configuration, RazorProjectFileSystem.Empty, configure);
|
||||
return factory.Create(configuration, RazorProjectFileSystem.Empty, b => { });
|
||||
}
|
||||
|
||||
private IProjectEngineFactory CreateFactory(RazorConfiguration configuration, string factoryTypeName)
|
||||
|
|
|
|||
|
|
@ -36,10 +36,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
|||
return Task.FromResult(TagHelperResolutionResult.Empty);
|
||||
}
|
||||
|
||||
var engine = _engineFactory.Create(project, RazorProjectFileSystem.Empty, b =>
|
||||
{
|
||||
b.Features.Add(new DefaultTagHelperDescriptorProvider() { DesignTime = true, });
|
||||
});
|
||||
var engine = _engineFactory.Create(project, RazorProjectFileSystem.Empty, b => { });
|
||||
return GetTagHelpersAsync(project, engine);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Microsoft.AspNetCore.Razor.Language.IntegrationTests;
|
||||
|
|
@ -13,22 +12,22 @@ using Microsoft.CodeAnalysis;
|
|||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.Emit;
|
||||
using Microsoft.CodeAnalysis.Razor;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.IntegrationTests
|
||||
{
|
||||
public class CodeGenerationIntegrationTest : IntegrationTestBase
|
||||
{
|
||||
private const string CurrentMvcShim = "Microsoft.AspNetCore.Razor.Test.MvcShim.dll";
|
||||
private static readonly RazorSourceDocument DefaultImports = MvcRazorTemplateEngine.GetDefaultImports();
|
||||
|
||||
private CSharpCompilation BaseCompilation => MvcShim.BaseCompilation.WithAssemblyName("AppCode");
|
||||
|
||||
#region Runtime
|
||||
[Fact]
|
||||
public void InvalidNamespaceAtEOF_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunRuntimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -39,9 +38,9 @@ public class MyService<TModel>
|
|||
{
|
||||
public string Html { get; set; }
|
||||
}";
|
||||
var compilationReferences = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(compilationReferences);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -63,9 +62,9 @@ public class MyModel
|
|||
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(references);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -87,44 +86,50 @@ public class MyModel
|
|||
{
|
||||
|
||||
}";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(references);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MalformedPageDirective_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunRuntimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunRuntimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sections_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
public class InputTestTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
public ModelExpression For {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunRuntimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void _ViewImports_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunRuntimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -136,9 +141,9 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(references);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -159,9 +164,9 @@ public class MyApp
|
|||
{
|
||||
public string MyProperty { get; set; }
|
||||
}";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(references);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -183,75 +188,81 @@ public class MyService<TModel>
|
|||
public string Html { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(references);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Model_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
var compilation = BaseCompilation;
|
||||
|
||||
RunRuntimeTest(references);
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModelExpressionTagHelper_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
public class InputTestTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
public ModelExpression For {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunRuntimeTest(references);
|
||||
";
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RazorPages_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class DivTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
|
||||
}}
|
||||
");
|
||||
RunRuntimeTest(references);
|
||||
";
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RazorPagesWithoutModel_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class DivTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
|
||||
}}
|
||||
");
|
||||
RunRuntimeTest(references);
|
||||
";
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PageWithNamespace_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunRuntimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViewWithNamespace_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunRuntimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViewComponentTagHelper_Runtime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class TestViewComponent
|
||||
{{
|
||||
public string Invoke(string firstName)
|
||||
|
|
@ -265,8 +276,11 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
{{
|
||||
public string Bar {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunRuntimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunRuntimeTest(compilation);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
@ -274,8 +288,8 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
[Fact]
|
||||
public void InvalidNamespaceAtEOF_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -288,8 +302,9 @@ public class MyService<TModel>
|
|||
}
|
||||
";
|
||||
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -312,8 +327,9 @@ public class MyModel
|
|||
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -337,43 +353,47 @@ public abstract class MyPageModel<T> : Page
|
|||
}
|
||||
";
|
||||
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MalformedPageDirective_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sections_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
public class InputTestTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
public ModelExpression For {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void _ViewImports_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -385,8 +405,9 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -408,8 +429,9 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -431,15 +453,16 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Model_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -451,66 +474,74 @@ public class ThisShouldBeGenerated
|
|||
|
||||
}";
|
||||
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModelExpressionTagHelper_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
public class InputTestTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
public ModelExpression For {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RazorPages_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class DivTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RazorPagesWithoutModel_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class DivTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PageWithNamespace_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViewWithNamespace_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViewComponentTagHelper_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class TestViewComponent
|
||||
{{
|
||||
public string Invoke(string firstName)
|
||||
|
|
@ -524,17 +555,22 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
{{
|
||||
public string Bar {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void RunRuntimeTest(
|
||||
IEnumerable<MetadataReference> compilationReferences,
|
||||
CSharpCompilation baseCompilation,
|
||||
IEnumerable<string> expectedErrors = null)
|
||||
{
|
||||
Assert.Empty(baseCompilation.GetDiagnostics());
|
||||
|
||||
// Arrange
|
||||
var engine = CreateRuntimeEngine(compilationReferences);
|
||||
var engine = CreateRuntimeEngine(baseCompilation);
|
||||
var document = CreateCodeDocument();
|
||||
|
||||
// Act
|
||||
|
|
@ -543,15 +579,17 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
// Assert
|
||||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertDocumentCompiles(document, compilationReferences, expectedErrors);
|
||||
AssertDocumentCompiles(document, baseCompilation, expectedErrors);
|
||||
}
|
||||
|
||||
private void RunDesignTimeTest(
|
||||
IEnumerable<MetadataReference> compilationReferences,
|
||||
CSharpCompilation baseCompilation,
|
||||
IEnumerable<string> expectedErrors = null)
|
||||
{
|
||||
Assert.Empty(baseCompilation.GetDiagnostics());
|
||||
|
||||
// Arrange
|
||||
var engine = CreateDesignTimeEngine(compilationReferences);
|
||||
var engine = CreateDesignTimeEngine(baseCompilation);
|
||||
var document = CreateCodeDocument();
|
||||
|
||||
// Act
|
||||
|
|
@ -561,25 +599,21 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertSourceMappingsMatchBaseline(document);
|
||||
AssertDocumentCompiles(document, compilationReferences, expectedErrors);
|
||||
}
|
||||
|
||||
private static IEnumerable<MetadataReference> CreateCompilationReferences(string mvcShimName, string appCode = null)
|
||||
{
|
||||
var shimReferences = CreateMvcShimReferences(mvcShimName);
|
||||
return CreateAppCodeReferences(appCode, shimReferences);
|
||||
AssertDocumentCompiles(document, baseCompilation, expectedErrors);
|
||||
}
|
||||
|
||||
private void AssertDocumentCompiles(
|
||||
RazorCodeDocument document,
|
||||
IEnumerable<MetadataReference> compilationReferences,
|
||||
CSharpCompilation baseCompilation,
|
||||
IEnumerable<string> expectedErrors = null)
|
||||
{
|
||||
var cSharp = document.GetCSharpDocument().GeneratedCode;
|
||||
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText(cSharp);
|
||||
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
|
||||
var compilation = CSharpCompilation.Create("CodeGenerationTestAssembly", new[] { syntaxTree }, compilationReferences, options);
|
||||
|
||||
var references = baseCompilation.References.Concat(new[] { baseCompilation.ToMetadataReference() });
|
||||
var compilation = CSharpCompilation.Create("CodeGenerationTestAssembly", new[] { syntaxTree }, references, options);
|
||||
|
||||
var diagnostics = compilation.GetDiagnostics();
|
||||
|
||||
|
|
@ -595,29 +629,29 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
}
|
||||
}
|
||||
|
||||
protected RazorEngine CreateDesignTimeEngine(IEnumerable<MetadataReference> references)
|
||||
protected RazorEngine CreateDesignTimeEngine(CSharpCompilation compilation)
|
||||
{
|
||||
var references = compilation.References.Concat(new[] { compilation.ToMetadataReference() });
|
||||
|
||||
return RazorEngine.CreateDesignTime(b =>
|
||||
{
|
||||
RazorExtensions.Register(b);
|
||||
|
||||
b.Features.Add(GetMetadataReferenceFeature(references));
|
||||
b.Features.Add(new CompilationTagHelperFeature());
|
||||
b.Features.Add(new DefaultTagHelperDescriptorProvider() { DesignTime = true });
|
||||
b.Features.Add(new ViewComponentTagHelperDescriptorProvider() { ForceEnabled = true });
|
||||
});
|
||||
}
|
||||
|
||||
protected RazorEngine CreateRuntimeEngine(IEnumerable<MetadataReference> references)
|
||||
protected RazorEngine CreateRuntimeEngine(CSharpCompilation compilation)
|
||||
{
|
||||
var references = compilation.References.Concat(new[] { compilation.ToMetadataReference() });
|
||||
|
||||
return RazorEngine.Create(b =>
|
||||
{
|
||||
RazorExtensions.Register(b);
|
||||
|
||||
b.Features.Add(GetMetadataReferenceFeature(references));
|
||||
b.Features.Add(new CompilationTagHelperFeature());
|
||||
b.Features.Add(new DefaultTagHelperDescriptorProvider() { DesignTime = true });
|
||||
b.Features.Add(new ViewComponentTagHelperDescriptorProvider() { ForceEnabled = true });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -664,48 +698,5 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
References = references.ToList()
|
||||
};
|
||||
}
|
||||
|
||||
private static IEnumerable<MetadataReference> CreateAppCodeReferences(string appCode, IEnumerable<MetadataReference> shimReferences)
|
||||
{
|
||||
var references = new List<MetadataReference>(shimReferences);
|
||||
|
||||
if (appCode != null)
|
||||
{
|
||||
var appCodeSyntaxTrees = new List<SyntaxTree> { CSharpSyntaxTree.ParseText(appCode) };
|
||||
|
||||
var compilation = CSharpCompilation.Create(
|
||||
"AppCode",
|
||||
appCodeSyntaxTrees,
|
||||
shimReferences,
|
||||
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
var stream = new MemoryStream();
|
||||
var compilationResult = compilation.Emit(stream, options: new EmitOptions());
|
||||
stream.Position = 0;
|
||||
|
||||
var diagString = string.Join(";", compilationResult.Diagnostics.Where(s => s.Severity == DiagnosticSeverity.Error).Select(s => s.ToString()));
|
||||
Assert.True(compilationResult.Success, string.Format("Application code needed for tests didn't compile!: {0}", diagString));
|
||||
|
||||
references.Add(MetadataReference.CreateFromStream(stream));
|
||||
}
|
||||
|
||||
return references;
|
||||
}
|
||||
|
||||
private static IEnumerable<MetadataReference> CreateMvcShimReferences(string mvcShimName)
|
||||
{
|
||||
var dllPath = Path.Combine(Directory.GetCurrentDirectory(), mvcShimName);
|
||||
var assembly = Assembly.LoadFile(dllPath);
|
||||
var assemblyDependencyContext = DependencyContext.Load(assembly);
|
||||
|
||||
var assemblyReferencePaths = assemblyDependencyContext.CompileLibraries.SelectMany(l => l.ResolveReferencePaths());
|
||||
|
||||
var references = assemblyReferencePaths
|
||||
.Select(assemblyPath => MetadataReference.CreateFromFile(assemblyPath))
|
||||
.ToList<MetadataReference>();
|
||||
|
||||
Assert.NotEmpty(references);
|
||||
|
||||
return references;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||
{
|
||||
internal static class MvcShim
|
||||
{
|
||||
public static readonly string AssemblyName = "Microsoft.AspNetCore.Razor.Test.MvcShim";
|
||||
|
||||
private static Assembly _assembly;
|
||||
private static CSharpCompilation _baseCompilation;
|
||||
|
||||
public static Assembly Assembly
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_assembly == null)
|
||||
{
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), AssemblyName + ".dll");
|
||||
_assembly = Assembly.LoadFrom(filePath);
|
||||
}
|
||||
|
||||
return _assembly;
|
||||
}
|
||||
}
|
||||
|
||||
public static CSharpCompilation BaseCompilation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_baseCompilation == null)
|
||||
{
|
||||
_baseCompilation = TestCompilation.Create(Assembly);
|
||||
}
|
||||
|
||||
return _baseCompilation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
|
|
@ -14,8 +15,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
// This is just a basic integration test. There are detailed tests for the VCTH visitor and descriptor factory.
|
||||
public class ViewComponentTagHelperDescriptorProviderTest
|
||||
{
|
||||
private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorProviderTest).GetTypeInfo().Assembly;
|
||||
|
||||
[Fact]
|
||||
public void DescriptorProvider_FindsVCTH()
|
||||
{
|
||||
|
|
@ -27,15 +26,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
}
|
||||
";
|
||||
|
||||
var testCompilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(code));
|
||||
var compilation = MvcShim.BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));
|
||||
|
||||
var context = TagHelperDescriptorProviderContext.Create();
|
||||
context.SetCompilation(testCompilation);
|
||||
context.SetCompilation(compilation);
|
||||
|
||||
var provider = new ViewComponentTagHelperDescriptorProvider()
|
||||
{
|
||||
Engine = RazorEngine.CreateEmpty(b => { }),
|
||||
ForceEnabled = true,
|
||||
};
|
||||
|
||||
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
|
||||
|
|
@ -68,8 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
|||
provider.Execute(context);
|
||||
|
||||
// Assert
|
||||
var descriptor = context.Results.FirstOrDefault(d => TagHelperDescriptorComparer.CaseSensitive.Equals(d, expectedDescriptor));
|
||||
Assert.NotNull(descriptor);
|
||||
Assert.Single(context.Results, d => TagHelperDescriptorComparer.CaseSensitive.Equals(d, expectedDescriptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,14 +20,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X.IntegrationTests
|
|||
{
|
||||
public class CodeGenerationIntegrationTest : IntegrationTestBase
|
||||
{
|
||||
private const string CurrentMvcShim = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X.dll";
|
||||
private static readonly RazorSourceDocument DefaultImports = MvcRazorTemplateEngine.GetDefaultImports();
|
||||
|
||||
private CSharpCompilation BaseCompilation => MvcShim.BaseCompilation.WithAssemblyName("AppCode");
|
||||
|
||||
[Fact]
|
||||
public void InvalidNamespaceAtEOF_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -40,8 +41,8 @@ public class MyService<TModel>
|
|||
}
|
||||
";
|
||||
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -64,8 +65,8 @@ public class MyModel
|
|||
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -89,36 +90,39 @@ public class MyModel
|
|||
}
|
||||
";
|
||||
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Basic_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sections_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
public class InputTestTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
public ModelExpression For {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void _ViewImports_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -130,8 +134,8 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -153,8 +157,8 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -176,15 +180,15 @@ public class MyApp
|
|||
public string MyProperty { get; set; }
|
||||
}
|
||||
";
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Model_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation;
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -196,28 +200,30 @@ public class ThisShouldBeGenerated
|
|||
|
||||
}";
|
||||
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode);
|
||||
RunDesignTimeTest(references);
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ModelExpressionTagHelper_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
public class InputTestTagHelper : {typeof(TagHelper).FullName}
|
||||
{{
|
||||
public ModelExpression For {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ViewComponentTagHelper_DesignTime()
|
||||
{
|
||||
var references = CreateCompilationReferences(CurrentMvcShim, appCode: $@"
|
||||
var appCode = $@"
|
||||
public class TestViewComponent
|
||||
{{
|
||||
public string Invoke(string firstName)
|
||||
|
|
@ -231,16 +237,21 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
{{
|
||||
public string Bar {{ get; set; }}
|
||||
}}
|
||||
");
|
||||
RunDesignTimeTest(references);
|
||||
";
|
||||
|
||||
var compilation = BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(appCode));
|
||||
|
||||
RunDesignTimeTest(compilation);
|
||||
}
|
||||
|
||||
private void RunDesignTimeTest(
|
||||
IEnumerable<MetadataReference> compilationReferences,
|
||||
CSharpCompilation baseCompilation,
|
||||
IEnumerable<string> expectedErrors = null)
|
||||
{
|
||||
Assert.Empty(baseCompilation.GetDiagnostics());
|
||||
|
||||
// Arrange
|
||||
var engine = CreateDesignTimeEngine(compilationReferences);
|
||||
var engine = CreateDesignTimeEngine(baseCompilation);
|
||||
var document = CreateCodeDocument();
|
||||
|
||||
// Act
|
||||
|
|
@ -250,25 +261,21 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
AssertDocumentNodeMatchesBaseline(document.GetDocumentIntermediateNode());
|
||||
AssertCSharpDocumentMatchesBaseline(document.GetCSharpDocument());
|
||||
AssertSourceMappingsMatchBaseline(document);
|
||||
AssertDocumentCompiles(document, compilationReferences, expectedErrors);
|
||||
}
|
||||
|
||||
private static IEnumerable<MetadataReference> CreateCompilationReferences(string mvcShimName, string appCode = null)
|
||||
{
|
||||
var shimReferences = CreateMvcShimReferences(mvcShimName);
|
||||
return CreateAppCodeReferences(appCode, shimReferences);
|
||||
AssertDocumentCompiles(document, baseCompilation, expectedErrors);
|
||||
}
|
||||
|
||||
private void AssertDocumentCompiles(
|
||||
RazorCodeDocument document,
|
||||
IEnumerable<MetadataReference> compilationReferences,
|
||||
CSharpCompilation baseCompilation,
|
||||
IEnumerable<string> expectedErrors = null)
|
||||
{
|
||||
var cSharp = document.GetCSharpDocument().GeneratedCode;
|
||||
|
||||
var syntaxTree = CSharpSyntaxTree.ParseText(cSharp);
|
||||
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
|
||||
var compilation = CSharpCompilation.Create("CodeGenerationTestAssembly", new[] { syntaxTree }, compilationReferences, options);
|
||||
|
||||
var references = baseCompilation.References.Concat(new[] { baseCompilation.ToMetadataReference() });
|
||||
var compilation = CSharpCompilation.Create("CodeGenerationTestAssembly", new[] { syntaxTree }, references, options);
|
||||
|
||||
var diagnostics = compilation.GetDiagnostics();
|
||||
|
||||
|
|
@ -284,8 +291,10 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
}
|
||||
}
|
||||
|
||||
protected RazorEngine CreateDesignTimeEngine(IEnumerable<MetadataReference> references)
|
||||
protected RazorEngine CreateDesignTimeEngine(CSharpCompilation compilation)
|
||||
{
|
||||
var references = compilation.References.Concat(new[] { compilation.ToMetadataReference() });
|
||||
|
||||
return RazorEngine.CreateDesignTime(b =>
|
||||
{
|
||||
RazorExtensions.Register(b);
|
||||
|
|
@ -293,8 +302,6 @@ public class AllTagHelper : {typeof(TagHelper).FullName}
|
|||
|
||||
b.Features.Add(GetMetadataReferenceFeature(references));
|
||||
b.Features.Add(new CompilationTagHelperFeature());
|
||||
b.Features.Add(new DefaultTagHelperDescriptorProvider() { DesignTime = true });
|
||||
b.Features.Add(new ViewComponentTagHelperDescriptorProvider() { ForceEnabled = true });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
|
||||
{
|
||||
internal static class MvcShim
|
||||
{
|
||||
public static readonly string AssemblyName = "Microsoft.AspNetCore.Razor.Test.MvcShim.Version1_X";
|
||||
|
||||
private static Assembly _assembly;
|
||||
private static CSharpCompilation _baseCompilation;
|
||||
|
||||
public static Assembly Assembly
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_assembly == null)
|
||||
{
|
||||
var filePath = Path.Combine(Directory.GetCurrentDirectory(), AssemblyName + ".dll");
|
||||
_assembly = Assembly.LoadFrom(filePath);
|
||||
}
|
||||
|
||||
return _assembly;
|
||||
}
|
||||
}
|
||||
|
||||
public static CSharpCompilation BaseCompilation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_baseCompilation == null)
|
||||
{
|
||||
_baseCompilation = TestCompilation.Create(Assembly);
|
||||
}
|
||||
|
||||
return _baseCompilation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
// This is just a basic integration test. There are detailed tests for the VCTH visitor and descriptor factory.
|
||||
public class ViewComponentTagHelperDescriptorProviderTest
|
||||
{
|
||||
private static readonly Assembly _assembly = typeof(ViewComponentTagHelperDescriptorProviderTest).GetTypeInfo().Assembly;
|
||||
|
||||
[Fact]
|
||||
public void DescriptorProvider_FindsVCTH()
|
||||
{
|
||||
|
|
@ -27,15 +25,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
}
|
||||
";
|
||||
|
||||
var testCompilation = TestCompilation.Create(_assembly, CSharpSyntaxTree.ParseText(code));
|
||||
var compilation = MvcShim.BaseCompilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(code));
|
||||
|
||||
var context = TagHelperDescriptorProviderContext.Create();
|
||||
context.SetCompilation(testCompilation);
|
||||
context.SetCompilation(compilation);
|
||||
|
||||
var provider = new ViewComponentTagHelperDescriptorProvider()
|
||||
{
|
||||
Engine = RazorEngine.CreateEmpty(b => { }),
|
||||
ForceEnabled = true,
|
||||
};
|
||||
|
||||
var expectedDescriptor = TagHelperDescriptorBuilder.Create(
|
||||
|
|
@ -68,8 +65,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X
|
|||
provider.Execute(context);
|
||||
|
||||
// Assert
|
||||
var descriptor = context.Results.FirstOrDefault(d => TagHelperDescriptorComparer.CaseSensitive.Equals(d, expectedDescriptor));
|
||||
Assert.NotNull(descriptor);
|
||||
Assert.Single(context.Results, d => TagHelperDescriptorComparer.CaseSensitive.Equals(d, expectedDescriptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.CodeAnalysis
|
|||
|
||||
public static string AssemblyName => "TestAssembly";
|
||||
|
||||
public static Compilation Create(Assembly assembly, SyntaxTree syntaxTree = null)
|
||||
public static CSharpCompilation Create(Assembly assembly, SyntaxTree syntaxTree = null)
|
||||
{
|
||||
IEnumerable<SyntaxTree> syntaxTrees = null;
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ namespace Microsoft.CodeAnalysis
|
|||
_referenceCache.TryAdd(assembly, metadataReferences);
|
||||
}
|
||||
|
||||
var compilation = CSharpCompilation.Create(AssemblyName, syntaxTrees, metadataReferences);
|
||||
var compilation = CSharpCompilation.Create(AssemblyName, syntaxTrees, metadataReferences, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
|
||||
EnsureValidCompilation(compilation);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
public sealed class ViewComponentAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
public sealed class ViewComponentAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -392,7 +392,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -443,7 +443,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -499,7 +499,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -559,7 +559,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -734,7 +734,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime, designTime);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -931,7 +931,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -968,7 +968,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
string expectedAttributeName)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1005,7 +1005,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(validProperty2.Name)
|
||||
.TypeName(validProperty2.PropertyType.FullName),
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(OverriddenAttributeTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1039,7 +1039,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(validProperty2.Name)
|
||||
.TypeName(validProperty2.PropertyType.FullName),
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(InheritedOverriddenAttributeTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1073,7 +1073,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(validProperty2.Name)
|
||||
.TypeName(validProperty2.PropertyType.FullName),
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(InheritedNotOverriddenAttributeTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1098,7 +1098,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(nameof(InheritedSingleAttributeTagHelper.IntAttribute))
|
||||
.TypeName(typeof(int).FullName)
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(InheritedSingleAttributeTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1124,7 +1124,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(intProperty.Name)
|
||||
.TypeName(intProperty.PropertyType.FullName)
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(SingleAttributeTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1151,7 +1151,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(validProperty.Name)
|
||||
.TypeName(validProperty.PropertyType.FullName)
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(MissingAccessorTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1178,7 +1178,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(validProperty.Name)
|
||||
.TypeName(validProperty.PropertyType.FullName)
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(NonPublicAccessorTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1203,7 +1203,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(nameof(NotBoundAttributeTagHelper.BoundProperty))
|
||||
.TypeName(typeof(object).FullName)
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(NotBoundAttributeTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1234,7 +1234,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
builder => builder.RequireTagName("p"),
|
||||
builder => builder.RequireTagName("div"),
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(MultiTagTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1260,7 +1260,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
.PropertyName(validProp.Name)
|
||||
.TypeName(validProp.PropertyType.FullName),
|
||||
});
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(InheritedMultiTagTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1284,7 +1284,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
builder => builder.RequireTagName("div"),
|
||||
});
|
||||
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(DuplicateTagNameTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1303,7 +1303,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
"data-condition",
|
||||
typeof(OverrideNameTagHelper).FullName,
|
||||
AssemblyName);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(OverrideNameTagHelper).FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1345,7 +1345,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var attribute = tagHelperType.GetAttributes().Single();
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1366,21 +1366,21 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
{
|
||||
// name, expectedNames
|
||||
return new TheoryData<string, IEnumerable<string>>
|
||||
{
|
||||
{ "p", new[] { "p" } },
|
||||
{ " p", new[] { "p" } },
|
||||
{ "p ", new[] { "p" } },
|
||||
{ " p ", new[] { "p" } },
|
||||
{ "p,div", new[] { "p", "div" } },
|
||||
{ " p,div", new[] { "p", "div" } },
|
||||
{ "p ,div", new[] { "p", "div" } },
|
||||
{ " p ,div", new[] { "p", "div" } },
|
||||
{ "p, div", new[] { "p", "div" } },
|
||||
{ "p,div ", new[] { "p", "div" } },
|
||||
{ "p, div ", new[] { "p", "div" } },
|
||||
{ " p, div ", new[] { "p", "div" } },
|
||||
{ " p , div ", new[] { "p", "div" } },
|
||||
};
|
||||
{
|
||||
{ "p", new[] { "p" } },
|
||||
{ " p", new[] { "p" } },
|
||||
{ "p ", new[] { "p" } },
|
||||
{ " p ", new[] { "p" } },
|
||||
{ "p,div", new[] { "p", "div" } },
|
||||
{ " p,div", new[] { "p", "div" } },
|
||||
{ "p ,div", new[] { "p", "div" } },
|
||||
{ " p ,div", new[] { "p", "div" } },
|
||||
{ "p, div", new[] { "p", "div" } },
|
||||
{ "p,div ", new[] { "p", "div" } },
|
||||
{ "p, div ", new[] { "p", "div" } },
|
||||
{ " p, div ", new[] { "p", "div" } },
|
||||
{ " p , div ", new[] { "p", "div" } },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1477,7 +1477,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
IEnumerable<BoundAttributeDescriptor> expectedAttributeDescriptors)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(type.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -1527,7 +1527,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var syntaxTree = CSharpSyntaxTree.ParseText(text);
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1567,7 +1567,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var syntaxTree = CSharpSyntaxTree.ParseText(text);
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1610,7 +1610,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var syntaxTree = CSharpSyntaxTree.ParseText(text);
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1656,7 +1656,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var syntaxTree = CSharpSyntaxTree.ParseText(text);
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1698,7 +1698,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var syntaxTree = CSharpSyntaxTree.ParseText(text);
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1739,7 +1739,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
var syntaxTree = CSharpSyntaxTree.ParseText(text);
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var tagHelperType = compilation.GetTypeByMetadataName("DynamicTestTagHelper");
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: false, excludeHidden: false);
|
||||
|
||||
// Act
|
||||
var descriptor = factory.CreateDescriptor(tagHelperType);
|
||||
|
|
@ -1754,7 +1754,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
{
|
||||
// Arrange
|
||||
var objectAssemblyName = typeof(Enumerable).GetTypeInfo().Assembly.GetName().Name;
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(typeof(Enumerable).FullName);
|
||||
var expectedDescriptor =
|
||||
CreateTagHelperDescriptor("enumerable", "System.Linq.Enumerable", typeSymbol.ContainingAssembly.Identity.Name);
|
||||
|
|
@ -2010,7 +2010,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
IEnumerable<RazorDiagnostic> expectedDiagnostics)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -2069,12 +2069,12 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
|
||||
[Theory]
|
||||
[MemberData(nameof(TagOutputHintData))]
|
||||
public void CreateDescriptor_CreatesDesignTimeDescriptorsWithOutputElementHint(
|
||||
public void CreateDescriptor_CreatesDescriptorsWithOutputElementHint(
|
||||
Type tagHelperType,
|
||||
TagHelperDescriptor expectedDescriptor)
|
||||
{
|
||||
// Arrange
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: true);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(Compilation, includeDocumentation: false, excludeHidden: false);
|
||||
var typeSymbol = Compilation.GetTypeByMetadataName(tagHelperType.FullName);
|
||||
|
||||
// Act
|
||||
|
|
@ -2102,7 +2102,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
{
|
||||
}");
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: true);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: true, excludeHidden: false);
|
||||
var typeSymbol = compilation.GetTypeByMetadataName("DocumentedTagHelper");
|
||||
var expectedDocumentation =
|
||||
@"<member name=""T:DocumentedTagHelper"">
|
||||
|
|
@ -2151,7 +2151,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces
|
|||
public List<bool> RemarksAndSummaryProperty { get; set; }
|
||||
}");
|
||||
var compilation = TestCompilation.Create(_assembly, syntaxTree);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, designTime: true);
|
||||
var factory = new DefaultTagHelperDescriptorFactory(compilation, includeDocumentation: true, excludeHidden: false);
|
||||
var typeSymbol = compilation.GetTypeByMetadataName("DocumentedTagHelper");
|
||||
var expectedDocumentations = new[]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
// Arrange
|
||||
var editorBrowsableTypeName = "Microsoft.CodeAnalysis.Razor.Workspaces.Test.EditorBrowsableTagHelper";
|
||||
var compilation = TestCompilation.Create(_assembly);
|
||||
var descriptorProvider = new DefaultTagHelperDescriptorProvider()
|
||||
{
|
||||
DesignTime = true,
|
||||
};
|
||||
var descriptorProvider = new DefaultTagHelperDescriptorProvider();
|
||||
|
||||
var context = TagHelperDescriptorProviderContext.Create();
|
||||
context.ExcludeHidden = true;
|
||||
|
||||
// Act
|
||||
descriptorProvider.Execute(context);
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ namespace Microsoft.VisualStudio.Editor.Razor
|
|||
|
||||
// Assert
|
||||
Assert.Single(engine.Engine.Features.OfType<MyCoolNewFeature>());
|
||||
Assert.Single(engine.Engine.Features.OfType<DefaultTagHelperDescriptorProvider>());
|
||||
Assert.Single(engine.Engine.Features.OfType<MvcLatest.ViewComponentTagHelperDescriptorProvider>());
|
||||
Assert.Single(engine.Engine.Features.OfType<MvcLatest.MvcViewDocumentClassifierPass>());
|
||||
Assert.Single(engine.Engine.Features.OfType<MvcLatest.ViewComponentTagHelperPass>());
|
||||
|
|
|
|||
Loading…
Reference in New Issue