Issue #65 merge RoutingContext and RequestContext
See the relevant PR in aspnet/Routing#60. This incorporates the breaking changes.
This commit is contained in:
parent
6b836e9e77
commit
69034b78b8
|
|
@ -11,26 +11,28 @@ namespace Microsoft.AspNet.Mvc
|
|||
public class 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;
|
||||
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;
|
||||
Router = router;
|
||||
RouteValues = routeValues;
|
||||
RouteData = routeData;
|
||||
ActionDescriptor = actionDescriptor;
|
||||
ModelState = new ModelStateDictionary();
|
||||
}
|
||||
|
||||
public HttpContext HttpContext { get; private set; }
|
||||
|
||||
public IRouter Router { get; private set; }
|
||||
|
||||
public IDictionary<string, object> RouteValues { get; private set; }
|
||||
public RouteData RouteData { get; private set; }
|
||||
|
||||
public ModelStateDictionary ModelState { get; private set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public override async Task ExecuteResultAsync([NotNull] ActionContext context)
|
||||
{
|
||||
var viewName = ViewName ?? context.ActionDescriptor.Name;
|
||||
var view = FindView(context.RouteValues, viewName);
|
||||
var view = FindView(context.RouteData.Values, viewName);
|
||||
|
||||
using (view as IDisposable)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,13 +25,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
_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 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)
|
||||
{
|
||||
|
|
@ -75,7 +70,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
(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>();
|
||||
foreach (var action in candidates)
|
||||
|
|
@ -86,12 +81,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
Action = action,
|
||||
};
|
||||
|
||||
// Issues #60 & #65 filed to deal with the ugliness of passing null here.
|
||||
var actionContext = new ActionContext(
|
||||
httpContext: context.HttpContext,
|
||||
router: null,
|
||||
routeValues: context.RouteValues,
|
||||
actionDescriptor: action);
|
||||
var actionContext = new ActionContext(context, action);
|
||||
var actionBindingContext = await _bindingProvider.GetActionBindingContextAsync(actionContext);
|
||||
|
||||
foreach (var parameter in action.Parameters.Where(p => p.ParameterBindingInfo != null))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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 Microsoft.AspNet.Routing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
// 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 Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public interface IActionConstraint
|
||||
{
|
||||
bool Accept(RequestContext context);
|
||||
bool Accept([NotNull] RouteContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// 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.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
|
@ -10,9 +9,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,17 +31,14 @@ namespace Microsoft.AspNet.Mvc
|
|||
// TODO: Throw an error here that's descriptive enough so that
|
||||
// users understand they should call the per request scoped middleware
|
||||
// or set HttpContext.Services manually
|
||||
|
||||
var requestContext = new RequestContext(context.HttpContext, context.Values);
|
||||
|
||||
var actionSelector = services.GetService<IActionSelector>();
|
||||
var actionDescriptor = await actionSelector.SelectAsync(requestContext);
|
||||
var actionDescriptor = await actionSelector.SelectAsync(context);
|
||||
if (actionDescriptor == null)
|
||||
{
|
||||
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>>();
|
||||
using (contextAccessor.SetContextSource(() => actionContext, PreventExchange))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -31,8 +32,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
public Task<ActionBindingContext> GetActionBindingContextAsync(ActionContext actionContext)
|
||||
{
|
||||
var requestContext = new RequestContext(actionContext.HttpContext, actionContext.RouteValues);
|
||||
var valueProviders = _valueProviderFactories.Select(factory => factory.GetValueProvider(requestContext))
|
||||
var routeContext = new RouteContext(actionContext.HttpContext);
|
||||
routeContext.RouteData = actionContext.RouteData;
|
||||
var valueProviders = _valueProviderFactories.Select(factory => factory.GetValueProvider(routeContext))
|
||||
.Where(vp => vp != null);
|
||||
var context = new ActionBindingContext(
|
||||
actionContext,
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
|
||||
var newViewData = new ViewDataDictionary(baseViewData, model);
|
||||
|
||||
var viewEngineResult = _viewEngine.FindPartialView(ViewContext.RouteValues, partialViewName);
|
||||
var viewEngineResult = _viewEngine.FindPartialView(ViewContext.RouteData.Values, partialViewName);
|
||||
if (!viewEngineResult.Success)
|
||||
{
|
||||
var locations = string.Empty;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
var fullViewName = modeViewPath + "/" + viewName;
|
||||
|
||||
// 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)
|
||||
{
|
||||
using (var writer = new StringWriter(CultureInfo.InvariantCulture))
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
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)
|
||||
{
|
||||
throw new ArgumentException(Resources.FormatPropertyOfTypeCannotBeNull(
|
||||
"RouteValues",
|
||||
typeof(RequestContext)),
|
||||
"Values",
|
||||
typeof(RouteData)),
|
||||
"context");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
public UrlHelper(IContextAccessor<ActionContext> contextAccessor, IActionSelector actionSelector)
|
||||
{
|
||||
_httpContext = contextAccessor.Value.HttpContext;
|
||||
_router = contextAccessor.Value.Router;
|
||||
_ambientValues = contextAccessor.Value.RouteValues;
|
||||
_router = contextAccessor.Value.RouteData.Routers.Peek();
|
||||
_ambientValues = contextAccessor.Value.RouteData.Values;
|
||||
_actionSelector = actionSelector;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
_viewName);
|
||||
}
|
||||
|
||||
var view = FindView(context.ViewContext.RouteValues, qualifiedViewName);
|
||||
var view = FindView(context.ViewContext.RouteData.Values, qualifiedViewName);
|
||||
|
||||
var childViewContext = new ViewContext(
|
||||
context.ViewContext,
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@
|
|||
<Compile Include="ModelValidationState.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs" />
|
||||
<Compile Include="RequestContext.cs" />
|
||||
<Compile Include="Validation\AssociatedValidatorProvider.cs" />
|
||||
<Compile Include="Validation\ClientModelValidationContext.cs" />
|
||||
<Compile Include="Validation\RequiredAttributeAdapter.cs" />
|
||||
|
|
@ -119,4 +118,4 @@
|
|||
<Compile Include="ValueProviders\ValueProviderResult.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -11,9 +12,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
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))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// 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.Threading.Tasks;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -10,8 +10,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
/// <summary>
|
||||
/// Get a value provider with values from the given <paramref name="requestContext"/>.
|
||||
/// </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>
|
||||
IValueProvider GetValueProvider(RequestContext requestContext);
|
||||
IValueProvider GetValueProvider([NotNull] RouteContext routeContext);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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 Microsoft.AspNet.Routing;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -9,15 +10,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
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.
|
||||
var storage = requestContext.HttpContext.Items;
|
||||
var storage = routeContext.HttpContext.Items;
|
||||
object value;
|
||||
IValueProvider provider;
|
||||
if (!storage.TryGetValue(_cacheKey, out value))
|
||||
{
|
||||
var queryCollection = requestContext.HttpContext.Request.Query;
|
||||
var queryCollection = routeContext.HttpContext.Request.Query;
|
||||
provider = new ReadableStringCollectionValueProvider(queryCollection, CultureInfo.InvariantCulture);
|
||||
storage[_cacheKey] = provider;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
// 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 Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.Mvc.Common": "",
|
||||
"Microsoft.AspNet.Routing": "0.1-alpha-*",
|
||||
"Microsoft.DataAnnotations": "0.1-alpha-*",
|
||||
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*",
|
||||
"Newtonsoft.Json": "5.0.8"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.Framework.DependencyInjection.NestedProviders;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Core.Test
|
||||
{
|
||||
|
|
@ -31,16 +32,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributeViaAcceptVerbs_ORsMultipleHttpMethods(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
{ "action", "Patch" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
{ "action", "Patch" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Patch", result.Name);
|
||||
|
|
@ -55,16 +55,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task HttpMethodAttribute_ActionWithMultipleHttpMethodAttributes_ORsMultipleHttpMethods(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
{ "action", "Put" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>()
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
{ "action", "Put" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Put", result.Name);
|
||||
|
|
@ -77,15 +76,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
// Note no action name is passed, hence should return a null action descriptor.
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>()
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_RestOnly" },
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(null, result);
|
||||
|
|
@ -98,15 +96,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
// Note no action name is passed, hence should return a null action descriptor.
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_DefaultMethodValidation" },
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "HttpMethodAttributeTests_DefaultMethodValidation" },
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Index", result.Name);
|
||||
|
|
@ -141,16 +138,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionNameAttribute_ActionGetsExposedViaActionName_UnreachableByConvention(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "ActionName" },
|
||||
{ "action", "RPCMethodWithHttpGet" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "ActionName" },
|
||||
{ "action", "RPCMethodWithHttpGet" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(null, result);
|
||||
|
|
@ -175,27 +171,26 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionNameAttribute_DifferentActionName_UsesActionNameFromActionNameAttribute(string verb, string actionName)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "ActionName" },
|
||||
{ "action", actionName }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "ActionName" },
|
||||
{ "action", actionName }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(actionName, result.Name);
|
||||
}
|
||||
|
||||
private async Task<ActionDescriptor> InvokeActionSelector(RequestContext context)
|
||||
private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context)
|
||||
{
|
||||
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 descriptorProvider =
|
||||
|
|
|
|||
|
|
@ -85,8 +85,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
|
|||
httpContext.Setup(o => o.Response).Returns(response);
|
||||
}
|
||||
|
||||
return new ActionContext(httpContext.Object, Mock.Of<IRouter>(), new Dictionary<string, object>(),
|
||||
new ActionDescriptor());
|
||||
return new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -69,9 +69,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
|
||||
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,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
routeData,
|
||||
new ActionDescriptor());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
|
|||
httpContext.Setup(o => o.Response).Returns(httpResponse.Object);
|
||||
|
||||
var actionContext = new ActionContext(httpContext.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
new RouteData(),
|
||||
new ActionDescriptor());
|
||||
IUrlHelper urlHelper = GetMockUrlHelper(expectedUrl);
|
||||
RedirectToActionResult result = new RedirectToActionResult(urlHelper, "SampleAction", null, null);
|
||||
|
|
@ -47,8 +46,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
|
|||
var httpContext = new Mock<HttpContext>();
|
||||
httpContext.Setup(o => o.Response).Returns(new Mock<HttpResponse>().Object);
|
||||
var actionContext = new ActionContext(httpContext.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
new RouteData(),
|
||||
new ActionDescriptor());
|
||||
|
||||
IUrlHelper urlHelper = GetMockUrlHelper(returnValue: null);
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ namespace Microsoft.AspNet.Mvc.Core
|
|||
httpContext.Setup(o => o.Response).Returns(httpResponse.Object);
|
||||
|
||||
var actionContext = new ActionContext(httpContext.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
new RouteData(),
|
||||
new ActionDescriptor());
|
||||
IUrlHelper urlHelper = GetMockUrlHelper(expectedUrl);
|
||||
RedirectToRouteResult result = new RedirectToRouteResult(urlHelper,
|
||||
|
|
@ -50,8 +49,7 @@ namespace Microsoft.AspNet.Mvc.Core
|
|||
var httpContext = new Mock<HttpContext>();
|
||||
httpContext.Setup(o => o.Response).Returns(new Mock<HttpResponse>().Object);
|
||||
var actionContext = new ActionContext(httpContext.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
new RouteData(),
|
||||
new ActionDescriptor());
|
||||
|
||||
IUrlHelper urlHelper = GetMockUrlHelper(returnValue: null);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.Framework.DependencyInjection.NestedProviders;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
|
@ -27,15 +28,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_IndexSelectedByDefaultInAbsenceOfVerbOnlyMethod(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Index", result.Name);
|
||||
|
|
@ -47,15 +47,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_PrefersVerbOnlyMethodOverIndex(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "MixedRpcAndRest" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "MixedRpcAndRest" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(verb, result.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -68,15 +67,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_IndexNotSelectedByDefaultExceptGetAndPostVerbs(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(null, result);
|
||||
|
|
@ -88,15 +86,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_NoConventionBasedRoutingForHeadAndOptions(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{"controller", "MixedRpcAndRest"},
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "MixedRpcAndRest" },
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(null, result);
|
||||
|
|
@ -108,16 +105,15 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_ActionNameBasedRoutingForHeadAndOptions(string verb)
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext(verb),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "MixedRpcAndRest" },
|
||||
{ "action", verb },
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext(verb));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "MixedRpcAndRest" },
|
||||
{ "action", verb },
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext);
|
||||
var result = await InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(verb, result.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -127,15 +123,14 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_ChangeDefaultConventionPicksCustomMethodForPost_DefaultMethodIsSelectedForGet()
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext("GET"),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext("GET"));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext, new CustomActionConvention());
|
||||
var result = await InvokeActionSelector(routeContext, new CustomActionConvention());
|
||||
|
||||
// Assert
|
||||
Assert.Equal("INDEX", result.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -145,26 +140,25 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task ActionSelection_ChangeDefaultConventionPicksCustomMethodForPost_CutomMethodIsSelected()
|
||||
{
|
||||
// Arrange
|
||||
var requestContext = new RequestContext(
|
||||
GetHttpContext("POST"),
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
});
|
||||
var routeContext = new RouteContext(GetHttpContext("POST"));
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>
|
||||
{
|
||||
{ "controller", "RpcOnly" }
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = await InvokeActionSelector(requestContext, new CustomActionConvention());
|
||||
var result = await InvokeActionSelector(routeContext, new CustomActionConvention());
|
||||
|
||||
// Assert
|
||||
Assert.Equal("PostSomething", result.Name);
|
||||
}
|
||||
|
||||
private async Task<ActionDescriptor> InvokeActionSelector(RequestContext context)
|
||||
private async Task<ActionDescriptor> InvokeActionSelector(RouteContext context)
|
||||
{
|
||||
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 descriptorProvider =
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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 System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -217,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
var actions = new ActionDescriptor[] { actionWithConstraints, actionWithoutConstraints };
|
||||
|
||||
var selector = CreateSelector(actions);
|
||||
var context = new RequestContext(CreateHttpContext("POST"), new Dictionary<string, object>());
|
||||
var context = CreateRouteContext("POST");
|
||||
|
||||
// Act
|
||||
var action = await selector.SelectAsync(context);
|
||||
|
|
@ -285,16 +286,27 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
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);
|
||||
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.Path).Returns(new PathString());
|
||||
|
||||
return context.Object;
|
||||
return new RouteContext(httpContext.Object)
|
||||
{
|
||||
RouteData = routeData,
|
||||
};
|
||||
}
|
||||
|
||||
private static ActionDescriptor CreateAction(string area, string controller, string action)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using Microsoft.AspNet.Http;
|
|||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.Fallback;
|
||||
using Moq;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Core.Test
|
||||
{
|
||||
|
|
@ -40,8 +41,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
// AuthorizationContext
|
||||
var actionContext = new ActionContext(
|
||||
httpContext: httpContext.Object,
|
||||
router: null,
|
||||
routeValues: null,
|
||||
routeData: new RouteData(),
|
||||
actionDescriptor: null
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
var context = new Mock<HttpContext>();
|
||||
context.SetupGet(c => c.Response)
|
||||
.Returns(response.Object);
|
||||
var actionContext = new ActionContext(context.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
var actionContext = new ActionContext(context.Object,
|
||||
new RouteData(),
|
||||
new ActionDescriptor());
|
||||
var result = new JsonResult(new { foo = "abcd" });
|
||||
|
||||
|
|
@ -57,8 +56,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
context.SetupGet(c => c.Response)
|
||||
.Returns(response.Object);
|
||||
var actionContext = new ActionContext(context.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
new Dictionary<string, object>(),
|
||||
new RouteData(),
|
||||
new ActionDescriptor());
|
||||
var result = new JsonResult(new { foo = "abcd" })
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Moq;
|
||||
|
|
@ -1291,8 +1292,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
var actionContext = new ActionContext(
|
||||
httpContext: httpContext.Object,
|
||||
router: null,
|
||||
routeValues: null,
|
||||
routeData: new RouteData(),
|
||||
actionDescriptor: actionDescriptor);
|
||||
|
||||
var controllerFactory = new Mock<IControllerFactory>(MockBehavior.Strict);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
public void SettingViewData_AlsoUpdatesViewBag()
|
||||
{
|
||||
// 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 replacementViewData = new ViewDataDictionary(metadataProvider: null);
|
||||
|
||||
|
|
|
|||
|
|
@ -466,9 +466,12 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
|
||||
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,
|
||||
router,
|
||||
new Dictionary<string, object>(),
|
||||
routeData,
|
||||
new ActionDescriptor());
|
||||
var contextAccessor = new Mock<IContextAccessor<ActionContext>>();
|
||||
contextAccessor.SetupGet(c => c.Value)
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
.Returns(response.Object);
|
||||
var routeDictionary = new Dictionary<string, object>();
|
||||
var actionContext = new ActionContext(context.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
routeDictionary,
|
||||
new RouteData() { Values = routeDictionary },
|
||||
new ActionDescriptor());
|
||||
var view = new Mock<IView>();
|
||||
view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>()))
|
||||
|
|
@ -73,8 +72,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
.Returns(response.Object);
|
||||
var routeDictionary = new Dictionary<string, object>();
|
||||
var actionContext = new ActionContext(context.Object,
|
||||
Mock.Of<IRouter>(),
|
||||
routeDictionary,
|
||||
new RouteData() { Values = routeDictionary },
|
||||
new ActionDescriptor());
|
||||
var view = new Mock<IView>();
|
||||
view.Setup(v => v.RenderAsync(It.IsAny<ViewContext>()))
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||
{
|
||||
|
|
@ -44,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
|||
Assert.Equal(CultureInfo.CurrentCulture, valueProvider.Culture);
|
||||
}
|
||||
|
||||
private static RequestContext CreateRequestContext(string contentType)
|
||||
private static RouteContext CreateRequestContext(string contentType)
|
||||
{
|
||||
var collection = Mock.Of<IReadableStringCollection>();
|
||||
var request = new Mock<HttpRequest>();
|
||||
|
|
@ -56,9 +58,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
|||
|
||||
var context = new Mock<HttpContext>();
|
||||
context.SetupGet(c => c.Request).Returns(request.Object);
|
||||
|
||||
var requestContext = new RequestContext(context.Object, new Dictionary<string, object>());
|
||||
return requestContext;
|
||||
|
||||
var routeContext = new RouteContext(context.Object);
|
||||
routeContext.RouteData.Values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
return routeContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ using Microsoft.AspNet.Http;
|
|||
using Moq;
|
||||
#endif
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
||||
{
|
||||
|
|
@ -25,10 +27,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
|
|||
var context = new Mock<HttpContext>();
|
||||
context.SetupGet(c => c.Items).Returns(new Dictionary<object, 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
|
||||
var result = _factory.GetValueProvider(requestContext);
|
||||
var result = _factory.GetValueProvider(routeContext);
|
||||
|
||||
// Assert
|
||||
var valueProvider = Assert.IsType<ReadableStringCollectionValueProvider>(result);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
"Microsoft.AspNet.Http": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.Mvc.ModelBinding" : "",
|
||||
"Microsoft.AspNet.PipelineCore": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.Routing": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.Testing": "0.1-alpha-*",
|
||||
"Microsoft.DataAnnotations" : "0.1-alpha-*",
|
||||
"Microsoft.Framework.DependencyInjection": "0.1-alpha-*",
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ Layout end
|
|||
var httpContext = new Mock<HttpContext>();
|
||||
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(
|
||||
actionContext,
|
||||
layoutView,
|
||||
|
|
|
|||
Loading…
Reference in New Issue