本文整理汇总了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;
}
}
示例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();
}
示例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);
}
示例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;
}
);
}