public void ExecuteMethodUntilSignal()
        {
            startEvent.WaitOne(int.MaxValue, false);

            while (!stopEvent.WaitOne(1, false))
            {
                ControllerMetaDescriptor desc1 = builder.BuildDescriptor(new Controller1());
                ControllerMetaDescriptor desc2 = builder.BuildDescriptor(new Controller2());

                Assert.AreEqual(0, desc1.ActionProviders.Count);
                Assert.AreEqual(1, desc1.Filters.Count);
                Assert.IsNotNull(desc1.Layout);
                Assert.IsNotNull(desc1.Rescues);

                Assert.AreEqual(0, desc2.ActionProviders.Count);
                Assert.AreEqual(1, desc2.Filters.Count);
                Assert.IsNotNull(desc2.Layout);
                Assert.IsNotNull(desc2.Rescues);

                ActionMetaDescriptor ac1 = desc1.GetAction(typeof(Controller1).GetMethod("Index"));
                Assert.IsNotNull(ac1.SkipRescue);
                Assert.AreEqual(1, ac1.SkipFilters.Count);

                ActionMetaDescriptor ac2 = desc2.GetAction(typeof(Controller2).GetMethod("Index", new Type[] { typeof(int) }));
                Assert.IsNotNull(ac2.SkipRescue);
                Assert.AreEqual(1, ac2.SkipFilters.Count);

                ActionMetaDescriptor ac3 = desc2.GetAction(typeof(Controller2).GetMethod("Index", new Type[] { typeof(String) }));
                Assert.IsNotNull(ac3.SkipRescue);
                Assert.AreEqual(0, ac3.SkipFilters.Count);
            }
        }
        /// <summary>
        /// Collects the accessible through.
        /// </summary>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <param name="method">The method.</param>
        private void CollectAccessibleThrough(ActionMetaDescriptor actionDescriptor, MethodInfo method)
        {
            var attributes = method.GetCustomAttributes(typeof(AccessibleThroughAttribute), true);

            if (attributes.Length != 0)
            {
                actionDescriptor.AccessibleThrough = (AccessibleThroughAttribute)attributes[0];
            }
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BaseExecutableAction"/> class.
		/// </summary>
		/// <param name="actionMetaDescriptor">The action meta descriptor.</param>
		protected BaseExecutableAction(ActionMetaDescriptor actionMetaDescriptor)
		{
			if (actionMetaDescriptor == null)
			{
				throw new ArgumentNullException("actionMetaDescriptor");
			}

			this.actionMetaDescriptor = actionMetaDescriptor;
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseExecutableAction"/> class.
        /// </summary>
        /// <param name="actionMetaDescriptor">The action meta descriptor.</param>
        protected BaseExecutableAction(ActionMetaDescriptor actionMetaDescriptor)
        {
            if (actionMetaDescriptor == null)
            {
                throw new ArgumentNullException("actionMetaDescriptor");
            }

            this.actionMetaDescriptor = actionMetaDescriptor;
        }
        /// <summary>
        /// Collects the skip rescue.
        /// </summary>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <param name="method">The method.</param>
        private void CollectSkipRescue(ActionMetaDescriptor actionDescriptor, MethodInfo method)
        {
            var attributes = method.GetCustomAttributes(typeof(SkipRescueAttribute), true);

            if (attributes.Length != 0)
            {
                actionDescriptor.SkipRescue = (SkipRescueAttribute)attributes[0];
            }
        }
        /// <summary>
        /// Collects the skip filter.
        /// </summary>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <param name="method">The method.</param>
        private void CollectSkipFilter(ActionMetaDescriptor actionDescriptor, MethodInfo method)
        {
            var attributes = method.GetCustomAttributes(typeof(SkipFilterAttribute), true);

            foreach (SkipFilterAttribute attr in attributes)
            {
                actionDescriptor.SkipFilters.Add(attr);
            }
        }
Ejemplo n.º 7
0
        public void ShouldReflectAbsenceOfConfigurationOnMetaDescriptor()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            Assert.IsFalse(executor.ShouldSkipAllFilters);
            Assert.IsFalse(executor.ShouldSkipRescues);
            Assert.IsFalse(executor.ShouldSkipFilter(typeof(DummyFilter)));
            Assert.IsNull(executor.LayoutOverride);
            Assert.AreEqual(0, executor.Resources.Length);
        }
Ejemplo n.º 8
0
        public void ShouldReturnTrueToSkipSpecifiedFiltersReflectingMeta()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            actionMeta.SkipFilters.Add(new SkipFilterAttribute(typeof(DummyFilter)));

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            Assert.IsTrue(executor.ShouldSkipFilter(typeof(DummyFilter)));
            Assert.IsFalse(executor.ShouldSkipRescues);
            Assert.IsFalse(executor.ShouldSkipAllFilters);
            Assert.IsNull(executor.LayoutOverride);
            Assert.AreEqual(0, executor.Resources.Length);
        }
Ejemplo n.º 9
0
        public void ShouldReturnResourcesReflectingMeta()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor
            {
                Resources = new[] { new ResourceDescriptor(typeof(BaseController), "name", "resname", "cult", "assm") }
            };

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            Assert.IsFalse(executor.ShouldSkipFilter(typeof(DummyFilter)));
            Assert.IsFalse(executor.ShouldSkipRescues);
            Assert.IsFalse(executor.ShouldSkipAllFilters);
            Assert.IsNull(executor.LayoutOverride);
            Assert.AreEqual(1, executor.Resources.Length);
        }
Ejemplo n.º 10
0
        public void ShouldReturnLayoutReflectingMeta()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor
            {
                Layout = new LayoutDescriptor("layoutname")
            };

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            Assert.IsFalse(executor.ShouldSkipFilter(typeof(DummyFilter)));
            Assert.IsFalse(executor.ShouldSkipRescues);
            Assert.IsFalse(executor.ShouldSkipAllFilters);
            Assert.AreEqual("layoutname", executor.LayoutOverride[0]);
            Assert.AreEqual(0, executor.Resources.Length);
        }
Ejemplo n.º 11
0
        public void ExecutesActionAndReturnValue()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            var            req           = new StubRequest();
            var            res           = new StubResponse();
            var            services      = new StubMonoRailServices();
            IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));
            var            retVal        = executor.Execute(engineContext, controller, new ControllerContext());

            Assert.IsTrue(controller.WasExecuted);
            Assert.AreEqual(1, retVal);
        }
        public void CompatibleExecutorDelegatesInvocationToControllerUsingDelegate()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            ActionMethodExecutorCompatible.InvokeOnController delegateToController = controller.InvokeMethodStub;

            var executor =
                new ActionMethodExecutorCompatible(GetActionMethod(controller), actionMeta, delegateToController);

            var            req           = new StubRequest();
            var            res           = new StubResponse();
            var            services      = new StubMonoRailServices();
            IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));
            var            retVal        = executor.Execute(engineContext, controller, new ControllerContext());

            Assert.IsTrue(controller.WasExecuted);
            Assert.AreEqual(2, retVal);
        }
		/// <summary>
		/// Collects the transform filter.
		/// </summary>
		/// <param name="actionDescriptor">The action descriptor.</param>
		/// <param name="method">The method.</param>
		private void CollectTransformFilter(ActionMetaDescriptor actionDescriptor, MethodInfo method)
		{
			actionDescriptor.TransformFilters = transformFilterDescriptorProvider.CollectFilters((method));
			Array.Sort(actionDescriptor.TransformFilters, TransformFilterDescriptorComparer.Instance);
		}
		/// <summary>
		/// Collects the skip filter.
		/// </summary>
		/// <param name="actionDescriptor">The action descriptor.</param>
		/// <param name="method">The method.</param>
		private void CollectSkipFilter(ActionMetaDescriptor actionDescriptor, MethodInfo method)
		{
			var attributes = method.GetCustomAttributes(typeof(SkipFilterAttribute), true);

			foreach(SkipFilterAttribute attr in attributes)
			{
				actionDescriptor.SkipFilters.Add(attr);
			}
		}
		/// <summary>
		/// Collects the accessible through.
		/// </summary>
		/// <param name="actionDescriptor">The action descriptor.</param>
		/// <param name="method">The method.</param>
		private void CollectAccessibleThrough(ActionMetaDescriptor actionDescriptor, MethodInfo method)
		{
			var attributes = method.GetCustomAttributes(typeof(AccessibleThroughAttribute), true);

			if (attributes.Length != 0)
			{
				actionDescriptor.AccessibleThrough = (AccessibleThroughAttribute) attributes[0];
			}
		}
		/// <summary>
		/// Collects the skip rescue.
		/// </summary>
		/// <param name="actionDescriptor">The action descriptor.</param>
		/// <param name="method">The method.</param>
		private void CollectSkipRescue(ActionMetaDescriptor actionDescriptor, MethodInfo method)
		{
			var attributes = method.GetCustomAttributes(typeof(SkipRescueAttribute), true);

			if (attributes.Length != 0)
			{
				actionDescriptor.SkipRescue = (SkipRescueAttribute) attributes[0];
			}
		}
		private void CollectActionLevelFiltersIntoActionDescriptor(MethodInfo method, ActionMetaDescriptor actionDescriptor)
		{
			// chat with John Simons: only take filters from the method (in case of inherited and overrided methods)
			var browseattributesonoverridedmethod = false;
			
			var filterattributes = (FilterAttribute[]) 
				method.GetCustomAttributes(
					typeof (FilterAttribute)
					, browseattributesonoverridedmethod
					);

			actionDescriptor.Filters = filterattributes.Select(attribute => new FilterDescriptor(attribute)).ToArray();
		}
 /// <summary>
 /// Collects the return type binder.
 /// </summary>
 /// <param name="actionDescriptor">The action descriptor.</param>
 /// <param name="method">The method.</param>
 private void CollectReturnTypeBinder(ActionMetaDescriptor actionDescriptor, MethodInfo method)
 {
     actionDescriptor.ReturnDescriptor = returnBinderDescriptorProvider.Collect(method);
 }
        private void CollectActionLevelFiltersIntoActionDescriptor(MethodInfo method, ActionMetaDescriptor actionDescriptor)
        {
            // chat with John Simons: only take filters from the method (in case of inherited and overrided methods)
            var browseattributesonoverridedmethod = false;

            var filterattributes = (FilterAttribute[])
                                   method.GetCustomAttributes(
                typeof(FilterAttribute)
                , browseattributesonoverridedmethod
                );

            actionDescriptor.Filters = filterattributes.Select(attribute => new FilterDescriptor(attribute)).ToArray();
        }
		/// <summary>
		/// Collects the return type binder.
		/// </summary>
		/// <param name="actionDescriptor">The action descriptor.</param>
		/// <param name="method">The method.</param>
		private void CollectReturnTypeBinder(ActionMetaDescriptor actionDescriptor, MethodInfo method)
		{
			actionDescriptor.ReturnDescriptor = returnBinderDescriptorProvider.Collect(method);
		}
Ejemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionMethodExecutorCompatible"/> class.
 /// </summary>
 /// <param name="actionMethod">The action method.</param>
 /// <param name="metaDescriptor">The meta descriptor.</param>
 /// <param name="invoke">The invoke.</param>
 public ActionMethodExecutorCompatible(MethodInfo actionMethod, ActionMetaDescriptor metaDescriptor,
                                       InvokeOnController invoke) :
     base(actionMethod, metaDescriptor)
 {
     this.invoke = invoke;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionMethodExecutor"/> class.
 /// </summary>
 /// <param name="actionMethod">The action method.</param>
 /// <param name="metaDescriptor">The meta descriptor.</param>
 public ActionMethodExecutor(MethodInfo actionMethod, ActionMetaDescriptor metaDescriptor)
     : base(metaDescriptor)
 {
     this.actionMethod = actionMethod;
 }
 /// <summary>
 /// Collects the transform filter.
 /// </summary>
 /// <param name="actionDescriptor">The action descriptor.</param>
 /// <param name="method">The method.</param>
 private void CollectTransformFilter(ActionMetaDescriptor actionDescriptor, MethodInfo method)
 {
     actionDescriptor.TransformFilters = transformFilterDescriptorProvider.CollectFilters((method));
     Array.Sort(actionDescriptor.TransformFilters, TransformFilterDescriptorComparer.Instance);
 }