-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from pfpack/release/v3.0.0
release/v3.0.0
- Loading branch information
Showing
10 changed files
with
217 additions
and
76 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
65 changes: 0 additions & 65 deletions
65
.../Unit.Tests/UnitSerializationTests/UnitSerializationTests.DeserializeSimpleValueToUnit.cs
This file was deleted.
Oops, something went wrong.
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
85 changes: 85 additions & 0 deletions
85
...e-unit/Unit.Tests/UnitSerializationTests/UnitSerializationTests.DeserializeValueToUnit.cs
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class UnitSerializationTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(DeserializeValueToUnit_ExpectNoException_Cases))] | ||
public static void DeserializeValueToUnitFromString_ExpectNoException( | ||
JsonValue source, | ||
JsonSerializerOptions? options) | ||
{ | ||
var sourceString = JsonSerializer.Serialize(source); | ||
_ = JsonSerializer.Deserialize<Unit>(sourceString, options); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(DeserializeValueToUnit_ExpectNoException_Cases))] | ||
public static void DeserializeValueToUnitFromObject_ExpectNoException( | ||
JsonValue source, | ||
JsonSerializerOptions? options) | ||
{ | ||
_ = JsonSerializer.Deserialize<Unit>(source, options); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(DeserializeValueToUnit_ExpectNoException_Cases))] | ||
public static void DeserializeDtoWithValueToDtoWithUnitFromString_ExpectNoException( | ||
JsonValue source, | ||
JsonSerializerOptions? options) | ||
{ | ||
var sourceString = JsonSerializer.Serialize(BuildDtoWithValueNode(source)); | ||
_ = JsonSerializer.Deserialize<DtoWithUnit>(sourceString, options); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(DeserializeValueToUnit_ExpectNoException_Cases))] | ||
public static void DeserializeDtoWithValueToDtoWithUnitFromObject_ExpectNoException( | ||
JsonValue source, | ||
JsonSerializerOptions? options) | ||
{ | ||
_ = JsonSerializer.Deserialize<DtoWithUnit>(BuildDtoWithValueNode(source), options); | ||
} | ||
|
||
public static TheoryData<JsonValue, JsonSerializerOptions?> DeserializeValueToUnit_ExpectNoException_Cases | ||
{ | ||
get | ||
{ | ||
var result = new TheoryData<JsonValue, JsonSerializerOptions?>(); | ||
|
||
foreach (var value in EnumerateValues()) | ||
{ | ||
foreach (var options in EnumerateJsonSerializerOptionsCases()) | ||
{ | ||
result.Add(value, options); | ||
} | ||
} | ||
|
||
return result; | ||
|
||
static IEnumerable<JsonValue> EnumerateValues() | ||
{ | ||
yield return JsonValue.Create(true); | ||
yield return JsonValue.Create(false); | ||
|
||
yield return JsonValue.Create(int.MinValue); | ||
yield return JsonValue.Create(-1); | ||
yield return JsonValue.Create(0); | ||
yield return JsonValue.Create(1.1m); | ||
yield return JsonValue.Create(1.2); | ||
yield return JsonValue.Create(int.MaxValue); | ||
|
||
yield return JsonValue.Create(double.MinValue); | ||
yield return JsonValue.Create(double.MaxValue); | ||
|
||
yield return JsonValue.Create(""); | ||
yield return JsonValue.Create("1"); | ||
yield return JsonValue.Create("0AFB2897-BA58-4E10-A083-4C33341B6238"); | ||
} | ||
} | ||
} | ||
} |
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
41 changes: 38 additions & 3 deletions
41
src/core-unit/Unit.Tests/UnitSerializationTests/UnitSerializationTests.cs
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,20 +1,55 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
public static partial class UnitSerializationTests | ||
{ | ||
private const string ValueName = "value"; | ||
|
||
public static TheoryData<JsonSerializerOptions?> JsonSerializerOptionsCases | ||
=> | ||
new(BuildJsonSerializerOptionsCollection().ToArray()); | ||
new(EnumerateJsonSerializerOptionsCases().ToArray()); | ||
|
||
private static IEnumerable<JsonSerializerOptions?> BuildJsonSerializerOptionsCollection() | ||
private static IEnumerable<JsonSerializerOptions?> EnumerateJsonSerializerOptionsCases() | ||
{ | ||
yield return null; | ||
yield return JsonSerializerOptions.Default; | ||
yield return new(JsonSerializerDefaults.General); | ||
yield return new(JsonSerializerDefaults.Web); | ||
} | ||
|
||
private static JsonObject BuildDtoWithUnitValueNode() | ||
=> | ||
new() { [ValueName] = new JsonObject() }; | ||
|
||
private static JsonObject BuildDtoWithNullValueNode() | ||
=> | ||
new() { [ValueName] = null }; | ||
|
||
private static JsonObject BuildDtoWithValueNode(JsonObject value) | ||
=> | ||
InnerBuildDtoWithValueNode(value); | ||
|
||
private static JsonObject BuildDtoWithValueNode(JsonArray value) | ||
=> | ||
InnerBuildDtoWithValueNode(value); | ||
|
||
private static JsonObject BuildDtoWithValueNode(JsonValue value) | ||
=> | ||
InnerBuildDtoWithValueNode(value); | ||
|
||
private static JsonObject InnerBuildDtoWithValueNode(JsonNode value) | ||
=> | ||
new() { [ValueName] = value.DeepClone() }; | ||
|
||
private sealed record DtoWithUnit | ||
{ | ||
[JsonPropertyName(ValueName)] | ||
public Unit Value { get; init; } | ||
} | ||
} |
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