Skip to content

Commit

Permalink
Merge pull request #158 from JakeGinnivan/pr156
Browse files Browse the repository at this point in the history
Continuation with updates of PR 156
  • Loading branch information
panmanphil committed Oct 22, 2020
2 parents a6e9aa1 + b1ccf16 commit a0ce8fc
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 85 deletions.
4 changes: 2 additions & 2 deletions WebApi.Hal.Build/WebApi.Hal.Commons.props
Expand Up @@ -6,9 +6,9 @@

<Company>Jake Ginnivan</Company>
<Description>Enabled Hypermedia support in Asp.net Web API using the HAL mediatype</Description>
<Copyright>Copyright © Jake Ginnvan 2012</Copyright>
<Copyright>Copyright © Jake Ginnvan 2020</Copyright>
<PackageProjectUrl>https://github.com/JakeGinnivan/WebApi.Hal</PackageProjectUrl>
<PackageLicenseUrl>$(PackageProjectUrl)/blob/master/LICENSE.md</PackageLicenseUrl>
<PackageLicense>$(PackageProjectUrl)/blob/master/LICENSE.md</PackageLicense>
<PackageReleaseNotes>$(PackageProjectUrl)/releases</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>

Expand Down
7 changes: 4 additions & 3 deletions WebApi.Hal.Tests/HalResourceListTests.cs
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Net.Http;
using Assent;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WebApi.Hal.Tests.Representations;
using Xunit;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void organisation_list_get_json_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());

// act
using (var stream = new StringWriter())
Expand All @@ -73,7 +74,7 @@ public void one_item_organisation_list_get_json_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());
var content = new StringContent(string.Empty);
var type = oneitemrepresentation.GetType();

Expand All @@ -89,4 +90,4 @@ public void one_item_organisation_list_get_json_test()
}
}
}
}
}
31 changes: 11 additions & 20 deletions WebApi.Hal.Tests/HalResourceMixedContentTest.cs
Expand Up @@ -7,9 +7,7 @@
using Assent;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.ObjectPool;
using Newtonsoft.Json;
Expand Down Expand Up @@ -41,7 +39,7 @@ public void peopledetail_get_json_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());

// act
using (var stream = new StringWriter())
Expand Down Expand Up @@ -71,7 +69,7 @@ public void peopledetail_non_empty_resource_list_get_json_test()
};

var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());

// act
using (var stream = new StringWriter())
Expand All @@ -96,7 +94,7 @@ public void peopledetail_empty_resource_list_get_json_test()
};

var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());

// act
using (var stream = new StringWriter())
Expand Down Expand Up @@ -137,7 +135,7 @@ public async Task peopledetail_post_json_props_test()
new JsonSerializerSettings { Formatting = Formatting.Indented },
ArrayPool<char>.Shared,
new DefaultObjectPoolProvider(),
new MvcOptions(), new MvcJsonOptions());
new MvcOptions(), new MvcNewtonsoftJsonOptions());

var type = typeof(OrganisationWithPeopleDetailRepresentation);
const string json = @"
Expand Down Expand Up @@ -181,7 +179,7 @@ public async Task peopledetail_post_json_links_test()
ArrayPool<char>.Shared,
new DefaultObjectPoolProvider(),
new MvcOptions(),
new MvcJsonOptions());
new MvcNewtonsoftJsonOptions());

var type = typeof(OrganisationWithPeopleRepresentation);
const string json = @"
Expand Down Expand Up @@ -243,7 +241,7 @@ public async Task peopledetail_post_json_embedded_singles_test()
ArrayPool<char>.Shared,
new DefaultObjectPoolProvider(),
new MvcOptions(),
new MvcJsonOptions());
new MvcNewtonsoftJsonOptions());

var type = typeof(OrganisationWithPeopleDetailRepresentation);
const string json = @"
Expand Down Expand Up @@ -294,7 +292,7 @@ public async Task peopledetail_post_json_embedded_arrays_test()
ArrayPool<char>.Shared,
new DefaultObjectPoolProvider(),
new MvcOptions(),
new MvcJsonOptions());
new MvcNewtonsoftJsonOptions());

var type = typeof(OrganisationWithPeopleDetailRepresentation);
const string json = @"
Expand Down Expand Up @@ -349,7 +347,7 @@ public async Task peopledetail_post_json_embedded_null_test()
ArrayPool<char>.Shared,
new DefaultObjectPoolProvider(),
new MvcOptions(),
new MvcJsonOptions());
new MvcNewtonsoftJsonOptions());

var type = typeof(OrganisationWithPeopleDetailRepresentation);
const string json = @"
Expand Down Expand Up @@ -402,7 +400,7 @@ public async Task simplelist_post_json_test()
ArrayPool<char>.Shared,
new DefaultObjectPoolProvider(),
new MvcOptions(),
new MvcJsonOptions());
new MvcNewtonsoftJsonOptions());

var type = typeof(MySimpleList);
const string json = @"
Expand Down Expand Up @@ -448,16 +446,9 @@ public async Task simplelist_post_json_test()
}
}

public static IModelMetadataProvider CreateDefaultProvider()
public static ModelMetadataProvider CreateDefaultProvider()
{
var detailsProviders = new IMetadataDetailsProvider[]
{
new DefaultBindingMetadataProvider(),
new DefaultValidationMetadataProvider()
};

var compositeDetailsProvider = new DefaultCompositeMetadataDetailsProvider(detailsProviders);
return new DefaultModelMetadataProvider(compositeDetailsProvider);
return new EmptyModelMetadataProvider();
}
}
}
11 changes: 6 additions & 5 deletions WebApi.Hal.Tests/HalResourceTest.cs
@@ -1,6 +1,7 @@
using System.Buffers;
using System.IO;
using Assent;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WebApi.Hal.Tests.Representations;
using Xunit;
Expand All @@ -21,7 +22,7 @@ public void organisation_get_json_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());

// act
using (var stream = new StringWriter())
Expand All @@ -40,7 +41,7 @@ public void organisation_get_json_with_app_path_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());
var resourceWithAppPath = new OrganisationWithAppPathRepresentation(1, "Org Name");

// act
Expand All @@ -60,7 +61,7 @@ public void organisation_get_json_with_no_href_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());
var resourceWithAppPath = new OrganisationWithNoHrefRepresentation(1, "Org Name");

// act
Expand All @@ -80,7 +81,7 @@ public void organisation_get_json_with_link_title_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());
var resourceWithAppPath = new OrganisationWithLinkTitleRepresentation(1, "Org Name");

// act
Expand Down Expand Up @@ -113,4 +114,4 @@ public void organisation_get_xml_test()
}
}
}
}
}
5 changes: 3 additions & 2 deletions WebApi.Hal.Tests/HalResourceWithPeopleTest.cs
@@ -1,6 +1,7 @@
using System.Buffers;
using System.IO;
using Assent;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WebApi.Hal.Tests.Representations;
using Xunit;
Expand All @@ -21,7 +22,7 @@ public void organisation_get_json_test()
{
// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions());

// act
using (var stream = new StringWriter())
Expand Down Expand Up @@ -53,4 +54,4 @@ public void organisation_get_xml_test()
}
}
}
}
}
3 changes: 2 additions & 1 deletion WebApi.Hal.Tests/HypermediaContainerTests.cs
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using Assent;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WebApi.Hal.Tests.HypermediaAppenders;
using WebApi.Hal.Tests.Representations;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void CanUseRegisterExtensionMethod()

// arrange
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, config);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions(), config);

// act
using (var stream = new StringWriter())
Expand Down
7 changes: 4 additions & 3 deletions WebApi.Hal.Tests/ResolvingHalResourceTest.cs
@@ -1,6 +1,7 @@
using System.Buffers;
using System.IO;
using Assent;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WebApi.Hal.Tests.HypermediaAppenders;
using WebApi.Hal.Tests.Representations;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void ProperlySerializesRepresentationToJson()

var config = builder.Build();
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, config);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions(), config);

// act
using (var stream = new StringWriter())
Expand All @@ -72,7 +73,7 @@ public void ProperlySerializesRepresentationWithoutLinksToJson()
var builder = Hypermedia.CreateBuilder();
var config = builder.Build();
var mediaFormatter = new JsonHalMediaTypeOutputFormatter(
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, config);
new JsonSerializerSettings { Formatting = Formatting.Indented }, ArrayPool<char>.Shared, new MvcOptions(), config);

// act
using (var stream = new StringWriter())
Expand All @@ -86,4 +87,4 @@ public void ProperlySerializesRepresentationWithoutLinksToJson()
}
}
}
}
}
12 changes: 6 additions & 6 deletions WebApi.Hal.Tests/WebApi.Hal.Tests.csproj
Expand Up @@ -3,19 +3,19 @@
<Import Project=".\..\WebApi.Hal.Build\WebApi.Hal.Commons.props" />

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.0-pre-1</Version>
<Authors>Jake Ginnivan, DotNetMedia Organizaion</Authors>
<Copyright>Copyright © Jake Ginnvan 2017</Copyright>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Assent" Version="1.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0">
<PackageReference Include="Assent" Version="1.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.9" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions WebApi.Hal.Web/FormattersMvcOptionsSetup.cs
Expand Up @@ -14,11 +14,11 @@ public class FormattersMvcOptionsSetup : IConfigureOptions<MvcOptions>
private readonly JsonSerializerSettings _jsonSerializerSettings;
private readonly ArrayPool<char> _charPool;
private readonly ObjectPoolProvider _objectPoolProvider;
private readonly MvcJsonOptions _mvcJsonOptions;
private readonly MvcNewtonsoftJsonOptions _mvcJsonOptions;

public FormattersMvcOptionsSetup(
ILoggerFactory loggerFactory,
IOptions<MvcJsonOptions> jsonOptions,
IOptions<MvcNewtonsoftJsonOptions> jsonOptions,
ArrayPool<char> charPool,
ObjectPoolProvider objectPoolProvider)
{
Expand All @@ -37,7 +37,7 @@ public class FormattersMvcOptionsSetup : IConfigureOptions<MvcOptions>
public void Configure(MvcOptions options)
{
options.OutputFormatters.Add(new XmlHalMediaTypeOutputFormatter());
options.OutputFormatters.Add(new JsonHalMediaTypeOutputFormatter(_jsonSerializerSettings, _charPool));
options.OutputFormatters.Add(new JsonHalMediaTypeOutputFormatter(_jsonSerializerSettings, _charPool, options));

// Register JsonPatchInputFormatter before JsonInputFormatter, otherwise
// JsonInputFormatter would consume "application/json-patch+json" requests
Expand Down

0 comments on commit a0ce8fc

Please sign in to comment.