public void Request_CreatesSessionfulHandler() { StringWriter writer = new StringWriter(); HttpResponse res = new HttpResponse(writer); HttpRequest req = new HttpRequest(Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "Handlers/Files/simplerequest.txt"), "http://localhost:1333/home/something", ""); RouteMatch routeMatch = new RouteMatch(); HttpContext httpCtx = new HttpContext(req, res); httpCtx.Items[RouteMatch.RouteMatchKey] = routeMatch; using(mockRepository.Record()) { ControllerMetaDescriptor controllerDesc = new ControllerMetaDescriptor(); controllerDesc.ControllerDescriptor = new ControllerDescriptor(typeof(Controller), "home", "", false); Expect.Call(controllerFactoryMock.CreateController("", "home")).IgnoreArguments().Return(controllerMock); Expect.Call(controllerDescriptorProviderMock.BuildDescriptor(controllerMock)).Return(controllerDesc); ControllerContext controllerContext = new ControllerContext(); controllerContext.ControllerDescriptor = new ControllerMetaDescriptor(); Expect.Call(controllerContextFactoryMock.Create("", "home", "something", controllerDesc, routeMatch)). Return(controllerContext); } using(mockRepository.Playback()) { IHttpHandler handler = handlerFactory.GetHandler(httpCtx, "GET", "", ""); Assert.IsNotNull(handler); Assert.IsInstanceOf(typeof(MonoRailHttpHandler), handler); } }
/// <summary> /// 依据当前Http路由请求和处理请求的控制器信息获取操作方法信息 /// </summary> /// <param name="context"></param> /// <returns></returns> public virtual ActionMethodInfo GetActionMethod(ControllerContext context) { if (context == null) { throw new ArgumentNullException("context"); } else { var newSelector = new NonParameterActionMethodSelector(context); var action = newSelector.GetActionMethod(ActionFlags); if (action != null && action.Attributes != null) { foreach (var attr in action.Attributes) { if (!attr.Validate(context.HttpContext)) { var eventArgs = new ActionAttributeValidateFailedEventArgs(context.Controller.Name, context.ActionName, attr); this._ActionAttributeValidateFailed(context.Controller, eventArgs); break; } } } return action; } }
public WindsorControllerProvider(HttpContextBase httpContext, HttpRequestBase request, HttpResponseBase response, ControllerContext controllerContext) { this.httpContext = httpContext; this.request = request; this.response = response; this.controllerContext = controllerContext; }
public void ControllerCallsInitialize() { var controller = new ControllerWithInitialize(); var context = new ControllerContext("controller", "", "action1", new ControllerMetaDescriptor()); controller.Process(engineContext, context); Assert.IsTrue(controller.Initialized); }
public ControllerExecutionContext(HttpContextBase httpContext, ControllerContext controllerContext, object controller, RouteData data, ControllerDescriptor controllerDescriptor) { HttpContext = httpContext; ControllerContext = controllerContext; Controller = controller; RouteData = data; ControllerDescriptor = controllerDescriptor; }
public void Invoked_should_do_a_custom_databind_if_parameter_is_decorated_with_a_CustomBinder() { var controllerContext = new ControllerContext(); var http = new Mock<HttpContextBase>(); var sink = new ActionExecutionSink(); http.SetupGet(ctx => ctx.Request.Params).Returns(new NameValueCollection{{"user.Name", "Lyle"}}); var routeData = new RouteData(); var context = new ControllerExecutionContext(http.Object, controllerContext, this, routeData, null) { SelectedAction = new MethodInfoActionDescriptor(GetType().GetMethod("WithCustomBinding")) }; sink.Invoke(context); Assert.IsTrue(invoked); Assert.AreEqual("Lyle", _user.Name); }
public void Invoked_should_bind_HttpContext_and_ControllerContext() { var controllerContext = new ControllerContext(); var http = new Mock<HttpContextBase>(); var sink = new ActionExecutionSink(); http.SetupGet(ctx => ctx.Request.Params).Returns(new NameValueCollection()); var routeData = new RouteData(); var context = new ControllerExecutionContext(http.Object, controllerContext, this, routeData, null) { SelectedAction = new MethodInfoActionDescriptor(GetType().GetMethod("WithContextParametersAction")) }; sink.Invoke(context); Assert.IsTrue(invoked); Assert.AreSame(http.Object, _httpContext); Assert.AreSame(controllerContext, _controllerContext); }
public override void Process(string templateName, string layoutName, TextWriter output, IDictionary<string, object> parameters) { ControllerContext controllerContext = new ControllerContext(); if (layoutName != null) { controllerContext.LayoutNames = new string[] { layoutName }; } foreach (KeyValuePair<string, object> pair in parameters) { controllerContext.PropertyBag[pair.Key] = pair.Value; } ; Process(templateName, output, null, null, controllerContext); }
public NonParameterActionMethodSelector(ControllerContext context) { this.Context = context; this.ControllerType = this.Context.Controller.GetType(); this.ActionName = this.Context.ActionName; this.HttpMethod = this.Context.HttpContext.Request.HttpMethod; }
public ViewContext(HttpContextBase httpContext, TextWriter writer, ControllerContext controllerContext) { HttpContext = httpContext; Writer = writer; ControllerContext = controllerContext; }
public override void Process(string templateName, string layoutName, TextWriter output, IDictionary<string, object> parameters) { var controllerContext = new ControllerContext(); if (layoutName != null) { controllerContext.LayoutNames = new[] { layoutName }; } foreach (var pair in parameters) { controllerContext.PropertyBag[pair.Key] = pair.Value; } Process(templateName, output, EngineContextLocator.Instance.LocateCurrentContext(), null, controllerContext); }
public object WithContextParametersAction(HttpContextBase httpContext, ControllerContext controllerContext) { invoked = true; _httpContext = httpContext; _controllerContext = controllerContext; return new object(); }