Minor fixes for MatchProcessorFactory
Fixing minor issues found doing DFA integration.
This commit is contained in:
parent
5f29e8b062
commit
02e1d78319
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue