示例#1
0
        public void GetFiltersUsesMethodReflectedTypeRatherThanMethodDeclaringType()
        {
            // DevDiv 208062: Action filters specified on derived class won't run if the action method is on a base class

            // Arrange
            ControllerBase    controller = new GetMemberChainDerivedController();
            ControllerContext context    = new Mock <ControllerContext>().Object;
            MethodInfo        methodInfo = typeof(GetMemberChainDerivedController).GetMethod("SomeVirtual");
            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(methodInfo);

            // Act
            FilterInfo filters = ad.GetFilters();

            // Assert
            Assert.AreEqual(2, filters.AuthorizationFilters.Count, "Wrong number of authorization filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.AuthorizationFilters[0]).Key);
            Assert.AreEqual("BaseMethod", ((KeyedFilterAttribute)filters.AuthorizationFilters[1]).Key);

            Assert.AreEqual(3, filters.ActionFilters.Count, "Wrong number of action filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.ActionFilters[0]).Key);
            Assert.AreEqual("BaseMethod", ((KeyedFilterAttribute)filters.ActionFilters[1]).Key);
            Assert.AreEqual("DerivedClass", ((KeyedFilterAttribute)filters.ActionFilters[2]).Key);

            Assert.AreEqual(3, filters.ResultFilters.Count, "Wrong number of result filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.ResultFilters[0]).Key);
            Assert.AreEqual("BaseMethod", ((KeyedFilterAttribute)filters.ResultFilters[1]).Key);
            Assert.AreEqual("DerivedClass", ((KeyedFilterAttribute)filters.ResultFilters[2]).Key);

            Assert.AreEqual(1, filters.ExceptionFilters.Count, "Wrong number of exception filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.ExceptionFilters[0]).Key);
        }
示例#2
0
        public void GetFilters()
        {
            // Arrange
            ControllerBase    controller = new GetMemberChainSubderivedController();
            ControllerContext context    = new Mock <ControllerContext>().Object;
            MethodInfo        methodInfo = typeof(GetMemberChainSubderivedController).GetMethod("SomeVirtual");
            ReflectedDelegatePatternActionDescriptor ad = GetActionDescriptor(methodInfo);

            // Act
            FilterInfo filters = ad.GetFilters();

            // Assert
            Assert.AreEqual(2, filters.AuthorizationFilters.Count, "Wrong number of authorization filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.AuthorizationFilters[0]).Key);
            Assert.AreEqual("BaseMethod", ((KeyedFilterAttribute)filters.AuthorizationFilters[1]).Key);

            Assert.AreEqual(5, filters.ActionFilters.Count, "Wrong number of action filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.ActionFilters[0]).Key);
            Assert.AreEqual("BaseMethod", ((KeyedFilterAttribute)filters.ActionFilters[1]).Key);
            Assert.AreEqual("DerivedClass", ((KeyedFilterAttribute)filters.ActionFilters[2]).Key);
            Assert.AreEqual("SubderivedClass", ((KeyedFilterAttribute)filters.ActionFilters[3]).Key);
            Assert.AreEqual("SubderivedMethod", ((KeyedFilterAttribute)filters.ActionFilters[4]).Key);

            Assert.AreEqual(5, filters.ResultFilters.Count, "Wrong number of result filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.ResultFilters[0]).Key);
            Assert.AreEqual("BaseMethod", ((KeyedFilterAttribute)filters.ResultFilters[1]).Key);
            Assert.AreEqual("DerivedClass", ((KeyedFilterAttribute)filters.ResultFilters[2]).Key);
            Assert.AreEqual("SubderivedClass", ((KeyedFilterAttribute)filters.ResultFilters[3]).Key);
            Assert.AreEqual("SubderivedMethod", ((KeyedFilterAttribute)filters.ResultFilters[4]).Key);

            Assert.AreEqual(1, filters.ExceptionFilters.Count, "Wrong number of exception filters.");
            Assert.AreEqual("BaseClass", ((KeyedFilterAttribute)filters.ExceptionFilters[0]).Key);
        }