FindActionMethod() public method

public FindActionMethod ( System.Web.Mvc.ControllerContext controllerContext, string actionName ) : ActionDescriptorCreator
controllerContext System.Web.Mvc.ControllerContext
actionName string
return ActionDescriptorCreator
        public void FindActionMethodDoesNotMatchEndMethod() {
            // Arrange
            Type controllerType = typeof(MethodLocatorController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act
            ActionDescriptorCreator creator = selector.FindActionMethod(null, "EndAsyncResultPattern");

            // Assert
            Assert.IsNull(creator, "No method should have matched.");
        }
コード例 #2
0
        public override ActionDescriptor FindAction(ControllerContext controllerContext, string actionName)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }
            if (String.IsNullOrEmpty(actionName))
            {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
            }

            ActionDescriptorCreator creator = _selector.FindActionMethod(controllerContext, actionName);

            if (creator == null)
            {
                return(null);
            }

            return(creator(actionName, this));
        }
        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);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act
            ActionDescriptorCreator creator = selector.FindActionMethod(null, "ShouldMatchMethodWithSelectionAttribute");
            ActionDescriptor actionDescriptor = creator("someName", new Mock<ControllerDescriptor>().Object);

            // Assert
            Assert.IsInstanceOfType(actionDescriptor, typeof(ReflectedActionDescriptor));
            ReflectedActionDescriptor castActionDescriptor = (ReflectedActionDescriptor)actionDescriptor;

            Assert.AreEqual("MethodHasSelectionAttribute1", castActionDescriptor.MethodInfo.Name);
        }
        public void FindActionMethodReturnsMatchingMethodIfOneMethodMatches() {
            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act
            ActionDescriptorCreator creator = selector.FindActionMethod(null, "OneMatch");
            ActionDescriptor actionDescriptor = creator("someName", new Mock<ControllerDescriptor>().Object);

            // Assert
            Assert.IsInstanceOfType(actionDescriptor, typeof(ReflectedActionDescriptor));
            ReflectedActionDescriptor castActionDescriptor = (ReflectedActionDescriptor)actionDescriptor;

            Assert.AreEqual("OneMatch", castActionDescriptor.MethodInfo.Name, "Method named OneMatch() should have matched.");
            Assert.AreEqual(typeof(string), castActionDescriptor.MethodInfo.GetParameters()[0].ParameterType, "Method overload OneMatch(string) should have matched.");
        }
        public void FindActionMethodWithEventPatternType() {
            // Arrange
            Type controllerType = typeof(MethodLocatorController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act
            ActionDescriptorCreator creator = selector.FindActionMethod(null, "EventPattern");
            ActionDescriptor actionDescriptor = creator("someName", new Mock<ControllerDescriptor>().Object);

            // Assert
            Assert.IsInstanceOfType(actionDescriptor, typeof(ReflectedEventPatternActionDescriptor));
            ReflectedEventPatternActionDescriptor castActionDescriptor = (ReflectedEventPatternActionDescriptor)actionDescriptor;

            Assert.AreEqual("EventPattern", castActionDescriptor.SetupMethod.Name);
            Assert.AreEqual("EventPatternCompleted", castActionDescriptor.CompletionMethod.Name);
        }
        public void FindActionMethodWithAsyncPatternTypeThrowsIfEndMethodNotFound() {
            // Arrange
            Type controllerType = typeof(MethodLocatorController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act & assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    selector.FindActionMethod(null, "AsyncResultPatternEndNotFound");
                },
                @"Could not locate a method named 'EndAsyncResultPatternEndNotFound' on controller type 'Microsoft.Web.Mvc.Test.AsyncActionMethodSelectorTest+MethodLocatorController'.");
        }
        public void FindActionMethodWithAsyncPatternTypeThrowsIfEndMethodIsAmbiguous() {
            // Arrange
            Type controllerType = typeof(MethodLocatorController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act & assert
            ExceptionHelper.ExpectException<AmbiguousMatchException>(
                delegate {
                    selector.FindActionMethod(null, "AsyncResultPatternWithConflict");
                },
                @"Lookup for method 'EndAsyncResultPatternWithRename2' on controller type 'MethodLocatorController' failed because of an ambiguity between the following methods:
Void EndAsyncResultPatternWithRename2(System.IAsyncResult) on type Microsoft.Web.Mvc.Test.AsyncActionMethodSelectorTest+MethodLocatorController
Void EndAsyncResultPatternWithRename2() on type Microsoft.Web.Mvc.Test.AsyncActionMethodSelectorTest+MethodLocatorController");
        }
        public void FindActionMethodThrowsIfMultipleMethodsMatch() {
            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act & veriy
            ExceptionHelper.ExpectException<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 Microsoft.Web.Mvc.Test.AsyncActionMethodSelectorTest+SelectionAttributeController
Void TwoMatch() on type Microsoft.Web.Mvc.Test.AsyncActionMethodSelectorTest+SelectionAttributeController");
        }
        public void FindActionMethodReturnsNullIfNoMethodMatches() {
            // Arrange
            Type controllerType = typeof(SelectionAttributeController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            // Act
            ActionDescriptorCreator creator = selector.FindActionMethod(null, "ZeroMatch");

            // Assert
            Assert.IsNull(creator, "No method should have matched.");
        }
コード例 #10
0
 public override ActionDescriptor FindAction(ControllerContext controllerContext, string actionName)
 {
     var selector = new AsyncActionMethodSelector(controllerContext.Controller.GetType());
     var creator = selector.FindActionMethod(controllerContext, actionName);
     return creator == null ? null : creator(actionName, this);
 }