diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs b/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs index cabcbbb0c6..425903e4e3 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs @@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.AspNetCore.Razor.Compilation.TagHelpers; using Microsoft.AspNetCore.Razor.Evolution; using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers; @@ -64,11 +63,6 @@ public static IMvcCoreBuilder AddRazorViewEngine( private static void AddRazorViewEngineFeatureProviders(IMvcCoreBuilder builder) { - if (!builder.PartManager.FeatureProviders.OfType().Any()) - { - builder.PartManager.FeatureProviders.Add(new TagHelperFeatureProvider()); - } - if (!builder.PartManager.FeatureProviders.OfType().Any()) { builder.PartManager.FeatureProviders.Add(new MetadataReferenceFeatureProvider()); @@ -158,12 +152,6 @@ internal static void AddRazorViewEngineServices(IServiceCollection services) services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(s => new TagHelperDescriptorFactory(designTime: false)); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - // Caches compilation artifacts across the lifetime of the application. services.TryAddSingleton(); diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CompositeTagHelperDescriptorResolver.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CompositeTagHelperDescriptorResolver.cs deleted file mode 100644 index fc4219a906..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CompositeTagHelperDescriptorResolver.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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.Collections.Generic; -using Microsoft.AspNetCore.Razor.Compilation.TagHelpers; -using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class CompositeTagHelperDescriptorResolver : ITagHelperDescriptorResolver - { - private readonly TagHelperDescriptorResolver _tagHelperDescriptorResolver; - private readonly ViewComponentTagHelperDescriptorResolver _viewComponentTagHelperDescriptorResolver; - - public CompositeTagHelperDescriptorResolver( - TagHelperDescriptorResolver tagHelperDescriptorResolver, - ViewComponentTagHelperDescriptorResolver viewComponentTagHelperDescriptorResolver) - { - _tagHelperDescriptorResolver = tagHelperDescriptorResolver; - _viewComponentTagHelperDescriptorResolver = viewComponentTagHelperDescriptorResolver; - } - - public IEnumerable Resolve(TagHelperDescriptorResolutionContext resolutionContext) - { - var descriptors = new List(); - - descriptors.AddRange(_tagHelperDescriptorResolver.Resolve(resolutionContext)); - descriptors.AddRange(_viewComponentTagHelperDescriptorResolver.Resolve(resolutionContext)); - - return descriptors; - } - } -} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs index 377d5106b5..a441c75de1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs @@ -5,7 +5,6 @@ using System.Linq; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; -using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -34,7 +33,6 @@ public static void AddTagHelpersAsServices(ApplicationPartManager manager, IServ } services.Replace(ServiceDescriptor.Transient()); - services.Replace(ServiceDescriptor.Transient()); } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewComponentTagHelperDescriptorFactory.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewComponentTagHelperDescriptorFactory.cs deleted file mode 100644 index 68879327be..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewComponentTagHelperDescriptorFactory.cs +++ /dev/null @@ -1,266 +0,0 @@ -// 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 System.Reflection; -using System.Text; -using Microsoft.AspNetCore.Mvc.Razor.Host; -using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.AspNetCore.Razor.Compilation.TagHelpers; -using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; -using Microsoft.Extensions.Internal; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - /// - /// Provides methods to create tag helper representations of view components. - /// - public class ViewComponentTagHelperDescriptorFactory - { - private readonly IViewComponentDescriptorProvider _descriptorProvider; - - /// - /// Creates a new , - /// then creates s for s - /// in the given . - /// - /// The provider of s. - public ViewComponentTagHelperDescriptorFactory(IViewComponentDescriptorProvider descriptorProvider) - { - if (descriptorProvider == null) - { - throw new ArgumentNullException(nameof(descriptorProvider)); - } - - _descriptorProvider = descriptorProvider; - } - - /// - /// Creates representations of s - /// in an represented by the given . - /// - /// The name of the assembly containing - /// the s to translate. - /// A , - /// one for each . - public IEnumerable CreateDescriptors(string assemblyName) - { - if (assemblyName == null) - { - throw new ArgumentNullException(nameof(assemblyName)); - } - - var viewComponentDescriptors = _descriptorProvider - .GetViewComponents() - .Where(viewComponent => string.Equals(assemblyName, viewComponent.TypeInfo.Assembly.GetName().Name, - StringComparison.Ordinal)); - - var tagHelperDescriptors = viewComponentDescriptors - .Where(d => !d.MethodInfo.ContainsGenericParameters) - .Select(viewComponentDescriptor => CreateDescriptor(viewComponentDescriptor)); - - return tagHelperDescriptors; - } - - private TagHelperDescriptor CreateDescriptor(ViewComponentDescriptor viewComponentDescriptor) - { - var assemblyName = viewComponentDescriptor.TypeInfo.Assembly.GetName().Name; - var tagName = GetTagName(viewComponentDescriptor); - var typeName = $"__Generated__{viewComponentDescriptor.ShortName}ViewComponentTagHelper"; - - var tagHelperDescriptor = new TagHelperDescriptor - { - TagName = tagName, - TypeName = typeName, - AssemblyName = assemblyName - }; - - SetAttributeDescriptors(viewComponentDescriptor, tagHelperDescriptor); - - tagHelperDescriptor.PropertyBag.Add( - ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey, viewComponentDescriptor.ShortName); - - return tagHelperDescriptor; - } - - private void SetAttributeDescriptors(ViewComponentDescriptor viewComponentDescriptor, - TagHelperDescriptor tagHelperDescriptor) - { - var methodParameters = viewComponentDescriptor.MethodInfo.GetParameters(); - var attributeDescriptors = new List(); - var indexerDescriptors = new List(); - var requiredAttributeDescriptors = new List(); - - foreach (var parameter in methodParameters) - { - var lowerKebabName = TagHelperDescriptorFactory.ToHtmlCase(parameter.Name); - var typeName = GetCSharpTypeName(parameter.ParameterType); - var descriptor = new TagHelperAttributeDescriptor - { - Name = lowerKebabName, - PropertyName = parameter.Name, - TypeName = typeName - }; - - descriptor.IsEnum = parameter.ParameterType.GetTypeInfo().IsEnum; - descriptor.IsIndexer = false; - - attributeDescriptors.Add(descriptor); - - var indexerDescriptor = GetIndexerAttributeDescriptor(parameter, lowerKebabName); - if (indexerDescriptor != null) - { - indexerDescriptors.Add(indexerDescriptor); - } - else - { - // Set required attributes only for non-indexer attributes. Indexer attributes can't be required attributes - // because there are two ways of setting values for the attribute. - requiredAttributeDescriptors.Add(new TagHelperRequiredAttributeDescriptor - { - Name = lowerKebabName - }); - } - } - - attributeDescriptors.AddRange(indexerDescriptors); - tagHelperDescriptor.Attributes = attributeDescriptors; - tagHelperDescriptor.RequiredAttributes = requiredAttributeDescriptors; - } - - private TagHelperAttributeDescriptor GetIndexerAttributeDescriptor(ParameterInfo parameter, string name) - { - var dictionaryTypeArguments = ClosedGenericMatcher.ExtractGenericInterface( - parameter.ParameterType, - typeof(IDictionary<,>)) - ?.GenericTypeArguments - .Select(t => t.IsGenericParameter ? null : t) - .ToArray(); - - if (dictionaryTypeArguments?[0] != typeof(string)) - { - return null; - } - - var type = dictionaryTypeArguments[1]; - var descriptor = new TagHelperAttributeDescriptor - { - Name = name + "-", - PropertyName = parameter.Name, - TypeName = GetCSharpTypeName(type), - IsEnum = type.GetTypeInfo().IsEnum, - IsIndexer = true - }; - - return descriptor; - } - - private string GetTagName(ViewComponentDescriptor descriptor) - { - return $"vc:{TagHelperDescriptorFactory.ToHtmlCase(descriptor.ShortName)}"; - } - - // Internal for testing. - internal static string GetCSharpTypeName(Type type) - { - var outputBuilder = new StringBuilder(); - WriteCSharpTypeName(type, outputBuilder); - - var typeName = outputBuilder.ToString(); - - // We don't want to add global:: to the top level type because Razor does that for us. - return typeName.Substring("global::".Length); - } - - private static void WriteCSharpTypeName(Type type, StringBuilder outputBuilder) - { - var typeInfo = type.GetTypeInfo(); - if (typeInfo.IsByRef) - { - WriteCSharpTypeName(typeInfo.GetElementType(), outputBuilder); - } - else if (typeInfo.IsNested) - { - WriteNestedTypes(type, outputBuilder); - } - else if (typeInfo.IsGenericType) - { - outputBuilder.Append("global::"); - var part = type.FullName.Substring(0, type.FullName.IndexOf('`')); - outputBuilder.Append(part); - - var genericArguments = type.GenericTypeArguments; - WriteGenericArguments(genericArguments, 0, genericArguments.Length, outputBuilder); - } - else - { - outputBuilder.Append("global::"); - outputBuilder.Append(type.FullName); - } - } - - private static void WriteNestedTypes(Type type, StringBuilder outputBuilder) - { - var nestedTypes = new List(); - var currentType = type; - do - { - nestedTypes.Insert(0, currentType); - currentType = currentType.DeclaringType; - } while (currentType.IsNested); - - nestedTypes.Insert(0, currentType); - - outputBuilder.Append("global::"); - outputBuilder.Append(currentType.Namespace); - outputBuilder.Append("."); - - var typeArgumentIndex = 0; - for (var i = 0; i < nestedTypes.Count; i++) - { - var nestedType = nestedTypes[i]; - var arityIndex = nestedType.Name.IndexOf('`'); - if (arityIndex >= 0) - { - var part = nestedType.Name.Substring(0, arityIndex); - outputBuilder.Append(part); - - var genericArguments = type.GenericTypeArguments; - var typeArgumentCount = nestedType.IsConstructedGenericType ? - nestedType.GenericTypeArguments.Length : nestedType.GetTypeInfo().GenericTypeParameters.Length; - - WriteGenericArguments(genericArguments, typeArgumentIndex, typeArgumentCount, outputBuilder); - - typeArgumentIndex = typeArgumentCount; - } - else - { - outputBuilder.Append(nestedType.Name); - } - - if (i + 1 < nestedTypes.Count) - { - outputBuilder.Append("."); - } - } - } - - private static void WriteGenericArguments(Type[] genericArguments, int startIndex, int length, StringBuilder outputBuilder) - { - outputBuilder.Append("<"); - - for (var i = startIndex; i < length; i++) - { - WriteCSharpTypeName(genericArguments[i], outputBuilder); - if (i + 1 < length) - { - outputBuilder.Append(", "); - } - } - - outputBuilder.Append(">"); - } - } -} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewComponentTagHelperDescriptorResolver.cs b/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewComponentTagHelperDescriptorResolver.cs deleted file mode 100644 index 2a6dd5f9c9..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewComponentTagHelperDescriptorResolver.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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.Collections.Generic; -using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.Compilation.TagHelpers; -using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class ViewComponentTagHelperDescriptorResolver : TagHelperDescriptorResolver - { - private readonly ViewComponentTagHelperDescriptorFactory _descriptorFactory; - - public ViewComponentTagHelperDescriptorResolver( - IViewComponentDescriptorProvider viewComponentDescriptorProvider) - : base(designTime: false) - { - _descriptorFactory = new ViewComponentTagHelperDescriptorFactory(viewComponentDescriptorProvider); - } - - protected override IEnumerable ResolveDescriptorsInAssembly( - string assemblyName, - SourceLocation documentLocation, - ErrorSink errorSink) - { - return _descriptorFactory.CreateDescriptors(assemblyName); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/FeatureTagHelperTypeResolver.cs b/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/FeatureTagHelperTypeResolver.cs deleted file mode 100644 index db55f0a496..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/FeatureTagHelperTypeResolver.cs +++ /dev/null @@ -1,94 +0,0 @@ -// 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 Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; -using System.Reflection; - -namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers -{ - /// - /// Resolves tag helper types from the - /// of the application. - /// - public class FeatureTagHelperTypeResolver : TagHelperTypeResolver - { - private readonly TagHelperFeature _feature; - - /// - /// Initializes a new instance. - /// - /// The of the application. - public FeatureTagHelperTypeResolver(ApplicationPartManager manager) - { - if (manager == null) - { - throw new ArgumentNullException(nameof(manager)); - } - - _feature = new TagHelperFeature(); - manager.PopulateFeature(_feature); - } - - /// - protected override IEnumerable GetExportedTypes(AssemblyName assemblyName) - { - if (assemblyName == null) - { - throw new ArgumentNullException(nameof(assemblyName)); - } - - var results = new List(); - for (var i = 0; i < _feature.TagHelpers.Count; i++) - { - var tagHelperAssemblyName = _feature.TagHelpers[i].Assembly.GetName(); - - if (AssemblyNameComparer.OrdinalIgnoreCase.Equals(tagHelperAssemblyName, assemblyName)) - { - results.Add(_feature.TagHelpers[i]); - } - } - - return results; - } - - /// - protected sealed override bool IsTagHelper(TypeInfo typeInfo) - { - // Return true always as we have already decided what types are tag helpers when GetExportedTypes - // gets called. - return true; - } - - private class AssemblyNameComparer : IEqualityComparer - { - public static readonly IEqualityComparer OrdinalIgnoreCase = new AssemblyNameComparer(); - - private AssemblyNameComparer() - { - } - - public bool Equals(AssemblyName x, AssemblyName y) - { - // Ignore case because that's what Assembly.Load does. - return string.Equals(x.Name, y.Name, StringComparison.OrdinalIgnoreCase) && - string.Equals(x.CultureName ?? string.Empty, y.CultureName ?? string.Empty, StringComparison.Ordinal); - } - - public int GetHashCode(AssemblyName obj) - { - var hashCode = 0; - if (obj.Name != null) - { - hashCode ^= obj.Name.GetHashCode(); - } - - hashCode ^= (obj.CultureName ?? string.Empty).GetHashCode(); - return hashCode; - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperFeatureProvider.cs b/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperFeatureProvider.cs deleted file mode 100644 index 32bd368d78..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperFeatureProvider.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; - -namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers -{ - /// - /// Discovers tag helpers from a list of instances. - /// - public class TagHelperFeatureProvider : IApplicationFeatureProvider - { - /// - public void PopulateFeature(IEnumerable parts, TagHelperFeature feature) - { - foreach (var type in parts.OfType()) - { - ProcessPart(type, feature); - } - } - - private static void ProcessPart(IApplicationPartTypeProvider part, TagHelperFeature feature) - { - foreach (var type in part.Types) - { - if (TagHelperConventions.IsTagHelper(type) && !feature.TagHelpers.Contains(type)) - { - feature.TagHelpers.Add(type); - } - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/Microsoft.AspNetCore.Mvc.Razor.Host.Test.csproj b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/Microsoft.AspNetCore.Mvc.Razor.Host.Test.csproj index 9980dc1556..2686ea0ef2 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/Microsoft.AspNetCore.Mvc.Razor.Host.Test.csproj +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/Microsoft.AspNetCore.Mvc.Razor.Host.Test.csproj @@ -20,6 +20,7 @@ + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/RawTextSymbol.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/RawTextSymbol.cs deleted file mode 100644 index de4d4ef83b..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/RawTextSymbol.cs +++ /dev/null @@ -1,73 +0,0 @@ -// 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.Globalization; -using Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.Parser.SyntaxTree; -using Microsoft.AspNetCore.Razor.Text; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols; - -namespace Microsoft.AspNetCore.Mvc.Razor -{ - internal class RawTextSymbol : ISymbol - { - public SourceLocation Start { get; private set; } - public string Content { get; private set; } - - public RawTextSymbol(SourceLocation start, string content) - { - if (content == null) - { - throw new ArgumentNullException(nameof(content)); - } - - Start = start; - Content = content; - } - - public override bool Equals(object obj) - { - var other = obj as RawTextSymbol; - return Equals(Start, other.Start) && Equals(Content, other.Content); - } - - internal bool EquivalentTo(ISymbol sym) - { - return Equals(Start, sym.Start) && Equals(Content, sym.Content); - } - - public override int GetHashCode() - { - return Start.GetHashCode() + - (13 * Content.GetHashCode()); - } - - public void OffsetStart(SourceLocation documentStart) - { - Start = documentStart + Start; - } - - public void ChangeStart(SourceLocation newStart) - { - Start = newStart; - } - - public override string ToString() - { - return string.Format(CultureInfo.InvariantCulture, "{0} RAW - [{1}]", Start, Content); - } - - internal void CalculateStart(Span prev) - { - if (prev == null) - { - Start = SourceLocation.Zero; - } - else - { - Start = new SourceLocationTracker(prev.Start).UpdateLocation(prev.Content).CurrentLocation; - } - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs deleted file mode 100644 index 026e54672d..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanConstructor.cs +++ /dev/null @@ -1,79 +0,0 @@ -// 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 Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.Chunks.Generators; -using Microsoft.AspNetCore.Razor.Editor; -using Microsoft.AspNetCore.Razor.Parser.SyntaxTree; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols; - -namespace Microsoft.AspNetCore.Mvc.Razor -{ - public class SpanConstructor - { - public SpanBuilder Builder { get; private set; } - - internal static IEnumerable TestTokenizer(string str) - { - yield return new RawTextSymbol(SourceLocation.Zero, str); - } - - public SpanConstructor(SpanKind kind, IEnumerable symbols) - { - Builder = new SpanBuilder(); - Builder.Kind = kind; - Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer); - foreach (ISymbol sym in symbols) - { - Builder.Accept(sym); - } - } - - private Span Build() - { - return Builder.Build(); - } - - public SpanConstructor With(ISpanChunkGenerator generator) - { - Builder.ChunkGenerator = generator; - return this; - } - - public SpanConstructor With(SpanEditHandler handler) - { - Builder.EditHandler = handler; - return this; - } - - public SpanConstructor With(Action generatorConfigurer) - { - generatorConfigurer(Builder.ChunkGenerator); - return this; - } - - public SpanConstructor With(Action handlerConfigurer) - { - handlerConfigurer(Builder.EditHandler); - return this; - } - - public static implicit operator Span(SpanConstructor self) - { - return self.Build(); - } - - public SpanConstructor Hidden() - { - Builder.ChunkGenerator = SpanChunkGenerator.Null; - return this; - } - - public SpanConstructor Accepts(AcceptedCharacters accepted) - { - return With(eh => eh.AcceptedCharacters = accepted); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanFactory.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanFactory.cs deleted file mode 100644 index df2575b8c3..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanFactory.cs +++ /dev/null @@ -1,110 +0,0 @@ -// 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.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.Parser.SyntaxTree; -using Microsoft.AspNetCore.Razor.Text; -using Microsoft.AspNetCore.Razor.Tokenizer; -using Microsoft.AspNetCore.Razor.Tokenizer.Internal; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal; - -namespace Microsoft.AspNetCore.Mvc.Razor -{ - public class SpanFactory - { - public Func MarkupTokenizerFactory { get; set; } - public Func CodeTokenizerFactory { get; set; } - public SourceLocationTracker LocationTracker { get; private set; } - - public static SpanFactory CreateCsHtml() - { - return new SpanFactory() - { - MarkupTokenizerFactory = doc => new HtmlTokenizer(doc), - CodeTokenizerFactory = doc => new CSharpTokenizer(doc) - }; - } - - public SpanFactory() - { - LocationTracker = new SourceLocationTracker(); - } - - public SpanConstructor Span(SpanKind kind, string content, CSharpSymbolType type) - { - return CreateSymbolSpan(kind, content, st => new CSharpSymbol(st, content, type)); - } - - public SpanConstructor Span(SpanKind kind, string content, HtmlSymbolType type) - { - return CreateSymbolSpan(kind, content, st => new HtmlSymbol(st, content, type)); - } - - public SpanConstructor Span(SpanKind kind, string content, bool markup) - { - return new SpanConstructor(kind, Tokenize(new[] { content }, markup)); - } - - public SpanConstructor Span(SpanKind kind, string[] content, bool markup) - { - return new SpanConstructor(kind, Tokenize(content, markup)); - } - - public SpanConstructor Span(SpanKind kind, params ISymbol[] symbols) - { - return new SpanConstructor(kind, symbols); - } - - private SpanConstructor CreateSymbolSpan(SpanKind kind, string content, Func ctor) - { - var start = LocationTracker.CurrentLocation; - LocationTracker.UpdateLocation(content); - return new SpanConstructor(kind, new[] { ctor(start) }); - } - - public void Reset() - { - LocationTracker.CurrentLocation = SourceLocation.Zero; - } - - private IEnumerable Tokenize(IEnumerable contentFragments, bool markup) - { - return contentFragments.SelectMany(fragment => Tokenize(fragment, markup)); - } - - private IEnumerable Tokenize(string content, bool markup) - { - var tok = MakeTokenizer(markup, new SeekableTextReader(content)); - ISymbol sym; - ISymbol last = null; - while ((sym = tok.NextSymbol()) != null) - { - OffsetStart(sym, LocationTracker.CurrentLocation); - last = sym; - yield return sym; - } - LocationTracker.UpdateLocation(content); - } - - private ITokenizer MakeTokenizer(bool markup, SeekableTextReader seekableTextReader) - { - if (markup) - { - return MarkupTokenizerFactory(seekableTextReader); - } - else - { - return CodeTokenizerFactory(seekableTextReader); - } - } - - private void OffsetStart(ISymbol sym, SourceLocation sourceLocation) - { - sym.OffsetStart(sourceLocation); - } - } -} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs deleted file mode 100644 index b5afa3732c..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/SpanFactoryExtensions.cs +++ /dev/null @@ -1,126 +0,0 @@ -// 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 Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.Chunks.Generators; -using Microsoft.AspNetCore.Razor.Parser; -using Microsoft.AspNetCore.Razor.Parser.SyntaxTree; -using Microsoft.AspNetCore.Razor.Text; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal; - -namespace Microsoft.AspNetCore.Mvc.Razor -{ - public static class SpanFactoryExtensions - { - public static UnclassifiedCodeSpanConstructor EmptyCSharp(this SpanFactory self) - { - var symbol = new CSharpSymbol(self.LocationTracker.CurrentLocation, string.Empty, CSharpSymbolType.Unknown); - return new UnclassifiedCodeSpanConstructor(self.Span(SpanKind.Code, symbol)); - } - - public static SpanConstructor EmptyHtml(this SpanFactory self) - { - var symbol = new HtmlSymbol(self.LocationTracker.CurrentLocation, string.Empty, HtmlSymbolType.Unknown); - return self.Span(SpanKind.Markup, symbol) - .With(new MarkupChunkGenerator()); - } - - public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content) - { - return new UnclassifiedCodeSpanConstructor( - self.Span(SpanKind.Code, content, markup: false)); - } - - public static SpanConstructor CodeTransition(this SpanFactory self) - { - return self.Span(SpanKind.Transition, SyntaxConstants.TransitionString, markup: false) - .Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor CodeTransition(this SpanFactory self, string content) - { - return self.Span(SpanKind.Transition, content, markup: false).Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor CodeTransition(this SpanFactory self, CSharpSymbolType type) - { - return self.Span(SpanKind.Transition, SyntaxConstants.TransitionString, type) - .Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor CodeTransition(this SpanFactory self, string content, CSharpSymbolType type) - { - return self.Span(SpanKind.Transition, content, type).Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor MarkupTransition(this SpanFactory self) - { - return self.Span(SpanKind.Transition, SyntaxConstants.TransitionString, markup: true) - .Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor MarkupTransition(this SpanFactory self, string content) - { - return self.Span(SpanKind.Transition, content, markup: true).Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor MarkupTransition(this SpanFactory self, HtmlSymbolType type) - { - return self.Span(SpanKind.Transition, SyntaxConstants.TransitionString, type) - .Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor MarkupTransition(this SpanFactory self, string content, HtmlSymbolType type) - { - return self.Span(SpanKind.Transition, content, type).Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor MetaCode(this SpanFactory self, string content) - { - return self.Span(SpanKind.MetaCode, content, markup: false); - } - - public static SpanConstructor MetaCode(this SpanFactory self, string content, CSharpSymbolType type) - { - return self.Span(SpanKind.MetaCode, content, type); - } - - public static SpanConstructor MetaMarkup(this SpanFactory self, string content) - { - return self.Span(SpanKind.MetaCode, content, markup: true); - } - - public static SpanConstructor MetaMarkup(this SpanFactory self, string content, HtmlSymbolType type) - { - return self.Span(SpanKind.MetaCode, content, type); - } - - public static SpanConstructor Comment(this SpanFactory self, string content, CSharpSymbolType type) - { - return self.Span(SpanKind.Comment, content, type); - } - - public static SpanConstructor Comment(this SpanFactory self, string content, HtmlSymbolType type) - { - return self.Span(SpanKind.Comment, content, type); - } - - public static SpanConstructor Markup(this SpanFactory self, string content) - { - return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator()); - } - - public static SpanConstructor Markup(this SpanFactory self, params string[] content) - { - return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator()); - } - - public static SourceLocation GetLocationAndAdvance(this SourceLocationTracker self, string content) - { - var ret = self.CurrentLocation; - self.UpdateLocation(content); - return ret; - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs deleted file mode 100644 index e3691f3ba0..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/SpanFactory/UnclassifiedCodeSpanConstructor.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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 Microsoft.AspNetCore.Razor.Chunks.Generators; - -namespace Microsoft.AspNetCore.Mvc.Razor -{ - public class UnclassifiedCodeSpanConstructor - { - private readonly SpanConstructor _self; - - public UnclassifiedCodeSpanConstructor(SpanConstructor self) - { - _self = self; - } - - public SpanConstructor As(ISpanChunkGenerator codeGenerator) - { - return _self.With(codeGenerator); - } - } -} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcBuilderExtensionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcBuilderExtensionsTest.cs index aab8b5a028..ef93c6eb6f 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcBuilderExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcBuilderExtensionsTest.cs @@ -26,7 +26,6 @@ public void AddTagHelpersAsServices_ReplacesTagHelperActivatorAndTagHelperTypeRe .ConfigureApplicationPartManager(manager => { manager.ApplicationParts.Add(new TestApplicationPart()); - manager.FeatureProviders.Add(new TagHelperFeatureProvider()); }); // Act @@ -35,9 +34,6 @@ public void AddTagHelpersAsServices_ReplacesTagHelperActivatorAndTagHelperTypeRe // Assert var activatorDescriptor = Assert.Single(services.ToList(), d => d.ServiceType == typeof(ITagHelperActivator)); Assert.Equal(typeof(ServiceBasedTagHelperActivator), activatorDescriptor.ImplementationType); - - var resolverDescriptor = Assert.Single(services.ToList(), d => d.ServiceType == typeof(ITagHelperTypeResolver)); - Assert.Equal(typeof(FeatureTagHelperTypeResolver), resolverDescriptor.ImplementationType); } [Fact] @@ -60,9 +56,9 @@ public void AddTagHelpersAsServices_RegistersDiscoveredTagHelpers() // Assert var collection = services.ToList(); - Assert.Equal(4, collection.Count); + Assert.Equal(3, collection.Count); - var tagHelperOne = Assert.Single(collection,t => t.ServiceType == typeof(TestTagHelperOne)); + var tagHelperOne = Assert.Single(collection, t => t.ServiceType == typeof(TestTagHelperOne)); Assert.Equal(typeof(TestTagHelperOne), tagHelperOne.ImplementationType); Assert.Equal(ServiceLifetime.Transient, tagHelperOne.Lifetime); @@ -73,10 +69,6 @@ public void AddTagHelpersAsServices_RegistersDiscoveredTagHelpers() var activator = Assert.Single(collection, t => t.ServiceType == typeof(ITagHelperActivator)); Assert.Equal(typeof(ServiceBasedTagHelperActivator), activator.ImplementationType); Assert.Equal(ServiceLifetime.Transient, activator.Lifetime); - - var typeResolver = Assert.Single(collection, t => t.ServiceType == typeof(ITagHelperTypeResolver)); - Assert.Equal(typeof(FeatureTagHelperTypeResolver), typeResolver.ImplementationType); - Assert.Equal(ServiceLifetime.Transient, typeResolver.Lifetime); } private class TestTagHelperOne : TagHelper diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcCoreBuilderExtensionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcCoreBuilderExtensionsTest.cs index e1aba6824e..2db533554f 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcCoreBuilderExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/DependencyInjection/MvcRazorMvcCoreBuilderExtensionsTest.cs @@ -115,7 +115,6 @@ public void AddTagHelpersAsServices_ReplacesTagHelperActivatorAndTagHelperTypeRe .ConfigureApplicationPartManager(manager => { manager.ApplicationParts.Add(new TestApplicationPart()); - manager.FeatureProviders.Add(new TagHelperFeatureProvider()); }); // Act @@ -124,9 +123,6 @@ public void AddTagHelpersAsServices_ReplacesTagHelperActivatorAndTagHelperTypeRe // Assert var activatorDescriptor = Assert.Single(services.ToList(), d => d.ServiceType == typeof(ITagHelperActivator)); Assert.Equal(typeof(ServiceBasedTagHelperActivator), activatorDescriptor.ImplementationType); - - var resolverDescriptor = Assert.Single(services.ToList(), d => d.ServiceType == typeof(ITagHelperTypeResolver)); - Assert.Equal(typeof(FeatureTagHelperTypeResolver), resolverDescriptor.ImplementationType); } [Fact] @@ -149,7 +145,7 @@ public void AddTagHelpersAsServices_RegistersDiscoveredTagHelpers() // Assert var collection = services.ToList(); - Assert.Equal(4, collection.Count); + Assert.Equal(3, collection.Count); var tagHelperOne = Assert.Single(collection, t => t.ServiceType == typeof(TestTagHelperOne)); Assert.Equal(typeof(TestTagHelperOne), tagHelperOne.ImplementationType); @@ -162,10 +158,6 @@ public void AddTagHelpersAsServices_RegistersDiscoveredTagHelpers() var activator = Assert.Single(collection, t => t.ServiceType == typeof(ITagHelperActivator)); Assert.Equal(typeof(ServiceBasedTagHelperActivator), activator.ImplementationType); Assert.Equal(ServiceLifetime.Transient, activator.Lifetime); - - var typeResolver = Assert.Single(collection, t => t.ServiceType == typeof(ITagHelperTypeResolver)); - Assert.Equal(typeof(FeatureTagHelperTypeResolver), typeResolver.ImplementationType); - Assert.Equal(ServiceLifetime.Transient, typeResolver.Lifetime); } private class TestTagHelperOne : TagHelper diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/ViewComponentTagHelperDescriptorFactoryTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/ViewComponentTagHelperDescriptorFactoryTest.cs deleted file mode 100644 index d49b45a05e..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/ViewComponentTagHelperDescriptorFactoryTest.cs +++ /dev/null @@ -1,368 +0,0 @@ -// 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 System.Reflection; -using Microsoft.AspNetCore.Mvc.Razor.Host; -using Microsoft.AspNetCore.Mvc.Razor.Internal; -using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.AspNetCore.Razor.Compilation.TagHelpers; -using Microsoft.AspNetCore.Razor.TagHelpers.Testing; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.Razor.Test.Internal -{ - public class ViewComponentTagHelperDescriptorFactoryTest - { - public static TheoryData AssemblyData - { - get - { - var provider = new TestViewComponentDescriptorProvider(); - - var assemblyOne = "Microsoft.AspNetCore.Mvc.Razor"; - var assemblyTwo = "Microsoft.AspNetCore.Mvc.Razor.Test"; - var assemblyNone = string.Empty; - - return new TheoryData> - { - { assemblyOne, new [] { provider.GetTagHelperDescriptorOne() } }, - { assemblyTwo, new [] { provider.GetTagHelperDescriptorTwo(), provider.GetTagHelperDescriptorGeneric() } }, - { assemblyNone, Enumerable.Empty() } - }; - } - } - - [Theory] - [MemberData(nameof(AssemblyData))] - public void CreateDescriptors_ReturnsCorrectDescriptors( - string assemblyName, - IEnumerable expectedDescriptors) - { - // Arrange - var provider = new TestViewComponentDescriptorProvider(); - var factory = new ViewComponentTagHelperDescriptorFactory(provider); - - // Act - var descriptors = factory.CreateDescriptors(assemblyName); - - // Assert - Assert.Equal(expectedDescriptors, descriptors, CaseSensitiveTagHelperDescriptorComparer.Default); - } - - public static TheoryData TypeData - { - get - { - var refParamType = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetMethod("MethodWithRefParam").GetParameters().First().ParameterType; - - return new TheoryData - { - { typeof(string), "System.String" }, - { typeof(string[,]), "System.String[,]" }, - { typeof(List), "System.Collections.Generic.List" }, - { typeof(List), "System.Collections.Generic.List" }, - { typeof(Dictionary>), - "System.Collections.Generic.Dictionary>" }, - { typeof(Dictionary>), - "System.Collections.Generic.Dictionary>" }, - { refParamType, "System.String[]" }, - { typeof(NonGeneric.Nested1.Nested2), - "Microsoft.AspNetCore.Mvc.Razor.Test.Internal.ViewComponentTagHelperDescriptorFactoryTest.NonGeneric.Nested1.Nested2" }, - { typeof(GenericType.GenericNestedType), - "Microsoft.AspNetCore.Mvc.Razor.Test.Internal.ViewComponentTagHelperDescriptorFactoryTest.GenericType.GenericNestedType" }, - { typeof(GenericType.NonGenericNested.MultiNestedType), - "Microsoft.AspNetCore.Mvc.Razor.Test.Internal.ViewComponentTagHelperDescriptorFactoryTest.GenericType.NonGenericNested.MultiNestedType" }, - { typeof(Dictionary.NonGenericNested.MultiNestedType, List>), - "System.Collections.Generic.Dictionary.NonGenericNested.MultiNestedType, global::System.Collections.Generic.List>" }, - }; - } - } - - [Theory] - [MemberData(nameof(TypeData))] - public void GetCSharpTypeName_ReturnsCorrectTypeNames(Type type, string expected) - { - // Act - var typeName = ViewComponentTagHelperDescriptorFactory.GetCSharpTypeName(type); - - // Assert - Assert.Equal(expected, typeName); - } - - // Separated from GetCSharpTypeName_ReturnsCorrectTypeNames to work around problems serializing and - // deserializing this ref type. - [Fact] - public void GetCSharpTypeName_ReturnsCorrectTypeNames_ForOutParameter() - { - // Arrange - var type = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetMethod("MethodWithOutParam").GetParameters().First().ParameterType; - var expected = "System.Collections.Generic.List"; - - // Act - var typeName = ViewComponentTagHelperDescriptorFactory.GetCSharpTypeName(type); - - // Assert - Assert.Equal(expected, typeName); - } - - // Test invokes are needed for method creation in TestViewComponentDescriptorProvider. - public enum TestEnum - { - A = 1, - B = 2, - C = 3 - } - - public void TestInvokeOne(string foo, string bar) - { - } - - public void TestInvokeTwo(TestEnum testEnum, string testString, int baz = 5) - { - } - - public void InvokeWithGenericParams(List Foo, Dictionary Bar) - { - } - - public void InvokeWithOpenGeneric(List baz) - { - } - - private class TestViewComponentDescriptorProvider : IViewComponentDescriptorProvider - { - private readonly ViewComponentDescriptor _viewComponentDescriptorOne = new ViewComponentDescriptor - { - DisplayName = "OneDisplayName", - FullName = "OneViewComponent", - ShortName = "One", - MethodInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.TestInvokeOne)), - TypeInfo = typeof(ViewComponentTagHelperDescriptorFactory).GetTypeInfo(), - Parameters = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.TestInvokeOne)).GetParameters() - }; - - private readonly ViewComponentDescriptor _viewComponentDescriptorTwo = new ViewComponentDescriptor - { - DisplayName = "TwoDisplayName", - FullName = "TwoViewComponent", - ShortName = "Two", - MethodInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.TestInvokeTwo)), - TypeInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetTypeInfo(), - Parameters = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.TestInvokeTwo)).GetParameters() - }; - - private readonly ViewComponentDescriptor _viewComponentDescriptorGeneric = new ViewComponentDescriptor - { - DisplayName = "GenericDisplayName", - FullName = "GenericViewComponent", - ShortName = "Generic", - MethodInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.InvokeWithGenericParams)), - TypeInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetTypeInfo(), - Parameters = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.InvokeWithGenericParams)).GetParameters() - }; - - private readonly ViewComponentDescriptor _viewComponentDescriptorOpenGeneric = new ViewComponentDescriptor - { - DisplayName = "OpenGenericDisplayName", - FullName = "OpenGenericViewComponent", - ShortName = "OpenGeneric", - MethodInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.InvokeWithOpenGeneric)), - TypeInfo = typeof(ViewComponentTagHelperDescriptorFactoryTest).GetTypeInfo(), - Parameters = typeof(ViewComponentTagHelperDescriptorFactoryTest) - .GetMethod(nameof(ViewComponentTagHelperDescriptorFactoryTest.InvokeWithOpenGeneric)).GetParameters() - }; - - public TagHelperDescriptor GetTagHelperDescriptorOne() - { - var descriptor = new TagHelperDescriptor - { - TagName = "vc:one", - TypeName = "__Generated__OneViewComponentTagHelper", - AssemblyName = "Microsoft.AspNetCore.Mvc.Razor", - Attributes = new List - { - new TagHelperAttributeDescriptor - { - Name = "foo", - PropertyName = "foo", - TypeName = typeof(string).FullName - }, - new TagHelperAttributeDescriptor - { - Name = "bar", - PropertyName = "bar", - TypeName = typeof(string).FullName - } - }, - RequiredAttributes = new List - { - new TagHelperRequiredAttributeDescriptor - { - Name = "foo" - }, - new TagHelperRequiredAttributeDescriptor - { - Name = "bar" - } - } - }; - - descriptor.PropertyBag.Add(ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey, "One"); - return descriptor; - } - - public TagHelperDescriptor GetTagHelperDescriptorTwo() - { - var descriptor = new TagHelperDescriptor - { - TagName = "vc:two", - TypeName = "__Generated__TwoViewComponentTagHelper", - AssemblyName = "Microsoft.AspNetCore.Mvc.Razor.Test", - Attributes = new List - { - new TagHelperAttributeDescriptor - { - Name = "test-enum", - PropertyName = "testEnum", - TypeName = ViewComponentTagHelperDescriptorFactory.GetCSharpTypeName(typeof(TestEnum)), - IsEnum = true - }, - - new TagHelperAttributeDescriptor - { - Name = "test-string", - PropertyName = "testString", - TypeName = typeof(string).FullName - }, - - new TagHelperAttributeDescriptor - { - Name = "baz", - PropertyName = "baz", - TypeName = typeof(int).FullName - } - }, - RequiredAttributes = new List - { - new TagHelperRequiredAttributeDescriptor - { - Name = "test-enum" - }, - - new TagHelperRequiredAttributeDescriptor - { - Name = "test-string" - }, - - new TagHelperRequiredAttributeDescriptor - { - Name = "baz" - } - } - }; - - descriptor.PropertyBag.Add(ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey, "Two"); - return descriptor; - } - - public TagHelperDescriptor GetTagHelperDescriptorGeneric() - { - var descriptor = new TagHelperDescriptor - { - TagName = "vc:generic", - TypeName = "__Generated__GenericViewComponentTagHelper", - AssemblyName = "Microsoft.AspNetCore.Mvc.Razor.Test", - Attributes = new List - { - new TagHelperAttributeDescriptor - { - Name = "foo", - PropertyName = "Foo", - TypeName = ViewComponentTagHelperDescriptorFactory.GetCSharpTypeName(typeof(List)) - }, - - new TagHelperAttributeDescriptor - { - Name = "bar", - PropertyName = "Bar", - TypeName = ViewComponentTagHelperDescriptorFactory.GetCSharpTypeName(typeof(Dictionary)) - }, - - new TagHelperAttributeDescriptor - { - Name = "bar-", - PropertyName = "Bar", - TypeName = typeof(int).FullName, - IsIndexer = true - } - }, - RequiredAttributes = new List - { - new TagHelperRequiredAttributeDescriptor - { - Name = "foo" - } - } - }; - - descriptor.PropertyBag.Add(ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey, "Generic"); - return descriptor; - } - - public IEnumerable GetViewComponents() - { - return new List - { - _viewComponentDescriptorOne, - _viewComponentDescriptorTwo, - _viewComponentDescriptorGeneric, - _viewComponentDescriptorOpenGeneric - }; - } - } - - public void MethodWithOutParam(out List foo) - { - foo = null; - } - - public void MethodWithRefParam(ref string[] bar) - { - } - - private class GenericType - { - public class GenericNestedType - { - } - - public class NonGenericNested - { - public class MultiNestedType - { - } - } - } - - private class NonGeneric - { - public class Nested1 - { - public class Nested2 - { - - } - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/SpanFactory.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/SpanFactory.cs deleted file mode 100644 index 2b61117885..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/SpanFactory.cs +++ /dev/null @@ -1,248 +0,0 @@ -// 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.Globalization; -using System.Linq; -using Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.Chunks.Generators; -using Microsoft.AspNetCore.Razor.Editor; -using Microsoft.AspNetCore.Razor.Parser.SyntaxTree; -using Microsoft.AspNetCore.Razor.Text; -using Microsoft.AspNetCore.Razor.Tokenizer; -using Microsoft.AspNetCore.Razor.Tokenizer.Internal; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols; -using Microsoft.AspNetCore.Razor.Tokenizer.Symbols.Internal; - -namespace Microsoft.AspNetCore.Mvc.Razor.Host.Test -{ - public static class SpanFactoryExtensions - { - public static SpanConstructor EmptyHtml(this SpanFactory self) - { - return self.Span(SpanKind.Markup, new HtmlSymbol(self.LocationTracker.CurrentLocation, String.Empty, HtmlSymbolType.Unknown)) - .With(new MarkupChunkGenerator()); - } - - public static UnclassifiedCodeSpanConstructor Code(this SpanFactory self, string content) - { - return new UnclassifiedCodeSpanConstructor( - self.Span(SpanKind.Code, content, markup: false)); - } - - public static SpanConstructor CodeTransition(this SpanFactory self, string content) - { - return self.Span(SpanKind.Transition, content, markup: false).Accepts(AcceptedCharacters.None); - } - - public static SpanConstructor MetaCode(this SpanFactory self, string content) - { - return self.Span(SpanKind.MetaCode, content, markup: false); - } - public static SpanConstructor Markup(this SpanFactory self, string content) - { - return self.Span(SpanKind.Markup, content, markup: true).With(new MarkupChunkGenerator()); - } - } - - public class SpanFactory - { - public Func MarkupTokenizerFactory { get; set; } - public Func CodeTokenizerFactory { get; set; } - public SourceLocationTracker LocationTracker { get; private set; } - - public static SpanFactory CreateCsHtml() - { - return new SpanFactory() - { - MarkupTokenizerFactory = doc => new HtmlTokenizer(doc), - CodeTokenizerFactory = doc => new CSharpTokenizer(doc) - }; - } - - public SpanFactory() - { - LocationTracker = new SourceLocationTracker(); - } - - - public SpanConstructor Span(SpanKind kind, string content, bool markup) - { - return new SpanConstructor(kind, Tokenize(new[] { content }, markup)); - } - - public SpanConstructor Span(SpanKind kind, params ISymbol[] symbols) - { - return new SpanConstructor(kind, symbols); - } - - private IEnumerable Tokenize(IEnumerable contentFragments, bool markup) - { - return contentFragments.SelectMany(fragment => Tokenize(fragment, markup)); - } - - private IEnumerable Tokenize(string content, bool markup) - { - ITokenizer tok = MakeTokenizer(markup, new SeekableTextReader(content)); - ISymbol sym; - ISymbol last = null; - while ((sym = tok.NextSymbol()) != null) - { - OffsetStart(sym, LocationTracker.CurrentLocation); - last = sym; - yield return sym; - } - LocationTracker.UpdateLocation(content); - } - - private ITokenizer MakeTokenizer(bool markup, SeekableTextReader seekableTextReader) - { - if (markup) - { - return MarkupTokenizerFactory(seekableTextReader); - } - else - { - return CodeTokenizerFactory(seekableTextReader); - } - } - - private void OffsetStart(ISymbol sym, SourceLocation sourceLocation) - { - sym.OffsetStart(sourceLocation); - } - } - - public static class SpanConstructorExtensions - { - public static SpanConstructor Accepts(this SpanConstructor self, AcceptedCharacters accepted) - { - return self.With(eh => eh.AcceptedCharacters = accepted); - } - } - - public class UnclassifiedCodeSpanConstructor - { - SpanConstructor _self; - - public UnclassifiedCodeSpanConstructor(SpanConstructor self) - { - _self = self; - } - - public SpanConstructor As(ISpanChunkGenerator codeGenerator) - { - return _self.With(codeGenerator); - } - } - - public class SpanConstructor - { - public SpanBuilder Builder { get; private set; } - - internal static IEnumerable TestTokenizer(string str) - { - yield return new RawTextSymbol(SourceLocation.Zero, str); - } - - public SpanConstructor(SpanKind kind, IEnumerable symbols) - { - Builder = new SpanBuilder(); - Builder.Kind = kind; - Builder.EditHandler = SpanEditHandler.CreateDefault(TestTokenizer); - foreach (ISymbol sym in symbols) - { - Builder.Accept(sym); - } - } - - private Span Build() - { - return Builder.Build(); - } - - public SpanConstructor With(ISpanChunkGenerator generator) - { - Builder.ChunkGenerator = generator; - return this; - } - - public SpanConstructor With(SpanEditHandler handler) - { - Builder.EditHandler = handler; - return this; - } - - public SpanConstructor With(Action handlerConfigurer) - { - handlerConfigurer(Builder.EditHandler); - return this; - } - - public static implicit operator Span(SpanConstructor self) - { - return self.Build(); - } - } - - internal class RawTextSymbol : ISymbol - { - public SourceLocation Start { get; private set; } - public string Content { get; private set; } - - public RawTextSymbol(SourceLocation start, string content) - { - if (content == null) - { - throw new ArgumentNullException(nameof(content)); - } - - Start = start; - Content = content; - } - - public override bool Equals(object obj) - { - RawTextSymbol other = obj as RawTextSymbol; - return Equals(Start, other.Start) && Equals(Content, other.Content); - } - - internal bool EquivalentTo(ISymbol sym) - { - return Equals(Start, sym.Start) && Equals(Content, sym.Content); - } - - public override int GetHashCode() - { - return Start.GetHashCode(); - } - - public void OffsetStart(SourceLocation documentStart) - { - Start = documentStart + Start; - } - - public void ChangeStart(SourceLocation newStart) - { - Start = newStart; - } - - public override string ToString() - { - return String.Format(CultureInfo.InvariantCulture, "{0} RAW - [{1}]", Start, Content); - } - - internal void CalculateStart(Span prev) - { - if (prev == null) - { - Start = SourceLocation.Zero; - } - else - { - Start = new SourceLocationTracker(prev.Start).UpdateLocation(prev.Content).CurrentLocation; - } - } - } -} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/TagHelpers/FeatureTagHelperTypeResolverTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/TagHelpers/FeatureTagHelperTypeResolverTest.cs deleted file mode 100644 index 48688a383c..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/TagHelpers/FeatureTagHelperTypeResolverTest.cs +++ /dev/null @@ -1,99 +0,0 @@ -// 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 System.Reflection; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.TagHelpers; -using Microsoft.AspNetCore.Razor; -using Microsoft.AspNetCore.Razor.TagHelpers; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers -{ - public class FeatureTagHelperTypeResolverTest - { - [Fact] - public void Resolve_ReturnsTagHelpers_FromApplicationParts() - { - // Arrange - var manager = new ApplicationPartManager(); - var types = new[] { typeof(TestTagHelper) }; - manager.ApplicationParts.Add(new TestApplicationPart(types)); - manager.FeatureProviders.Add(new TestFeatureProvider()); - - var resolver = new FeatureTagHelperTypeResolver(manager); - - var assemblyName = typeof(FeatureTagHelperTypeResolverTest).GetTypeInfo().Assembly.GetName().Name; - - // Act - var result = resolver.Resolve(assemblyName, SourceLocation.Undefined, new ErrorSink()); - - // Assert - var type = Assert.Single(result); - Assert.Equal(typeof(TestTagHelper), type); - } - - [Fact] - public void Resolve_ReturnsTagHelpers_FilteredByAssembly() - { - // Arrange - var manager = new ApplicationPartManager(); - var types = new[] { typeof(TestTagHelper) }; - manager.ApplicationParts.Add(new AssemblyPart(typeof(InputTagHelper).GetTypeInfo().Assembly)); - manager.ApplicationParts.Add(new TestApplicationPart(types)); - manager.FeatureProviders.Add(new TestFeatureProvider()); - - var resolver = new FeatureTagHelperTypeResolver(manager); - - var assemblyName = typeof(FeatureTagHelperTypeResolverTest).GetTypeInfo().Assembly.GetName().Name; - - // Act - var result = resolver.Resolve(assemblyName, SourceLocation.Undefined, new ErrorSink()); - - // Assert - var type = Assert.Single(result); - Assert.Equal(typeof(TestTagHelper), type); - } - - [Fact] - public void Resolve_ReturnsEmptyTypesList_IfAssemblyLoadFails() - { - // Arrange - var manager = new ApplicationPartManager(); - var types = new[] { typeof(TestTagHelper) }; - manager.ApplicationParts.Add(new AssemblyPart(typeof(InputTagHelper).GetTypeInfo().Assembly)); - manager.ApplicationParts.Add(new TestApplicationPart(types)); - manager.FeatureProviders.Add(new TestFeatureProvider()); - - var resolver = new FeatureTagHelperTypeResolver(manager); - - // Act - var result = resolver.Resolve("UnknownAssembly", SourceLocation.Undefined, new ErrorSink()); - - // Assert - Assert.Empty(result); - } - - private class TestFeatureProvider : IApplicationFeatureProvider - { - public void PopulateFeature(IEnumerable parts, TagHelperFeature feature) - { - foreach (var type in parts.OfType().SelectMany(tp => tp.Types)) - { - feature.TagHelpers.Add(type); - } - } - } - - private class TestTagHelper : TagHelper - { - } - - private class NotInPartsTagHelper : TagHelper - { - } - } -} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/TagHelpers/TagHelperFeatureProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/TagHelpers/TagHelperFeatureProviderTest.cs deleted file mode 100644 index 5753a179c4..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/TagHelpers/TagHelperFeatureProviderTest.cs +++ /dev/null @@ -1,87 +0,0 @@ -// 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.Collections.Generic; -using System.Reflection; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.Razor.TagHelpers.TagHelperFeatureProviderTests; -using Microsoft.AspNetCore.Razor.TagHelpers; -using Xunit; - -namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers -{ - public class TagHelperFeatureProviderTest - { - [Fact] - public void Populate_IncludesTagHelpers() - { - // Arrange - var manager = new ApplicationPartManager(); - manager.ApplicationParts.Add(new TestApplicationPart(typeof(DiscoveryTagHelper))); - manager.FeatureProviders.Add(new TagHelperFeatureProvider()); - - var feature = new TagHelperFeature(); - - // Act - manager.PopulateFeature(feature); - - // Assert - var tagHelperType = Assert.Single(feature.TagHelpers, th => th == typeof(DiscoveryTagHelper).GetTypeInfo()); - } - - [Fact] - public void Populate_DoesNotIncludeDuplicateTagHelpers() - { - // Arrange - var manager = new ApplicationPartManager(); - manager.ApplicationParts.Add(new TestApplicationPart(typeof(DiscoveryTagHelper))); - manager.ApplicationParts.Add(new TestApplicationPart(typeof(DiscoveryTagHelper))); - manager.FeatureProviders.Add(new TagHelperFeatureProvider()); - - var feature = new TagHelperFeature(); - - // Act - manager.PopulateFeature(feature); - - // Assert - var tagHelperType = Assert.Single(feature.TagHelpers, th => th == typeof(DiscoveryTagHelper).GetTypeInfo()); - } - - [Fact] - public void Populate_OnlyRunsOnPartsThatExportTypes() - { - // Arrange - var manager = new ApplicationPartManager(); - manager.ApplicationParts.Add(new TestApplicationPart(typeof(DiscoveryTagHelper))); - manager.ApplicationParts.Add(new NonApplicationTypeProviderPart()); - manager.FeatureProviders.Add(new TagHelperFeatureProvider()); - - var feature = new TagHelperFeature(); - - // Act - manager.PopulateFeature(feature); - - // Assert - var tagHelperType = Assert.Single(feature.TagHelpers, th => th == typeof(DiscoveryTagHelper).GetTypeInfo()); - } - - private class NonApplicationTypeProviderPart : ApplicationPart - { - public override string Name => nameof(NonApplicationTypeProviderPart); - - public IEnumerable Types => new[] { typeof(AnotherTagHelper).GetTypeInfo() }; - } - } -} - -// These types need to be public for the test to work. -namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers.TagHelperFeatureProviderTests -{ - public class DiscoveryTagHelper : TagHelper - { - } - - public class AnotherTagHelper : TagHelper - { - } -} diff --git a/test/Microsoft.AspNetCore.Mvc.Test/MvcServiceCollectionExtensionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Test/MvcServiceCollectionExtensionsTest.cs index 6c902cb0e7..b0c72b7c55 100644 --- a/test/Microsoft.AspNetCore.Mvc.Test/MvcServiceCollectionExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Test/MvcServiceCollectionExtensionsTest.cs @@ -212,7 +212,6 @@ public void AddMvcTwice_DoesNotAddApplicationFeatureProvidersTwice() Assert.Collection(manager.FeatureProviders, feature => Assert.IsType(feature), feature => Assert.IsType(feature), - feature => Assert.IsType(feature), feature => Assert.IsType(feature), feature => Assert.IsType(feature)); } diff --git a/test/Microsoft.AspNetCore.Mvc.TestCommon/Microsoft.AspNetCore.Mvc.TestCommon.csproj b/test/Microsoft.AspNetCore.Mvc.TestCommon/Microsoft.AspNetCore.Mvc.TestCommon.csproj index 3009d69847..260e618011 100644 --- a/test/Microsoft.AspNetCore.Mvc.TestCommon/Microsoft.AspNetCore.Mvc.TestCommon.csproj +++ b/test/Microsoft.AspNetCore.Mvc.TestCommon/Microsoft.AspNetCore.Mvc.TestCommon.csproj @@ -11,7 +11,6 @@ - diff --git a/test/Microsoft.AspNetCore.Mvc.TestCommon/PlatformNormalizer.cs b/test/Microsoft.AspNetCore.Mvc.TestCommon/PlatformNormalizer.cs index f74ee505f2..3c8737c9b9 100644 --- a/test/Microsoft.AspNetCore.Mvc.TestCommon/PlatformNormalizer.cs +++ b/test/Microsoft.AspNetCore.Mvc.TestCommon/PlatformNormalizer.cs @@ -1,10 +1,8 @@ // 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.Text.RegularExpressions; -using Microsoft.AspNetCore.Razor; using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Mvc @@ -42,14 +40,5 @@ public static string NormalizeContent(string input) return input; } - - // Assuming windows based source location is passed in, - // it gets normalized to other platforms. - public static SourceLocation NormalizedSourceLocation(int absoluteIndex, int lineIndex, int characterIndex) - { - var windowsNewLineLength = "\r\n".Length; - var differenceInLength = windowsNewLineLength - Environment.NewLine.Length; - return new SourceLocation(absoluteIndex - (differenceInLength * lineIndex), lineIndex, characterIndex); - } } } \ No newline at end of file diff --git a/test/WebSites/ControllersFromServicesWebSite/TagHelpers/InServicesTagHelper.cs b/test/WebSites/ControllersFromServicesWebSite/TagHelpers/InServicesTagHelper.cs index e6d2ec6ac3..7fa57a1e7b 100644 --- a/test/WebSites/ControllersFromServicesWebSite/TagHelpers/InServicesTagHelper.cs +++ b/test/WebSites/ControllersFromServicesWebSite/TagHelpers/InServicesTagHelper.cs @@ -1,10 +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 System.Threading.Tasks; using Microsoft.AspNetCore.Razor.TagHelpers; namespace ControllersFromServicesWebSite.TagHelpers