本文整理汇总了C#中System.Web.Mvc.ControllerBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ControllerBuilder类的具体用法?C# ControllerBuilder怎么用?C# ControllerBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ControllerBuilder类属于System.Web.Mvc命名空间,在下文中一共展示了ControllerBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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();
}
示例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;
}
}
示例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();
}
示例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());
}
示例6: ControllerBuilderAdaptor
public ControllerBuilderAdaptor(
ControllerBuilder controllerBuilder
)
{
if (controllerBuilder == null)
throw new ArgumentNullException("controllerBuilder");
this.controllerBuilder = controllerBuilder;
}
示例7: RegisterControllerFactoryWithMvcBootstrapperTask
//MiniProfiler miniProfiler)
public RegisterControllerFactoryWithMvcBootstrapperTask(IServiceLocator serviceLocator,
ControllerBuilder currentControllerBuilder,
IFeatureManifest<Feature> featureManifest)
{
_serviceLocator = serviceLocator;
_currentControllerBuilder = currentControllerBuilder;
_featureManifest = featureManifest;
//_miniProfiler = miniProfiler;
}
示例8: ControllerBuilderReturnsDefaultControllerBuilderByDefault
public void ControllerBuilderReturnsDefaultControllerBuilderByDefault() {
// Arrange
ControllerBuilder cb = new ControllerBuilder();
// Act
IControllerFactory cf = cb.GetControllerFactory();
// Assert
Assert.IsInstanceOfType(cf, typeof(DefaultControllerFactory));
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}