-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated parameter to optional (expected).
- Loading branch information
1 parent
730a7f1
commit 80901fc
Showing
5 changed files
with
47 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |