-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
SendRequestHelper.cs
32 lines (25 loc) · 1.03 KB
/
SendRequestHelper.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace System.Net.Http.WinHttpHandlerUnitTests
{
public static class SendRequestHelper
{
public static HttpResponseMessage Send(WinHttpHandler handler, Action setup)
{
return Send(handler, setup, TestServer.FakeServerEndpoint);
}
public static HttpResponseMessage Send(WinHttpHandler handler, Action setup, string fakeServerEndpoint)
{
TestServer.SetResponse(DecompressionMethods.None, TestServer.ExpectedResponseBody);
setup();
var invoker = new HttpMessageInvoker(handler, false);
var request = new HttpRequestMessage(HttpMethod.Get, fakeServerEndpoint);
Task<HttpResponseMessage> task = invoker.SendAsync(request, CancellationToken.None);
return task.GetAwaiter().GetResult();
}
}
}