本文整理汇总了C#中IFilter.Select方法的典型用法代码示例。如果您正苦于以下问题:C# IFilter.Select方法的具体用法?C# IFilter.Select怎么用?C# IFilter.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFilter
的用法示例。
在下文中一共展示了IFilter.Select方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInvoker
private TestControllerActionInvoker CreateInvoker(
IFilter[] filters,
bool actionThrows = false,
ITempDataDictionary tempData = null,
int maxAllowedErrorsInModelState = 200)
{
var actionDescriptor = new ControllerActionDescriptor()
{
FilterDescriptors = new List<FilterDescriptor>(),
Parameters = new List<ParameterDescriptor>(),
};
if (actionThrows)
{
actionDescriptor.MethodInfo = typeof(ControllerActionInvokerTest).GetMethod("ThrowingActionMethod");
}
else
{
actionDescriptor.MethodInfo = typeof(ControllerActionInvokerTest).GetMethod("ActionMethod");
}
tempData = tempData ?? new Mock<ITempDataDictionary>().Object;
var httpContext = new Mock<HttpContext>(MockBehavior.Loose);
var httpRequest = new DefaultHttpContext().Request;
var httpResponse = new DefaultHttpContext().Response;
httpContext.SetupGet(c => c.Request).Returns(httpRequest);
httpContext.SetupGet(c => c.Response).Returns(httpResponse);
httpContext.Setup(o => o.RequestServices.GetService(typeof(ITempDataDictionary)))
.Returns(tempData);
httpContext.Setup(o => o.RequestServices.GetService(typeof(ILogger<ObjectResult>)))
.Returns(new Mock<ILogger<ObjectResult>>().Object);
httpResponse.Body = new MemoryStream();
var formatter = new Mock<IOutputFormatter>();
formatter
.Setup(f => f.CanWriteResult(It.IsAny<OutputFormatterContext>(), It.IsAny<MediaTypeHeaderValue>()))
.Returns(true);
formatter
.Setup(f => f.WriteAsync(It.IsAny<OutputFormatterContext>()))
.Returns<OutputFormatterContext>(async c =>
{
await c.HttpContext.Response.WriteAsync(c.Object.ToString());
});
var options = new MvcOptions();
options.OutputFormatters.Add(formatter.Object);
var optionsAccessor = new Mock<IOptions<MvcOptions>>();
optionsAccessor
.SetupGet(o => o.Options)
.Returns(options);
httpContext
.Setup(o => o.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
.Returns(optionsAccessor.Object);
var actionContext = new ActionContext(
httpContext: httpContext.Object,
routeData: new RouteData(),
actionDescriptor: actionDescriptor);
var filterProvider = new Mock<IFilterProvider>(MockBehavior.Strict);
filterProvider
.Setup(fp => fp.OnProvidersExecuting(It.IsAny<FilterProviderContext>()))
.Callback<FilterProviderContext>(context =>
{
foreach (var filter in filters.Select(f => new FilterItem(null, f)))
{
context.Results.Add(filter);
}
});
filterProvider.Setup(fp => fp.OnProvidersExecuted(It.IsAny<FilterProviderContext>()))
.Verifiable();
filterProvider.SetupGet(fp => fp.Order)
.Returns(DefaultOrder.DefaultFrameworkSortOrder);
var invoker = new TestControllerActionInvoker(
actionContext,
new[] { filterProvider.Object },
new MockControllerFactory(this),
actionDescriptor,
new IInputFormatter[0],
new IOutputFormatter[0],
Mock.Of<IControllerActionArgumentBinder>(),
new IModelBinder[0],
new IModelValidatorProvider[0],
new IValueProviderFactory[0],
new MockScopedInstance<ActionBindingContext>(),
tempData,
new NullLoggerFactory(),
maxAllowedErrorsInModelState);
return invoker;
}
示例2: CreateInvoker
private ReflectedActionInvoker CreateInvoker(IFilter[] filters, bool actionThrows = false)
{
var actionDescriptor = new ReflectedActionDescriptor()
{
FilterDescriptors = new List<FilterDescriptor>(),
Parameters = new List<ParameterDescriptor>(),
};
if (actionThrows)
{
actionDescriptor.MethodInfo = typeof(ReflectedActionInvokerTest).GetMethod("ThrowingActionMethod");
}
else
{
actionDescriptor.MethodInfo = typeof(ReflectedActionInvokerTest).GetMethod("ActionMethod");
}
var httpContext = new Mock<HttpContext>(MockBehavior.Loose);
var httpResponse = new Mock<HttpResponse>(MockBehavior.Loose);
httpContext.SetupGet(c => c.Response).Returns(httpResponse.Object);
httpResponse.SetupGet(r => r.Body).Returns(new MemoryStream());
var actionContext = new ActionContext(
httpContext: httpContext.Object,
routeData: new RouteData(),
actionDescriptor: actionDescriptor);
var controllerFactory = new Mock<IControllerFactory>();
controllerFactory.Setup(c => c.CreateController(It.IsAny<ActionContext>())).Returns(this);
var actionBindingContextProvider = new Mock<IActionBindingContextProvider>(MockBehavior.Strict);
actionBindingContextProvider
.Setup(abcp => abcp.GetActionBindingContextAsync(It.IsAny<ActionContext>()))
.Returns(Task.FromResult(new ActionBindingContext(null, null, null, null, null, null)));
var filterProvider = new Mock<INestedProviderManager<FilterProviderContext>>(MockBehavior.Strict);
filterProvider
.Setup(fp => fp.Invoke(It.IsAny<FilterProviderContext>()))
.Callback<FilterProviderContext>(
context => context.Results.AddRange(filters.Select(f => new FilterItem(null, f))));
var invoker = new ReflectedActionInvoker(
actionContext,
actionDescriptor,
controllerFactory.Object,
actionBindingContextProvider.Object,
filterProvider.Object);
return invoker;
}
示例3: FilterQueryEditorViewModel
public FilterQueryEditorViewModel(IFilter[] clusters)
{
var filter = QueryCompiler.ToFilter("(" + String.Join("|", clusters.Select(s => s.ToQuery())) + ")");
this.Text = filter.ToQuery();
}
示例4: CreateInvoker
private TestControllerActionInvoker CreateInvoker(
IFilter[] filters,
bool actionThrows = false,
ITempDataDictionary tempData = null)
{
var actionDescriptor = new ControllerActionDescriptor()
{
FilterDescriptors = new List<FilterDescriptor>(),
Parameters = new List<ParameterDescriptor>(),
};
if (actionThrows)
{
actionDescriptor.MethodInfo = typeof(ControllerActionInvokerTest).GetMethod("ThrowingActionMethod");
}
else
{
actionDescriptor.MethodInfo = typeof(ControllerActionInvokerTest).GetMethod("ActionMethod");
}
tempData = tempData ?? new Mock<ITempDataDictionary>().Object;
var httpContext = new Mock<HttpContext>(MockBehavior.Loose);
var httpRequest = new DefaultHttpContext().Request;
var httpResponse = new DefaultHttpContext().Response;
var mockFormattersProvider = new Mock<IOutputFormattersProvider>();
mockFormattersProvider.SetupGet(o => o.OutputFormatters)
.Returns(
new List<IOutputFormatter>()
{
new JsonOutputFormatter()
});
httpContext.SetupGet(c => c.Request).Returns(httpRequest);
httpContext.SetupGet(c => c.Response).Returns(httpResponse);
httpContext.Setup(o => o.RequestServices.GetService(typeof(IOutputFormattersProvider)))
.Returns(mockFormattersProvider.Object);
httpContext.Setup(o => o.RequestServices.GetService(typeof(ITempDataDictionary)))
.Returns(tempData);
httpResponse.Body = new MemoryStream();
var options = new Mock<IOptions<MvcOptions>>();
options.SetupGet(o => o.Options)
.Returns(new MvcOptions());
httpContext.Setup(o => o.RequestServices.GetService(typeof(IOptions<MvcOptions>)))
.Returns(options.Object);
var actionContext = new ActionContext(
httpContext: httpContext.Object,
routeData: new RouteData(),
actionDescriptor: actionDescriptor);
var filterProvider = new Mock<IFilterProvider>(MockBehavior.Strict);
filterProvider
.Setup(fp => fp.OnProvidersExecuting(It.IsAny<FilterProviderContext>()))
.Callback<FilterProviderContext>(context =>
{
foreach (var filter in filters.Select(f => new FilterItem(null, f)))
{
context.Results.Add(filter);
}
});
filterProvider.Setup(fp => fp.OnProvidersExecuted(It.IsAny<FilterProviderContext>()))
.Verifiable();
filterProvider.SetupGet(fp => fp.Order)
.Returns(DefaultOrder.DefaultFrameworkSortOrder);
var inputFormattersProvider = new Mock<IInputFormattersProvider>();
inputFormattersProvider.SetupGet(o => o.InputFormatters)
.Returns(new List<IInputFormatter>());
var excludeFilterProvider = new Mock<IValidationExcludeFiltersProvider>();
excludeFilterProvider.SetupGet(o => o.ExcludeFilters)
.Returns(new List<IExcludeTypeValidationFilter>());
var invoker = new TestControllerActionInvoker(
actionContext,
new[] { filterProvider.Object },
new MockControllerFactory(this),
actionDescriptor,
inputFormattersProvider.Object,
Mock.Of<IControllerActionArgumentBinder>(),
new MockModelBinderProvider(),
new MockModelValidatorProviderProvider(),
new MockValueProviderFactoryProvider(),
new MockScopedInstance<ActionBindingContext>(),
tempData);
return invoker;
}