コード例 #1
0
        public async static Task Run(
            Action <HttpConfiguration> withConfiguration,
            Func <HttpRequestMessage> withRequest,
            Func <ApiController, HttpResponseMessage> assertInAction,
            Action <HttpResponseMessage> assertResponse)
        {
            var config = new HttpConfiguration();

            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { controller = "test", action = "get", id = RouteParameter.Optional });
            config.Filters.Add(new AssertExceptionFilter());
            var service = new TestControllerService(config, assertInAction);

            config.Services.Replace(typeof(IHttpControllerActivator), service);
            withConfiguration(config);

            var server = new HttpServer(config);
            var client = new HttpClient(server);
            var resp   = await client.SendAsync(withRequest());

            object assertionException;

            if (resp.RequestMessage.Properties.TryGetValue("AssertException", out assertionException))
            {
                ExceptionUtility.RethrowWithNoStackTraceLoss(assertionException as AssertException);
            }
            assertResponse(resp);
        }
コード例 #2
0
ファイル: Tester.cs プロジェクト: joergjo/WebApiBook.Security
        public async static Task Run(
            Action<HttpConfiguration> withConfiguration,
            Func<HttpRequestMessage> withRequest,
            Func<ApiController, HttpResponseMessage> assertInAction,
            Action<HttpResponseMessage> assertResponse)
        {
            var config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { controller = "test", action = "get", id = RouteParameter.Optional });
            config.Filters.Add(new AssertExceptionFilter());
            var service = new TestControllerService(config, assertInAction);
            config.Services.Replace(typeof(IHttpControllerActivator), service);
            withConfiguration(config);

            var server = new HttpServer(config);
            var client = new HttpClient(server);
            var resp = await client.SendAsync(withRequest());
            object assertionException;
            if (resp.RequestMessage.Properties.TryGetValue("AssertException", out assertionException))
            {
                ExceptionUtility.RethrowWithNoStackTraceLoss(assertionException as AssertException);
            }
            assertResponse(resp);
        }