Issue #1525 - Enhancements to ActionContext
- Adding a new constructor that takes ModelState. - Removing an extra constructor that's not needed - docs - test cleanup
This commit is contained in:
parent
17aa21dc25
commit
08a578d01f
|
|
@ -1,42 +1,78 @@
|
||||||
// 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.Generic;
|
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc
|
namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Context object for execution of action which has been selected as part of an HTTP request.
|
||||||
|
/// </summary>
|
||||||
public class ActionContext
|
public class ActionContext
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ActionContext"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="actionContext">The <see cref="ActionContext"/> to copy.</param>
|
||||||
public ActionContext([NotNull] ActionContext actionContext)
|
public ActionContext([NotNull] ActionContext actionContext)
|
||||||
: this(actionContext.HttpContext, actionContext.RouteData, actionContext.ActionDescriptor)
|
: this(actionContext.HttpContext, actionContext.RouteData, actionContext.ActionDescriptor)
|
||||||
{
|
{
|
||||||
ModelState = actionContext.ModelState;
|
ModelState = actionContext.ModelState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionContext([NotNull] RouteContext routeContext, [NotNull] ActionDescriptor actionDescriptor)
|
/// <summary>
|
||||||
: this(routeContext.HttpContext, routeContext.RouteData, actionDescriptor)
|
/// Creates a new <see cref="ActionContext"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpContext">The <see cref="Http.HttpContext"/> for the current request.</param>
|
||||||
|
/// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
|
||||||
|
/// <param name="actionDescriptor">The <see cref="Mvc.ActionDescriptor"/> for the selected action.</param>
|
||||||
|
public ActionContext(
|
||||||
|
[NotNull] HttpContext httpContext,
|
||||||
|
[NotNull] RouteData routeData,
|
||||||
|
[NotNull] ActionDescriptor actionDescriptor)
|
||||||
|
: this(httpContext, routeData, actionDescriptor, new ModelStateDictionary())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionContext([NotNull] HttpContext httpContext,
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ActionContext"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpContext">The <see cref="Http.HttpContext"/> for the current request.</param>
|
||||||
|
/// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
|
||||||
|
/// <param name="actionDescriptor">The <see cref="Mvc.ActionDescriptor"/> for the selected action.</param>
|
||||||
|
/// <param name="modelState">The <see cref="ModelStateDictionary"/>.</param>
|
||||||
|
public ActionContext(
|
||||||
|
[NotNull] HttpContext httpContext,
|
||||||
[NotNull] RouteData routeData,
|
[NotNull] RouteData routeData,
|
||||||
[NotNull] ActionDescriptor actionDescriptor)
|
[NotNull] ActionDescriptor actionDescriptor,
|
||||||
|
[NotNull] ModelStateDictionary modelState)
|
||||||
{
|
{
|
||||||
HttpContext = httpContext;
|
HttpContext = httpContext;
|
||||||
RouteData = routeData;
|
RouteData = routeData;
|
||||||
ActionDescriptor = actionDescriptor;
|
ActionDescriptor = actionDescriptor;
|
||||||
ModelState = new ModelStateDictionary();
|
ModelState = modelState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpContext HttpContext { get; private set; }
|
/// <summary>
|
||||||
|
/// Gets the <see cref="Mvc.ActionDescriptor"/> for the selected action.
|
||||||
|
/// </summary>
|
||||||
|
public ActionDescriptor ActionDescriptor { get; }
|
||||||
|
|
||||||
public RouteData RouteData { get; private set; }
|
/// <summary>
|
||||||
|
/// Gets the <see cref="Http.HttpContext"/> for the current request.
|
||||||
|
/// </summary>
|
||||||
|
public HttpContext HttpContext { get; }
|
||||||
|
|
||||||
public ModelStateDictionary ModelState { get; private set; }
|
/// <summary>
|
||||||
|
/// Gets the <see cref="ModelStateDictionary"/>.
|
||||||
|
/// </summary>
|
||||||
|
public ModelStateDictionary ModelState { get; }
|
||||||
|
|
||||||
public ActionDescriptor ActionDescriptor { get; private set; }
|
/// <summary>
|
||||||
|
/// Gets the <see cref="AspNet.Routing.RouteData"/> for the current request.
|
||||||
|
/// </summary>
|
||||||
|
public RouteData RouteData { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2027,9 +2027,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var context = new Mock<HttpContext>();
|
var context = new Mock<HttpContext>();
|
||||||
context.SetupGet(c => c.Items)
|
context.SetupGet(c => c.Items)
|
||||||
.Returns(new Dictionary<object, object>());
|
.Returns(new Dictionary<object, object>());
|
||||||
var routeContext = new RouteContext(context.Object);
|
|
||||||
|
|
||||||
var actionContext = new ActionContext(routeContext, actionDescriptor);
|
var actionContext = new ActionContext(context.Object, new RouteData(), actionDescriptor);
|
||||||
|
|
||||||
var controllerFactory = new Mock<IControllerFactory>();
|
var controllerFactory = new Mock<IControllerFactory>();
|
||||||
controllerFactory.Setup(c => c.CreateController(It.IsAny<ActionContext>()))
|
controllerFactory.Setup(c => c.CreateController(It.IsAny<ActionContext>()))
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
.Returns(httpRequest);
|
.Returns(httpRequest);
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(services);
|
.Returns(services);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var controller = new TestController();
|
var controller = new TestController();
|
||||||
var context = new ActionContext(routeContext, new ActionDescriptor());
|
var context = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var activator = new DefaultControllerActivator();
|
var activator = new DefaultControllerActivator();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -50,9 +50,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(services);
|
.Returns(services);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var controller = new TestController();
|
var controller = new TestController();
|
||||||
var context = new ActionContext(routeContext, new ActionDescriptor());
|
var context = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var activator = new DefaultControllerActivator();
|
var activator = new DefaultControllerActivator();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -74,10 +74,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(services);
|
.Returns(services);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
|
|
||||||
var controller = new TestController();
|
var controller = new TestController();
|
||||||
var context = new ActionContext(routeContext, new ActionDescriptor());
|
var context = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
|
|
||||||
var activator = new DefaultControllerActivator();
|
var activator = new DefaultControllerActivator();
|
||||||
|
|
||||||
|
|
@ -98,9 +97,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(services);
|
.Returns(services);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var controller = new TestController();
|
var controller = new TestController();
|
||||||
var context = new ActionContext(routeContext, new ActionDescriptor());
|
var context = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var activator = new DefaultControllerActivator();
|
var activator = new DefaultControllerActivator();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -121,9 +120,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
.Returns(Mock.Of<HttpResponse>());
|
.Returns(Mock.Of<HttpResponse>());
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(services);
|
.Returns(services);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var controller = new TestController();
|
var controller = new TestController();
|
||||||
var context = new ActionContext(routeContext, new ActionDescriptor());
|
var context = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var activator = new DefaultControllerActivator();
|
var activator = new DefaultControllerActivator();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var httpContext = new Mock<DefaultHttpContext>();
|
var httpContext = new Mock<DefaultHttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider);
|
.Returns(serviceProvider);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
return new ViewContext(actionContext,
|
return new ViewContext(actionContext,
|
||||||
Mock.Of<IView>(),
|
Mock.Of<IView>(),
|
||||||
new ViewDataDictionary(new EmptyModelMetadataProvider()),
|
new ViewDataDictionary(new EmptyModelMetadataProvider()),
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,8 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http.Core;
|
||||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -53,8 +52,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var actionContext = new ActionContext(
|
var actionContext = new ActionContext(
|
||||||
new RouteContext(Mock.Of<HttpContext>()),
|
new DefaultHttpContext(),
|
||||||
Mock.Of<ActionDescriptor>());
|
new RouteData(),
|
||||||
|
new ControllerActionDescriptor());
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
var modelMetadata = metadataProvider.GetMetadataForType(
|
var modelMetadata = metadataProvider.GetMetadataForType(
|
||||||
|
|
@ -81,8 +81,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
var methodInfo = type.GetMethod("ParameterWithNoBindAttribute");
|
var methodInfo = type.GetMethod("ParameterWithNoBindAttribute");
|
||||||
|
|
||||||
var actionContext = new ActionContext(
|
var actionContext = new ActionContext(
|
||||||
new RouteContext(Mock.Of<HttpContext>()),
|
new DefaultHttpContext(),
|
||||||
Mock.Of<ActionDescriptor>());
|
new RouteData(),
|
||||||
|
Mock.Of<ControllerActionDescriptor>());
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
var modelMetadata = metadataProvider.GetMetadataForParameter(modelAccessor: null,
|
var modelMetadata = metadataProvider.GetMetadataForParameter(modelAccessor: null,
|
||||||
|
|
@ -112,8 +113,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
var methodInfo = type.GetMethod(actionMethodName);
|
var methodInfo = type.GetMethod(actionMethodName);
|
||||||
|
|
||||||
var actionContext = new ActionContext(
|
var actionContext = new ActionContext(
|
||||||
new RouteContext(Mock.Of<HttpContext>()),
|
new DefaultHttpContext(),
|
||||||
Mock.Of<ActionDescriptor>());
|
new RouteData(),
|
||||||
|
Mock.Of<ControllerActionDescriptor>());
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
var modelMetadata = metadataProvider.GetMetadataForParameter(modelAccessor: null,
|
var modelMetadata = metadataProvider.GetMetadataForParameter(modelAccessor: null,
|
||||||
|
|
@ -143,8 +145,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
var methodInfo = type.GetMethod(actionMethodName);
|
var methodInfo = type.GetMethod(actionMethodName);
|
||||||
|
|
||||||
var actionContext = new ActionContext(
|
var actionContext = new ActionContext(
|
||||||
new RouteContext(Mock.Of<HttpContext>()),
|
new DefaultHttpContext(),
|
||||||
Mock.Of<ActionDescriptor>());
|
new RouteData(),
|
||||||
|
Mock.Of<ControllerActionDescriptor>());
|
||||||
|
|
||||||
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
var metadataProvider = new DataAnnotationsModelMetadataProvider();
|
||||||
var modelMetadata = metadataProvider.GetMetadataForParameter(modelAccessor: null,
|
var modelMetadata = metadataProvider.GetMetadataForParameter(modelAccessor: null,
|
||||||
|
|
@ -190,7 +193,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
})
|
})
|
||||||
.Returns(Task.FromResult(result: false));
|
.Returns(Task.FromResult(result: false));
|
||||||
|
|
||||||
var actionContext = new ActionContext(new RouteContext(Mock.Of<HttpContext>()), actionDescriptor);
|
var actionContext = new ActionContext(
|
||||||
|
new DefaultHttpContext(),
|
||||||
|
new RouteData(),
|
||||||
|
actionDescriptor);
|
||||||
|
|
||||||
var actionBindingContext = new ActionBindingContext()
|
var actionBindingContext = new ActionBindingContext()
|
||||||
{
|
{
|
||||||
|
|
@ -238,7 +244,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
})
|
})
|
||||||
.Returns(Task.FromResult(result: true));
|
.Returns(Task.FromResult(result: true));
|
||||||
|
|
||||||
var actionContext = new ActionContext(new RouteContext(Mock.Of<HttpContext>()), actionDescriptor);
|
var actionContext = new ActionContext(
|
||||||
|
new DefaultHttpContext(),
|
||||||
|
new RouteData(),
|
||||||
|
actionDescriptor);
|
||||||
|
|
||||||
var actionBindingContext = new ActionBindingContext()
|
var actionBindingContext = new ActionBindingContext()
|
||||||
{
|
{
|
||||||
|
|
@ -293,7 +302,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
||||||
})
|
})
|
||||||
.Returns(Task.FromResult(result: true));
|
.Returns(Task.FromResult(result: true));
|
||||||
|
|
||||||
var actionContext = new ActionContext(new RouteContext(Mock.Of<HttpContext>()), actionDescriptor);
|
var actionContext = new ActionContext(
|
||||||
|
new DefaultHttpContext(),
|
||||||
|
new RouteData(),
|
||||||
|
actionDescriptor);
|
||||||
|
|
||||||
var actionBindingContext = new ActionBindingContext()
|
var actionBindingContext = new ActionBindingContext()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
private static ViewComponentContext GetViewComponentContext(IView view, Stream stream)
|
private static ViewComponentContext GetViewComponentContext(IView view, Stream stream)
|
||||||
{
|
{
|
||||||
var actionContext = new ActionContext(new RouteContext(new DefaultHttpContext()), new ActionDescriptor());
|
var actionContext = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
||||||
var viewContext = new ViewContext(actionContext, view, viewData, TextWriter.Null);
|
var viewContext = new ViewContext(actionContext, view, viewData, TextWriter.Null);
|
||||||
var writer = new StreamWriter(stream) { AutoFlush = true };
|
var writer = new StreamWriter(stream) { AutoFlush = true };
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
private static ViewComponentContext GetViewComponentContext(IView view, Stream stream)
|
private static ViewComponentContext GetViewComponentContext(IView view, Stream stream)
|
||||||
{
|
{
|
||||||
var actionContext = new ActionContext(new RouteContext(new DefaultHttpContext()), new ActionDescriptor());
|
var actionContext = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
||||||
var viewContext = new ViewContext(actionContext, view, viewData, TextWriter.Null);
|
var viewContext = new ViewContext(actionContext, view, viewData, TextWriter.Null);
|
||||||
var writer = new StreamWriter(stream) { AutoFlush = true };
|
var writer = new StreamWriter(stream) { AutoFlush = true };
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
private static ViewComponentContext GetViewComponentContext(IView view, ViewDataDictionary viewData)
|
private static ViewComponentContext GetViewComponentContext(IView view, ViewDataDictionary viewData)
|
||||||
{
|
{
|
||||||
var actionContext = new ActionContext(new RouteContext(new DefaultHttpContext()), new ActionDescriptor());
|
var actionContext = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||||
var viewContext = new ViewContext(actionContext, view, viewData, TextWriter.Null);
|
var viewContext = new ViewContext(actionContext, view, viewData, TextWriter.Null);
|
||||||
var viewComponentContext = new ViewComponentContext(typeof(object).GetTypeInfo(), viewContext, TextWriter.Null);
|
var viewComponentContext = new ViewComponentContext(typeof(object).GetTypeInfo(), viewContext, TextWriter.Null);
|
||||||
return viewComponentContext;
|
return viewComponentContext;
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider.Object);
|
.Returns(serviceProvider.Object);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var viewContext = new ViewContext(actionContext,
|
var viewContext = new ViewContext(actionContext,
|
||||||
Mock.Of<IView>(),
|
Mock.Of<IView>(),
|
||||||
new ViewDataDictionary(new EmptyModelMetadataProvider()),
|
new ViewDataDictionary(new EmptyModelMetadataProvider()),
|
||||||
|
|
@ -64,8 +64,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider.Object);
|
.Returns(serviceProvider.Object);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var viewContext = new ViewContext(actionContext,
|
var viewContext = new ViewContext(actionContext,
|
||||||
Mock.Of<IView>(),
|
Mock.Of<IView>(),
|
||||||
new ViewDataDictionary(new EmptyModelMetadataProvider()),
|
new ViewDataDictionary(new EmptyModelMetadataProvider()),
|
||||||
|
|
@ -99,8 +99,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider.Object);
|
.Returns(serviceProvider.Object);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider())
|
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider())
|
||||||
{
|
{
|
||||||
Model = new MyModel()
|
Model = new MyModel()
|
||||||
|
|
@ -134,8 +134,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider.Object);
|
.Returns(serviceProvider.Object);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var viewData = new ViewDataDictionary<MyModel>(new EmptyModelMetadataProvider())
|
var viewData = new ViewDataDictionary<MyModel>(new EmptyModelMetadataProvider())
|
||||||
{
|
{
|
||||||
Model = new MyModel()
|
Model = new MyModel()
|
||||||
|
|
@ -169,8 +169,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider.Object);
|
.Returns(serviceProvider.Object);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
||||||
var viewContext = new ViewContext(actionContext,
|
var viewContext = new ViewContext(actionContext,
|
||||||
Mock.Of<IView>(),
|
Mock.Of<IView>(),
|
||||||
|
|
@ -235,8 +235,6 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class MyModel
|
private class MyModel
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
var httpContext = new Mock<HttpContext>();
|
var httpContext = new Mock<HttpContext>();
|
||||||
httpContext.SetupGet(c => c.RequestServices)
|
httpContext.SetupGet(c => c.RequestServices)
|
||||||
.Returns(serviceProvider.Object);
|
.Returns(serviceProvider.Object);
|
||||||
var routeContext = new RouteContext(httpContext.Object);
|
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());
|
||||||
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
|
||||||
var viewContext = new ViewContext(actionContext,
|
var viewContext = new ViewContext(actionContext,
|
||||||
Mock.Of<IView>(),
|
Mock.Of<IView>(),
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new BadRequestErrorMessageResult("Error");
|
var result = new BadRequestErrorMessageResult("Error");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -46,7 +46,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new BadRequestErrorMessageResult("Error");
|
var result = new BadRequestErrorMessageResult("Error");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace System.Web.Http
|
||||||
public async Task ConflictResult_SetsStatusCode()
|
public async Task ConflictResult_SetsStatusCode()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var context = new ActionContext(new RouteContext(new DefaultHttpContext()), new ActionDescriptor());
|
var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||||
var result = new ConflictResult();
|
var result = new ConflictResult();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new ExceptionResult(new Exception("hello, world!"), includeErrorDetail: false);
|
var result = new ExceptionResult(new Exception("hello, world!"), includeErrorDetail: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -46,7 +46,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new ExceptionResult(new Exception("hello, world!"), includeErrorDetail: false);
|
var result = new ExceptionResult(new Exception("hello, world!"), includeErrorDetail: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace System.Web.Http
|
||||||
public async Task InternalServerErrorResult_SetsStatusCode()
|
public async Task InternalServerErrorResult_SetsStatusCode()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var context = new ActionContext(new RouteContext(new DefaultHttpContext()), new ActionDescriptor());
|
var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||||
var result = new InternalServerErrorResult();
|
var result = new InternalServerErrorResult();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
|
|
||||||
var modelState = new ModelStateDictionary();
|
var modelState = new ModelStateDictionary();
|
||||||
modelState.AddModelError("product.Name", "Name is required.");
|
modelState.AddModelError("product.Name", "Name is required.");
|
||||||
|
|
@ -51,7 +51,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
|
|
||||||
var modelState = new ModelStateDictionary();
|
var modelState = new ModelStateDictionary();
|
||||||
modelState.AddModelError("product.Name", "Name is required.");
|
modelState.AddModelError("product.Name", "Name is required.");
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new NegotiatedContentResult<Product>(HttpStatusCode.Ambiguous, new Product());
|
var result = new NegotiatedContentResult<Product>(HttpStatusCode.Ambiguous, new Product());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -47,7 +47,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new NegotiatedContentResult<Product>(HttpStatusCode.Ambiguous, new Product());
|
var result = new NegotiatedContentResult<Product>(HttpStatusCode.Ambiguous, new Product());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace System.Web.Http
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
httpContext.Response.Body = stream;
|
httpContext.Response.Body = stream;
|
||||||
|
|
||||||
var context = new ActionContext(new RouteContext(httpContext), new ActionDescriptor());
|
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
var result = new OkNegotiatedContentResult<Product>(new Product());
|
var result = new OkNegotiatedContentResult<Product>(new Product());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace System.Web.Http
|
||||||
public async Task OkResult_SetsStatusCode()
|
public async Task OkResult_SetsStatusCode()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var context = new ActionContext(new RouteContext(new DefaultHttpContext()), new ActionDescriptor());
|
var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||||
var result = new OkResult();
|
var result = new OkResult();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace System.Web.Http
|
||||||
httpContext.User = new ClaimsPrincipal();
|
httpContext.User = new ClaimsPrincipal();
|
||||||
|
|
||||||
var routeContext = new RouteContext(httpContext);
|
var routeContext = new RouteContext(httpContext);
|
||||||
var actionContext = new ActionContext(routeContext, new ActionDescriptor());
|
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
controller.ActionContext = actionContext;
|
controller.ActionContext = actionContext;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue