/// <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(); }