Merge pull request #617 from dotnet-maestro-bot/merge/release/2.2-to-master

[automated] Merge branch 'release/2.2' => 'master'
This commit is contained in:
Ryan Nowak 2018-07-16 21:30:34 -07:00 committed by GitHub
commit 1b4eb54e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 10 deletions

View File

@ -3,7 +3,6 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Routing.Matchers
@ -11,16 +10,13 @@ namespace Microsoft.AspNetCore.Routing.Matchers
internal class DefaultMatchProcessorFactory : MatchProcessorFactory
{
private readonly RouteOptions _options;
private readonly ILogger<DefaultMatchProcessorFactory> _logger;
private readonly IServiceProvider _serviceProvider;
public DefaultMatchProcessorFactory(
IOptions<RouteOptions> options,
ILogger<DefaultMatchProcessorFactory> logger,
IServiceProvider serviceProvider)
{
_options = options.Value;
_logger = logger;
_serviceProvider = serviceProvider;
}
@ -67,13 +63,16 @@ namespace Microsoft.AspNetCore.Routing.Matchers
{
throw new InvalidOperationException(
Resources.FormatDefaultInlineConstraintResolver_TypeNotConstraint(
constraintType, constraintName, typeof(IRouteConstraint).Name));
constraintType,
constraintName,
typeof(IRouteConstraint).Name));
}
try
{
return CreateMatchProcessorFromRouteConstraint(
matchProcessorReference.ParameterName,
matchProcessorReference.Optional,
constraintType,
constraintArgument);
}
@ -91,11 +90,20 @@ namespace Microsoft.AspNetCore.Routing.Matchers
private MatchProcessor CreateMatchProcessorFromRouteConstraint(
string parameterName,
bool optional,
Type constraintType,
string constraintArgument)
{
var routeConstraint = DefaultInlineConstraintResolver.CreateConstraint(constraintType, constraintArgument);
return (new MatchProcessorReference(parameterName, routeConstraint)).MatchProcessor;
var matchProcessor = new MatchProcessorReference(parameterName, routeConstraint).MatchProcessor;
if (optional)
{
matchProcessor = new OptionalMatchProcessor(matchProcessor);
}
matchProcessor.Initialize(parameterName, constraintArgument);
return matchProcessor;
}
private MatchProcessor ResolveMatchProcessor(

View File

@ -801,7 +801,6 @@ namespace Microsoft.AspNetCore.Routing
return new DefaultLinkGenerator(
new DefaultMatchProcessorFactory(
Options.Create(new RouteOptions()),
NullLogger<DefaultMatchProcessorFactory>.Instance,
Mock.Of<IServiceProvider>()),
new DefaultObjectPool<UriBuildingContext>(new UriBuilderContextPooledObjectPolicy()),
NullLogger<DefaultLinkGenerator>.Instance);

View File

@ -31,9 +31,10 @@ namespace Microsoft.AspNetCore.Routing.Matchers
throw new ArgumentNullException(nameof(feature));
}
var path = httpContext.Request.Path.Value;
for (var i = 0; i < Matchers.Length; i++)
{
if (Matchers[i].TryMatch(httpContext.Request.Path.Value))
if (Matchers[i].TryMatch(path))
{
feature.Endpoint = Matchers[i].Endpoint;
feature.Values = new RouteValueDictionary();

View File

@ -56,6 +56,20 @@ namespace Microsoft.AspNetCore.Routing.Matchers
Assert.False(isMatch);
}
[Fact]
public void Create_CreatesMatchProcessor_FromConstraintText_AndRouteConstraint_Optional()
{
// Arrange
var factory = GetMatchProcessorFactory();
var matchProcessorReference = new MatchProcessorReference("id", true, "int");
// Act
var processor = factory.Create(matchProcessorReference);
// Assert
Assert.IsType<OptionalMatchProcessor>(processor);
}
[Fact]
public void Create_CreatesMatchProcessor_FromConstraintText_AndCustomMatchProcessor()
{
@ -143,7 +157,6 @@ namespace Microsoft.AspNetCore.Routing.Matchers
return new DefaultMatchProcessorFactory(
Options.Create(options),
NullLogger<DefaultMatchProcessorFactory>.Instance,
services.BuildServiceProvider());
}

View File

@ -33,7 +33,6 @@ namespace Microsoft.AspNetCore.Routing.Matchers
var compositeDataSource = new CompositeEndpointDataSource(new[] { endpointDataSource });
var defaultInlineConstraintResolver = new DefaultMatchProcessorFactory(
Options.Create(new RouteOptions()),
NullLogger<DefaultMatchProcessorFactory>.Instance,
Mock.Of<IServiceProvider>());
var endpointSelector = new EndpointSelector(
compositeDataSource,