当前位置: 首页>>代码示例>>C#>>正文


C# IFilter.Select方法代码示例

本文整理汇总了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;
        }
开发者ID:shrknt35,项目名称:sonarlint-vs,代码行数:99,代码来源:ControllerActionInvokerTest.cs

示例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;
        }
开发者ID:Nakro,项目名称:Mvc,代码行数:50,代码来源:ReflectedActionInvokerTest.cs

示例3: FilterQueryEditorViewModel

 public FilterQueryEditorViewModel(IFilter[] clusters)
 {
     var filter = QueryCompiler.ToFilter("(" + String.Join("|", clusters.Select(s => s.ToQuery())) + ")");
     this.Text = filter.ToQuery();
 }
开发者ID:sor593,项目名称:Mystique,代码行数:5,代码来源:FilterQueryEditorViewModel.cs

示例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;
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:89,代码来源:ControllerActionInvokerTest.cs


注:本文中的IFilter.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。