RouteCollection -> RouteBuilder changes for MVC.
This commit is contained in:
parent
dffc58dedc
commit
b96da245cb
|
|
@ -21,16 +21,17 @@ namespace Microsoft.AspNet.Builder
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IBuilder UseMvc([NotNull] this IBuilder app, [NotNull] Action<IRouteCollection> configureRoutes)
|
public static IBuilder UseMvc([NotNull] this IBuilder app, [NotNull] Action<IRouteBuilder> configureRoutes)
|
||||||
{
|
{
|
||||||
var routes = new RouteCollection
|
var routes = new RouteBuilder
|
||||||
{
|
{
|
||||||
DefaultHandler = new MvcRouteHandler()
|
DefaultHandler = new MvcRouteHandler(),
|
||||||
|
ServiceProvider = app.ApplicationServices
|
||||||
};
|
};
|
||||||
|
|
||||||
configureRoutes(routes);
|
configureRoutes(routes);
|
||||||
|
|
||||||
return app.UseRouter(routes);
|
return app.UseRouter(routes.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// 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.Collections.Generic;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
@ -394,7 +395,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
public void RouteUrlWithRouteNameAndDefaults()
|
public void RouteUrlWithRouteNameAndDefaults()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var routeCollection = GetRouteCollection("MyRouteName", "any/url");
|
var routeCollection = GetRouter("MyRouteName", "any/url");
|
||||||
var urlHelper = CreateUrlHelper("/app", routeCollection);
|
var urlHelper = CreateUrlHelper("/app", routeCollection);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -512,25 +513,28 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
|
|
||||||
private static UrlHelper CreateUrlHelperWithRouteCollection(string appPrefix)
|
private static UrlHelper CreateUrlHelperWithRouteCollection(string appPrefix)
|
||||||
{
|
{
|
||||||
var routeCollection = GetRouteCollection();
|
var routeCollection = GetRouter();
|
||||||
return CreateUrlHelper("/app", routeCollection);
|
return CreateUrlHelper("/app", routeCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RouteCollection GetRouteCollection()
|
private static IRouter GetRouter()
|
||||||
{
|
{
|
||||||
return GetRouteCollection("mockRoute", "/mockTemplate");
|
return GetRouter("mockRoute", "/mockTemplate");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RouteCollection GetRouteCollection(string mockRouteName, string mockTemplateValue)
|
private static IRouter GetRouter(string mockRouteName, string mockTemplateValue)
|
||||||
{
|
{
|
||||||
var rt = new RouteCollection();
|
var rt = new RouteBuilder();
|
||||||
var target = new Mock<IRouter>(MockBehavior.Strict);
|
var target = new Mock<IRouter>(MockBehavior.Strict);
|
||||||
target
|
target
|
||||||
.Setup(e => e.GetVirtualPath(It.IsAny<VirtualPathContext>()))
|
.Setup(e => e.GetVirtualPath(It.IsAny<VirtualPathContext>()))
|
||||||
.Callback<VirtualPathContext>(c => c.IsBound = true)
|
.Callback<VirtualPathContext>(c => c.IsBound = true)
|
||||||
.Returns<VirtualPathContext>(rc => null);
|
.Returns<VirtualPathContext>(rc => null);
|
||||||
rt.DefaultHandler = target.Object;
|
rt.DefaultHandler = target.Object;
|
||||||
|
var serviceProviderMock = new Mock<IServiceProvider>();
|
||||||
|
serviceProviderMock.Setup(o => o.GetService(typeof(IInlineConstraintResolver)))
|
||||||
|
.Returns(new DefaultInlineConstraintResolver());
|
||||||
|
rt.ServiceProvider = serviceProviderMock.Object;
|
||||||
rt.MapRoute(string.Empty,
|
rt.MapRoute(string.Empty,
|
||||||
"{controller}/{action}/{id}",
|
"{controller}/{action}/{id}",
|
||||||
new RouteValueDictionary(new { id = "defaultid" }));
|
new RouteValueDictionary(new { id = "defaultid" }));
|
||||||
|
|
@ -544,8 +548,8 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
mockRouteName)
|
mockRouteName)
|
||||||
)))
|
)))
|
||||||
.Returns(mockTemplateValue);
|
.Returns(mockTemplateValue);
|
||||||
rt.Add(mockHttpRoute.Object);
|
rt.Routes.Add(mockHttpRoute.Object);
|
||||||
return rt;
|
return rt.Build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue