CR feedback
This commit is contained in:
parent
5d34a61bd9
commit
d2a3bd3490
|
|
@ -8,12 +8,12 @@ namespace RoutingSample
|
|||
{
|
||||
internal class PrefixRoute : IRouter
|
||||
{
|
||||
private readonly IRouter _next;
|
||||
private readonly IRouter _target;
|
||||
private readonly string _prefix;
|
||||
|
||||
public PrefixRoute(IRouter next, string prefix)
|
||||
public PrefixRoute(IRouter target, string prefix)
|
||||
{
|
||||
_next = next;
|
||||
_target = target;
|
||||
|
||||
if (prefix == null)
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ namespace RoutingSample
|
|||
}
|
||||
}
|
||||
|
||||
await _next.RouteAsync(context);
|
||||
await _target.RouteAsync(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace RoutingSample
|
||||
|
|
@ -8,6 +9,11 @@ namespace RoutingSample
|
|||
{
|
||||
public static IRouteCollection AddPrefixRoute(this IRouteCollection routes, string prefix)
|
||||
{
|
||||
if (routes.DefaultHandler == null)
|
||||
{
|
||||
throw new InvalidOperationException("DefaultHandler must be set.");
|
||||
}
|
||||
|
||||
return AddPrefixRoute(routes, prefix, routes.DefaultHandler);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#if NET45
|
||||
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.Routing.Owin;
|
||||
using Microsoft.AspNet.Routing.Template;
|
||||
using Owin;
|
||||
|
||||
|
|
@ -28,7 +26,7 @@ namespace RoutingSample
|
|||
|
||||
routes.DefaultHandler = endpoint1;
|
||||
routes.AddPrefixRoute("api/store");
|
||||
routes.AddTemplateRoute("api/{controller}/{*extra}", new { controller = "Store" });
|
||||
routes.MapRoute("api/{controller}/{*extra}", new { controller = "Store" });
|
||||
|
||||
routes.AddPrefixRoute("hello/world", endpoint2);
|
||||
routes.AddPrefixRoute("", endpoint2);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Routing
|
|||
|
||||
public bool IsBound { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
public string BoundPath { get; set; }
|
||||
|
||||
public IDictionary<string, object> Values { get; private set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Routing.Owin
|
||||
namespace Microsoft.AspNet.Abstractions
|
||||
{
|
||||
public static class BuilderExtensions
|
||||
{
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Routing.Owin
|
||||
namespace Microsoft.AspNet.Abstractions
|
||||
{
|
||||
public class RouterMiddleware
|
||||
{
|
||||
|
|
@ -1,25 +1,31 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Routing.Template
|
||||
{
|
||||
public static class RouteCollectionExtensions
|
||||
{
|
||||
public static IRouteCollection AddTemplateRoute(this IRouteCollection routes, string template)
|
||||
public static IRouteCollection MapRoute(this IRouteCollection routes, string template)
|
||||
{
|
||||
AddTemplateRoute(routes, template, null);
|
||||
MapRoute(routes, template, null);
|
||||
return routes;
|
||||
}
|
||||
|
||||
public static IRouteCollection AddTemplateRoute(this IRouteCollection routes, string template, object defaults)
|
||||
public static IRouteCollection MapRoute(this IRouteCollection routes, string template, object defaults)
|
||||
{
|
||||
AddTemplateRoute(routes, template, new RouteValueDictionary(defaults));
|
||||
MapRoute(routes, template, new RouteValueDictionary(defaults));
|
||||
return routes;
|
||||
}
|
||||
|
||||
public static IRouteCollection AddTemplateRoute(this IRouteCollection routes, string template, IDictionary<string, object> defaults)
|
||||
public static IRouteCollection MapRoute(this IRouteCollection routes, string template, IDictionary<string, object> defaults)
|
||||
{
|
||||
if (routes.DefaultHandler == null)
|
||||
{
|
||||
throw new InvalidOperationException("DefaultHandler must be set.");
|
||||
}
|
||||
|
||||
routes.Add(new TemplateRoute(routes.DefaultHandler, template, defaults));
|
||||
return routes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,25 +10,25 @@ namespace Microsoft.AspNet.Routing.Template
|
|||
public class TemplateRoute : IRouter
|
||||
{
|
||||
private readonly IDictionary<string, object> _defaults;
|
||||
private readonly IRouter _next;
|
||||
private readonly IRouter _target;
|
||||
private readonly Template _parsedTemplate;
|
||||
private readonly string _routeTemplate;
|
||||
private readonly TemplateMatcher _matcher;
|
||||
private readonly TemplateBinder _binder;
|
||||
|
||||
public TemplateRoute(IRouter next, string routeTemplate)
|
||||
: this(next, routeTemplate, null)
|
||||
public TemplateRoute(IRouter target, string routeTemplate)
|
||||
: this(target, routeTemplate, null)
|
||||
{
|
||||
}
|
||||
|
||||
public TemplateRoute(IRouter next, string routeTemplate, IDictionary<string, object> defaults)
|
||||
public TemplateRoute(IRouter target, string routeTemplate, IDictionary<string, object> defaults)
|
||||
{
|
||||
if (next == null)
|
||||
if (target == null)
|
||||
{
|
||||
throw new ArgumentNullException("next");
|
||||
throw new ArgumentNullException("target");
|
||||
}
|
||||
|
||||
_next = next;
|
||||
_target = target;
|
||||
_routeTemplate = routeTemplate ?? string.Empty;
|
||||
_defaults = defaults ?? new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Routing.Template
|
|||
}
|
||||
else
|
||||
{
|
||||
await _next.RouteAsync(new RouteContext(context.HttpContext){ Values = values });
|
||||
await _target.RouteAsync(new RouteContext(context.HttpContext){ Values = values });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,11 +83,13 @@ namespace Microsoft.AspNet.Routing.Template
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_next.BindPath(context);
|
||||
if (context.IsBound && context.Path == null)
|
||||
|
||||
context.BoundPath = path;
|
||||
_target.BindPath(context);
|
||||
|
||||
if (!context.IsBound)
|
||||
{
|
||||
context.Path = path;
|
||||
context.BoundPath = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.True(context.IsBound);
|
||||
Assert.Equal("Home", context.Path);
|
||||
Assert.Equal("Home", context.BoundPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.False(context.IsBound);
|
||||
Assert.Null(context.Path);
|
||||
Assert.Null(context.BoundPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.False(context.IsBound);
|
||||
Assert.Null(context.Path);
|
||||
Assert.Null(context.BoundPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -162,7 +162,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
// Assert
|
||||
Assert.True(context.IsBound);
|
||||
Assert.Equal("Home/Index", context.Path);
|
||||
Assert.Equal("Home/Index", context.BoundPath);
|
||||
}
|
||||
|
||||
private static BindPathContext CreateRouteBindContext(object values)
|
||||
|
|
@ -186,26 +186,26 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
|
||||
private static TemplateRoute CreateRoute(string template, bool accept = true)
|
||||
{
|
||||
return new TemplateRoute(CreateEndpoint(accept), template);
|
||||
return new TemplateRoute(CreateTarget(accept), template);
|
||||
}
|
||||
|
||||
private static TemplateRoute CreateRoute(string template, object defaults, bool accept = true)
|
||||
{
|
||||
return new TemplateRoute(CreateEndpoint(accept), template, new RouteValueDictionary(defaults));
|
||||
return new TemplateRoute(CreateTarget(accept), template, new RouteValueDictionary(defaults));
|
||||
}
|
||||
|
||||
private static IRouter CreateEndpoint(bool accept = true)
|
||||
private static IRouter CreateTarget(bool accept = true)
|
||||
{
|
||||
var endpoint = new Mock<IRouter>(MockBehavior.Strict);
|
||||
endpoint
|
||||
var target = new Mock<IRouter>(MockBehavior.Strict);
|
||||
target
|
||||
.Setup(e => e.BindPath(It.IsAny<BindPathContext>()))
|
||||
.Callback<BindPathContext>(c => c.IsBound = accept);
|
||||
|
||||
endpoint
|
||||
target
|
||||
.Setup(e => e.RouteAsync(It.IsAny<RouteContext>()))
|
||||
.Callback<RouteContext>(async (c) => c.IsHandled = accept);
|
||||
|
||||
return endpoint.Object;
|
||||
return target.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue