Skip to content

Commit

Permalink
v1.3.0 (#18)
Browse files Browse the repository at this point in the history
* Upgrade the NuGet packages for the unit tests to the last version.
* Remove the shortcut of .editorconfig in Directory.Build.props.
* Migrates the Azure Pipelines to GitHub actions (#17).
* Add new overrides BeJsonDeserializableInto() to test the string collections, string and numeric values (#16).
  • Loading branch information
GillesTourreau authored Jun 28, 2024
1 parent a66f8b2 commit 1c07aaf
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 96 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/github-actions-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Continuous Integration

on:
pull_request:
branches: [ "main" ]
push:
branches: [ "releases/**" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup .NET 8.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Build
run: dotnet build --property:Configuration=Debug "PosInformatique.FluentAssertions.Json.sln"

- name: Test with the dotnet CLI
run: dotnet test --property:Configuration=Debug "PosInformatique.FluentAssertions.Json.sln"
36 changes: 36 additions & 0 deletions .github/workflows/github-actions-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
workflow_dispatch:
inputs:
VersionPrefix:
type: string
description: The version of the library
required: true
default: 1.3.0
VersionSuffix:
type: string
description: The version suffix of the library (for example rc.1)

run-name: ${{ inputs.VersionPrefix }}-${{ inputs.VersionSuffix }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup .NET 8.x
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x'

- name: Build
run: dotnet pack
--property:Configuration=Release
--property:VersionPrefix=${{ github.event.inputs.VersionPrefix }}
--property:VersionSuffix=${{ github.event.inputs.VersionSuffix }}
"src/FluentAssertions.Json/FluentAssertions.Json.csproj"

- name: Publish the package to nuget.org
run: dotnet nuget push "src/FluentAssertions.Json/bin/Release/*.nupkg" --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json
4 changes: 0 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
<Link>stylecop.json</Link>
</AdditionalFiles>
</ItemGroup>

<ItemGroup>
<None Include="..\..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<!-- Common NuGet packages -->
<ItemGroup>
Expand Down
7 changes: 0 additions & 7 deletions PosInformatique.FluentAssertions.Json.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7928175B
tests\.editorconfig = tests\.editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E7CF7FC5-E257-4A28-8641-F41032340CA9}"
ProjectSection(SolutionItems) = preProject
build\azure-pipelines-ci.yaml = build\azure-pipelines-ci.yaml
build\azure-pipelines-release.yaml = build\azure-pipelines-release.yaml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -48,7 +42,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7928175B-C3B3-4F81-B956-BF4E4F816436} = {882949E5-7DCE-4EB6-8E9A-CB88FD0ED1F9}
{E7CF7FC5-E257-4A28-8641-F41032340CA9} = {882949E5-7DCE-4EB6-8E9A-CB88FD0ED1F9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0582B8EB-4FA4-488E-9953-9B7CEEE4E94F}
Expand Down
24 changes: 0 additions & 24 deletions build/azure-pipelines-ci.yaml

This file was deleted.

54 changes: 0 additions & 54 deletions build/azure-pipelines-release.yaml

This file was deleted.

6 changes: 5 additions & 1 deletion src/FluentAssertions.Json/FluentAssertions.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
<PackageProjectUrl>https://github.com/PosInformatique/PosInformatique.FluentAssertions.Json</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
1.3.0
- Add new overload BeJsonDeserializableInto() method to test the string collections.
- Add new overload BeJsonDeserializableInto() method to test the string and numeric values.

1.2.0
- Add new override BeJsonSerializableInto() method to test polymorphism serialization with discriminator JSON property.
- Add new overload BeJsonSerializableInto() method to test polymorphism serialization with discriminator JSON property.
- Add the support to assert the deserialization of root JSON array.

1.1.0
Expand Down
98 changes: 97 additions & 1 deletion src/FluentAssertions.Json/JsonFluentAssertionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace FluentAssertions
using FluentAssertions.Collections;
using FluentAssertions.Common;
using FluentAssertions.Equivalency;
using FluentAssertions.Numeric;
using FluentAssertions.Primitives;
using PosInformatique.FluentAssertions.Json;

Expand Down Expand Up @@ -105,7 +106,7 @@ public static void BeJsonDeserializableInto<T>(this ObjectAssertions assertions,
/// </summary>
/// <typeparam name="TElement">Type of the element of the collection to check the JSON deserialization.</typeparam>
/// <typeparam name="T">Type of the object to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="ObjectAssertions"/> which contains the JSON collection subject to deserialize.</param>
/// <param name="assertions"><see cref="GenericCollectionAssertions{T}"/> which contains the JSON collection subject to deserialize.</param>
/// <param name="expectedObject">Expected collection deserialized expected.</param>
/// <param name="options"><see cref="JsonSerializerOptions"/> to use to assert the deserialization. If not specified
/// the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/> of the <see cref="FluentAssertionsJson.Configuration"/>
Expand All @@ -115,6 +116,49 @@ public static void BeJsonDeserializableInto<TElement, T>(this GenericCollectionA
BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, GetSerializerOptions(options));
}

/// <summary>
/// Check if the JSON subject string collection is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
/// <typeparam name="T">Type of the object to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="StringCollectionAssertions"/> which contains the JSON string collection subject to deserialize.</param>
/// <param name="expectedObject">Expected string collection deserialized expected.</param>
/// <param name="options"><see cref="JsonSerializerOptions"/> to use to assert the deserialization. If not specified
/// the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/> of the <see cref="FluentAssertionsJson.Configuration"/>
/// will be used.</param>
public static void BeJsonDeserializableInto<T>(this StringCollectionAssertions assertions, T expectedObject, JsonSerializerOptions? options = null)
{
BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, GetSerializerOptions(options));
}

/// <summary>
/// Check if the JSON subject numeric is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
/// <typeparam name="T">Type of the object to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="NumericAssertions{T}"/> which contains the JSON numeric subject to deserialize.</param>
/// <param name="expectedObject">Expected numeric value deserialized expected.</param>
/// <param name="options"><see cref="JsonSerializerOptions"/> to use to assert the deserialization. If not specified
/// the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/> of the <see cref="FluentAssertionsJson.Configuration"/>
/// will be used.</param>
public static void BeJsonDeserializableInto<T>(this NumericAssertions<T> assertions, T expectedObject, JsonSerializerOptions? options = null)
where T : struct, IComparable<T>
{
BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, GetSerializerOptions(options));

Check warning on line 145 in src/FluentAssertions.Json/JsonFluentAssertionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'subject' in 'void JsonFluentAssertionsExtensions.BeJsonDeserializableIntoCore<T>(object subject, T expectedObject, JsonSerializerOptions options)'.
}

/// <summary>
/// Check if the JSON subject string is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
/// <typeparam name="T">Type of the object to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="StringAssertions"/> which contains the JSON string subject to deserialize.</param>
/// <param name="expectedObject">Expected string value deserialized expected.</param>
/// <param name="options"><see cref="JsonSerializerOptions"/> to use to assert the deserialization. If not specified
/// the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/> of the <see cref="FluentAssertionsJson.Configuration"/>
/// will be used.</param>
public static void BeJsonDeserializableInto<T>(this StringAssertions assertions, T expectedObject, JsonSerializerOptions? options = null)
{
BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, GetSerializerOptions(options));
}

/// <summary>
/// Check if the JSON subject object is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
Expand Down Expand Up @@ -150,6 +194,58 @@ public static void BeJsonDeserializableInto<TElement, T>(this GenericCollectionA
BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, optionsCopy);
}

/// <summary>
/// Check if the JSON subject string collection is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
/// <typeparam name="T">Type of the object to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="ObjectAssertions"/> which contains the JSON string collection subject to deserialize.</param>
/// <param name="expectedObject">Expected string collection deserialized expected.</param>
/// <param name="configureOptions">Allows to change the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/>
/// of the <see cref="FluentAssertionsJson.Configuration"/> used to assert the deserialization.</param>
public static void BeJsonDeserializableInto<T>(this StringCollectionAssertions assertions, T expectedObject, Action<JsonSerializerOptions> configureOptions)
{
var optionsCopy = new JsonSerializerOptions(FluentAssertionsJson.Configuration.JsonSerializerOptions);

configureOptions(optionsCopy);

BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, optionsCopy);
}

/// <summary>
/// Check if the JSON subject numeric is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
/// <typeparam name="T">Type of the numeric value to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="ObjectAssertions"/> which contains the JSON numeric subject to deserialize.</param>
/// <param name="expectedObject">Expected numeric value deserialized expected.</param>
/// <param name="configureOptions">Allows to change the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/>
/// of the <see cref="FluentAssertionsJson.Configuration"/> used to assert the deserialization.</param>
public static void BeJsonDeserializableInto<T>(this NumericAssertions<T> assertions, T expectedObject, Action<JsonSerializerOptions> configureOptions)
where T : struct, IComparable<T>
{
var optionsCopy = new JsonSerializerOptions(FluentAssertionsJson.Configuration.JsonSerializerOptions);

configureOptions(optionsCopy);

BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, optionsCopy);

Check warning on line 229 in src/FluentAssertions.Json/JsonFluentAssertionsExtensions.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'subject' in 'void JsonFluentAssertionsExtensions.BeJsonDeserializableIntoCore<T>(object subject, T expectedObject, JsonSerializerOptions options)'.
}

/// <summary>
/// Check if the JSON subject string is deserializable into the specified <paramref name="expectedObject"/> argument.
/// </summary>
/// <typeparam name="T">Type of the string value to deserialize from JSON.</typeparam>
/// <param name="assertions"><see cref="StringAssertions"/> which contains the JSON string subject to deserialize.</param>
/// <param name="expectedObject">Expected string value deserialized expected.</param>
/// <param name="configureOptions">Allows to change the default <see cref="IFluentAssertionsJsonConfiguration.JsonSerializerOptions"/>
/// of the <see cref="FluentAssertionsJson.Configuration"/> used to assert the deserialization.</param>
public static void BeJsonDeserializableInto<T>(this StringAssertions assertions, T expectedObject, Action<JsonSerializerOptions> configureOptions)
{
var optionsCopy = new JsonSerializerOptions(FluentAssertionsJson.Configuration.JsonSerializerOptions);

configureOptions(optionsCopy);

BeJsonDeserializableIntoCore(assertions.Subject, expectedObject, optionsCopy);
}

private static void BeJsonSerializableIntoCore<TBase>(ObjectAssertions assertions, object? expectedJson, JsonSerializerOptions options)
{
if (assertions.Subject is not null && assertions.Subject is not TBase)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>

<!-- Disable the StyleCop 'XML comment analysis is disabled due to project configuration' warning. -->
<NoWarn>$(NoWarn);SA0001</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 1c07aaf

Please sign in to comment.