From 091cb94094a776b53ca6323c4251a38afc5ceef3 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 2 Aug 2018 01:17:09 -0700 Subject: [PATCH] Change metadata namespace Change EndpointOptions visibility to internal Add IRequiredValuesMetadata --- .../Benchmarks/StartupUsingEndpointRouting.cs | 11 ++--- .../Matching/MatcherBenchmarkBase.cs | 2 - .../UseEndpointRoutingStartup.cs | 14 ++---- .../CompositeEndpointDataSource.cs | 14 +++--- .../EndpointOptions.cs | 3 +- .../{Metadata => }/HttpMethodMetadata.cs | 2 +- .../{Metadata => }/IHttpMethodMetadata.cs | 2 +- .../IRouteValuesAddressMetadata.cs | 13 +++++ .../ISuppressLinkGenerationMetadata.cs | 2 +- .../Matching/HttpMethodMatcherPolicy.cs | 2 - .../Matching/MatcherEndpoint.cs | 5 -- .../RouteValuesAddressMetadata.cs | 48 +++++++++++++++++++ .../RouteValuesBasedEndpointFinder.cs | 6 +-- ...a.cs => SuppressLinkGenerationMetadata.cs} | 5 +- .../CompositeEndpointDataSourceTest.cs | 2 - .../EndpointFactory.cs | 11 +++-- .../Matching/CandidateSetTest.cs | 1 - .../DataSourceDependentMatcherTest.cs | 1 - .../Matching/DefaultEndpointSelectorTest.cs | 1 - .../Matching/DfaMatcherBuilderTest.cs | 1 - .../Matching/DfaMatcherTest.cs | 1 - .../HttpMethodMatcherPolicyIntegrationTest.cs | 2 - .../Matching/HttpMethodMatcherPolicyTest.cs | 2 - .../Matching/MatcherConformanceTest.cs | 1 - .../Matching/MatcherEndpointComparerTest.cs | 1 - .../RouteValueBasedEndpointFinderTest.cs | 20 ++------ .../RouteValuesAddressMetadataTests.cs | 33 +++++++++++++ 27 files changed, 133 insertions(+), 73 deletions(-) rename src/Microsoft.AspNetCore.Routing/{Metadata => }/HttpMethodMetadata.cs (96%) rename src/Microsoft.AspNetCore.Routing/{Metadata => }/IHttpMethodMetadata.cs (88%) create mode 100644 src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs create mode 100644 src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs rename src/Microsoft.AspNetCore.Routing/{IRouteNameMetadata.cs => SuppressLinkGenerationMetadata.cs} (71%) create mode 100644 test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs diff --git a/benchmarkapps/Benchmarks/StartupUsingEndpointRouting.cs b/benchmarkapps/Benchmarks/StartupUsingEndpointRouting.cs index c04f28decc..2c5fa5a7d9 100644 --- a/benchmarkapps/Benchmarks/StartupUsingEndpointRouting.cs +++ b/benchmarkapps/Benchmarks/StartupUsingEndpointRouting.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Matching; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; namespace Benchmarks { @@ -18,9 +19,7 @@ namespace Benchmarks { services.AddRouting(); - services.Configure(options => - { - options.DataSources.Add(new DefaultEndpointDataSource(new[] + var endpointDataSource = new DefaultEndpointDataSource(new[] { new MatcherEndpoint( invoker: (next) => (httpContext) => @@ -33,12 +32,12 @@ namespace Benchmarks return response.Body.WriteAsync(_helloWorldPayload, 0, payloadLength); }, routePattern: RoutePatternFactory.Parse("/plaintext"), - requiredValues: new RouteValueDictionary(), order: 0, metadata: EndpointMetadataCollection.Empty, displayName: "Plaintext"), - })); - }); + }); + + services.TryAddEnumerable(ServiceDescriptor.Singleton(endpointDataSource)); } public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app) diff --git a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matching/MatcherBenchmarkBase.cs b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matching/MatcherBenchmarkBase.cs index 76802c758d..4b030f84dc 100644 --- a/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matching/MatcherBenchmarkBase.cs +++ b/benchmarks/Microsoft.AspNetCore.Routing.Performance/Matching/MatcherBenchmarkBase.cs @@ -7,7 +7,6 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing.Metadata; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.DependencyInjection; @@ -44,7 +43,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template), - new RouteValueDictionary(), 0, new EndpointMetadataCollection(metadata), template); diff --git a/samples/RoutingSample.Web/UseEndpointRoutingStartup.cs b/samples/RoutingSample.Web/UseEndpointRoutingStartup.cs index d67d5fbe2a..77b41e87a8 100644 --- a/samples/RoutingSample.Web/UseEndpointRoutingStartup.cs +++ b/samples/RoutingSample.Web/UseEndpointRoutingStartup.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Matching; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; namespace RoutingSample.Web { @@ -26,9 +27,7 @@ namespace RoutingSample.Web options.ConstraintMap.Add("endsWith", typeof(EndsWithStringMatchProcessor)); }); - services.Configure(options => - { - options.DataSources.Add(new DefaultEndpointDataSource(new[] + var endpointDataSource = new DefaultEndpointDataSource(new[] { new MatcherEndpoint((next) => (httpContext) => { @@ -40,7 +39,6 @@ namespace RoutingSample.Web return response.Body.WriteAsync(_homePayload, 0, payloadLength); }, RoutePatternFactory.Parse("/"), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, "Home"), @@ -54,7 +52,6 @@ namespace RoutingSample.Web return response.Body.WriteAsync(_helloWorldPayload, 0, payloadLength); }, RoutePatternFactory.Parse("/plaintext"), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, "Plaintext"), @@ -66,7 +63,6 @@ namespace RoutingSample.Web return response.WriteAsync("WithConstraints"); }, RoutePatternFactory.Parse("/withconstraints/{id:endsWith(_001)}"), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, "withconstraints"), @@ -78,12 +74,12 @@ namespace RoutingSample.Web return response.WriteAsync("withoptionalconstraints"); }, RoutePatternFactory.Parse("/withoptionalconstraints/{id:endsWith(_001)?}"), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, "withoptionalconstraints"), - })); - }); + }); + + services.TryAddEnumerable(ServiceDescriptor.Singleton(endpointDataSource)); } public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app) diff --git a/src/Microsoft.AspNetCore.Routing/CompositeEndpointDataSource.cs b/src/Microsoft.AspNetCore.Routing/CompositeEndpointDataSource.cs index e9157ea578..3341b21796 100644 --- a/src/Microsoft.AspNetCore.Routing/CompositeEndpointDataSource.cs +++ b/src/Microsoft.AspNetCore.Routing/CompositeEndpointDataSource.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Text; using System.Threading; using Microsoft.AspNetCore.Routing.Matching; -using Microsoft.AspNetCore.Routing.Metadata; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Routing @@ -127,15 +126,18 @@ namespace Microsoft.AspNetCore.Routing var template = matcherEndpoint.RoutePattern.RawText; template = string.IsNullOrEmpty(template) ? "\"\"" : template; sb.Append(template); - sb.Append(", Required Values: new { "); - sb.Append(string.Join(", ", FormatValues(matcherEndpoint.RequiredValues))); - sb.Append(" }"); sb.Append(", Defaults: new { "); sb.Append(string.Join(", ", FormatValues(matcherEndpoint.RoutePattern.Defaults))); sb.Append(" }"); - var routeNameMetadata = matcherEndpoint.Metadata.GetMetadata(); + var routeValuesAddressMetadata = matcherEndpoint.Metadata.GetMetadata(); sb.Append(", Route Name: "); - sb.Append(routeNameMetadata?.Name); + sb.Append(routeValuesAddressMetadata?.Name); + if (routeValuesAddressMetadata?.RequiredValues != null) + { + sb.Append(", Required Values: new { "); + sb.Append(string.Join(", ", FormatValues(routeValuesAddressMetadata.RequiredValues))); + sb.Append(" }"); + } sb.Append(", Order: "); sb.Append(matcherEndpoint.Order); diff --git a/src/Microsoft.AspNetCore.Routing/EndpointOptions.cs b/src/Microsoft.AspNetCore.Routing/EndpointOptions.cs index bd03d3c7a2..8f364d6eaa 100644 --- a/src/Microsoft.AspNetCore.Routing/EndpointOptions.cs +++ b/src/Microsoft.AspNetCore.Routing/EndpointOptions.cs @@ -5,7 +5,8 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.Routing { - public class EndpointOptions + // Internal for 2.2. Public API for configuring endpoints will be added in 3.0 + internal class EndpointOptions { public IList DataSources { get; } = new List(); } diff --git a/src/Microsoft.AspNetCore.Routing/Metadata/HttpMethodMetadata.cs b/src/Microsoft.AspNetCore.Routing/HttpMethodMetadata.cs similarity index 96% rename from src/Microsoft.AspNetCore.Routing/Metadata/HttpMethodMetadata.cs rename to src/Microsoft.AspNetCore.Routing/HttpMethodMetadata.cs index af342a2f36..7d76b56cd0 100644 --- a/src/Microsoft.AspNetCore.Routing/Metadata/HttpMethodMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/HttpMethodMetadata.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -namespace Microsoft.AspNetCore.Routing.Metadata +namespace Microsoft.AspNetCore.Routing { [DebuggerDisplay("{DebuggerToString(),nq}")] public sealed class HttpMethodMetadata : IHttpMethodMetadata diff --git a/src/Microsoft.AspNetCore.Routing/Metadata/IHttpMethodMetadata.cs b/src/Microsoft.AspNetCore.Routing/IHttpMethodMetadata.cs similarity index 88% rename from src/Microsoft.AspNetCore.Routing/Metadata/IHttpMethodMetadata.cs rename to src/Microsoft.AspNetCore.Routing/IHttpMethodMetadata.cs index 9d6447d1e0..83b99d8f72 100644 --- a/src/Microsoft.AspNetCore.Routing/Metadata/IHttpMethodMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/IHttpMethodMetadata.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; -namespace Microsoft.AspNetCore.Routing.Metadata +namespace Microsoft.AspNetCore.Routing { public interface IHttpMethodMetadata { diff --git a/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs b/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs new file mode 100644 index 0000000000..0d60e5db92 --- /dev/null +++ b/src/Microsoft.AspNetCore.Routing/IRouteValuesAddressMetadata.cs @@ -0,0 +1,13 @@ +// 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; + +namespace Microsoft.AspNetCore.Routing +{ + public interface IRouteValuesAddressMetadata + { + string Name { get; } + IReadOnlyDictionary RequiredValues { get; } + } +} diff --git a/src/Microsoft.AspNetCore.Routing/ISuppressLinkGenerationMetadata.cs b/src/Microsoft.AspNetCore.Routing/ISuppressLinkGenerationMetadata.cs index 2e6a7da5d8..23c5e168d8 100644 --- a/src/Microsoft.AspNetCore.Routing/ISuppressLinkGenerationMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/ISuppressLinkGenerationMetadata.cs @@ -6,4 +6,4 @@ namespace Microsoft.AspNetCore.Routing public interface ISuppressLinkGenerationMetadata { } -} +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs b/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs index 315c3d8409..9968395b29 100644 --- a/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs +++ b/src/Microsoft.AspNetCore.Routing/Matching/HttpMethodMatcherPolicy.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing.Metadata; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; @@ -232,7 +231,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return Task.CompletedTask; }, RoutePatternFactory.Parse("/"), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, Http405EndpointDisplayName); diff --git a/src/Microsoft.AspNetCore.Routing/Matching/MatcherEndpoint.cs b/src/Microsoft.AspNetCore.Routing/Matching/MatcherEndpoint.cs index 9dc34cac6a..194fb0dc3d 100644 --- a/src/Microsoft.AspNetCore.Routing/Matching/MatcherEndpoint.cs +++ b/src/Microsoft.AspNetCore.Routing/Matching/MatcherEndpoint.cs @@ -19,7 +19,6 @@ namespace Microsoft.AspNetCore.Routing.Matching public MatcherEndpoint( Func invoker, RoutePattern routePattern, - RouteValueDictionary requiredValues, int order, EndpointMetadataCollection metadata, string displayName) @@ -37,7 +36,6 @@ namespace Microsoft.AspNetCore.Routing.Matching Invoker = invoker; RoutePattern = routePattern; - RequiredValues = requiredValues; Order = order; } @@ -45,9 +43,6 @@ namespace Microsoft.AspNetCore.Routing.Matching public int Order { get; } - // Values required by an endpoint for it to be successfully matched on link generation - public IReadOnlyDictionary RequiredValues { get; } - public RoutePattern RoutePattern { get; } } } diff --git a/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs b/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs new file mode 100644 index 0000000000..6d110a70d6 --- /dev/null +++ b/src/Microsoft.AspNetCore.Routing/RouteValuesAddressMetadata.cs @@ -0,0 +1,48 @@ +// 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.Diagnostics; +using System.Linq; + +namespace Microsoft.AspNetCore.Routing +{ + [DebuggerDisplay("{DebuggerToString(),nq}")] + public sealed class RouteValuesAddressMetadata : IRouteValuesAddressMetadata + { + public RouteValuesAddressMetadata(string name, IReadOnlyDictionary requiredValues) + { + Name = name; + RequiredValues = requiredValues; + } + + public string Name { get; } + + public IReadOnlyDictionary RequiredValues { get; } + + internal string DebuggerToString() + { + return $"Name: {Name} - Required values: {string.Join(", ", FormatValues(RequiredValues))}"; + + IEnumerable FormatValues(IEnumerable> values) + { + if (values == null) + { + return Array.Empty(); + } + + return values.Select( + kvp => + { + var value = "null"; + if (kvp.Value != null) + { + value = "\"" + kvp.Value.ToString() + "\""; + } + return kvp.Key + " = " + value; + }); + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Routing/RouteValuesBasedEndpointFinder.cs b/src/Microsoft.AspNetCore.Routing/RouteValuesBasedEndpointFinder.cs index 19a24fe439..2821c73aaf 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteValuesBasedEndpointFinder.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteValuesBasedEndpointFinder.cs @@ -137,16 +137,16 @@ namespace Microsoft.AspNetCore.Routing private OutboundRouteEntry CreateOutboundRouteEntry(MatcherEndpoint endpoint) { - var routeNameMetadata = endpoint.Metadata.GetMetadata(); + var routeValuesAddressMetadata = endpoint.Metadata.GetMetadata(); var entry = new OutboundRouteEntry() { Handler = NullRouter.Instance, Order = endpoint.Order, Precedence = RoutePrecedence.ComputeOutbound(endpoint.RoutePattern), - RequiredLinkValues = new RouteValueDictionary(endpoint.RequiredValues), + RequiredLinkValues = new RouteValueDictionary(routeValuesAddressMetadata?.RequiredValues), RouteTemplate = new RouteTemplate(endpoint.RoutePattern), Data = endpoint, - RouteName = routeNameMetadata?.Name, + RouteName = routeValuesAddressMetadata?.Name, }; entry.Defaults = new RouteValueDictionary(endpoint.RoutePattern.Defaults); return entry; diff --git a/src/Microsoft.AspNetCore.Routing/IRouteNameMetadata.cs b/src/Microsoft.AspNetCore.Routing/SuppressLinkGenerationMetadata.cs similarity index 71% rename from src/Microsoft.AspNetCore.Routing/IRouteNameMetadata.cs rename to src/Microsoft.AspNetCore.Routing/SuppressLinkGenerationMetadata.cs index efc1136904..599267c570 100644 --- a/src/Microsoft.AspNetCore.Routing/IRouteNameMetadata.cs +++ b/src/Microsoft.AspNetCore.Routing/SuppressLinkGenerationMetadata.cs @@ -3,8 +3,7 @@ namespace Microsoft.AspNetCore.Routing { - public interface IRouteNameMetadata + public sealed class SuppressLinkGenerationMetadata : ISuppressLinkGenerationMetadata { - string Name { get; } } -} +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Routing.Tests/CompositeEndpointDataSourceTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/CompositeEndpointDataSourceTest.cs index dad43417ab..d04f0d96de 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/CompositeEndpointDataSourceTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/CompositeEndpointDataSourceTest.cs @@ -149,14 +149,12 @@ namespace Microsoft.AspNetCore.Routing private MatcherEndpoint CreateEndpoint( string template, object defaults = null, - object requiredValues = null, int order = 0, string routeName = null) { return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, defaults, constraints: null), - new RouteValueDictionary(requiredValues), order, EndpointMetadataCollection.Empty, null); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs b/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs index 6711ff64d6..6ff5f8b909 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/EndpointFactory.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Routing.Matching; using Microsoft.AspNetCore.Routing.Patterns; +using System; +using System.Collections.Generic; namespace Microsoft.AspNetCore.Routing { @@ -17,18 +19,17 @@ namespace Microsoft.AspNetCore.Routing string displayName = null, params object[] metadata) { - var metadataCollection = EndpointMetadataCollection.Empty; - if (metadata != null) + var d = new List(metadata ?? Array.Empty()); + if (requiredValues != null) { - metadataCollection = new EndpointMetadataCollection(metadata); + d.Add(new RouteValuesAddressMetadata(null, new RouteValueDictionary(requiredValues))); } return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, defaults, constraints), - new RouteValueDictionary(requiredValues), order, - metadataCollection, + new EndpointMetadataCollection(d), displayName); } } diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/CandidateSetTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/CandidateSetTest.cs index 54db9ca02d..ac78dcaf7b 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/CandidateSetTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/CandidateSetTest.cs @@ -85,7 +85,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, "test"); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DataSourceDependentMatcherTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DataSourceDependentMatcherTest.cs index e88c707217..07c1db9537 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DataSourceDependentMatcherTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DataSourceDependentMatcherTest.cs @@ -37,7 +37,6 @@ namespace Microsoft.AspNetCore.Routing.Matching var endpoint = new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse("a/b/c"), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, "test"); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DefaultEndpointSelectorTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DefaultEndpointSelectorTest.cs index d8586f23d6..5ec095bc4e 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DefaultEndpointSelectorTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DefaultEndpointSelectorTest.cs @@ -216,7 +216,6 @@ test: /test3", ex.Message); return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template), - new RouteValueDictionary(), 0, EndpointMetadataCollection.Empty, $"test: {template}"); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherBuilderTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherBuilderTest.cs index e712210e44..a8735c02fa 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherBuilderTest.cs @@ -860,7 +860,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints)), - new RouteValueDictionary(), 0, new EndpointMetadataCollection(metadata), "test"); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherTest.cs index 7e80607008..b77650deda 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/DfaMatcherTest.cs @@ -20,7 +20,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, defaults, constraints: null), - new RouteValueDictionary(), order, metadata ?? EndpointMetadataCollection.Empty, template); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyIntegrationTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyIntegrationTest.cs index d3ae78485b..5d5c0eccd8 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyIntegrationTest.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Routing.Metadata; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -343,7 +342,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, defaults, constraints), - new RouteValueDictionary(), order, new EndpointMetadataCollection(metadata), displayName); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyTest.cs index f302bebb10..e8c7121597 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/HttpMethodMatcherPolicyTest.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Routing.Metadata; using Microsoft.AspNetCore.Routing.Patterns; using Xunit; using static Microsoft.AspNetCore.Routing.Matching.HttpMethodMatcherPolicy; @@ -288,7 +287,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template), - new RouteValueDictionary(), 0, new EndpointMetadataCollection(metadata), $"test: {template}"); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherConformanceTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherConformanceTest.cs index 9e4986c543..9dbc881548 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherConformanceTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherConformanceTest.cs @@ -43,7 +43,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, defaults, constraints), - new RouteValueDictionary(), order ?? 0, EndpointMetadataCollection.Empty, "endpoint: " + template); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherEndpointComparerTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherEndpointComparerTest.cs index 87bbc0c877..96539d8304 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherEndpointComparerTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Matching/MatcherEndpointComparerTest.cs @@ -222,7 +222,6 @@ namespace Microsoft.AspNetCore.Routing.Matching return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template), - new RouteValueDictionary(), order, new EndpointMetadataCollection(metadata), "test: " + template); diff --git a/test/Microsoft.AspNetCore.Routing.Tests/RouteValueBasedEndpointFinderTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/RouteValueBasedEndpointFinderTest.cs index c18b0f5f2f..af2cd3faf9 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/RouteValueBasedEndpointFinderTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/RouteValueBasedEndpointFinderTest.cs @@ -263,37 +263,29 @@ namespace Microsoft.AspNetCore.Routing { if (metadataCollection == null) { - metadataCollection = EndpointMetadataCollection.Empty; - if (!string.IsNullOrEmpty(routeName)) + var metadata = new List(); + if (!string.IsNullOrEmpty(routeName) || requiredValues != null) { - metadataCollection = new EndpointMetadataCollection(new[] { new RouteNameMetadata(routeName) }); + metadata.Add(new RouteValuesAddressMetadata(routeName, new RouteValueDictionary(requiredValues))); } + metadataCollection = new EndpointMetadataCollection(metadata); } return new MatcherEndpoint( MatcherEndpoint.EmptyInvoker, RoutePatternFactory.Parse(template, defaults, constraints: null), - new RouteValueDictionary(requiredValues), order, metadataCollection, null); } - private class RouteNameMetadata : IRouteNameMetadata - { - public RouteNameMetadata(string name) - { - Name = name; - } - public string Name { get; } - } - private class NameMetadata : INameMetadata { public NameMetadata(string name) { Name = name; } + public string Name { get; } } @@ -318,7 +310,5 @@ namespace Microsoft.AspNetCore.Routing return matches; } } - - private class SuppressLinkGenerationMetadata : ISuppressLinkGenerationMetadata { } } } diff --git a/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs b/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs new file mode 100644 index 0000000000..f05e763484 --- /dev/null +++ b/test/Microsoft.AspNetCore.Routing.Tests/RouteValuesAddressMetadataTests.cs @@ -0,0 +1,33 @@ +// 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; +using Xunit; + +namespace Microsoft.AspNetCore.Routing +{ + public class RouteValuesAddressMetadataTests + { + [Fact] + public void DebuggerToString_NoNameAndRequiredValues_ReturnsString() + { + var metadata = new RouteValuesAddressMetadata(null, null); + + Assert.Equal("Name: - Required values: ", metadata.DebuggerToString()); + } + + [Fact] + public void DebuggerToString_HasNameAndRequiredValues_ReturnsString() + { + var metadata = new RouteValuesAddressMetadata("Name!", new Dictionary + { + ["requiredValue1"] = "One", + ["requiredValue2"] = 2, + }); + + Assert.Equal("Name: Name! - Required values: requiredValue1 = \"One\", requiredValue2 = \"2\"", metadata.DebuggerToString()); + } + } +}