Skip to content

Commit

Permalink
Updated parameter to optional (expected).
Browse files Browse the repository at this point in the history
  • Loading branch information
electricessence committed Jan 14, 2020
1 parent 730a7f1 commit 80901fc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal JsonSerializerInternal GetSerializerInternal(IJsonSerializationOptions?
public IJsonSerializer GetSerializer(IJsonSerializationOptions? options = null, bool caseSensitive = false)
=> GetSerializerInternal(options, caseSensitive);

public IJsonObjectSerializer GetObjectSerializer(IJsonSerializationOptions? options, bool caseSensitive = false)
public IJsonObjectSerializer GetObjectSerializer(IJsonSerializationOptions? options = null, bool caseSensitive = false)
=> GetSerializerInternal(options, caseSensitive);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<RepositoryUrl>https://github.com/electricessence/Open.Serialization</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>serialization json newtonsoft</PackageTags>
<Version>2.2.2</Version>
<Version>2.2.3</Version>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Open.Serialization.Json.Utf8Json/JsonSerializerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal JsonSerializerInternal GetSerializerInternal(IJsonSerializationOptions?
public IJsonSerializer GetSerializer(IJsonSerializationOptions? options = null, bool caseSensitive = false)
=> GetSerializerInternal(options, caseSensitive);

public IJsonObjectSerializer GetObjectSerializer(IJsonSerializationOptions? options, bool caseSensitive = false)
public IJsonObjectSerializer GetObjectSerializer(IJsonSerializationOptions? options = null, bool caseSensitive = false)
=> GetSerializerInternal(options, caseSensitive);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Part of the "Open" set of libraries.
<RepositoryUrl>https://github.com/electricessence/Open.Serialization</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>serialization json utf8json</PackageTags>
<Version>2.2.2</Version>
<Version>2.2.3</Version>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
59 changes: 43 additions & 16 deletions Open.Serialization.Tests/ParityTests.cs
Original file line number Diff line number Diff line change
@@ -1,48 +1,75 @@
using Open.Serialization.Json;
using Open.Serialization.Json.Utf8Json;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Xunit;

namespace Open.Serialization.Tests
{
public static class ParityTests
{
[Fact]
public static void EnsureBasicParity()
public static async Task EnsureBasicParity()
{
{
var newtonsoftFactory = new Json.Newtonsoft.JsonSerializerFactory(Json.Newtonsoft.CamelCaseJson.Minimal(true));
var systemFactory = new Json.System.JsonSerializerFactory(Json.System.CamelCaseJson.Minimal(true));

CompareFactories(newtonsoftFactory, systemFactory);
await CompareFactories(newtonsoftFactory, systemFactory);
}

{
var newtonsoftFactory = new Json.Newtonsoft.JsonSerializerFactory(Json.Newtonsoft.CamelCaseJson.Minimal(true));
var systemFactory = new JsonSerializerFactory(Utf8Json.Resolvers.StandardResolver.ExcludeNullCamelCase, true);
var newtonsoftFactory = new Json.Newtonsoft.JsonSerializerFactory();
var systemFactory = new Json.System.JsonSerializerFactory();

CompareFactories(newtonsoftFactory, systemFactory);
await CompareFactories(newtonsoftFactory, systemFactory);
}

{
var newtonsoftFactory = new Json.Newtonsoft.JsonSerializerFactory();
var systemFactory = new Json.System.JsonSerializerFactory();
var newtonsoftFactory = new Json.Newtonsoft.JsonSerializerFactory(Json.Newtonsoft.CamelCaseJson.Minimal(true));
var utf8JsonFactory = new Json.Utf8Json.JsonSerializerFactory(Utf8Json.Resolvers.StandardResolver.ExcludeNullCamelCase, true);

await CompareFactories(newtonsoftFactory, utf8JsonFactory);

CompareFactories(newtonsoftFactory, systemFactory);
var ns = newtonsoftFactory.GetObjectSerializer();
var utf8 = utf8JsonFactory.GetObjectSerializer();

var instance = SampleModel.Instance;
var type = SampleModel.Instance.GetType();
var expected = ns.Serialize(instance, type);
var actual = utf8.Serialize(instance, type);
if (Debugger.IsAttached) Debug.Assert(expected == actual);
Assert.Equal(expected, actual);
}
}

static void CompareFactories(IJsonSerializerFactory expectedFactory, IJsonSerializerFactory actualFactory)
static async ValueTask CompareFactories(IJsonSerializerFactory expectedFactory, IJsonSerializerFactory actualFactory)
{
var expectedSerializer = expectedFactory.GetSerializer();
var actualSerializer = actualFactory.GetSerializer();

Assert.Equal(expectedSerializer.Serialize(SampleModel.Instance), actualSerializer.Serialize(SampleModel.Instance));
Assert.Equal(expectedSerializer.Serialize(SampleModel.DecimalList), actualSerializer.Serialize(SampleModel.DecimalList));
Assert.Equal(expectedSerializer.Serialize(SampleModel.DecimalLookup), actualSerializer.Serialize(SampleModel.DecimalLookup));
Assert.Equal(expectedSerializer.Serialize(SampleModel.DoubleLookup), actualSerializer.Serialize(SampleModel.DoubleLookup));

await CompareSerializer(SampleModel.Instance);
await CompareSerializer(SampleModel.DecimalList);
await CompareSerializer(SampleModel.DecimalLookup);
await CompareSerializer(SampleModel.DoubleLookup);
expectedFactory.GetSerializer().Deserialize<SampleModel>(actualSerializer.Serialize(SampleModel.Instance));
actualFactory.GetSerializer().Deserialize<SampleModel>(expectedSerializer.Serialize(SampleModel.Instance));

async ValueTask CompareSerializer<T>(T instance)
{
var expected = expectedSerializer.Serialize(instance);
var actual = actualSerializer.Serialize(instance);
if (Debugger.IsAttached) Debug.Assert(expected == actual);
Assert.Equal(expected, actual);

using var stream = new MemoryStream();
await actualSerializer.SerializeAsync(stream, instance);

stream.Position = 0;
var result = await actualSerializer.DeserializeAsync<T>(stream);
var actualAsync = actualSerializer.Serialize(result);
if (Debugger.IsAttached) Debug.Assert(expected == actualAsync);
Assert.Equal(expected, actual);
}
}
}
}

0 comments on commit 80901fc

Please sign in to comment.