Skip to content

Commit c54cc3d

Browse files
committed
Bump to version 3.0.0-preview.1
1 parent 089e4a0 commit c54cc3d

4 files changed

Lines changed: 163 additions & 43 deletions

File tree

CodeQuality.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoloX.CodeQuality.Test", "s
99
EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{57F5BB2E-CD03-470B-BF16-31FE02A386B1}"
1111
ProjectSection(SolutionItems) = preProject
12+
documents\BreakingChanges.md = documents\BreakingChanges.md
1213
LICENSE = LICENSE
1314
README.md = README.md
1415
src\SharedProperties.props = src\SharedProperties.props

README.md

Lines changed: 94 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CodeQuality
22

3-
This project provides an easy way to set up .Net Core [static code analysis](#coding-style-and-analysis) with pre-configured quality and coding style
3+
This project provides an easy way to set up .NET [static code analysis](#coding-style-and-analysis) with pre-configured quality and coding style
44
rules for your Test and your Prod C# projects.
55

66
It also provides:
@@ -14,15 +14,20 @@ It also provides:
1414
[![Build - CI](https://github.com/xaviersolau/CodeQuality/actions/workflows/build-ci.yml/badge.svg)](https://github.com/xaviersolau/CodeQuality/actions/workflows/build-ci.yml)
1515
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
1616

17-
| Package | Nuget.org | Pre-release |
18-
|-----------------------------------------|-----------|-------------|
19-
|**SoloX.CodeQuality.Prod** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Prod.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Prod) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Prod.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Prod)
20-
|**SoloX.CodeQuality.Test** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test)
21-
|**SoloX.CodeQuality.Playwright** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Playwright.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Playwright) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Playwright.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Playwright)
22-
|**SoloX.CodeQuality.Test.Helpers** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers)
23-
|**SoloX.CodeQuality.Test.Helpers.XUnit** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.XUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.XUnit) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.XUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.XUnit)
24-
|**SoloX.CodeQuality.Test.Helpers.NUnit** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.NUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.NUnit) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.NUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.NUnit)
25-
|**SoloX.CodeQuality.WebHost** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.WebHost.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.WebHost) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.WebHost.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.WebHost)
17+
| Package | Nuget.org | Pre-release |
18+
|---------------------------------------------|-----------|-------------|
19+
|**SoloX.CodeQuality.Prod** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Prod.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Prod) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Prod.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Prod)
20+
|**SoloX.CodeQuality.Test** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test)
21+
|**SoloX.CodeQuality.Playwright** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Playwright.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Playwright) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Playwright.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Playwright)
22+
|**SoloX.CodeQuality.Test.Helpers** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers)
23+
|~~**SoloX.CodeQuality.Test.Helpers.XUnit**~~ |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.XUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.XUnit) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.XUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.XUnit)
24+
|**SoloX.CodeQuality.Test.Helpers.XUnit.V3** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.XUnit.V3.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.XUnit.V3) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.XUnit.V3.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.XUnit.V3)
25+
|**SoloX.CodeQuality.Test.Helpers.NUnit** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.Test.Helpers.NUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.NUnit) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.Test.Helpers.NUnit.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.Test.Helpers.NUnit)
26+
|**SoloX.CodeQuality.WebHost** |[![NuGet Beta](https://img.shields.io/nuget/v/SoloX.CodeQuality.WebHost.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.WebHost) |[![NuGet Beta](https://img.shields.io/nuget/vpre/SoloX.CodeQuality.WebHost.svg)](https://www.nuget.org/packages/SoloX.CodeQuality.WebHost)
27+
28+
> Find out the [Breaking changes](documents/BreakingChanges.md) from one version to another.
29+
30+
> Note that from version 3.0.* the `SoloX.CodeQuality.Test.Helpers.XUnit` package is obsolete since [xUnit.net](https://xunit.net) switched to V3.
2631
2732
## License and credits
2833

@@ -42,7 +47,7 @@ This project is not implementing analysis by itself, it is using existing analys
4247

4348

4449
**Note that before version 2.1.0 the AnalysisLevel property was set to "latest" resulting in breaking the build just on framework update.**
45-
**So from version 2.1.0 the analysis level is fixed to a specific version (in our case 8.0)**
50+
**So from version 2.1.0 the analysis level is fixed to a specific version (currently 10.0 with version 3.0.0)**
4651

4752
* * *
4853

@@ -52,26 +57,26 @@ You can checkout this Github repository or you can use the NuGet package:
5257

5358
**Install using the command line from the Package Manager:**
5459
```bash
55-
Install-Package SoloX.CodeQuality.Prod -version 2.3.6
60+
Install-Package SoloX.CodeQuality.Prod -version 3.0.0-preview.1
5661
or
57-
Install-Package SoloX.CodeQuality.Test -version 2.3.6
62+
Install-Package SoloX.CodeQuality.Test -version 3.0.0-preview.1
5863
```
5964

6065
**Install using the .Net CLI:**
6166
```bash
62-
dotnet add package SoloX.CodeQuality.Prod --version 2.3.6
67+
dotnet add package SoloX.CodeQuality.Prod --version 3.0.0-preview.1
6368
or
64-
dotnet add package SoloX.CodeQuality.Test --version 2.3.6
69+
dotnet add package SoloX.CodeQuality.Test --version 3.0.0-preview.1
6570
```
6671

6772
**Install editing your project file (csproj):**
6873
```xml
69-
<PackageReference Include="SoloX.CodeQuality.Prod" Version="2.3.6">
74+
<PackageReference Include="SoloX.CodeQuality.Prod" Version="3.0.0-preview.1">
7075
<PrivateAssets>all</PrivateAssets>
7176
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
7277
</PackageReference>
7378
or
74-
<PackageReference Include="SoloX.CodeQuality.Test" Version="2.3.6">
79+
<PackageReference Include="SoloX.CodeQuality.Test" Version="3.0.0-preview.1">
7580
<PrivateAssets>all</PrivateAssets>
7681
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
7782
</PackageReference>
@@ -218,17 +223,17 @@ You can checkout this Github repository or use the NuGet package:
218223

219224
**Install using the command line from the Package Manager:**
220225
```bash
221-
Install-Package SoloX.CodeQuality.Playwright -version 2.3.6
226+
Install-Package SoloX.CodeQuality.Playwright -version 3.0.0-preview.1
222227
```
223228

224229
**Install using the .Net CLI:**
225230
```bash
226-
dotnet add package SoloX.CodeQuality.Playwright --version 2.3.6
231+
dotnet add package SoloX.CodeQuality.Playwright --version 3.0.0-preview.1
227232
```
228233

229234
**Install editing your project file (csproj):**
230235
```xml
231-
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.6" />
236+
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="3.0.0-preview.1" />
232237
```
233238

234239
* * *
@@ -309,8 +314,8 @@ builder.WithLocalHost(localHostBuilder =>
309314
});
310315
```
311316

312-
> Note that your host must be based on .Net 8.0 and it must use the `WebApplication.CreateBuilder(args)` method to build your Web host. If
313-
> you still use the hold way with `Host.CreateDefaultBuilder(args)` and a `Startup.cs` file, you will get an exception like this
317+
> Note that your host must be based on .NET 8.0 or later and it must use the `WebApplication.CreateBuilder(args)` method to build your Web host. If
318+
> you still use the old way with `Host.CreateDefaultBuilder(args)` and a `Startup.cs` file, you will get an exception like this
314319
> `System.InvalidOperationException : Build can only be called once.` and you won't be able to start your test.
315320
316321
On-line host:
@@ -424,29 +429,35 @@ You can checkout this Github repository or you can use the NuGet package:
424429

425430
**Install using the command line from the Package Manager:**
426431
```bash
427-
Install-Package SoloX.CodeQuality.Test.Helpers -version 2.3.6
432+
Install-Package SoloX.CodeQuality.Test.Helpers -version 3.0.0-preview.1
428433

429-
Install-Package SoloX.CodeQuality.Test.Helpers.XUnit -version 2.3.6
434+
Install-Package SoloX.CodeQuality.Test.Helpers.XUnit -version 3.0.0-preview.1
430435

431-
Install-Package SoloX.CodeQuality.Test.Helpers.NUnit -version 2.3.6
436+
Install-Package SoloX.CodeQuality.Test.Helpers.XUnit.V3 -version 3.0.0-preview.1
437+
438+
Install-Package SoloX.CodeQuality.Test.Helpers.NUnit -version 3.0.0-preview.1
432439
```
433440

434441
**Install using the .Net CLI:**
435442
```bash
436-
dotnet add package SoloX.CodeQuality.Test.Helpers --version 2.3.6
443+
dotnet add package SoloX.CodeQuality.Test.Helpers --version 3.0.0-preview.1
444+
445+
dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit --version 3.0.0-preview.1
437446

438-
dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit --version 2.3.6
447+
dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit.V3 --version 3.0.0-preview.1
439448

440-
dotnet add package SoloX.CodeQuality.Test.Helpers.NUnit --version 2.3.6
449+
dotnet add package SoloX.CodeQuality.Test.Helpers.NUnit --version 3.0.0-preview.1
441450
```
442451

443452
**Install editing your project file (csproj):**
444453
```xml
445-
<PackageReference Include="SoloX.CodeQuality.Test.Helpers" Version="2.3.6" />
454+
<PackageReference Include="SoloX.CodeQuality.Test.Helpers" Version="3.0.0-preview.1" />
446455

447-
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit" Version="2.3.6" />
456+
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit" Version="3.0.0-preview.1" />
448457

449-
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.NUnit" Version="2.3.6" />
458+
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit.V3" Version="3.0.0-preview.1" />
459+
460+
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.NUnit" Version="3.0.0-preview.1" />
450461
```
451462

452463
* * *
@@ -479,23 +490,68 @@ var response = await httpClient.GetFromJsonAsync<Person>("target");
479490

480491
```
481492

493+
* * *
494+
495+
### Snapshot testing
496+
497+
Snapshot testing is a powerful technique for testing text and image outputs. The `SnapshotHelper` class provided in
498+
`SoloX.CodeQuality.Test.Helpers` makes it easy to create and maintain snapshot tests.
499+
500+
Snapshots are stored on disk and compared against test outputs. This is useful for testing scenarios such as:
501+
* Text comparisons (JSON, XML, code generation outputs, etc.)
502+
* Image comparisons
503+
* Large data structure validations
504+
505+
#### Basic usage
506+
507+
To use the `SnapshotHelper` in your tests, simply create an instance and use its methods to verify outputs:
508+
509+
```csharp
510+
using SoloX.CodeQuality.Test.Helpers.Snapshot;
511+
512+
var snapshotHelper = new SnapshotHelper();
513+
514+
// For text snapshots
515+
string generatedOutput = GenerateContent();
516+
await snapshotHelper.CompareTextSnapshotAsync(nameof(MyTest), generatedOutput);
517+
518+
// For image snapshots
519+
Stream generatedPngImage = GeneratePngImage();
520+
await snapshotHelper.ComparePngSnapshotAsync(nameof(MyTest), generatedImage);
521+
```
522+
523+
#### Configuration
524+
525+
You can configure the `SnapshotHelper` with custom options:
526+
527+
```csharp
528+
var snapshotHelper = new SnapshotHelper(options =>
529+
{
530+
options.IntermediateFolder = "CustomSnapshotsFolder";
531+
options.RootPath = "/path/to/test/project";
532+
});
533+
```
534+
535+
The snapshots are stored in a `Snapshots` folder by default and can be reviewed and updated when the expected output changes.
536+
537+
* * *
538+
482539
### ILogger\<T> mocking
483540

484541
We often need to provide a ILogger\<T> instance to the class we want to test. This is easy to provide a
485542
mock of this interface but sometime it is actually useful to be able to write the logs into the test
486543
output. In order to write the logs in the test console output you can use the TestLogger available for
487544
XUnit and NUnit.
488545

489-
#### With XUnit
546+
#### With XUnit or XUnit.V3
490547

491-
The XUnit TestLogger is provided in the package `SoloX.CodeQuality.Test.Helpers.XUnit` and it can be
492-
used like this:
548+
The XUnit TestLogger is provided in the package `SoloX.CodeQuality.Test.Helpers.XUnit.V3` (or
549+
`SoloX.CodeQuality.Test.Helpers.XUnit` for XUnit V2) and it can be used like this:
493550

494551
```csharp
495552
using Microsoft.Extensions.Logging;
496-
using SoloX.CodeQuality.Test.Helpers.XUnit.Logger;
553+
using SoloX.CodeQuality.Test.Helpers.XUnit.V3.Logger;
497554
using Xunit;
498-
using Xunit.Abstractions;
499555

500556
public class LoggerTest
501557
{
@@ -524,9 +580,8 @@ some integration tests using a service provider:
524580
```csharp
525581
using Microsoft.Extensions.DependencyInjection;
526582
using Microsoft.Extensions.Logging;
527-
using SoloX.CodeQuality.Test.Helpers.XUnit.Logger;
583+
using SoloX.CodeQuality.Test.Helpers.XUnit.V3.Logger;
528584
using Xunit;
529-
using Xunit.Abstractions;
530585

531586
public class LoggerTest
532587
{
@@ -555,7 +610,6 @@ public class LoggerTest
555610
}
556611
```
557612

558-
559613
#### With NUnit
560614

561615
The NUnit TestLogger is provided in the package `SoloX.CodeQuality.Test.Helpers.NUnit` and it can be
@@ -603,9 +657,8 @@ public class LoggerTest
603657
var logger = serviceProvider.GetRequiredService<ILogger<LoggerTest>>();
604658

605659
logger.LogError("This is an error log message!");
606-
660+
607661
Assert.Pass();
608662
}
609663
}
610664
```
611-

documents/BreakingChanges.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Breaking Changes
2+
3+
## Since version 3.0.*
4+
5+
### Snapshot Helper Rework
6+
7+
The `SnapshotHelper` API has been significantly reworked with breaking changes to the available methods and their signatures:
8+
9+
#### Key Changes
10+
- **Moved** from `SoloX.CodeQuality.Test.Helpers.XUnit` to `SoloX.CodeQuality.Test.Helpers` project and namespace.
11+
12+
- **Dependency change**: The `SnapshotHelper` class no longer depends on xUnit-specific types, making it more flexible and reusable
13+
across different testing frameworks.
14+
15+
- **Static to instance**: The `SnapshotHelper` class is no longer static. You must create an instance of `SnapshotHelper` to use its methods.
16+
17+
- **New asynchronous API**: All snapshot methods are now async (`Task`-based) and must be awaited.
18+
- Old: `AssertSnapshot(string generated, string snapshotName, string location)`
19+
- New: `await CompareTextSnapshotAsync(string name, string content)`
20+
21+
- **PNG file snapshot support**: New support for comparing PNG image snapshots has been added via `ComparePngSnapshotAsync()`.
22+
- Includes configurable `differencesThreshold` parameter for image comparison tolerance.
23+
24+
- **Configuration-based initialization**: The constructor now uses a fluent configuration pattern.
25+
- Old: location was specified as parameter of the static AssertSnapshot method.
26+
- New: `new SnapshotHelper(options => options.IntermediateFolder = intermediateFolder)`
27+
28+
- **Force replace capability**: All comparison methods now support a `forceReplaceSnapshot` parameter to update existing snapshots.
29+
30+
#### Migration Example
31+
32+
```csharp
33+
// Old code (no longer works)
34+
var location = "Path where to read/write snapshot files";
35+
SnapshotHelper.AssertSnapshot("Some text to match against the snapshot", snapshotName, location);
36+
37+
// New code
38+
var helper = new SnapshotHelper(options => options.RootPath = "Root path where to read/write snapshot files");
39+
await helper.CompareTextSnapshotAsync(snapshotName, "Some text to match against the snapshot");
40+
41+
// For PNG snapshots (new capability)
42+
await helper.ComparePngSnapshotAsync(snapshotName, pngStream, differencesThreshold: 0.01);
43+
```
44+
45+
#### Migration Steps
46+
47+
1. Setup with `SnapshotHelper` instantiation and use the configuration action.
48+
2. Change all `SnapshotHelper.AssertSnapshot()` calls to `CompareTextSnapshotAsync()` and add `await`.
49+
3. Review snapshot test methods and mark them as `async Task`.
50+
4. Existing snapshot text files (`.snapshot`) are compatible; you just need to rename with (`.snapshot.ref.txt`).
51+
52+
### Dependency Changes
53+
54+
- **FluentAssertions** dependency has been **removed** from the package.
55+
- The package no longer includes FluentAssertions as a transitive dependency.
56+
- If your project requires FluentAssertions, you can still use it by explicitly adding it as a project dependency.
57+
- Consider using alternative assertion libraries such as:
58+
- xUnit's built-in assertions
59+
- Shouldly (already used in CodeQuality project)
60+
- Other assertion frameworks compatible with .NET
61+
62+
### xUnit V3 Support
63+
64+
- New **xUnit V3 support** has been added through the `SoloX.CodeQuality.Test.Helpers.XUnit.V3` package.
65+
- Projects migrating to xUnit V3 should use the new V3-specific helpers instead of the legacy helpers.
66+
- The legacy xUnit V2 support is still available but may not receive further updates.

src/SharedProperties.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<Version>2.3.6</Version>
4+
<Version>3.0.0-preview.1</Version>
55
<Authors>Xavier Solau</Authors>
66
<Copyright>Copyright © 2021 Xavier Solau</Copyright>
77
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -14,7 +14,7 @@
1414
<CodeQualityHeaderLicense>$(PackageLicenseExpression)</CodeQualityHeaderLicense>
1515
<CodeQualityHeaderLicenseFile>LICENSE</CodeQualityHeaderLicenseFile>
1616

17-
<AssemblyVersion>2.3.6.0</AssemblyVersion>
17+
<AssemblyVersion>3.0.0.0</AssemblyVersion>
1818
<LangVersion>14</LangVersion>
1919

2020
</PropertyGroup>

0 commit comments

Comments
 (0)