• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Mvc.ControllerBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Mvc.ControllerBuilder的典型用法代码示例。如果您正苦于以下问题:C# ControllerBuilder类的具体用法?C# ControllerBuilder怎么用?C# ControllerBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ControllerBuilder类属于System.Web.Mvc命名空间,在下文中一共展示了ControllerBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ProcessRequestAddsServerHeaderCallsExecute

        public void ProcessRequestAddsServerHeaderCallsExecute() {
            // Arrange
            Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectMvcVersionResponseHeader().Verifiable();

            RouteData rd = new RouteData();
            rd.Values.Add("controller", "foo");
            RequestContext requestContext = new RequestContext(contextMock.Object, rd);
            MvcHandler mvcHandler = new MvcHandler(requestContext);

            Mock<ControllerBase> controllerMock = new Mock<ControllerBase>();
            controllerMock.Protected().Setup("Execute", requestContext).Verifiable();

            ControllerBuilder cb = new ControllerBuilder();
            Mock<IControllerFactory> controllerFactoryMock = new Mock<IControllerFactory>();
            controllerFactoryMock.Setup(o => o.CreateController(requestContext, "foo")).Returns(controllerMock.Object);
            controllerFactoryMock.Setup(o => o.ReleaseController(controllerMock.Object));
            cb.SetControllerFactory(controllerFactoryMock.Object);
            mvcHandler.ControllerBuilder = cb;

            // Act
            mvcHandler.ProcessRequest(contextMock.Object);

            // Assert
            contextMock.Verify();
            controllerMock.Verify();
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:27,代码来源:MvcHandlerTest.cs


示例2: ProcessRequestWithNormalControlFlowForAsynchronousController

        public void ProcessRequestWithNormalControlFlowForAsynchronousController() {
            // Arrange
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.ExpectMvcVersionResponseHeader().Verifiable();

            RequestContext requestContext = new RequestContext(mockHttpContext.Object, GetRouteData());
            MvcAsyncHandler handler = new MvcAsyncHandler(requestContext);

            MockAsyncResult asyncResult = new MockAsyncResult();
            Mock<IAsyncController> mockController = new Mock<IAsyncController>();
            mockController.Expect(c => c.BeginExecute(requestContext, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Returns(asyncResult).Verifiable();
            mockController.Expect(c => c.EndExecute(asyncResult)).Verifiable();
            mockController.As<IDisposable>().Expect(c => c.Dispose()).AtMostOnce().Verifiable();

            ControllerBuilder builder = new ControllerBuilder();
            builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object));
            handler.ControllerBuilder = builder;

            // Act
            IAsyncResult returnedAsyncResult = handler.BeginProcessRequest(mockHttpContext.Object, null, null);
            handler.EndProcessRequest(returnedAsyncResult);

            mockHttpContext.Verify();
            mockController.Verify();
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:25,代码来源:MvcAsyncHandlerTest.cs


示例3: ProcessRequestWithDisabledServerHeaderOnlyCallsExecute

        public void ProcessRequestWithDisabledServerHeaderOnlyCallsExecute() {
            bool oldResponseHeaderValue = MvcHandler.DisableMvcResponseHeader;
            try {
                // Arrange
                MvcHandler.DisableMvcResponseHeader = true;
                Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();

                RouteData rd = new RouteData();
                rd.Values.Add("controller", "foo");
                RequestContext requestContext = new RequestContext(contextMock.Object, rd);
                MvcHandler mvcHandler = new MvcHandler(requestContext);

                Mock<ControllerBase> controllerMock = new Mock<ControllerBase>();
                controllerMock.Protected().Expect("Execute", requestContext).Verifiable();

                ControllerBuilder cb = new ControllerBuilder();
                Mock<IControllerFactory> controllerFactoryMock = new Mock<IControllerFactory>();
                controllerFactoryMock.Expect(o => o.CreateController(requestContext, "foo")).Returns(controllerMock.Object);
                controllerFactoryMock.Expect(o => o.ReleaseController(controllerMock.Object));
                cb.SetControllerFactory(controllerFactoryMock.Object);
                mvcHandler.ControllerBuilder = cb;

                // Act
                mvcHandler.ProcessRequest(contextMock.Object);

                // Assert
                controllerMock.Verify();
            }
            finally {
                MvcHandler.DisableMvcResponseHeader = oldResponseHeaderValue;
            }
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:32,代码来源:MvcHandlerTest.cs


示例4: ProcessRequestWhereControllerBeginExecuteThrows

        public void ProcessRequestWhereControllerBeginExecuteThrows() {
            // Arrange
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.ExpectMvcVersionResponseHeader().Verifiable();

            RequestContext requestContext = new RequestContext(mockHttpContext.Object, GetRouteData());
            MvcAsyncHandler handler = new MvcAsyncHandler(requestContext);

            Mock<IAsyncController> mockController = new Mock<IAsyncController>();
            mockController.Expect(c => c.BeginExecute(requestContext, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Throws(new InvalidOperationException("Some exception text.")).Verifiable();
            mockController.As<IDisposable>().Expect(c => c.Dispose()).AtMostOnce().Verifiable();

            ControllerBuilder builder = new ControllerBuilder();
            builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object));
            handler.ControllerBuilder = builder;

            // Act
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    handler.BeginProcessRequest(mockHttpContext.Object, null, null);
                },
                @"Some exception text.");

            mockHttpContext.Verify();
            mockController.Verify();
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:26,代码来源:MvcAsyncHandlerTest.cs


示例5: Should_be_able_to_register_controller_factory

        public void Should_be_able_to_register_controller_factory()
        {
            var builder = new ControllerBuilder();

            new RegisterControllerFactory(adapter.Object, builder).Execute();

            Assert.Same(controllerFactory.Object, builder.GetControllerFactory());
        }
开发者ID:rootzhou,项目名称:Core,代码行数:8,代码来源:RegisterControllerFactoryTests.cs


示例6: ControllerBuilderAdaptor

        public ControllerBuilderAdaptor(
            ControllerBuilder controllerBuilder
            )
        {
            if (controllerBuilder == null)
                throw new ArgumentNullException("controllerBuilder");

            this.controllerBuilder = controllerBuilder;
        }
开发者ID:chaoaretasty,项目名称:MvcSiteMapProvider,代码行数:9,代码来源:ControllerBuilderAdaptor.cs


示例7: RegisterControllerFactoryWithMvcBootstrapperTask

 //MiniProfiler miniProfiler)
 public RegisterControllerFactoryWithMvcBootstrapperTask(IServiceLocator serviceLocator,
                                                         ControllerBuilder currentControllerBuilder,
                                                         IFeatureManifest<Feature> featureManifest)
 {
     _serviceLocator = serviceLocator;
     _currentControllerBuilder = currentControllerBuilder;
     _featureManifest = featureManifest;
     //_miniProfiler = miniProfiler;
 }
开发者ID:GiveCampUK,项目名称:CTTSearch,代码行数:10,代码来源:RegisterControllerFactoryWithMvcBootstrapperTask.cs


示例8: ControllerBuilderReturnsDefaultControllerBuilderByDefault

        public void ControllerBuilderReturnsDefaultControllerBuilderByDefault() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.IsInstanceOfType(cf, typeof(DefaultControllerFactory));
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:10,代码来源:ControllerBuilderTest.cs


示例9: RegisterControllerFactory

        public static void RegisterControllerFactory(ControllerBuilder controllerBuilder, IEngine engine)
        {
            engine.RegisterControllers(Assembly.GetExecutingAssembly());

            var controllerFactory = engine.Resolve<ControllerFactoryConfigurator>()
                //.NotFound<StartController>(sc => sc.NotFound())
                .ControllerFactory;

            controllerBuilder.SetControllerFactory(controllerFactory);
        }
开发者ID:spmason,项目名称:n2cms,代码行数:10,代码来源:Global.asax.cs


示例10: RegisterControllerFactory

		public void RegisterControllerFactory(ControllerBuilder controllerBuilder, IEngine engine)
		{
			engine.RegisterAllControllers();

			var controllerFactory = engine.Resolve<ControllerFactoryConfigurator>()
				.NotFound<StartController>(sc => sc.NotFound())
				.ControllerFactory;

			controllerBuilder.SetControllerFactory(controllerFactory);
		}
开发者ID:nagarjunachallapalli,项目名称:n2cms,代码行数:10,代码来源:Global.asax.cs


示例11: Should_not_register_controller_factory_when_excluded

        public void Should_not_register_controller_factory_when_excluded()
        {
            RegisterControllerFactory.Excluded = true;
            DependencyResolver.SetResolver(null);

            var builder = new ControllerBuilder();

            new RegisterControllerFactory(adapter.Object, builder).Execute();

            Assert.NotSame(controllerFactory.Object, builder.GetControllerFactory());
        }
开发者ID:rootzhou,项目名称:Core,代码行数:11,代码来源:RegisterControllerFactoryTests.cs


示例12: RegisterControllerFactory

		public static void RegisterControllerFactory(ControllerBuilder controllerBuilder, IEngine engine)
		{
			// Registers controllers in the solution for dependency injection using the IoC container provided by N2
			engine.RegisterAllControllers();

			var controllerFactory = engine.Resolve<ControllerFactoryConfigurator>()
				.NotFound<Controllers.StartPageController>(sc => sc.NotFound())
				.ControllerFactory;

			controllerBuilder.SetControllerFactory(controllerFactory);
		}
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:11,代码来源:GlobalMvcStarter.cs


示例13: CreateControllerWithFactoryInstanceReturnsInstance

        public void CreateControllerWithFactoryInstanceReturnsInstance() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            DefaultControllerFactory factory = new DefaultControllerFactory();
            cb.SetControllerFactory(factory);

            // Act
            IControllerFactory cf = cb.GetControllerFactory();

            // Assert
            Assert.AreSame(factory, cf);
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:12,代码来源:ControllerBuilderTest.cs


示例14: DefaultOrchardHost

 public DefaultOrchardHost(
     IShellSettingsManager shellSettingsManager,
     IShellContextFactory shellContextFactory,
     IRunningShellTable runningShellTable,
     ControllerBuilder controllerBuilder)
 {
     //_containerProvider = containerProvider;
     _shellSettingsManager = shellSettingsManager;
     _shellContextFactory = shellContextFactory;
     _runningShellTable = runningShellTable;
     _controllerBuilder = controllerBuilder;
     Logger = NullLogger.Instance;
 }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:13,代码来源:DefaultOrchardHost.cs


示例15: Start

        public static void Start(HttpConfiguration config, ControllerBuilder builder)
        {
            // innitialize the IoC using Structure Map.
            IoC.Initialize();

            var container = ObjectFactory.Container;

            // Standard settings for SM for MVC4.
            config.DependencyResolver = new SmDependencyResolver(container);

            // Used as a test to overide some issues with Injecting dependenices on Api controllers.
            // Though the Api controllers are not used in this version of the application
            builder.SetControllerFactory(new StructureMapControllerFactory());
        }
开发者ID:emir01,项目名称:NoteBoard-KO,代码行数:14,代码来源:StructureMapConfig.cs


示例16: RegisterMvc

        public static void RegisterMvc(ControllerBuilder controllerBuilder, GlobalFilterCollection globalFilters)
        {
            //controllers
            Container.Register<IController, HomeController>("Home").AsMultiInstance();

            //filters
            var filters = Container.ResolveAll<IMvcFilter>();
            foreach (var filter in filters)
            {
                globalFilters.Add(filter);
            }

            //controller factory
            controllerBuilder.SetControllerFactory(new TinyIocControllerFactory(Container));
        }
开发者ID:rbwestmoreland,项目名称:ACK,代码行数:15,代码来源:IoCConfig.cs


示例17: Init

        public void Init() {
            var clock = new StubClock();
            var appDataFolder = new StubAppDataFolder(clock);

            _controllerBuilder = new ControllerBuilder();
            _routeCollection = new RouteCollection();
            _modelBinderDictionary = new ModelBinderDictionary();
            _viewEngineCollection = new ViewEngineCollection { new WebFormViewEngine() };

            _container = OrchardStarter.CreateHostContainer(
                builder => {
                    builder.RegisterInstance(new StubShellSettingsLoader()).As<IShellSettingsManager>();
                    builder.RegisterType<RoutePublisher>().As<IRoutePublisher>();
                    builder.RegisterType<ModelBinderPublisher>().As<IModelBinderPublisher>();
                    builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
                    builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
                    builder.RegisterType<StubVirtualPathMonitor>().As<IVirtualPathMonitor>();
                    builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
                    builder.RegisterInstance(_controllerBuilder);
                    builder.RegisterInstance(_routeCollection);
                    builder.RegisterInstance(_modelBinderDictionary);
                    builder.RegisterInstance(_viewEngineCollection);
                    builder.RegisterAutoMocking()
                        .Ignore<IExtensionFolders>()
                        .Ignore<IRouteProvider>()
                        .Ignore<IHttpRouteProvider>()
                        .Ignore<IModelBinderProvider>()
                        .Ignore<IWorkContextEvents>()
                        .Ignore<IOwinMiddlewareProvider>();
                });
            _lifetime = _container.BeginLifetimeScope();

            _container.Mock<IContainerProvider>()
                .SetupGet(cp => cp.ApplicationContainer).Returns(_container);
            _container.Mock<IContainerProvider>()
                .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime);
            _container.Mock<IContainerProvider>()
                .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose());

            _container.Mock<IShellDescriptorManager>()
                .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor));

            _container.Mock<IOrchardShellEvents>()
                .Setup(e => e.Activated());

            _container.Mock<IOrchardShellEvents>()
                .Setup(e => e.Terminating()).Callback(() => new object());
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:48,代码来源:DefaultOrchardHostTests.cs


示例18: CreateControllerWithFactoryThatReturnsNullThrows

        public void CreateControllerWithFactoryThatReturnsNullThrows() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(ControllerFactoryReturnsNull));

            // Act
            ExceptionHelper.ExpectException<InvalidOperationException>(
                delegate {
                    RequestContext reqContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
                    reqContext.RouteData.Values["controller"] = "boo";
                    MvcHandlerWithNoVersionHeader handler = new MvcHandlerWithNoVersionHeader(reqContext) {
                        ControllerBuilder = cb
                    };
                    handler.ProcessRequest(reqContext.HttpContext);
                },
                "The IControllerFactory 'System.Web.Mvc.Test.ControllerBuilderTest+ControllerFactoryReturnsNull' did not return a controller for the name 'boo'.");
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:17,代码来源:ControllerBuilderTest.cs


示例19: CreateControllerWithFactoryThatCannotBeCreatedThrows

        public void CreateControllerWithFactoryThatCannotBeCreatedThrows() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(ControllerFactoryThrowsFromConstructor));

            // Act
            ExceptionHelper.ExpectException<InvalidOperationException>(
                delegate {
                    RequestContext reqContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
                    reqContext.RouteData.Values["controller"] = "foo";
                    MvcHandlerWithNoVersionHeader handler = new MvcHandlerWithNoVersionHeader(reqContext) {
                        ControllerBuilder = cb
                    };
                    handler.ProcessRequest(reqContext.HttpContext);
                },
                "An error occurred when trying to create the IControllerFactory 'System.Web.Mvc.Test.ControllerBuilderTest+ControllerFactoryThrowsFromConstructor'. Make sure that the controller factory has a public parameterless constructor.");
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:17,代码来源:ControllerBuilderTest.cs


示例20: CreateControllerWithFactoryThatThrowsDoesNothingSpecial

        public void CreateControllerWithFactoryThatThrowsDoesNothingSpecial() {
            // Arrange
            ControllerBuilder cb = new ControllerBuilder();
            cb.SetControllerFactory(typeof(ControllerFactoryThrows));

            // Act
            ExceptionHelper.ExpectException<Exception>(
                delegate {
                    RequestContext reqContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());
                    reqContext.RouteData.Values["controller"] = "foo";
                    MvcHandlerWithNoVersionHeader handler = new MvcHandlerWithNoVersionHeader(reqContext) {
                        ControllerBuilder = cb
                    };
                    handler.ProcessRequest(reqContext.HttpContext);
                },
                "ControllerFactoryThrows");
        }
开发者ID:pruiz,项目名称:AspMvc2,代码行数:17,代码来源:ControllerBuilderTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mvc.ControllerContext类代码示例发布时间:2022-05-26
下一篇:
C# Mvc.ControllerBase类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap