Ejemplo n.º 1
0
        public void GetCustomAttributes_Returns_ActionAttributes()
        {
            Func <string, string, User>   echoUserMethod   = _controller.AddAdmin;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor {
                MethodInfo = echoUserMethod.Method
            };

            IEnumerable <IFilter>          filters = actionDescriptor.GetCustomAttributes <IFilter>();
            IEnumerable <HttpGetAttribute> httpGet = actionDescriptor.GetCustomAttributes <HttpGetAttribute>();

            Assert.NotNull(filters);
            Assert.Equal(1, filters.Count());
            Assert.Equal(typeof(AuthorizeAttribute), filters.First().GetType());
            Assert.NotNull(httpGet);
            Assert.Equal(1, httpGet.Count());
        }
Ejemplo n.º 2
0
        public void GetCustomAttributes_Returns_ActionAttributes()
        {
            Func <string, string, User>   echoUserMethod   = _controller.AddAdmin;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor {
                MethodInfo = echoUserMethod.Method
            };

            IEnumerable <IFilter>          filters = actionDescriptor.GetCustomAttributes <IFilter>();
            IEnumerable <HttpGetAttribute> httpGet = actionDescriptor.GetCustomAttributes <HttpGetAttribute>();

            Assert.NotNull(filters);
            IFilter filter = Assert.Single(filters);

            Assert.IsType <AuthorizeAttribute>(filter);
            Assert.NotNull(httpGet);
            Assert.Single(httpGet);
        }
Ejemplo n.º 3
0
        public override HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
        {
            HttpActionDescriptor actionDescriptor = base.SelectAction(controllerContext);

            ReflectedHttpActionDescriptor reflectedActionDescriptor = actionDescriptor as ReflectedHttpActionDescriptor;

            if (null == reflectedActionDescriptor)
            {
                return(actionDescriptor);
            }

            CacheAttribute cacheAttribute = reflectedActionDescriptor.GetCustomAttributes <CacheAttribute>().FirstOrDefault()
                                            ?? reflectedActionDescriptor.ControllerDescriptor.GetCustomAttributes <CacheAttribute>().FirstOrDefault();

            if (null == cacheAttribute)
            {
                return(actionDescriptor);
            }
            return(new CacheableActionDescriptor(reflectedActionDescriptor, cacheAttribute));
        }
        public void GetCustomAttributes_Returns_ActionAttributes()
        {
            Func<string, string, User> echoUserMethod = _controller.AddAdmin;
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor { MethodInfo = echoUserMethod.Method };

            IEnumerable<IFilter> filters = actionDescriptor.GetCustomAttributes<IFilter>();
            IEnumerable<HttpGetAttribute> httpGet = actionDescriptor.GetCustomAttributes<HttpGetAttribute>();

            Assert.NotNull(filters);
            Assert.Equal(1, filters.Count());
            Assert.Equal(typeof(AuthorizeAttribute), filters.First().GetType());
            Assert.NotNull(httpGet);
            Assert.Equal(1, httpGet.Count());
        }