mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-27 08:49:04 -10:00
Commit migrated from https://github.com/dotnet/corefx/commit/93719a61bb57729d940a8f20d7884e06dd935af7
51 lines
1.9 KiB
C#
51 lines
1.9 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 sealed 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.ThrowsAsync<TaskCanceledException>(() => 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()
|
|
{
|
|
var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage())));
|
|
client.Dispose();
|
|
|
|
Assert.Throws<ObjectDisposedException>(() => { client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])); });
|
|
}
|
|
}
|
|
}
|