From 1c34d88f4c21998cdd7c902563437c87db0c3b75 Mon Sep 17 00:00:00 2001 From: apxoht Date: Mon, 23 Nov 2015 23:46:34 +0200 Subject: [PATCH] Removed unnecessary dependency of IActionSelector in UrlHelper --- .../Routing/UrlHelper.cs | 7 +---- .../LocalRedirectResultTest.cs | 3 +- .../RedirectResultTest.cs | 3 +- .../Routing/UrlHelperTest.cs | 28 +++++++------------ .../RemoteAttributeTest.cs | 6 ++-- .../UrlHelperWebSite/CustomUrlHelper.cs | 3 +- 6 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs index d00cbd6770..ec1d5d4443 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Routing/UrlHelper.cs @@ -18,7 +18,6 @@ namespace Microsoft.AspNet.Mvc.Routing public class UrlHelper : IUrlHelper { private readonly IActionContextAccessor _actionContextAccessor; - private readonly IActionSelector _actionSelector; /// /// Initializes a new instance of the class using the specified action context and @@ -26,13 +25,9 @@ namespace Microsoft.AspNet.Mvc.Routing /// /// The to access the action context /// of the current request. - /// The to be used for verifying the correctness of - /// supplied parameters for a route. - /// - public UrlHelper(IActionContextAccessor actionContextAccessor, IActionSelector actionSelector) + public UrlHelper(IActionContextAccessor actionContextAccessor) { _actionContextAccessor = actionContextAccessor; - _actionSelector = actionSelector; } protected IDictionary AmbientValues => ActionContext.RouteData.Values; diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/LocalRedirectResultTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/LocalRedirectResultTest.cs index 8925f1a1a8..60aaa4d69d 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/LocalRedirectResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/LocalRedirectResultTest.cs @@ -116,8 +116,7 @@ namespace Microsoft.AspNet.Mvc var httpContext = new Mock(); var actionContext = GetActionContext(httpContext.Object); var actionContextAccessor = new ActionContextAccessor() { ActionContext = actionContext }; - var mockActionSelector = new Mock(); - var urlHelper = new UrlHelper(actionContextAccessor, mockActionSelector.Object); + var urlHelper = new UrlHelper(actionContextAccessor); var serviceProvider = GetServiceProvider(urlHelper); httpContext.Setup(o => o.Response) diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/RedirectResultTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/RedirectResultTest.cs index cf90dd4991..be20c92ff6 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/RedirectResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/RedirectResultTest.cs @@ -124,8 +124,7 @@ namespace Microsoft.AspNet.Mvc var httpContext = new Mock(); var actionContext = GetActionContext(httpContext.Object); var actionContextAccessor = new ActionContextAccessor() { ActionContext = actionContext }; - var mockActionSelector = new Mock(); - var urlHelper = new UrlHelper(actionContextAccessor, mockActionSelector.Object); + var urlHelper = new UrlHelper(actionContextAccessor); var serviceProvider = GetServiceProvider(urlHelper); httpContext.Setup(o => o.Response) diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Routing/UrlHelperTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Routing/UrlHelperTest.cs index b5ec39d241..9f0446285d 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Routing/UrlHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Routing/UrlHelperTest.cs @@ -883,17 +883,13 @@ namespace Microsoft.AspNet.Mvc.Routing var services = GetServices(); var context = CreateHttpContext(services, string.Empty); var actionContext = CreateActionContext(context); - - var actionSelector = new Mock(MockBehavior.Strict); - return new UrlHelper(actionContext, actionSelector.Object); + + return new UrlHelper(actionContext); } private static UrlHelper CreateUrlHelper(IServiceProvider services) { - var actionSelector = new Mock(MockBehavior.Strict); - return new UrlHelper( - services.GetRequiredService(), - actionSelector.Object); + return new UrlHelper(services.GetRequiredService()); } private static UrlHelper CreateUrlHelper(string host) @@ -903,9 +899,8 @@ namespace Microsoft.AspNet.Mvc.Routing context.Request.Host = new HostString(host); var actionContext = CreateActionContext(context); - - var actionSelector = new Mock(MockBehavior.Strict); - return new UrlHelper(actionContext, actionSelector.Object); + + return new UrlHelper(actionContext); } private static UrlHelper CreateUrlHelper(string host, string protocol, IRouter router) @@ -916,15 +911,13 @@ namespace Microsoft.AspNet.Mvc.Routing context.Request.Scheme = protocol; var actionContext = CreateActionContext(context, router); - - var actionSelector = new Mock(MockBehavior.Strict); - return new UrlHelper(actionContext, actionSelector.Object); + + return new UrlHelper(actionContext); } private static UrlHelper CreateUrlHelper(IActionContextAccessor contextAccessor) { - var actionSelector = new Mock(MockBehavior.Strict); - return new UrlHelper(contextAccessor, actionSelector.Object); + return new UrlHelper(contextAccessor); } private static UrlHelper CreateUrlHelper(string appBase, IRouter router) @@ -932,9 +925,8 @@ namespace Microsoft.AspNet.Mvc.Routing var services = GetServices(); var context = CreateHttpContext(services, appBase); var actionContext = CreateActionContext(context, router); - - var actionSelector = new Mock(MockBehavior.Strict); - return new UrlHelper(actionContext, actionSelector.Object); + + return new UrlHelper(actionContext); } private static UrlHelper CreateUrlHelperWithRouteCollection(IServiceProvider services, string appPrefix) diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/RemoteAttributeTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/RemoteAttributeTest.cs index e750b02148..c383a6a3fb 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/RemoteAttributeTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/RemoteAttributeTest.cs @@ -472,8 +472,7 @@ namespace Microsoft.AspNet.Mvc } var contextAccessor = GetContextAccessor(serviceProvider, routeData); - var actionSelector = new Mock(MockBehavior.Strict); - var urlHelper = new UrlHelper(contextAccessor, actionSelector.Object); + var urlHelper = new UrlHelper(contextAccessor); serviceCollection.AddSingleton(urlHelper); serviceProvider = serviceCollection.BuildServiceProvider(); @@ -494,8 +493,7 @@ namespace Microsoft.AspNet.Mvc }; var contextAccessor = GetContextAccessor(serviceProvider, routeData); - var actionSelector = new Mock(MockBehavior.Strict); - var urlHelper = new UrlHelper(contextAccessor, actionSelector.Object); + var urlHelper = new UrlHelper(contextAccessor); serviceCollection.AddSingleton(urlHelper); serviceProvider = serviceCollection.BuildServiceProvider(); diff --git a/test/WebSites/UrlHelperWebSite/CustomUrlHelper.cs b/test/WebSites/UrlHelperWebSite/CustomUrlHelper.cs index ef2da4c524..93dbc8af37 100644 --- a/test/WebSites/UrlHelperWebSite/CustomUrlHelper.cs +++ b/test/WebSites/UrlHelperWebSite/CustomUrlHelper.cs @@ -21,9 +21,8 @@ namespace UrlHelperWebSite public CustomUrlHelper( IActionContextAccessor contextAccessor, - IActionSelector actionSelector, IOptions appOptions) - : base(contextAccessor, actionSelector) + : base(contextAccessor) { _appOptions = appOptions; _httpContext = contextAccessor.ActionContext.HttpContext;