Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Fixing Functional test project
Browse files Browse the repository at this point in the history
  • Loading branch information
joperezr committed Mar 25, 2020
1 parent 43143ca commit 13ab13b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 91 deletions.
32 changes: 16 additions & 16 deletions src/System.Net.Http.Json/System.Net.Http.Json.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Release|Any CPU.Build.0 = Release|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Release|Any CPU.Build.0 = Release|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Release|Any CPU.Build.0 = Release|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Release|Any CPU.Build.0 = Release|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{1D422B1D-D7C4-41B9-862D-EB3D98DF37DE}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
{132BF813-FC40-4D39-8B6F-E55D7633F0ED}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Debug|Any CPU.ActiveCfg = netfx-Debug|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Debug|Any CPU.Build.0 = netfx-Debug|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{DC607A29-7C8D-4933-9AEB-23CF696B2BC6}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Debug|Any CPU.ActiveCfg = netfx-Debug|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Debug|Any CPU.Build.0 = netfx-Debug|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{54A8AEE1-BEF2-454A-B1A1-548D73F25F0E}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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.Net.Http.Headers;
using System.Net.Test.Common;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;

namespace System.Net.Http.Json.Functional.Tests
{
public partial class JsonContentTests
{
[Fact]
public async Task JsonContentMediaTypeValidateOnServerAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
using (HttpClient client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("foo/bar; charset=utf-8");
request.Content = JsonContent.Create(Person.Create(), mediaType: mediaType);
await client.SendAsync(request);
}
},
async server => {
HttpRequestData req = await server.HandleRequestAsync();
Assert.Equal("foo/bar; charset=utf-8", req.GetSingleHeaderValue("Content-Type"));
});
}

[Fact]
public static async Task ValidateUtf16IsTranscodedAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
using (HttpClient client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("application/json; charset=utf-16");
// Pass new options to avoid using the Default Web Options that use camelCase.
request.Content = JsonContent.Create(Person.Create(), mediaType: mediaType, options: new JsonSerializerOptions());
await client.SendAsync(request);
}
},
async server => {
HttpRequestData req = await server.HandleRequestAsync();
Assert.Equal("application/json; charset=utf-16", req.GetSingleHeaderValue("Content-Type"));
Person per = JsonSerializer.Deserialize<Person>(Encoding.Unicode.GetString(req.Body));
per.Validate();
});
}

[Fact]
public async Task TestJsonContentNullContentTypeAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
using (HttpClient client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("application/json; charset=utf-16");
JsonContent content = JsonContent.Create(Person.Create(), mediaType: mediaType);
content.Headers.ContentType = null;
request.Content = content;
await client.SendAsync(request);
}
},
async server => {
HttpRequestData req = await server.HandleRequestAsync();
Assert.Equal(0, req.GetHeaderValueCount("Content-Type"));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace System.Net.Http.Json.Functional.Tests
{
public class JsonContentTests
public partial class JsonContentTests
{

private class Foo { }
Expand Down Expand Up @@ -92,26 +92,6 @@ public void TestJsonContentContentTypeIsNotTheSameOnMultipleInstances()
Assert.NotSame(jsonContent1.Headers.ContentType, jsonContent2.Headers.ContentType);
}

[Fact]
public async Task JsonContentMediaTypeValidateOnServerAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
using (HttpClient client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("foo/bar; charset=utf-8");
request.Content = JsonContent.Create(Person.Create(), mediaType: mediaType);
await client.SendAsync(request);
}
},
async server => {
HttpRequestData req = await server.HandleRequestAsync();
Assert.Equal("foo/bar; charset=utf-8", req.GetSingleHeaderValue("Content-Type"));
});
}

[Fact]
public void JsonContentMediaTypeDefaultIfNull()
{
Expand Down Expand Up @@ -152,29 +132,6 @@ public void JsonContentThrowsOnIncompatibleTypeAsync()
Assert.Contains(afterInputTypeMessage, ex.Message);
}

[Fact]
public static async Task ValidateUtf16IsTranscodedAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
using (HttpClient client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("application/json; charset=utf-16");
// Pass new options to avoid using the Default Web Options that use camelCase.
request.Content = JsonContent.Create(Person.Create(), mediaType: mediaType, options: new JsonSerializerOptions());
await client.SendAsync(request);
}
},
async server => {
HttpRequestData req = await server.HandleRequestAsync();
Assert.Equal("application/json; charset=utf-16", req.GetSingleHeaderValue("Content-Type"));
Person per = JsonSerializer.Deserialize<Person>(Encoding.Unicode.GetString(req.Body));
per.Validate();
});
}

[Fact]
public async Task EnsureDefaultJsonSerializerOptionsAsync()
{
Expand All @@ -185,28 +142,5 @@ public async Task EnsureDefaultJsonSerializerOptionsAsync()
request.Content = JsonContent.Create(obj);
await client.SendAsync(request);
}

[Fact]
public async Task TestJsonContentNullContentTypeAsync()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
using (HttpClient client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
MediaTypeHeaderValue mediaType = MediaTypeHeaderValue.Parse("application/json; charset=utf-16");
JsonContent content = JsonContent.Create(Person.Create(), mediaType: mediaType);
content.Headers.ContentType = null;
request.Content = content;
await client.SendAsync(request);
}
},
async server => {
HttpRequestData req = await server.HandleRequestAsync();
Assert.Equal(0, req.GetHeaderValueCount("Content-Type"));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
<Configurations>netcoreapp-Debug;netcoreapp-Release;netfx-Debug;netfx-Release</Configurations>
</PropertyGroup>
<ItemGroup>
<Compile Include="HttpClientJsonExtensionsTests.cs" />
<Compile Include="HttpContentJsonExtensionsTests.cs" />
<Compile Include="JsonContentTests.cs" />
<Compile Include="TestClasses.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<Compile Include="JsonContentLoopbackTests.cs" />
<Compile Include="HttpClientJsonExtensionsTests.cs" />
<Compile Include="HttpContentJsonExtensionsTests.cs" />
<Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackServer.cs">
<Link>Common\System\Net\Http\LoopbackServer.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackServer.AuthenticationHelpers.cs">
<Link>Common\System\Net\Http\LoopbackServer.AuthenticationHelpers.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)\System\Net\Capability.Security.cs">
<Link>Common\System\Net\Capability.Security.cs</Link>
Expand All @@ -24,12 +33,6 @@
<Compile Include="$(CommonTestPath)\System\Net\Configuration.Security.cs">
<Link>Common\System\Net\Configuration.Security.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackServer.cs">
<Link>Common\System\Net\Http\LoopbackServer.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Http\LoopbackServer.AuthenticationHelpers.cs">
<Link>Common\System\Net\Http\LoopbackServer.AuthenticationHelpers.cs</Link>
</Compile>
<Compile Include="$(CommonTestPath)\System\Net\Http\GenericLoopbackServer.cs">
<Link>Common\System\Net\Http\GenericLoopbackServer.cs</Link>
</Compile>
Expand Down

0 comments on commit 13ab13b

Please sign in to comment.