Skip to content

Commit

Permalink
Merge pull request #28 from pfpack/release/v3.0.0
Browse files Browse the repository at this point in the history
release/v3.0.0
  • Loading branch information
andreise authored Jun 8, 2024
2 parents ae359c1 + 20c41b3 commit 17881de
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/core-unit/Unit.Tests/Unit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn);xUnit1044</NoWarn>
<NoWarn>$(NoWarn);xUnit1044;xUnit1045</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ public static void DeserializeArrayToUnitFromObject_ExpectNoException(
_ = JsonSerializer.Deserialize<Unit>(source, options);
}

[Theory]
[MemberData(nameof(DeserializeArrayToUnit_ExpectNoException_Cases))]
public static void DeserializeDtoWithArrayToDtoWithUnitFromString_ExpectNoException(
JsonArray source,
JsonSerializerOptions? options)
{
var sourceString = JsonSerializer.Serialize(BuildDtoWithValueNode(source));
_ = JsonSerializer.Deserialize<DtoWithUnit>(sourceString, options);
}

[Theory]
[MemberData(nameof(DeserializeArrayToUnit_ExpectNoException_Cases))]
public static void DeserializeDtoWithArrayToDtoWithUnitFromObject_ExpectNoException(
JsonArray source,
JsonSerializerOptions? options)
{
_ = JsonSerializer.Deserialize<DtoWithUnit>(BuildDtoWithValueNode(source), options);
}

public static TheoryData<JsonArray, JsonSerializerOptions?> DeserializeArrayToUnit_ExpectNoException_Cases
{
get
Expand All @@ -39,7 +58,7 @@ public static void DeserializeArrayToUnitFromObject_ExpectNoException(

foreach (var array in arrays)
{
foreach (var options in BuildJsonSerializerOptionsCollection())
foreach (var options in EnumerateJsonSerializerOptionsCases())
{
result.Add(array, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ public static void DeserializeNonEmptyObjectToUnitFromObject_ExpectNoException(
_ = JsonSerializer.Deserialize<Unit>(source, options);
}

[Theory]
[MemberData(nameof(DeserializeNonEmptyObjectToUnit_ExpectNoException_Cases))]
public static void DeserializeDtoWithNonEmptyObjectToDtoWithUnitFromString_ExpectNoException(
JsonObject source,
JsonSerializerOptions? options)
{
var sourceString = JsonSerializer.Serialize(BuildDtoWithValueNode(source));
_ = JsonSerializer.Deserialize<DtoWithUnit>(sourceString, options);
}

[Theory]
[MemberData(nameof(DeserializeNonEmptyObjectToUnit_ExpectNoException_Cases))]
public static void DeserializeDtoWithNonEmptyObjectToDtoWithUnitFromObject_ExpectNoException(
JsonObject source,
JsonSerializerOptions? options)
{
_ = JsonSerializer.Deserialize<DtoWithUnit>(BuildDtoWithValueNode(source), options);
}

public static TheoryData<JsonObject, JsonSerializerOptions?> DeserializeNonEmptyObjectToUnit_ExpectNoException_Cases
{
get
Expand Down Expand Up @@ -58,7 +77,7 @@ public static void DeserializeNonEmptyObjectToUnitFromObject_ExpectNoException(

foreach (var obj in objects)
{
foreach (var options in BuildJsonSerializerOptionsCollection())
foreach (var options in EnumerateJsonSerializerOptionsCases())
{
result.Add(obj, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ partial class UnitSerializationTests
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void DeserializeNullToUnitFromString_ExpectNoException(JsonSerializerOptions? options)
{
var source = JsonSerializer.Serialize<JsonNode?>(null);
_ = JsonSerializer.Deserialize<Unit>(source, options);
var sourceString = JsonSerializer.Serialize<JsonNode?>(null);
_ = JsonSerializer.Deserialize<Unit>(sourceString, options);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void DeserializeNullToUnitFromNode_ExpectNoException(JsonSerializerOptions? options)
{
JsonNode? source = null;
_ = JsonSerializer.Deserialize<Unit>(source, options);
_ = JsonSerializer.Deserialize<Unit>((JsonNode?)null, options);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void DeserializeDtoWithNullToDtoWithUnitFromString_ExpectNoException(JsonSerializerOptions? options)
{
var sourceString = JsonSerializer.Serialize<JsonNode?>(BuildDtoWithNullValueNode());
_ = JsonSerializer.Deserialize<DtoWithUnit>(sourceString, options);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void DeserializeDtoWithNullToDtoWithUnitFromNode_ExpectNoException(JsonSerializerOptions? options)
{
_ = JsonSerializer.Deserialize<DtoWithUnit>(BuildDtoWithNullValueNode(), options);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,20 @@ public static void DeserializeUnitFromNode_ExpectNoException(JsonSerializerOptio
var source = new JsonObject();
_ = JsonSerializer.Deserialize<Unit>(source, options);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void DeserializeDtoWithUnitFromString_ExpectNoException(JsonSerializerOptions? options)
{
var source = JsonSerializer.Serialize(BuildDtoWithUnitValueNode()); // default options expected
_ = JsonSerializer.Deserialize<DtoWithUnit>(source, options);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void DeserializeDtoWithUnitFromNode_ExpectNoException(JsonSerializerOptions? options)
{
var source = BuildDtoWithUnitValueNode();
_ = JsonSerializer.Deserialize<DtoWithUnit>(source, options);
}
}
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");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ public static void SerializeUnitToNode_ExpectEmptyJsonObject(JsonSerializerOptio
var expected = new JsonObject();
Assert.Equal(expected, actual);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void SerializeDtoWithUnitToString_ExpectEmptyJsonObject(JsonSerializerOptions? options)
{
var actual = JsonSerializer.Serialize(new DtoWithUnit(), options);
var expected = JsonSerializer.Serialize(BuildDtoWithUnitValueNode()); // default options expected
Assert.Equal(expected, actual);
}

[Theory]
[MemberData(nameof(JsonSerializerOptionsCases))]
public static void SerializeDtoWithUnitToNode_ExpectEmptyJsonObject(JsonSerializerOptions? options)
{
var actual = JsonSerializer.SerializeToNode(new DtoWithUnit(), options);
var expected = BuildDtoWithUnitValueNode();
Assert.Equal(expected, actual);
}
}
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; }
}
}
2 changes: 1 addition & 1 deletion src/core-unit/Unit/Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Description>PrimeFuncPack Core.Unit is a core library for .NET consisting of Unit type targeted for use in functional programming.</Description>
<RootNamespace>System</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.Unit</AssemblyName>
<Version>3.0.0-rc.1</Version>
<Version>3.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 17881de

Please sign in to comment.