Skip to content

Instantly share code, notes, and snippets.

@joncloud
Created February 21, 2017 16:07
Show Gist options
  • Select an option

  • Save joncloud/b017b5efb3fe0fff92d306d8c0f8cda4 to your computer and use it in GitHub Desktop.

Select an option

Save joncloud/b017b5efb3fe0fff92d306d8c0f8cda4 to your computer and use it in GitHub Desktop.
class FilterTest
{
public FilterTest(Dictionary<Type, object> parameters)
{
HttpContext httpContext = new DefaultHttpContext();
RouteData routeData = new RouteData();
List<ParameterDescriptor> parameterDescriptors =
parameters.Select(pair => new ParameterDescriptor
{
BindingInfo = new BindingInfo
{
BindingSource = BindingSource.Body
},
Name = pair.Key.Name,
ParameterType = pair.Key
})
.ToList();
ActionDescriptor actionDescriptor = new ActionDescriptor
{
Parameters = parameterDescriptors
};
ActionContext = new ActionContext(
httpContext,
routeData,
actionDescriptor);
Filters = new List<IFilterMetadata>();
ActionArguments = parameters.ToDictionary(pair => pair.Key.Name, pair => pair.Value);
Controller = new object();
}
public ActionContext ActionContext { get; }
public IList<IFilterMetadata> Filters { get; }
public IDictionary<string, object> ActionArguments { get; }
public object Controller { get; }
public ActionExecutingContext CreateActionExecutingContext()
=> new ActionExecutingContext(ActionContext, Filters, ActionArguments, Controller);
public ActionExecutedContext CreateActionExecutedContext()
=> new ActionExecutedContext(ActionContext, Filters, Controller);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment