mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-27 13:19:31 -10:00
Commit migrated from https://github.com/dotnet/corefx/commit/98bef0d6aa268bffd640e9de165a670157b4fb28
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
using Xunit;
|
|
|
|
namespace System.Net.Http.Functional.Tests
|
|
{
|
|
public partial class HttpClientTest
|
|
{
|
|
[Fact]
|
|
public async Task PatchAsync_Canceled_Throws()
|
|
{
|
|
using (var client = new HttpClient(new CustomResponseHandler((r, c) => WhenCanceled<HttpResponseMessage>(c))))
|
|
{
|
|
var content = new ByteArrayContent(new byte[1]);
|
|
var cts = new CancellationTokenSource();
|
|
|
|
Task t1 = client.PatchAsync(CreateFakeUri(), content, cts.Token);
|
|
|
|
cts.Cancel();
|
|
|
|
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t1);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PatchAsync_Success()
|
|
{
|
|
Action<HttpResponseMessage> verify = message => { using (message) Assert.Equal(HttpStatusCode.OK, message.StatusCode); };
|
|
using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage()))))
|
|
{
|
|
verify(await client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])));
|
|
verify(await client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1]), CancellationToken.None));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Dispose_UsePatchAfterDispose_Throws()
|
|
{
|
|
HttpClient client = CreateHttpClient();
|
|
client.Dispose();
|
|
|
|
Assert.Throws<ObjectDisposedException>(() => { client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])); });
|
|
}
|
|
}
|
|
}
|