Пример #1
0
        public void Service_ReturnsMethodNotAllowed_WhenActionsDoesNotSupportTheRequestHttpMethod()
        {
            string     controllerName = "Exception";
            string     actionName     = "GetString";
            HttpMethod requestMethod  = HttpMethod.Post;
            string     requestUrl     = String.Format("{0}/{1}/{2}", ScenarioHelper.BaseAddress, controllerName, actionName);

            ScenarioHelper.RunTest(
                controllerName,
                "/{action}",
                new HttpRequestMessage(requestMethod, requestUrl),
                (response) =>
            {
                Assert.Equal(HttpStatusCode.MethodNotAllowed, response.StatusCode);
                Assert.Equal(
                    String.Format(SRResources.ApiControllerActionSelector_HttpMethodNotSupported, requestMethod.Method),
                    response.Content.ReadAsAsync <string>().Result);
            }
                );
        }
Пример #2
0
        public async Task Service_ReturnsNotFound_WhenActionNameDoesNotExist()
        {
            string controllerName = "Exception";
            string actionName     = "actionNotFound";
            string requestUrl     = String.Format("{0}/{1}/{2}", ScenarioHelper.BaseAddress, controllerName, actionName);

            await ScenarioHelper.RunTestAsync(
                controllerName,
                "/{action}",
                new HttpRequestMessage(HttpMethod.Post, requestUrl),
                async (response) =>
            {
                Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
                var result = await response.Content.ReadAsAsync <HttpError>();
                Assert.Equal(
                    String.Format(SRResources.ApiControllerActionSelector_ActionNameNotFound, controllerName, actionName),
                    result["MessageDetail"]);
            }
                );
        }
Пример #3
0
        public async Task ThrowingHttpResponseException_FromAction_GetsReturnedToClient(
            string actionName
            )
        {
            string controllerName = "Exception";
            string requestUrl     = String.Format(
                "{0}/{1}/{2}",
                ScenarioHelper.BaseAddress,
                controllerName,
                actionName
                );

            await ScenarioHelper.RunTestAsync(
                controllerName,
                "/{action}",
                new HttpRequestMessage(HttpMethod.Post, requestUrl),
                (response) =>
            {
                Assert.Equal(HttpStatusCode.ServiceUnavailable, response.StatusCode);
                return(Task.FromResult(0));
            }
                );
        }