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.");
        }
        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.");
        }
        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 FindActionMethodWithDelegatePatternType()
        {
            // Arrange
            Type controllerType = typeof(MethodLocatorController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

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

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

            Assert.AreEqual("DelegatePattern", castActionDescriptor.ActionMethod.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 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);
        }