Esempio n. 1
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);
        }
Esempio n. 2
0
        public void FindAction_MultipleMethodsSameActionOneWithRouteAttributeAndRouteWasMatched_ReturnsMethodWithRoutingAttribute()
        {
            // Arrange
            Type controllerType = typeof(WithRoutingAttributeController);
            AsyncActionMethodSelector selector = new AsyncActionMethodSelector(controllerType);

            var context = new ControllerContext();

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

            // Act
            ActionDescriptor matchedAction = selector.FindAction(context, "Action")("Action", new ReflectedAsyncControllerDescriptor(controllerType));
            var matchedMethod = ((ReflectedActionDescriptor)matchedAction).MethodInfo;

            // Assert
            Assert.Equal(context.RouteData.GetTargetActionMethod(), matchedMethod);
        }
Esempio n. 3
0
        public void GetControllerType_WithMatchedDirectRoute_UseTargetMethodType()
        {
            // Arrange
            var requestContext = new RequestContext();

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

            var expectedControllerType = typeof(WithRoutingAttributeController);

            var controllerActivator = new Mock <IControllerActivator>(MockBehavior.Strict).Object;
            var activatorResolver   = new Resolver <IControllerActivator>();

            var factory = new DefaultControllerFactory(controllerActivator, activatorResolver, null);

            // Act
            // if it would not get the controller type from the DirectRoute, then it would not
            // be able to find any controller
            var type = factory.GetControllerType(requestContext, "no_such_controller");

            // Assert
            Assert.Equal(expectedControllerType, type);
        }