Exemplo n.º 1
0
        public void Invoke_should_execute_the_selected_action()
        {
            var sink = new ActionExecutionSink();

            var context = new ControllerExecutionContext(null, new ControllerContext(), this, new RouteData(), null)
            {
                SelectedAction = new TestActionDescriptor(FakeAction)
            };

            sink.Invoke(context);

            Assert.IsTrue(invoked);
        }
        public void Invoke_should_thrown_an_404_if_cannot_find_a_action()
        {
            var data = new RouteData();
            data.Values.Add("action", "Foo");

            var sink = new ActionResolutionSink();
            var descriptor = new ControllerDescriptor(GetType(), "TestController", "Test");
            descriptor.Actions.Add(new TestActionDescriptor());

            var context = new ControllerExecutionContext(null, new ControllerContext(), this, data, descriptor);

            sink.Invoke(context);
        }
Exemplo n.º 3
0
        public void Invoke_should_thrown_an_404_if_cannot_find_a_action()
        {
            var data = new RouteData();

            data.Values.Add("action", "Foo");

            var sink       = new ActionResolutionSink();
            var descriptor = new ControllerDescriptor(GetType(), "TestController", "Test");

            descriptor.Actions.Add(new TestActionDescriptor());

            var context = new ControllerExecutionContext(null, new ControllerContext(), this, data, descriptor);

            sink.Invoke(context);
        }
		public override void Invoke(ControllerExecutionContext executionCtx)
		{
			var descriptor = executionCtx.SelectedAction;

			object result;
			
			if (descriptor.IsParameterLess)
				result = PerformSimpleExecution(executionCtx, descriptor);
			else
				result = PerformDataBindedExecution(executionCtx, descriptor);

			executionCtx.InvocationResult = result;

			Proceed(executionCtx);
		}
        public void Invoke_should_execute_ActionResult_if_present()
        {
            var controllerCtx = new ControllerContext();
            var descriptor = new ControllerDescriptor(GetType(), "TestController", "Test");
            var sink = new ActionResultExecutionSink();
            var result = new TestActionResult();
            var context = new ControllerExecutionContext(null, controllerCtx, this, new RouteData(), descriptor)
                          	{
                          		InvocationResult = result,
                                SelectedAction = new TestActionDescriptor()
                          	};

            sink.Invoke(context);

            Assert.IsTrue(result.executed);
        }
        public void Invoke_should_find_action_on_controller()
        {
            var data = new RouteData();
            data.Values.Add("action", "TestAction");

            var sink = new ActionResolutionSink();
            var descriptor = new ControllerDescriptor(GetType(), "TestController", "Test");
            descriptor.Actions.Add(new TestActionDescriptor());

            var context = new ControllerExecutionContext(null, new ControllerContext(), this, data, descriptor);

            sink.Invoke(context);

            Assert.IsNotNull(context.SelectedAction);
            Assert.AreEqual("TestAction", context.SelectedAction.Name);
        }
Exemplo n.º 7
0
        public void Invoke_should_execute_ActionResult_if_present()
        {
            var controllerCtx = new ControllerContext();
            var descriptor    = new ControllerDescriptor(GetType(), "TestController", "Test");
            var sink          = new ActionResultExecutionSink();
            var result        = new TestActionResult();
            var context       = new ControllerExecutionContext(null, controllerCtx, this, new RouteData(), descriptor)
            {
                InvocationResult = result,
                SelectedAction   = new TestActionDescriptor()
            };

            sink.Invoke(context);

            Assert.IsTrue(result.executed);
        }
Exemplo n.º 8
0
        public void Invoke_should_find_action_on_controller()
        {
            var data = new RouteData();

            data.Values.Add("action", "TestAction");

            var sink       = new ActionResolutionSink();
            var descriptor = new ControllerDescriptor(GetType(), "TestController", "Test");

            descriptor.Actions.Add(new TestActionDescriptor());

            var context = new ControllerExecutionContext(null, new ControllerContext(), this, data, descriptor);

            sink.Invoke(context);

            Assert.IsNotNull(context.SelectedAction);
            Assert.AreEqual("TestAction", context.SelectedAction.Name);
        }
		private object PerformDataBindedExecution(ControllerExecutionContext executionCtx, ActionDescriptor descriptor)
		{
			var args = new List<object>();
			

			foreach (var param in descriptor.Parameters.Values)
			{
				if (!param.DemandsCustomDataBinding)
				{
					DoDefaultDataBind(param, args, executionCtx);					
				}
				else
				{
					DoCustomDataBind(param, args, executionCtx);
				}
			}

			return descriptor.Action(executionCtx.Controller, args.ToArray());
		}
Exemplo n.º 10
0
        public void Invoke_should_bind_parameters_using_request_data()
        {
            var http = new Mock <HttpContextBase>();
            var sink = new ActionExecutionSink();

            http.SetupGet(ctx => ctx.Request.Params).Returns(new NameValueCollection {
                { "a", "the value" }, { "b", "123" }
            });

            var context = new ControllerExecutionContext(http.Object, new ControllerContext(), this, new RouteData(), null)
            {
                SelectedAction = new MethodInfoActionDescriptor(GetType().GetMethod("WithPrimitiveParametersAction"))
            };

            sink.Invoke(context);

            Assert.IsTrue(invoked);
            Assert.AreEqual("the value", _a);
            Assert.AreEqual(123, _b);
        }
Exemplo n.º 11
0
        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 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);
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
		private void DoDefaultDataBind(ParameterDescriptor param, List<object> args, ControllerExecutionContext executionCtx)
		{
			var requestParams = executionCtx.HttpContext.Request.Params;

			string value;

			if (requestParams.AllKeys.Any(key => key == param.Name))
			{
				value = requestParams[param.Name];

				TryConvert(param, value, args);
				return;
			}

			if (executionCtx.RouteData.Values.ContainsKey(param.Name))
			{
				value = (string) executionCtx.RouteData.Values[param.Name];

				TryConvert(param, value, args);
				return;
			}

			if (typeof(HttpContextBase).IsAssignableFrom(param.Type))
			{
				args.Add(executionCtx.HttpContext);
				return;
			}

			if (typeof(ControllerContext).IsAssignableFrom(param.Type))
			{
				args.Add(executionCtx.ControllerContext);
				return;
			}

			args.Add(null);
		}
 public abstract void Invoke(ControllerExecutionContext executionCtx);
        public void Invoke_should_bind_parameters_using_routing_data()
        {
            var http = new Mock<HttpContextBase>();
            var sink = new ActionExecutionSink();

            http.SetupGet(ctx => ctx.Request.Params).Returns(new NameValueCollection());

            var routeData = new RouteData();
            routeData.Values.Add("a", "other value");
            routeData.Values.Add("b", "123");

            var context = new ControllerExecutionContext(http.Object, new ControllerContext(), this, routeData, null)
                          	{
                          		SelectedAction = new MethodInfoActionDescriptor(GetType().GetMethod("WithPrimitiveParametersAction"))
                          	};

            sink.Invoke(context);

            Assert.IsTrue(invoked);
            Assert.AreEqual("other value", _a);
        }
Exemplo n.º 17
0
		private void DoCustomDataBind(ParameterDescriptor param, List<object> args, ControllerExecutionContext executionCtx)
		{
			args.Add(param.CustomBinder.Bind(executionCtx.HttpContext, param));
		}
        public void Invoke_should_execute_the_selected_action()
        {
            var sink = new ActionExecutionSink();

            var context = new ControllerExecutionContext(null, new ControllerContext(), this, new RouteData(), null)
                          	{
                          		SelectedAction = new TestActionDescriptor(FakeAction)
                          	};

            sink.Invoke(context);

            Assert.IsTrue(invoked);
        }
Exemplo n.º 19
0
		private object PerformSimpleExecution(ControllerExecutionContext executionCtx, ActionDescriptor descriptor)
		{
			return descriptor.Action(executionCtx.Controller, new object[0]);
		}
        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 Invoke(ControllerExecutionContext executionCtx)
 {
     invoked = true;
 }
 protected void Proceed(ControllerExecutionContext executionCtx)
 {
     if (Next != null)
         Next.Invoke(executionCtx);
 }
 public void Invoke(ControllerExecutionContext executionCtx)
 {
 }