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"); ReflectedEventPatternActionDescriptor ad = GetActionDescriptor(methodInfo, null /* completionMethod */); // 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); }
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); }