Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit dff5efc

Browse files
committed
Made tests only apply to netcoreapp
1 parent d67255e commit dff5efc

File tree

5 files changed

+90
-23
lines changed

5 files changed

+90
-23
lines changed

src/System.Net.Http/tests/FunctionalTests/HttpClientTest.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace System.Net.Http.Functional.Tests
1414
{
15-
public class HttpClientTest : HttpClientTestBase
15+
public partial class HttpClientTest : HttpClientTestBase
1616
{
1717
[Fact]
1818
public void Dispose_MultipleTimes_Success()
@@ -257,7 +257,7 @@ public async Task GetAsync_InvalidUrl_ExpectedExceptionThrown()
257257
}
258258

259259
[Fact]
260-
public async Task GetPutPostDeletePatchAsync_Canceled_Throws()
260+
public async Task GetPutPostDeleteAsync_Canceled_Throws()
261261
{
262262
using (var client = new HttpClient(new CustomResponseHandler((r, c) => WhenCanceled<HttpResponseMessage>(c))))
263263
{
@@ -269,7 +269,6 @@ public async Task GetPutPostDeletePatchAsync_Canceled_Throws()
269269
Task t3 = client.PostAsync(CreateFakeUri(), content, cts.Token);
270270
Task t4 = client.PutAsync(CreateFakeUri(), content, cts.Token);
271271
Task t5 = client.DeleteAsync(CreateFakeUri(), cts.Token);
272-
Task t6 = client.PatchAsync(CreateFakeUri(), content, cts.Token);
273272

274273
cts.Cancel();
275274

@@ -278,12 +277,11 @@ public async Task GetPutPostDeletePatchAsync_Canceled_Throws()
278277
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t3);
279278
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t4);
280279
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t5);
281-
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t6);
282280
}
283281
}
284282

285283
[Fact]
286-
public async Task GetPutPostDeletePatchAsync_Success()
284+
public async Task GetPutPostDeleteAsync_Success()
287285
{
288286
Action<HttpResponseMessage> verify = message => { using (message) Assert.Equal(HttpStatusCode.OK, message.StatusCode); };
289287
using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage()))))
@@ -301,9 +299,6 @@ public async Task GetPutPostDeletePatchAsync_Success()
301299

302300
verify(await client.DeleteAsync(CreateFakeUri()));
303301
verify(await client.DeleteAsync(CreateFakeUri(), CancellationToken.None));
304-
305-
verify(await client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])));
306-
verify(await client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1]), CancellationToken.None));
307302
}
308303
}
309304

@@ -374,7 +369,6 @@ public void Dispose_UseAfterDispose_Throws()
374369
Assert.Throws<ObjectDisposedException>(() => { client.GetByteArrayAsync(CreateFakeUri()); });
375370
Assert.Throws<ObjectDisposedException>(() => { client.GetStreamAsync(CreateFakeUri()); });
376371
Assert.Throws<ObjectDisposedException>(() => { client.GetStringAsync(CreateFakeUri()); });
377-
Assert.Throws<ObjectDisposedException>(() => { client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])); });
378372
Assert.Throws<ObjectDisposedException>(() => { client.PostAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])); });
379373
Assert.Throws<ObjectDisposedException>(() => { client.PutAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])); });
380374
Assert.Throws<ObjectDisposedException>(() => { client.SendAsync(new HttpRequestMessage(HttpMethod.Get, CreateFakeUri())); });
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
4+
using Xunit;
5+
6+
namespace System.Net.Http.Functional.Tests
7+
{
8+
public partial class HttpClientTest
9+
{
10+
[Fact]
11+
public async Task PatchAsync_Canceled_Throws()
12+
{
13+
using (var client = new HttpClient(new CustomResponseHandler((r, c) => WhenCanceled<HttpResponseMessage>(c))))
14+
{
15+
var content = new ByteArrayContent(new byte[1]);
16+
var cts = new CancellationTokenSource();
17+
18+
Task t1 = client.PatchAsync(CreateFakeUri(), content, cts.Token);
19+
20+
cts.Cancel();
21+
22+
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => t1);
23+
}
24+
}
25+
26+
[Fact]
27+
public async Task PatchAsync_Success()
28+
{
29+
Action<HttpResponseMessage> verify = message => { using (message) Assert.Equal(HttpStatusCode.OK, message.StatusCode); };
30+
using (var client = new HttpClient(new CustomResponseHandler((r, c) => Task.FromResult(new HttpResponseMessage()))))
31+
{
32+
verify(await client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])));
33+
verify(await client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1]), CancellationToken.None));
34+
}
35+
}
36+
37+
[Fact]
38+
public void Dispose_UsePatchAfterDispose_Throws()
39+
{
40+
HttpClient client = CreateHttpClient();
41+
client.Dispose();
42+
43+
Assert.Throws<ObjectDisposedException>(() => { client.PatchAsync(CreateFakeUri(), new ByteArrayContent(new byte[1])); });
44+
}
45+
}
46+
}

src/System.Net.Http/tests/FunctionalTests/HttpMethodTest.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@
1111

1212
namespace System.Net.Http.Functional.Tests
1313
{
14-
public class HttpMethodTest
14+
public partial class HttpMethodTest
1515
{
16-
private static readonly object[][] s_staticHttpMethods =
16+
public static IEnumerable<object[]> StaticHttpMethods { get; }
17+
18+
static HttpMethodTest()
1719
{
18-
new object[] { HttpMethod.Get },
19-
new object[] { HttpMethod.Put },
20-
new object[] { HttpMethod.Post },
21-
new object[] { HttpMethod.Delete },
22-
new object[] { HttpMethod.Head },
23-
new object[] { HttpMethod.Options },
24-
new object[] { HttpMethod.Trace },
25-
new object[] { HttpMethod.Patch }
26-
};
27-
28-
public static IEnumerable<object[]> StaticHttpMethods { get { return s_staticHttpMethods; } }
20+
List<object[]> staticHttpMethods = new List<object[]>
21+
{
22+
new object[] { HttpMethod.Get },
23+
new object[] { HttpMethod.Put },
24+
new object[] { HttpMethod.Post },
25+
new object[] { HttpMethod.Delete },
26+
new object[] { HttpMethod.Head },
27+
new object[] { HttpMethod.Options },
28+
new object[] { HttpMethod.Trace }
29+
};
30+
AddStaticHttpMethods(staticHttpMethods);
31+
StaticHttpMethods = staticHttpMethods;
32+
}
33+
34+
static partial void AddStaticHttpMethods(List<object[]> staticHttpMethods);
2935

3036
[Fact]
3137
public void StaticProperties_VerifyValues_PropertyNameMatchesHttpMethodName()
@@ -37,7 +43,6 @@ public void StaticProperties_VerifyValues_PropertyNameMatchesHttpMethodName()
3743
Assert.Equal("HEAD", HttpMethod.Head.Method);
3844
Assert.Equal("OPTIONS", HttpMethod.Options.Method);
3945
Assert.Equal("TRACE", HttpMethod.Trace.Method);
40-
Assert.Equal("PATCH", HttpMethod.Patch.Method);
4146
}
4247

4348
[Fact]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
3+
using Xunit;
4+
5+
namespace System.Net.Http.Functional.Tests
6+
{
7+
public partial class HttpMethodTest
8+
{
9+
[Fact]
10+
public void Patch_VerifyValue_PropertyNameMatchesHttpMethodName()
11+
{
12+
Assert.Equal("PATCH", HttpMethod.Patch.Method);
13+
}
14+
15+
static partial void AddStaticHttpMethods(List<object[]> staticHttpMethods)
16+
{
17+
staticHttpMethods.Add(new object[] { HttpMethod.Patch });
18+
}
19+
}
20+
}

src/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
<Compile Include="ManagedHandlerTest.cs" />
114114
<Compile Include="HttpClientHandlerTest.AcceptAllCerts.cs" />
115115
<Compile Include="ReadOnlyMemoryContentTest.cs" />
116+
<Compile Include="HttpClientTest.netcoreapp.cs" />
117+
<Compile Include="HttpMethodTest.netcoreapp.cs" />
116118
</ItemGroup>
117119
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard'">
118120
<Compile Include="$(CommonTestPath)\System\IO\StreamSpanExtensions.netstandard.cs">

0 commit comments

Comments
 (0)