Issue #65 merge RoutingContext and RequestContext

See the relevant PR in aspnet/Routing#60.

This incorporates the breaking changes.
This commit is contained in:
Ryan Nowak 2014-06-04 18:02:18 -07:00
parent 6b836e9e77
commit 69034b78b8
37 changed files with 200 additions and 218 deletions

View File

@ -11,26 +11,28 @@ namespace Microsoft.AspNet.Mvc
public class ActionContext public class ActionContext
{ {
public ActionContext([NotNull] ActionContext actionContext) public ActionContext([NotNull] ActionContext actionContext)
: this(actionContext.HttpContext, actionContext.Router, actionContext.RouteValues, actionContext.ActionDescriptor) : this(actionContext.HttpContext, actionContext.RouteData, actionContext.ActionDescriptor)
{ {
ModelState = actionContext.ModelState; ModelState = actionContext.ModelState;
Controller = actionContext.Controller; Controller = actionContext.Controller;
} }
public ActionContext(HttpContext httpContext, IRouter router, IDictionary<string, object> routeValues, ActionDescriptor actionDescriptor) public ActionContext([NotNull] RouteContext routeContext, [NotNull] ActionDescriptor actionDescriptor)
: this(routeContext.HttpContext, routeContext.RouteData, actionDescriptor)
{
}
public ActionContext([NotNull] HttpContext httpContext, [NotNull] RouteData routeData, [NotNull] ActionDescriptor actionDescriptor)
{ {
HttpContext = httpContext; HttpContext = httpContext;
Router = router; RouteData = routeData;
RouteValues = routeValues;
ActionDescriptor = actionDescriptor; ActionDescriptor = actionDescriptor;
ModelState = new ModelStateDictionary(); ModelState = new ModelStateDictionary();
} }
public HttpContext HttpContext { get; private set; } public HttpContext HttpContext { get; private set; }
public IRouter Router { get; private set; } public RouteData RouteData { get; private set; }
public IDictionary<string, object> RouteValues { get; private set; }
public ModelStateDictionary ModelState { get; private set; } public ModelStateDictionary ModelState { get; private set; }

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Mvc
public override async Task ExecuteResultAsync([NotNull] ActionContext context) public override async Task ExecuteResultAsync([NotNull] ActionContext context)
{ {
var viewName = ViewName ?? context.ActionDescriptor.Name; var viewName = ViewName ?? context.ActionDescriptor.Name;
var view = FindView(context.RouteValues, viewName); var view = FindView(context.RouteData.Values, viewName);
using (view as IDisposable) using (view as IDisposable)
{ {

View File

@ -25,13 +25,8 @@ namespace Microsoft.AspNet.Mvc
_bindingProvider = bindingProvider; _bindingProvider = bindingProvider;
} }
public async Task<ActionDescriptor> SelectAsync(RequestContext context) public async Task<ActionDescriptor> SelectAsync([NotNull] RouteContext context)
{ {
if (context == null)
{
throw new ArgumentNullException("context");
}
var allDescriptors = GetActions(); var allDescriptors = GetActions();
var matching = allDescriptors.Where(ad => Match(ad, context)).ToList(); var matching = allDescriptors.Where(ad => Match(ad, context)).ToList();
@ -63,7 +58,7 @@ namespace Microsoft.AspNet.Mvc
} }
} }
public bool Match(ActionDescriptor descriptor, RequestContext context) public bool Match(ActionDescriptor descriptor, RouteContext context)
{ {
if (descriptor == null) if (descriptor == null)
{ {
@ -75,7 +70,7 @@ namespace Microsoft.AspNet.Mvc
(descriptor.DynamicConstraints == null || descriptor.DynamicConstraints.All(c => c.Accept(context))); (descriptor.DynamicConstraints == null || descriptor.DynamicConstraints.All(c => c.Accept(context)));
} }
protected virtual async Task<ActionDescriptor> SelectBestCandidate(RequestContext context, List<ActionDescriptor> candidates) protected virtual async Task<ActionDescriptor> SelectBestCandidate(RouteContext context, List<ActionDescriptor> candidates)
{ {
var applicableCandiates = new List<ActionDescriptorCandidate>(); var applicableCandiates = new List<ActionDescriptorCandidate>();
foreach (var action in candidates) foreach (var action in candidates)
@ -86,12 +81,7 @@ namespace Microsoft.AspNet.Mvc
Action = action, Action = action,
}; };
// Issues #60 & #65 filed to deal with the ugliness of passing null here. var actionContext = new ActionContext(context, action);
var actionContext = new ActionContext(
httpContext: context.HttpContext,
router: null,
routeValues: context.RouteValues,
actionDescriptor: action);
var actionBindingContext = await _bindingProvider.GetActionBindingContextAsync(actionContext); var actionBindingContext = await _bindingProvider.GetActionBindingContextAsync(actionContext);
foreach (var parameter in action.Parameters.Where(p => p.ParameterBindingInfo != null)) foreach (var parameter in action.Parameters.Where(p => p.ParameterBindingInfo != null))

View File

@ -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 Microsoft.AspNet.Routing;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Mvc
} }
} }
public bool Accept(RequestContext context) public bool Accept([NotNull] RouteContext context)
{ {
if (context == null) if (context == null)
{ {

View File

@ -1,10 +1,12 @@
// 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 Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
public interface IActionConstraint public interface IActionConstraint
{ {
bool Accept(RequestContext context); bool Accept([NotNull] RouteContext context);
} }
} }

View File

@ -1,7 +1,6 @@
// 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.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
@ -10,9 +9,9 @@ namespace Microsoft.AspNet.Mvc
{ {
public interface IActionSelector public interface IActionSelector
{ {
Task<ActionDescriptor> SelectAsync(RequestContext context); Task<ActionDescriptor> SelectAsync(RouteContext context);
bool Match(ActionDescriptor descriptor, RequestContext context); bool Match(ActionDescriptor descriptor, RouteContext context);
bool HasValidAction(VirtualPathContext context); bool HasValidAction(VirtualPathContext context);

View File

@ -31,17 +31,14 @@ namespace Microsoft.AspNet.Mvc
// TODO: Throw an error here that's descriptive enough so that // TODO: Throw an error here that's descriptive enough so that
// users understand they should call the per request scoped middleware // users understand they should call the per request scoped middleware
// or set HttpContext.Services manually // or set HttpContext.Services manually
var requestContext = new RequestContext(context.HttpContext, context.Values);
var actionSelector = services.GetService<IActionSelector>(); var actionSelector = services.GetService<IActionSelector>();
var actionDescriptor = await actionSelector.SelectAsync(requestContext); var actionDescriptor = await actionSelector.SelectAsync(context);
if (actionDescriptor == null) if (actionDescriptor == null)
{ {
return; return;
} }
var actionContext = new ActionContext(context.HttpContext, context.Router, context.Values, actionDescriptor); var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor);
var contextAccessor = services.GetService<IContextAccessor<ActionContext>>(); var contextAccessor = services.GetService<IContextAccessor<ActionContext>>();
using (contextAccessor.SetContextSource(() => actionContext, PreventExchange)) using (contextAccessor.SetContextSource(() => actionContext, PreventExchange))

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -31,8 +32,9 @@ namespace Microsoft.AspNet.Mvc
public Task<ActionBindingContext> GetActionBindingContextAsync(ActionContext actionContext) public Task<ActionBindingContext> GetActionBindingContextAsync(ActionContext actionContext)
{ {
var requestContext = new RequestContext(actionContext.HttpContext, actionContext.RouteValues); var routeContext = new RouteContext(actionContext.HttpContext);
var valueProviders = _valueProviderFactories.Select(factory => factory.GetValueProvider(requestContext)) routeContext.RouteData = actionContext.RouteData;
var valueProviders = _valueProviderFactories.Select(factory => factory.GetValueProvider(routeContext))
.Where(vp => vp != null); .Where(vp => vp != null);
var context = new ActionBindingContext( var context = new ActionBindingContext(
actionContext, actionContext,

View File

@ -381,7 +381,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var newViewData = new ViewDataDictionary(baseViewData, model); var newViewData = new ViewDataDictionary(baseViewData, model);
var viewEngineResult = _viewEngine.FindPartialView(ViewContext.RouteValues, partialViewName); var viewEngineResult = _viewEngine.FindPartialView(ViewContext.RouteData.Values, partialViewName);
if (!viewEngineResult.Success) if (!viewEngineResult.Success)
{ {
var locations = string.Empty; var locations = string.Empty;

View File

@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
var fullViewName = modeViewPath + "/" + viewName; var fullViewName = modeViewPath + "/" + viewName;
// Forcing synchronous behavior so users don't have to await templates. // Forcing synchronous behavior so users don't have to await templates.
var viewEngineResult = _viewEngine.FindPartialView(_viewContext.RouteValues, fullViewName); var viewEngineResult = _viewEngine.FindPartialView(_viewContext.RouteData.Values, fullViewName);
if (viewEngineResult.Success) if (viewEngineResult.Success)
{ {
using (var writer = new StringWriter(CultureInfo.InvariantCulture)) using (var writer = new StringWriter(CultureInfo.InvariantCulture))

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -117,14 +118,14 @@ namespace Microsoft.AspNet.Mvc
} }
} }
public bool Accept([NotNull] RequestContext context) public bool Accept([NotNull] RouteContext context)
{ {
var routeValues = context.RouteValues; var routeValues = context.RouteData.Values;
if (routeValues == null) if (routeValues == null)
{ {
throw new ArgumentException(Resources.FormatPropertyOfTypeCannotBeNull( throw new ArgumentException(Resources.FormatPropertyOfTypeCannotBeNull(
"RouteValues", "Values",
typeof(RequestContext)), typeof(RouteData)),
"context"); "context");
} }

View File

@ -21,8 +21,8 @@ namespace Microsoft.AspNet.Mvc
public UrlHelper(IContextAccessor<ActionContext> contextAccessor, IActionSelector actionSelector) public UrlHelper(IContextAccessor<ActionContext> contextAccessor, IActionSelector actionSelector)
{ {
_httpContext = contextAccessor.Value.HttpContext; _httpContext = contextAccessor.Value.HttpContext;
_router = contextAccessor.Value.Router; _router = contextAccessor.Value.RouteData.Routers.Peek();
_ambientValues = contextAccessor.Value.RouteValues; _ambientValues = contextAccessor.Value.RouteData.Values;
_actionSelector = actionSelector; _actionSelector = actionSelector;
} }

View File

@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Mvc
_viewName); _viewName);
} }
var view = FindView(context.ViewContext.RouteValues, qualifiedViewName); var view = FindView(context.ViewContext.RouteData.Values, qualifiedViewName);
var childViewContext = new ViewContext( var childViewContext = new ViewContext(
context.ViewContext, context.ViewContext,

View File

@ -69,7 +69,6 @@
<Compile Include="ModelValidationState.cs" /> <Compile Include="ModelValidationState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs" /> <Compile Include="Properties\Resources.Designer.cs" />
<Compile Include="RequestContext.cs" />
<Compile Include="Validation\AssociatedValidatorProvider.cs" /> <Compile Include="Validation\AssociatedValidatorProvider.cs" />
<Compile Include="Validation\ClientModelValidationContext.cs" /> <Compile Include="Validation\ClientModelValidationContext.cs" />
<Compile Include="Validation\RequiredAttributeAdapter.cs" /> <Compile Include="Validation\RequiredAttributeAdapter.cs" />
@ -119,4 +118,4 @@
<Compile Include="ValueProviders\ValueProviderResult.cs" /> <Compile Include="ValueProviders\ValueProviderResult.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project> </Project>

View File

@ -1,23 +0,0 @@
// 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.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
namespace Microsoft.AspNet.Mvc
{
public class RequestContext
{
public RequestContext([NotNull]HttpContext context,
[NotNull]IDictionary<string, object> routeValues)
{
HttpContext = context;
RouteValues = routeValues;
}
public virtual IDictionary<string, object> RouteValues { get; set; }
public virtual HttpContext HttpContext { get; set; }
}
}

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -11,9 +12,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
private const string FormEncodedContentType = "application/x-www-form-urlencoded"; private const string FormEncodedContentType = "application/x-www-form-urlencoded";
public IValueProvider GetValueProvider(RequestContext requestContext) public IValueProvider GetValueProvider([NotNull] RouteContext routeContext)
{ {
var request = requestContext.HttpContext.Request; var request = routeContext.HttpContext.Request;
if (IsSupportedContentType(request)) if (IsSupportedContentType(request))
{ {

View File

@ -1,7 +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.Threading.Tasks; using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -10,8 +10,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <summary> /// <summary>
/// Get a value provider with values from the given <paramref name="requestContext"/>. /// Get a value provider with values from the given <paramref name="requestContext"/>.
/// </summary> /// </summary>
/// <param name="requestContext">RequestContext that value provider will populate from</param> /// <param name="routeContext">RouteContext that value provider will populate from</param>
/// <returns>a value provider instance or null</returns> /// <returns>a value provider instance or null</returns>
IValueProvider GetValueProvider(RequestContext requestContext); IValueProvider GetValueProvider([NotNull] RouteContext routeContext);
} }
} }

View File

@ -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 Microsoft.AspNet.Routing;
using System.Globalization; using System.Globalization;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
@ -9,15 +10,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
private static readonly object _cacheKey = new object(); private static readonly object _cacheKey = new object();
public IValueProvider GetValueProvider([NotNull] RequestContext requestContext) public IValueProvider GetValueProvider([NotNull] RouteContext routeContext)
{ {
// Process the query collection once-per request. // Process the query collection once-per request.
var storage = requestContext.HttpContext.Items; var storage = routeContext.HttpContext.Items;
object value; object value;
IValueProvider provider; IValueProvider provider;
if (!storage.TryGetValue(_cacheKey, out value)) if (!storage.TryGetValue(_cacheKey, out value))
{ {
var queryCollection = requestContext.HttpContext.Request.Query; var queryCollection = routeContext.HttpContext.Request.Query;
provider = new ReadableStringCollectionValueProvider(queryCollection, CultureInfo.InvariantCulture); provider = new ReadableStringCollectionValueProvider(queryCollection, CultureInfo.InvariantCulture);
storage[_cacheKey] = provider; storage[_cacheKey] = provider;
} }

View File

@ -1,13 +1,15 @@
// 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 Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
public class RouteValueValueProviderFactory : IValueProviderFactory public class RouteValueValueProviderFactory : IValueProviderFactory
{ {
public IValueProvider GetValueProvider(RequestContext requestContext) public IValueProvider GetValueProvider([NotNull] RouteContext routeContext)
{ {
return new DictionaryBasedValueProvider(requestContext.RouteValues); return new DictionaryBasedValueProvider(routeContext.RouteData.Values);
} }
} }
} }

View File

@ -6,6 +6,7 @@
"dependencies": { "dependencies": {
"Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.Http": "0.1-alpha-*",
"Microsoft.AspNet.Mvc.Common": "", "Microsoft.AspNet.Mvc.Common": "",
"Microsoft.AspNet.Routing": "0.1-alpha-*",
"Microsoft.DataAnnotations": "0.1-alpha-*", "Microsoft.DataAnnotations": "0.1-alpha-*",
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.Framework.DependencyInjection": "0.1-alpha-*",
"Newtonsoft.Json": "5.0.8" "Newtonsoft.Json": "5.0.8"

View File

@ -12,6 +12,7 @@ using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection.NestedProviders; using Microsoft.Framework.DependencyInjection.NestedProviders;
using Moq; using Moq;
using Xunit; using Xunit;
using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc.Core.Test namespace Microsoft.AspNet.Mvc.Core.Test
{ {
@ -31,16 +32,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributeViaAcceptVerbs_ORsMultipleHttpMethods(string verb) public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributeViaAcceptVerbs_ORsMultipleHttpMethods(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "HttpMethodAttributeTests_RestOnly" },
{ "controller", "HttpMethodAttributeTests_RestOnly" }, { "action", "Patch" }
{ "action", "Patch" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal("Patch", result.Name); Assert.Equal("Patch", result.Name);
@ -55,16 +55,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributes_ORsMultipleHttpMethods(string verb) public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributes_ORsMultipleHttpMethods(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>()
new Dictionary<string, object> {
{ { "controller", "HttpMethodAttributeTests_RestOnly" },
{ "controller", "HttpMethodAttributeTests_RestOnly" }, { "action", "Put" }
{ "action", "Put" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal("Put", result.Name); Assert.Equal("Put", result.Name);
@ -77,15 +76,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
{ {
// Arrange // Arrange
// Note no action name is passed, hence should return a null action descriptor. // Note no action name is passed, hence should return a null action descriptor.
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>()
new Dictionary<string, object> {
{ { "controller", "HttpMethodAttributeTests_RestOnly" },
{ "controller", "HttpMethodAttributeTests_RestOnly" }, };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(null, result); Assert.Equal(null, result);
@ -98,15 +96,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
{ {
// Arrange // Arrange
// Note no action name is passed, hence should return a null action descriptor. // Note no action name is passed, hence should return a null action descriptor.
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "HttpMethodAttributeTests_DefaultMethodValidation" },
{ "controller", "HttpMethodAttributeTests_DefaultMethodValidation" }, };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal("Index", result.Name); Assert.Equal("Index", result.Name);
@ -141,16 +138,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionNameAttribute_ActionGetsExposedViaActionName_UnreachableByConvention(string verb) public async Task ActionNameAttribute_ActionGetsExposedViaActionName_UnreachableByConvention(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "ActionName" },
{ "controller", "ActionName" }, { "action", "RPCMethodWithHttpGet" }
{ "action", "RPCMethodWithHttpGet" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(null, result); Assert.Equal(null, result);
@ -175,27 +171,26 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionNameAttribute_DifferentActionName_UsesActionNameFromActionNameAttribute(string verb, string actionName) public async Task ActionNameAttribute_DifferentActionName_UsesActionNameFromActionNameAttribute(string verb, string actionName)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "ActionName" },
{ "controller", "ActionName" }, { "action", actionName }
{ "action", actionName } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(actionName, result.Name); Assert.Equal(actionName, result.Name);
} }
private async Task<ActionDescriptor> InvokeActionSelector(RequestContext context) private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context)
{ {
return await InvokeActionSelector(context, _actionDiscoveryConventions); return await InvokeActionSelector(context, _actionDiscoveryConventions);
} }
private async Task<ActionDescriptor> InvokeActionSelector(RequestContext context, DefaultActionDiscoveryConventions actionDiscoveryConventions) private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context, DefaultActionDiscoveryConventions actionDiscoveryConventions)
{ {
var actionDescriptorProvider = GetActionDescriptorProvider(actionDiscoveryConventions); var actionDescriptorProvider = GetActionDescriptorProvider(actionDiscoveryConventions);
var descriptorProvider = var descriptorProvider =

View File

@ -85,8 +85,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
httpContext.Setup(o => o.Response).Returns(response); httpContext.Setup(o => o.Response).Returns(response);
} }
return new ActionContext(httpContext.Object, Mock.Of<IRouter>(), new Dictionary<string, object>(), return new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
new ActionDescriptor());
} }
} }
} }

View File

@ -69,9 +69,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
private static ActionContext GetActionContext(HttpContext httpContext) private static ActionContext GetActionContext(HttpContext httpContext)
{ {
var routeData = new RouteData()
{
Values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase),
};
routeData.Routers.Push(new Mock<IRouter>().Object);
return new ActionContext(httpContext, return new ActionContext(httpContext,
Mock.Of<IRouter>(), routeData,
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
} }

View File

@ -24,8 +24,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
httpContext.Setup(o => o.Response).Returns(httpResponse.Object); httpContext.Setup(o => o.Response).Returns(httpResponse.Object);
var actionContext = new ActionContext(httpContext.Object, var actionContext = new ActionContext(httpContext.Object,
Mock.Of<IRouter>(), new RouteData(),
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
IUrlHelper urlHelper = GetMockUrlHelper(expectedUrl); IUrlHelper urlHelper = GetMockUrlHelper(expectedUrl);
RedirectToActionResult result = new RedirectToActionResult(urlHelper, "SampleAction", null, null); RedirectToActionResult result = new RedirectToActionResult(urlHelper, "SampleAction", null, null);
@ -47,8 +46,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
var httpContext = new Mock<HttpContext>(); var httpContext = new Mock<HttpContext>();
httpContext.Setup(o => o.Response).Returns(new Mock<HttpResponse>().Object); httpContext.Setup(o => o.Response).Returns(new Mock<HttpResponse>().Object);
var actionContext = new ActionContext(httpContext.Object, var actionContext = new ActionContext(httpContext.Object,
Mock.Of<IRouter>(), new RouteData(),
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
IUrlHelper urlHelper = GetMockUrlHelper(returnValue: null); IUrlHelper urlHelper = GetMockUrlHelper(returnValue: null);

View File

@ -25,8 +25,7 @@ namespace Microsoft.AspNet.Mvc.Core
httpContext.Setup(o => o.Response).Returns(httpResponse.Object); httpContext.Setup(o => o.Response).Returns(httpResponse.Object);
var actionContext = new ActionContext(httpContext.Object, var actionContext = new ActionContext(httpContext.Object,
Mock.Of<IRouter>(), new RouteData(),
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
IUrlHelper urlHelper = GetMockUrlHelper(expectedUrl); IUrlHelper urlHelper = GetMockUrlHelper(expectedUrl);
RedirectToRouteResult result = new RedirectToRouteResult(urlHelper, RedirectToRouteResult result = new RedirectToRouteResult(urlHelper,
@ -50,8 +49,7 @@ namespace Microsoft.AspNet.Mvc.Core
var httpContext = new Mock<HttpContext>(); var httpContext = new Mock<HttpContext>();
httpContext.Setup(o => o.Response).Returns(new Mock<HttpResponse>().Object); httpContext.Setup(o => o.Response).Returns(new Mock<HttpResponse>().Object);
var actionContext = new ActionContext(httpContext.Object, var actionContext = new ActionContext(httpContext.Object,
Mock.Of<IRouter>(), new RouteData(),
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
IUrlHelper urlHelper = GetMockUrlHelper(returnValue: null); IUrlHelper urlHelper = GetMockUrlHelper(returnValue: null);

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection.NestedProviders; using Microsoft.Framework.DependencyInjection.NestedProviders;
using Moq; using Moq;
using Xunit; using Xunit;
@ -27,15 +28,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_IndexSelectedByDefaultInAbsenceOfVerbOnlyMethod(string verb) public async Task ActionSelection_IndexSelectedByDefaultInAbsenceOfVerbOnlyMethod(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "RpcOnly" }
{ "controller", "RpcOnly" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal("Index", result.Name); Assert.Equal("Index", result.Name);
@ -47,15 +47,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_PrefersVerbOnlyMethodOverIndex(string verb) public async Task ActionSelection_PrefersVerbOnlyMethodOverIndex(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "MixedRpcAndRest" }
{ "controller", "MixedRpcAndRest" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(verb, result.Name, StringComparer.OrdinalIgnoreCase); Assert.Equal(verb, result.Name, StringComparer.OrdinalIgnoreCase);
@ -68,15 +67,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_IndexNotSelectedByDefaultExceptGetAndPostVerbs(string verb) public async Task ActionSelection_IndexNotSelectedByDefaultExceptGetAndPostVerbs(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "RpcOnly" }
{ "controller", "RpcOnly" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(null, result); Assert.Equal(null, result);
@ -88,15 +86,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_NoConventionBasedRoutingForHeadAndOptions(string verb) public async Task ActionSelection_NoConventionBasedRoutingForHeadAndOptions(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "MixedRpcAndRest" },
{"controller", "MixedRpcAndRest"}, };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(null, result); Assert.Equal(null, result);
@ -108,16 +105,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_ActionNameBasedRoutingForHeadAndOptions(string verb) public async Task ActionSelection_ActionNameBasedRoutingForHeadAndOptions(string verb)
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext(verb));
GetHttpContext(verb), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "MixedRpcAndRest" },
{ "controller", "MixedRpcAndRest" }, { "action", verb },
{ "action", verb }, };
});
// Act // Act
var result = await InvokeActionSelector(requestContext); var result = await InvokeActionSelector(routeContext);
// Assert // Assert
Assert.Equal(verb, result.Name, StringComparer.OrdinalIgnoreCase); Assert.Equal(verb, result.Name, StringComparer.OrdinalIgnoreCase);
@ -127,15 +123,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_ChangeDefaultConventionPicksCustomMethodForPost_DefaultMethodIsSelectedForGet() public async Task ActionSelection_ChangeDefaultConventionPicksCustomMethodForPost_DefaultMethodIsSelectedForGet()
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext("GET"));
GetHttpContext("GET"), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "RpcOnly" }
{ "controller", "RpcOnly" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext, new CustomActionConvention()); var result = await InvokeActionSelector(routeContext, new CustomActionConvention());
// Assert // Assert
Assert.Equal("INDEX", result.Name, StringComparer.OrdinalIgnoreCase); Assert.Equal("INDEX", result.Name, StringComparer.OrdinalIgnoreCase);
@ -145,26 +140,25 @@ namespace Microsoft.AspNet.Mvc.Core.Test
public async Task ActionSelection_ChangeDefaultConventionPicksCustomMethodForPost_CutomMethodIsSelected() public async Task ActionSelection_ChangeDefaultConventionPicksCustomMethodForPost_CutomMethodIsSelected()
{ {
// Arrange // Arrange
var requestContext = new RequestContext( var routeContext = new RouteContext(GetHttpContext("POST"));
GetHttpContext("POST"), routeContext.RouteData.Values = new Dictionary<string, object>
new Dictionary<string, object> {
{ { "controller", "RpcOnly" }
{ "controller", "RpcOnly" } };
});
// Act // Act
var result = await InvokeActionSelector(requestContext, new CustomActionConvention()); var result = await InvokeActionSelector(routeContext, new CustomActionConvention());
// Assert // Assert
Assert.Equal("PostSomething", result.Name); Assert.Equal("PostSomething", result.Name);
} }
private async Task<ActionDescriptor> InvokeActionSelector(RequestContext context) private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context)
{ {
return await InvokeActionSelector(context, _actionDiscoveryConventions); return await InvokeActionSelector(context, _actionDiscoveryConventions);
} }
private async Task<ActionDescriptor> InvokeActionSelector(RequestContext context, DefaultActionDiscoveryConventions actionDiscoveryConventions) private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context, DefaultActionDiscoveryConventions actionDiscoveryConventions)
{ {
var actionDescriptorProvider = GetActionDescriptorProvider(actionDiscoveryConventions); var actionDescriptorProvider = GetActionDescriptorProvider(actionDiscoveryConventions);
var descriptorProvider = var descriptorProvider =

View File

@ -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 System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -217,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
var actions = new ActionDescriptor[] { actionWithConstraints, actionWithoutConstraints }; var actions = new ActionDescriptor[] { actionWithConstraints, actionWithoutConstraints };
var selector = CreateSelector(actions); var selector = CreateSelector(actions);
var context = new RequestContext(CreateHttpContext("POST"), new Dictionary<string, object>()); var context = CreateRouteContext("POST");
// Act // Act
var action = await selector.SelectAsync(context); var action = await selector.SelectAsync(context);
@ -285,16 +286,27 @@ namespace Microsoft.AspNet.Mvc.Core.Test
new RouteValueDictionary(routeValues)); new RouteValueDictionary(routeValues));
} }
private static HttpContext CreateHttpContext(string httpMethod) private static RouteContext CreateRouteContext(string httpMethod)
{ {
var context = new Mock<HttpContext>(MockBehavior.Strict); var routeData = new RouteData()
{
Values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase),
};
routeData.Routers.Push(new Mock<IRouter>(MockBehavior.Strict).Object);
var httpContext = new Mock<HttpContext>(MockBehavior.Strict);
var request = new Mock<HttpRequest>(MockBehavior.Strict); var request = new Mock<HttpRequest>(MockBehavior.Strict);
context.SetupGet(c => c.Request).Returns(request.Object); httpContext.SetupGet(c => c.Request).Returns(request.Object);
request.SetupGet(r => r.Method).Returns(httpMethod); request.SetupGet(r => r.Method).Returns(httpMethod);
request.SetupGet(r => r.Path).Returns(new PathString());
return context.Object; return new RouteContext(httpContext.Object)
{
RouteData = routeData,
};
} }
private static ActionDescriptor CreateAction(string area, string controller, string action) private static ActionDescriptor CreateAction(string area, string controller, string action)

View File

@ -8,6 +8,7 @@ using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback; using Microsoft.Framework.DependencyInjection.Fallback;
using Moq; using Moq;
using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc.Core.Test namespace Microsoft.AspNet.Mvc.Core.Test
{ {
@ -40,8 +41,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
// AuthorizationContext // AuthorizationContext
var actionContext = new ActionContext( var actionContext = new ActionContext(
httpContext: httpContext.Object, httpContext: httpContext.Object,
router: null, routeData: new RouteData(),
routeValues: null,
actionDescriptor: null actionDescriptor: null
); );

View File

@ -31,9 +31,8 @@ namespace Microsoft.AspNet.Mvc
var context = new Mock<HttpContext>(); var context = new Mock<HttpContext>();
context.SetupGet(c => c.Response) context.SetupGet(c => c.Response)
.Returns(response.Object); .Returns(response.Object);
var actionContext = new ActionContext(context.Object, var actionContext = new ActionContext(context.Object,
Mock.Of<IRouter>(), new RouteData(),
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
var result = new JsonResult(new { foo = "abcd" }); var result = new JsonResult(new { foo = "abcd" });
@ -57,8 +56,7 @@ namespace Microsoft.AspNet.Mvc
context.SetupGet(c => c.Response) context.SetupGet(c => c.Response)
.Returns(response.Object); .Returns(response.Object);
var actionContext = new ActionContext(context.Object, var actionContext = new ActionContext(context.Object,
Mock.Of<IRouter>(), new RouteData(),
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
var result = new JsonResult(new { foo = "abcd" }) var result = new JsonResult(new { foo = "abcd" })
{ {

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Testing; using Microsoft.AspNet.Testing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Moq; using Moq;
@ -1291,8 +1292,7 @@ namespace Microsoft.AspNet.Mvc
var actionContext = new ActionContext( var actionContext = new ActionContext(
httpContext: httpContext.Object, httpContext: httpContext.Object,
router: null, routeData: new RouteData(),
routeValues: null,
actionDescriptor: actionDescriptor); actionDescriptor: actionDescriptor);
var controllerFactory = new Mock<IControllerFactory>(MockBehavior.Strict); var controllerFactory = new Mock<IControllerFactory>(MockBehavior.Strict);

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
public void SettingViewData_AlsoUpdatesViewBag() public void SettingViewData_AlsoUpdatesViewBag()
{ {
// Arrange (eventually passing null to these consturctors will throw) // Arrange (eventually passing null to these consturctors will throw)
var context = new ViewContext(new ActionContext(null, null, null, null), view: null, viewData: null, writer: null); var context = new ViewContext(new ActionContext(null, null, null), view: null, viewData: null, writer: null);
var originalViewData = context.ViewData = new ViewDataDictionary(metadataProvider: null); var originalViewData = context.ViewData = new ViewDataDictionary(metadataProvider: null);
var replacementViewData = new ViewDataDictionary(metadataProvider: null); var replacementViewData = new ViewDataDictionary(metadataProvider: null);

View File

@ -466,9 +466,12 @@ namespace Microsoft.AspNet.Mvc.Core.Test
private static IContextAccessor<ActionContext> CreateActionContext(HttpContext context, IRouter router) private static IContextAccessor<ActionContext> CreateActionContext(HttpContext context, IRouter router)
{ {
var routeData = new RouteData();
routeData.Values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
routeData.Routers.Push(router);
var actionContext = new ActionContext(context, var actionContext = new ActionContext(context,
router, routeData,
new Dictionary<string, object>(),
new ActionDescriptor()); new ActionDescriptor());
var contextAccessor = new Mock<IContextAccessor<ActionContext>>(); var contextAccessor = new Mock<IContextAccessor<ActionContext>>();
contextAccessor.SetupGet(c => c.Value) contextAccessor.SetupGet(c => c.Value)

View File

@ -32,8 +32,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
.Returns(response.Object); .Returns(response.Object);
var routeDictionary = new Dictionary<string, object>(); var routeDictionary = new Dictionary<string, object>();
var actionContext = new ActionContext(context.Object, var actionContext = new ActionContext(context.Object,
Mock.Of<IRouter>(), new RouteData() { Values = routeDictionary },
routeDictionary,
new ActionDescriptor()); new ActionDescriptor());
var view = new Mock<IView>(); var view = new Mock<IView>();
view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>())) view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>()))
@ -73,8 +72,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
.Returns(response.Object); .Returns(response.Object);
var routeDictionary = new Dictionary<string, object>(); var routeDictionary = new Dictionary<string, object>();
var actionContext = new ActionContext(context.Object, var actionContext = new ActionContext(context.Object,
Mock.Of<IRouter>(), new RouteData() { Values = routeDictionary },
routeDictionary,
new ActionDescriptor()); new ActionDescriptor());
var view = new Mock<IView>(); var view = new Mock<IView>();
view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>())) view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>()))

View File

@ -6,8 +6,10 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using Moq; using Moq;
using Xunit; using Xunit;
using System;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{ {
@ -44,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture); Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture);
} }
private static RequestContext CreateRequestContext(string contentType) private static RouteContext CreateRequestContext(string contentType)
{ {
var collection = Mock.Of<IReadableStringCollection>(); var collection = Mock.Of<IReadableStringCollection>();
var request = new Mock<HttpRequest>(); var request = new Mock<HttpRequest>();
@ -56,9 +58,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
var context = new Mock<HttpContext>(); var context = new Mock<HttpContext>();
context.SetupGet(c => c.Request).Returns(request.Object); context.SetupGet(c => c.Request).Returns(request.Object);
var requestContext = new RequestContext(context.Object, new Dictionary<string, object>()); var routeContext = new RouteContext(context.Object);
return requestContext; routeContext.RouteData.Values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
return routeContext;
} }
} }
} }

View File

@ -8,6 +8,8 @@ using Microsoft.AspNet.Http;
using Moq; using Moq;
#endif #endif
using Xunit; using Xunit;
using Microsoft.AspNet.Routing;
using System;
namespace Microsoft.AspNet.Mvc.ModelBinding.Test namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{ {
@ -25,10 +27,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
var context = new Mock<HttpContext>(); var context = new Mock<HttpContext>();
context.SetupGet(c => c.Items).Returns(new Dictionary<object, object>()); context.SetupGet(c => c.Items).Returns(new Dictionary<object, object>());
context.SetupGet(c => c.Request).Returns(request.Object); context.SetupGet(c => c.Request).Returns(request.Object);
var requestContext = new RequestContext(context.Object, new Dictionary<string, object>()); var routeContext = new RouteContext(context.Object);
routeContext.RouteData.Values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
// Act // Act
var result = _factory.GetValueProvider(requestContext); var result = _factory.GetValueProvider(routeContext);
// Assert // Assert
var valueProvider = Assert.IsType<ReadableStringCollectionValueProvider>(result); var valueProvider = Assert.IsType<ReadableStringCollectionValueProvider>(result);

View File

@ -7,6 +7,7 @@
"Microsoft.AspNet.Http": "0.1-alpha-*", "Microsoft.AspNet.Http": "0.1-alpha-*",
"Microsoft.AspNet.Mvc.ModelBinding" : "", "Microsoft.AspNet.Mvc.ModelBinding" : "",
"Microsoft.AspNet.PipelineCore": "0.1-alpha-*", "Microsoft.AspNet.PipelineCore": "0.1-alpha-*",
"Microsoft.AspNet.Routing": "0.1-alpha-*",
"Microsoft.AspNet.Testing": "0.1-alpha-*", "Microsoft.AspNet.Testing": "0.1-alpha-*",
"Microsoft.DataAnnotations" : "0.1-alpha-*", "Microsoft.DataAnnotations" : "0.1-alpha-*",
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*", "Microsoft.Framework.DependencyInjection": "0.1-alpha-*",

View File

@ -303,7 +303,7 @@ Layout end
var httpContext = new Mock<HttpContext>(); var httpContext = new Mock<HttpContext>();
httpContext.SetupGet(c => c.RequestServices).Returns(serviceProvider.Object); httpContext.SetupGet(c => c.RequestServices).Returns(serviceProvider.Object);
var actionContext = new ActionContext(httpContext.Object, null, null, null); var actionContext = new ActionContext(httpContext.Object, null, null);
return new ViewContext( return new ViewContext(
actionContext, actionContext,
layoutView, layoutView,