forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatchingTest.cs
More file actions
68 lines (58 loc) · 2.43 KB
/
Copy pathBatchingTest.cs
File metadata and controls
68 lines (58 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Batch;
using System.Web.Http.WebHost.Routing;
using System.Web.Routing;
using Microsoft.TestCommon;
namespace System.Web.Http.WebHost
{
public class BatchingTest
{
// Regression test for Codeplex-2103
//
// When batching is used in web host, we need to wrap the HttpRequestMessages in an HttpContextBase
// adapter and pass system to system.web. In 2103 there were bugs in this wrapper, and we weren't
// following the contract with respect to %-encoding.
[Fact]
public async Task WebHost_Batching_WithSpecialCharactersInUrl()
{
// Arrange
var handler = new SuccessMessageHandler();
var routeCollection = new HostedHttpRouteCollection(new RouteCollection(), "/");
routeCollection.Add("default", routeCollection.CreateRoute(
"values/ space",
defaults: null,
constraints: null,
dataTokens: null,
handler: handler));
var configuration = new HttpConfiguration(routeCollection);
var server = new HttpServer(configuration);
var batchHandler = new DefaultHttpBatchHandler(server);
var request = new HttpRequestMessage
{
Content = new MultipartContent("mixed")
{
new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, "http://contoso.com/values/ space"))
}
};
// Arrange
var response = await batchHandler.ProcessBatchAsync(request, CancellationToken.None);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.True(handler.IsCalled);
}
private class SuccessMessageHandler : HttpMessageHandler
{
public bool IsCalled { get; private set; }
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
IsCalled = true;
return Task.FromResult(request.CreateResponse(HttpStatusCode.OK));
}
}
}
}