public void SetUp() { controller = new ReturnBinderTestController(); viewEngineManager = new InjectableStubViewEngineManager(); PrepareController(controller); services = controller.Context.Services as StubMonoRailServices; services.ViewEngineManager = viewEngineManager; engineContext = controller.Context as StubEngineContext; engineContext.Request.Headers.Add("User-Agent", "Test Fixture"); controllerContext = services.ControllerContextFactory. Create("", "ReturnBinderTest", "Index", services.ControllerDescriptorProvider.BuildDescriptor(controller)); controller.Contextualize(controller.Context, controllerContext); viewEngineManager.RegisterTemplate(string.Format("ReturnBinderTest{0}Index", Path.DirectorySeparatorChar)); }
/// <summary> /// Prepares the controller giving it mock implementations /// of the service it requires to function normally. /// </summary> /// <param name="controller">The controller.</param> /// <param name="areaName">Name of the area (cannot be null).</param> /// <param name="controllerName">Name of the controller.</param> /// <param name="actionName">Name of the action.</param> /// <param name="contextInitializer">The context initializer.</param> protected void PrepareController(Controller controller, string areaName, string controllerName, string actionName, ContextInitializer contextInitializer) { if (controller == null) { throw new ArgumentNullException("controller", "'controller' cannot be null"); } if (areaName == null) { throw new ArgumentNullException("areaName"); } if (controllerName == null) { throw new ArgumentNullException("controllerName"); } if (actionName == null) { throw new ArgumentNullException("actionName"); } cookies = new Dictionary<string, HttpCookie>(StringComparer.InvariantCultureIgnoreCase); BuildEngineContext(areaName, controllerName, actionName, contextInitializer); controllerContext = services.ControllerContextFactory.Create(areaName, controllerName, actionName, services.ControllerDescriptorProvider.BuildDescriptor(controller)); controller.Contextualize(Context, controllerContext); controller.CreateStandardHelpers(); controller.Initialize(); }