当前位置: 首页>>代码示例>>C#>>正文


C# HttpServer.Dispose方法代码示例

本文整理汇总了C#中System.Web.Http.HttpServer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServer.Dispose方法的具体用法?C# HttpServer.Dispose怎么用?C# HttpServer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Http.HttpServer的用法示例。


在下文中一共展示了HttpServer.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UseWebApi

        public static IAppBuilder UseWebApi(this IAppBuilder builder, HttpConfiguration configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            HttpServer server = new HttpServer(configuration);

            try
            {
                HttpMessageHandlerOptions options = CreateOptions(builder, server, configuration);
                return UseMessageHandler(builder, options);
            }
            catch
            {
                server.Dispose();
                throw;
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:25,代码来源:WebApiAppBuilderExtensions.cs

示例2: cache_singleton_in_pipeline

        public void cache_singleton_in_pipeline()
        {
            _cache = new Mock<IApiOutputCache>();

            var conf = new HttpConfiguration();
            conf.CacheOutputConfiguration().RegisterCacheOutputProvider(() => _cache.Object);

            conf.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            _server = new HttpServer(conf);

            var client = new HttpClient(_server);
            var result = client.GetAsync(_url + "Get_c100_s100").Result;

            _cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(2));

            var result2 = client.GetAsync(_url + "Get_c100_s100").Result;
            _cache.Verify(s => s.Contains(It.Is<string>(x => x == "webapi.outputcache.v2.tests.testcontrollers.samplecontroller-get_c100_s100:application/json; charset=utf-8")), Times.Exactly(4));

            _server.Dispose();
        }
开发者ID:hermsdorff,项目名称:AspNetWebApi-OutputCache,代码行数:25,代码来源:ConfigurationTests.cs

示例3: Post_NoContent_RequestMethodIsPost

        public void Post_NoContent_RequestMethodIsPost()
        {
            var config = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always };
            var messageHandler = new CaptureRequestMessageHandler();
            config.MessageHandlers.Add(messageHandler);
            var server = new HttpServer(config);

            server.Post("http://www.sample.com", string.Empty);
            server.Dispose();

            Assert.Equal(HttpMethod.Post, messageHandler.CapturedRequest.Method);
        }
开发者ID:ExploreMqt,项目名称:Peiro,代码行数:12,代码来源:HttpServerExtensionTests.cs

示例4: DisposedReturnsServiceUnavailable

        public Task<HttpResponseMessage> DisposedReturnsServiceUnavailable()
        {
            // Arrange
            Mock<HttpControllerDispatcher> dispatcherMock = new Mock<HttpControllerDispatcher>();
            HttpServer server = new HttpServer(dispatcherMock.Object);
            HttpMessageInvoker invoker = new HttpMessageInvoker(server);
            server.Dispose();
            HttpRequestMessage request = new HttpRequestMessage();

            // Act
            return invoker.SendAsync(request, CancellationToken.None).ContinueWith(
                (reqTask) =>
                {
                    // Assert
                    dispatcherMock.Protected().Verify<Task<HttpResponseMessage>>("SendAsync", Times.Never(), request, CancellationToken.None);
                    Assert.Equal(HttpStatusCode.ServiceUnavailable, reqTask.Result.StatusCode);
                    return reqTask.Result;
                }
            );
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:20,代码来源:HttpServerTest.cs


注:本文中的System.Web.Http.HttpServer.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。