-
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.
Showing
14 changed files
with
1,154 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- File name extension must be .runsettings --> | ||
<RunSettings> | ||
<DataCollectionRunSettings> | ||
<DataCollectors> | ||
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> | ||
<Configuration> | ||
<CodeCoverage> | ||
|
||
<!-- Match assembly file paths: --> | ||
<ModulePaths> | ||
<Include> | ||
<ModulePath>.*\.dll$</ModulePath> | ||
</Include> | ||
<Exclude> | ||
<ModulePath>.*xunit.*</ModulePath> | ||
<ModulePath>.*webjobs.*</ModulePath> | ||
<ModulePath>moq.*</ModulePath> | ||
<ModulePath>.*durabletask.*</ModulePath> | ||
<ModulePath>microsoft.*</ModulePath> | ||
<ModulePath>bouncycastle.*</ModulePath> | ||
<ModulePath>.*tests\.dll$</ModulePath> | ||
</Exclude> | ||
</ModulePaths> | ||
|
||
<Attributes> | ||
<Exclude> | ||
<!-- Exclude generated code from code coverage --> | ||
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute> | ||
<Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute> | ||
</Exclude> | ||
</Attributes> | ||
|
||
<CompanyNames> | ||
<Include> | ||
<CompanyName>.*PosInformatique.*</CompanyName> | ||
</Include> | ||
</CompanyNames> | ||
|
||
<!-- We recommend you do not change the following values: --> | ||
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation> | ||
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses> | ||
<CollectFromChildProcesses>True</CollectFromChildProcesses> | ||
<CollectAspDotNet>False</CollectAspDotNet> | ||
|
||
</CodeCoverage> | ||
</Configuration> | ||
</DataCollector> | ||
</DataCollectors> | ||
</DataCollectionRunSettings> | ||
</RunSettings> |
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,52 @@ | ||
<Project> | ||
|
||
<!-- Common properties --> | ||
<PropertyGroup> | ||
<Authors>Gilles TOURREAU</Authors> | ||
<Company>P.O.S Informatique</Company> | ||
<Product>P.O.S Informatique</Product> | ||
<Copyright>Copyright (c) P.O.S Informatique. All rights reserved.</Copyright> | ||
<RepositoryUrl>https://github.com/PosInformatique/PosInformatique.FluentAssertions.Json.git</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
|
||
<!-- Enable the last version of C# --> | ||
<LangVersion>latest</LangVersion> | ||
|
||
<!-- Enable implict usings --> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
|
||
<!-- Disable the Analyzers in Release configuration --> | ||
<RunAnalyzers Condition="'$(Configuration)' == 'Release'">false</RunAnalyzers> | ||
|
||
<!-- Disable the StyleCop 'XML comment analysis is disabled due to project configuration' warning. --> | ||
<NoWarn>$(NoWarn);SA0001</NoWarn> | ||
|
||
<!-- By default prefix all the assemblies name with ChantierConnect --> | ||
<AssemblyName>PosInformatique.$(MSBuildProjectName)</AssemblyName> | ||
<RootNamespace>PosInformatique.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<AdditionalFiles Include="..\..\stylecop.json"> | ||
<Link>stylecop.json</Link> | ||
</AdditionalFiles> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\.editorconfig" Link=".editorconfig" /> | ||
</ItemGroup> | ||
|
||
<!-- Common NuGet packages --> | ||
<ItemGroup> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<!-- Add the default using directive for all the code --> | ||
<ItemGroup> | ||
<Using Include="System" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,56 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.34024.191 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.Json", "src\FluentAssertions.Json\FluentAssertions.Json.csproj", "{6181FF63-A928-45E9-A06A-C39D6A605EA0}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentAssertions.Json.Tests", "tests\FluentAssertions.Json.Tests\FluentAssertions.Json.Tests.csproj", "{4C522E59-A843-4538-BC99-512A70D673AB}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{882949E5-7DCE-4EB6-8E9A-CB88FD0ED1F9}" | ||
ProjectSection(SolutionItems) = preProject | ||
.gitignore = .gitignore | ||
CodeCoverage.runsettings = CodeCoverage.runsettings | ||
Directory.Build.props = Directory.Build.props | ||
LICENSE = LICENSE | ||
README.md = README.md | ||
stylecop.json = stylecop.json | ||
EndProjectSection | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7928175B-C3B3-4F81-B956-BF4E4F816436}" | ||
ProjectSection(SolutionItems) = preProject | ||
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 | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6181FF63-A928-45E9-A06A-C39D6A605EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6181FF63-A928-45E9-A06A-C39D6A605EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6181FF63-A928-45E9-A06A-C39D6A605EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6181FF63-A928-45E9-A06A-C39D6A605EA0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4C522E59-A843-4538-BC99-512A70D673AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4C522E59-A843-4538-BC99-512A70D673AB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4C522E59-A843-4538-BC99-512A70D673AB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4C522E59-A843-4538-BC99-512A70D673AB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
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} | ||
EndGlobalSection | ||
EndGlobal |
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,2 +1,119 @@ | ||
# PosInformatique.FluentAssertions.Json | ||
PosInformatique.FluentAssertions.Json is a library to assert JSON serialization using the FluentAssertion style coding. | ||
PosInformatique.FluentAssertions.Json is a library to assert JSON serialization using the *Fluent Assertions* library style coding. | ||
|
||
## Installing from NuGet | ||
The [PosInformatique.FluentAssertions.Json](https://www.nuget.org/packages/PosInformatique.FluentAssertions.Json/) | ||
library is available directly on the | ||
[NuGet](https://www.nuget.org/packages/PosInformatique.FluentAssertions.Json/) official website. | ||
|
||
To download and install the library to your Visual Studio unit test projects use the following NuGet command line | ||
|
||
``` | ||
Install-Package PosInformatique.AspNet.WebForms.DependencyInjection | ||
``` | ||
|
||
## How it is work? | ||
Imagine that you have the following JSON class: | ||
|
||
```csharp | ||
public class Customer | ||
{ | ||
[JsonPropertyName("id")] | ||
[JsonPropertyOrder(1)] | ||
public int Id { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
[JsonPropertyOrder(2)] | ||
public string Name { get; set; } | ||
} | ||
``` | ||
|
||
With the following instance: | ||
|
||
```csharp | ||
var customer = new Customer() | ||
{ | ||
Id = 1234, | ||
Name = "Gilles TOURREAU", | ||
}; | ||
``` | ||
|
||
You would like to check this class is serializable into the following JSON object: | ||
|
||
```json | ||
{ | ||
"id": 1234, | ||
"name": "Gilles TOURREAU", | ||
} | ||
``` | ||
|
||
Using standard assertions you should write the following code :fearful:: | ||
``` | ||
[Fact] | ||
public void Serialization() | ||
{ | ||
var customer = new Customer() | ||
{ | ||
Id = 1234, | ||
Name = "Gilles TOURREAU", | ||
}; | ||
var json = JsonSerializer.Serialize(customer); | ||
json.Should().Be("{\"id\":1234,\"name\":\"Gilles TOURREAU\"}"); | ||
// Or | ||
json.Should().Be(@"{""id"":1234,""name"":""Gilles TOURREAU""}"); | ||
} | ||
``` | ||
|
||
With the following kind of exception when the unit test is incorrect: | ||
![Ugly exception](./docs/UglyExceptionExample.png) | ||
|
||
As you can see the previous code is not sexy to read (and to write!) and the exception is | ||
hard to understand... | ||
|
||
## Test the serialization of a .NET Object to a JSON object. | ||
With the new fluent style using this library you can write previous unit test like that: | ||
|
||
```csharp | ||
[Fact] | ||
public void Serialization() | ||
{ | ||
var customer = new Customer() | ||
{ | ||
Id = 1234, | ||
Name = "Gilles TOURREAU", | ||
}; | ||
|
||
customer.Should().BeJsonSerializableInto(new | ||
{ | ||
id = 1234, | ||
name = "Gilles TOURREAU", | ||
}); | ||
} | ||
``` | ||
|
||
And when an exception is occured, the exception message contains the JSON path of the property which is error: | ||
![Pretty exception](./docs/PrettyExceptionExample.png) | ||
|
||
### Test the deserialization of a JSON object to a .NET Object | ||
You can in the same way test the deserialization JSON object into a .NET object. | ||
|
||
``` | ||
[Fact] | ||
public void Deserialization() | ||
{ | ||
var json = new | ||
{ | ||
id = 1234, | ||
name = "Gilles TOURREAU", | ||
}; | ||
json.Should().BeJsonDeserializableInto(new Customer() | ||
{ | ||
Id = 1234, | ||
Name = "Gilles TOURREAU", | ||
}); | ||
} | ||
``` |
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,24 @@ | ||
trigger: none | ||
|
||
pool: | ||
vmImage: ubuntu-latest | ||
|
||
jobs: | ||
- job: Build | ||
displayName: Build the library | ||
steps: | ||
- task: DotNetCoreCLI@2 | ||
name: BuildLibrary | ||
displayName: Build the library | ||
inputs: | ||
command: 'build' | ||
projects: 'PosInformatique.FluentAssertions.Json.sln' | ||
arguments: '--property:Configuration=Debug' | ||
|
||
- task: DotNetCoreCLI@2 | ||
name: ExecuteUnitTests | ||
displayName: Execute the unit tests | ||
inputs: | ||
command: 'test' | ||
projects: 'PosInformatique.FluentAssertions.Json.sln' | ||
arguments: '--property:Configuration=Debug' |
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,46 @@ | ||
parameters: | ||
- name: VersionPrefix | ||
displayName: The version of the library | ||
type: string | ||
default: 1.0.0 | ||
- name: VersionSuffix | ||
displayName: The version suffix of the library (rc.1) | ||
type: string | ||
default: rc.1 | ||
|
||
trigger: none | ||
pr: none | ||
|
||
pool: | ||
vmImage: ubuntu-latest | ||
|
||
jobs: | ||
- job: Build | ||
displayName: Build the library | ||
steps: | ||
- task: PowerShell@2 | ||
name: UpdateBuildNumber | ||
displayName: Update build number | ||
inputs: | ||
targetType: 'inline' | ||
script: 'Write-Host "##vso[build.updatebuildnumber]${{parameters.VersionPrefix}}-${{parameters.VersionSuffix}}"' | ||
|
||
- task: DotNetCoreCLI@2 | ||
name: BuildLibrary | ||
displayName: Build the library | ||
inputs: | ||
command: 'pack' | ||
packagesToPack: 'src/FluentAssertions.Json/FluentAssertions.Json.csproj' | ||
configuration: 'Release' | ||
versioningScheme: 'off' | ||
buildProperties: 'VersionPrefix=${{parameters.VersionPrefix}};VersionSuffix=${{parameters.VersionSuffix}}' | ||
verbosityPack: 'Normal' | ||
|
||
- task: NuGetCommand@2 | ||
name: PublishNuGetPackages | ||
displayName: Publish to NuGet | ||
inputs: | ||
command: 'push' | ||
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' | ||
nuGetFeedType: 'external' | ||
publishFeedCredentials: 'nuget.org' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\"/> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.