public void should_only_invoke_public_instance_method()
        {
            var matchedRoute = new HttpRoute(typeof(ControllerWithNonPublicAction), "Get", HttpMethod.Get);

            var controllerTypeResolver = new DefaultHttpControllerTypeResolver();
            var resolver = new DefaultDependencyResolver(controllerTypeResolver.GetControllerTypes(ControllerAssemblies));
            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, resolver);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public void should_only_register_public_controller()
        {
            var matchedRoute = new HttpRoute(typeof(NonPublicController), "Get", HttpMethod.Get);

            var controllerTypeResolver = new DefaultHttpControllerTypeResolver();
            var resolver = new DefaultDependencyResolver(controllerTypeResolver.GetControllerTypes(ControllerAssemblies));
            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, resolver);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public void should_return_method_not_allowd_for_non_annotated_method()
        {
            var matchedRoute = new HttpRoute(typeof(ControllerWithoutMethodAnnotation), "Get", HttpMethod.Get);

            var controllerTypeResolver = new DefaultHttpControllerTypeResolver();
            var resolver = new DefaultDependencyResolver(controllerTypeResolver.GetControllerTypes(ControllerAssemblies));
            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, resolver);

            Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
        }
        public void should_return_internal_server_error_if_no_controller_is_found()
        {
            var matchedRoute = new HttpRoute(typeof(ControllerWithoutAction), "Get", HttpMethod.Get);

            var controllerTypeResolver = new DefaultHttpControllerTypeResolver();
            var resolver = new DefaultDependencyResolver(
                controllerTypeResolver.GetControllerTypes(new[] { Assembly.GetExecutingAssembly() }));
            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, resolver);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public void should_invoke_case_insensitively()
        {
            var matchedRoute = new HttpRoute("ControllerWithPublicAction", "GET", HttpMethod.Get);

            ICollection <Type> controllerTypes = new DefaultHttpControllerTypeResolver()
                                                 .GetControllerTypes(ControllerAssemblies);
            var resolver = new DefaultDependencyResolver(controllerTypes);
            var factory  = new DefaultControllerFactory();

            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, controllerTypes, resolver, factory);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public void should_only_invoke_public_instance_method()
        {
            var matchedRoute = new HttpRoute("ControllerWithNonPublicAction", "Get", HttpMethod.Get);

            ICollection <Type> controllerTypes = new DefaultHttpControllerTypeResolver()
                                                 .GetControllerTypes(ControllerAssemblies);
            var resolver = new DefaultDependencyResolver(controllerTypes);
            var factory  = new DefaultControllerFactory();

            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, controllerTypes, resolver, factory);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
        public void should_only_register_public_controller()
        {
            var matchedRoute = new HttpRoute("NonPublicController", "Get", HttpMethod.Get);

            ICollection <Type> controllerTypes = new DefaultHttpControllerTypeResolver()
                                                 .GetControllerTypes(ControllerAssemblies);
            var resolver = new DefaultDependencyResolver(controllerTypes);
            var factory  = new DefaultControllerFactory();

            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, controllerTypes, resolver, factory);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public void should_return_method_not_allowed_for_non_annotated_method()
        {
            var matchedRoute = new HttpRoute("ControllerWithoutMethodAnnotation", "Get", HttpMethod.Get);

            ICollection <Type> controllerTypes = new DefaultHttpControllerTypeResolver()
                                                 .GetControllerTypes(ControllerAssemblies);
            var resolver = new DefaultDependencyResolver(controllerTypes);
            var factory  = new DefaultControllerFactory();

            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, controllerTypes, resolver, factory);

            Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
        }
        public void should_get_internal_server_error_when_exception_occurs()
        {
            var matchedRoute = new HttpRoute("ControllerWithErrorAction", "Get", HttpMethod.Get);

            ICollection <Type> controllerTypes = new DefaultHttpControllerTypeResolver()
                                                 .GetControllerTypes(ControllerAssemblies);
            var resolver = new DefaultDependencyResolver(controllerTypes);
            var factory  = new DefaultControllerFactory();

            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, controllerTypes, resolver, factory);

            Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
        }
        public void should_invoke_method_with_multiple_methods(string method)
        {
            var matchedRoute = new HttpRoute(
                typeof(ControllerWithMultipleMethodAnnotation),
                "Invoke",
                new HttpMethod(method));

            var controllerTypeResolver = new DefaultHttpControllerTypeResolver();
            var resolver = new DefaultDependencyResolver(controllerTypeResolver.GetControllerTypes(ControllerAssemblies));
            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, resolver);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public void should_invoke_method_with_multiple_methods(string method)
        {
            var matchedRoute = new HttpRoute(
                "ControllerWithMultipleMethodAnnotation",
                "Invoke",
                new HttpMethod(method));

            ICollection <Type> controllerTypes = new DefaultHttpControllerTypeResolver()
                                                 .GetControllerTypes(ControllerAssemblies);
            var resolver = new DefaultDependencyResolver(controllerTypes);
            var factory  = new DefaultControllerFactory();

            HttpResponseMessage response = ControllerActionInvoker.InvokeAction(
                matchedRoute, controllerTypes, resolver, factory);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }