public void FindActionMethodReturnsMethodMultipleMatchesOverOneOptOut()
        {
            // Arrange
            Type controllerType           = typeof(ControllerMatchMultipleAttributes);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(new ControllerContext(), "Match");

            // Assert
            Assert.Equal("Match", matchedMethod.Name);
        }
        public void FindActionMethodReturnsNullIfNoMethodMatches()
        {
            // Arrange
            Type controllerType           = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "ZeroMatch");

            // Assert
            Assert.Null(matchedMethod);
        }
Beispiel #3
0
        public void FindActionMethodReturnsMethodWithAttributeWhenOthersOptOutAndNoAttribute()
        {
            // Arrange
            Type controllerType           = typeof(ControllerMatchMiddleWithAttribute);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(new ControllerContext(), "MiddleMatch");

            // Assert
            Assert.Equal("MiddleMatch", matchedMethod.Name);
        }
        public void FindActionMethod_IgnoresDirectRouteAttributedMethods_NoMatch()
        {
            // Arrange
            Type controllerType           = typeof(WithRoutingAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(new ControllerContext(), "DirectRouteOnly");

            // Assert
            Assert.Null(matchedMethod);
        }
        public void FindActionMethodReturnsNullIfNoMethodMatches()
        {
            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "ZeroMatch");

            // Assert
            Assert.Null(matchedMethod);
        }
        public void FindActionMethodReturnsMethodWithoutAttributeWhenOthersOptOut()
        {
            // Arrange
            Type controllerType = typeof(ControllerMatchMiddleNoAttribute);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "MiddleMatch");

            // Assert
            Assert.Equal("MiddleMatch", matchedMethod.Name);
        }
        public void FindActionMethodReturnsMatchingMethodIfOneMethodMatches()
        {
            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "OneMatch");

            // Assert
            Assert.Equal("OneMatch", matchedMethod.Name);
            Assert.Equal(typeof(string), matchedMethod.GetParameters()[0].ParameterType);
        }
        public void FindActionMethodThrowsIfMultipleMethodsMatch()
        {
            // Arrange
            Type controllerType           = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act & veriy
            Assert.Throws <AmbiguousMatchException>(
                delegate { selector.FindActionMethod(null, "TwoMatch"); },
                @"The current request for action 'TwoMatch' on controller type 'SelectionAttributeController' is ambiguous between the following action methods:
Void TwoMatch2() on type System.Web.Mvc.Test.ActionMethodSelectorTest+SelectionAttributeController
Void TwoMatch() on type System.Web.Mvc.Test.ActionMethodSelectorTest+SelectionAttributeController");
        }
        public void FindActionMethodReturnsMatchingMethodIfOneMethodMatches()
        {
            // Arrange
            Type controllerType           = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "OneMatch");

            // Assert
            Assert.Equal("OneMatch", matchedMethod.Name);
            Assert.Equal(typeof(string), matchedMethod.GetParameters()[0].ParameterType);
        }
        public void FindActionMethodReturnsMethodWithActionSelectionAttributeIfMultipleMethodsMatchRequest()
        {
            // DevDiv Bugs 212062: If multiple action methods match a request, we should match only the methods with an
            // [ActionMethod] attribute since we assume those methods are more specific.

            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "ShouldMatchMethodWithSelectionAttribute");

            // Assert
            Assert.Equal("MethodHasSelectionAttribute1", matchedMethod.Name);
        }
        public void FindActionMethodReturnsMethodWithActionSelectionAttributeIfMultipleMethodsMatchRequest()
        {
            // DevDiv Bugs 212062: If multiple action methods match a request, we should match only the methods with an
            // [ActionMethod] attribute since we assume those methods are more specific.

            // Arrange
            Type controllerType           = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "ShouldMatchMethodWithSelectionAttribute");

            // Assert
            Assert.Equal("MethodHasSelectionAttribute1", matchedMethod.Name);
        }
        public void FindActionMethod_IgnoresDirectRouteAttributedMethods_NoMatch()
        {
            // Arrange
            Type controllerType           = typeof(WithRoutingAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // This simulates what AttributeRoutingMapper will do
            selector.StandardRouteMethods.Remove(controllerType.GetMethod("ActionWithoutRoute"));
            selector.StandardRouteMethods.Remove(controllerType.GetMethod("DirectRouteOnly"));

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(new ControllerContext(), "DirectRouteOnly");

            // Assert
            Assert.Null(matchedMethod);
        }
Beispiel #13
0
        public void FindActionMethod_MultipleMethodsSameActionOneWithRouteAttributeAndRouteWasMatched_ReturnsMethodWithRoutingAttribute()
        {
            // Arrange
            Type controllerType           = typeof(WithRoutingAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            var context = new ControllerContext();

            context.RouteData       = new RouteData();
            context.RouteData.Route = DirectRouteTestHelpers.BuildDirectRouteStubsFrom <WithRoutingAttributeController>(c => c.Action())[0];

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(context, "Action");

            // Assert
            Assert.Equal("Action", matchedMethod.Name);
        }
        public void FindActionMethod_IgnoresDirectRouteAttributedMethods_NoMatch()
        {
            // Arrange
            Type controllerType = typeof(WithRoutingAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(new ControllerContext(), "DirectRouteOnly");

            // Assert
            Assert.Null(matchedMethod);
        }
        public void FindActionMethodReturnsMethodMultipleMatchesOverOneOptOut()
        {
            // Arrange
            Type controllerType = typeof(ControllerMatchMultipleAttributes);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(null, "Match");

            // Assert
            Assert.Equal("Match", matchedMethod.Name);
        }
        public void FindActionMethod_MultipleMethodsSameActionOneWithRouteAttributeAndRouteWasMatched_ReturnsMethodWithRoutingAttribute()
        {
            // Arrange
            Type controllerType = typeof(WithRoutingAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            var context = new ControllerContext();
            context.RouteData = new RouteData();
            context.RouteData.Route = DirectRouteTestHelpers.BuildDirectRouteStubsFrom<WithRoutingAttributeController>(c => c.Action())[0];

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(context, "Action");

            // Assert
            Assert.Equal("Action", matchedMethod.Name);
        }
        public void FindActionMethodThrowsIfMultipleMethodsMatch()
        {
            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // Act & veriy
            Assert.Throws<AmbiguousMatchException>(
                delegate { selector.FindActionMethod(null, "TwoMatch"); },
                @"The current request for action 'TwoMatch' on controller type 'SelectionAttributeController' is ambiguous between the following action methods:
Void TwoMatch2() on type System.Web.Mvc.Test.ActionMethodSelectorTest+SelectionAttributeController
Void TwoMatch() on type System.Web.Mvc.Test.ActionMethodSelectorTest+SelectionAttributeController");
        }
        public void FindActionMethod_IgnoresDirectRouteAttributedMethods_NoMatch()
        {
            // Arrange
            Type controllerType = typeof(WithRoutingAttributeController);
            ActionMethodSelector selector = new ActionMethodSelector(controllerType);

            // This simulates what AttributeRoutingMapper will do
            selector.StandardRouteMethods.Remove(controllerType.GetMethod("ActionWithoutRoute"));
            selector.StandardRouteMethods.Remove(controllerType.GetMethod("DirectRouteOnly"));

            // Act
            MethodInfo matchedMethod = selector.FindActionMethod(new ControllerContext(), "DirectRouteOnly");

            // Assert
            Assert.Null(matchedMethod);
        }