Scand.StormPetrel.FileSnapshotInfrastructure
2.0.0
Prefix Reserved
dotnet add package Scand.StormPetrel.FileSnapshotInfrastructure --version 2.0.0
NuGet\Install-Package Scand.StormPetrel.FileSnapshotInfrastructure -Version 2.0.0
<PackageReference Include="Scand.StormPetrel.FileSnapshotInfrastructure" Version="2.0.0" />
paket add Scand.StormPetrel.FileSnapshotInfrastructure --version 2.0.0
#r "nuget: Scand.StormPetrel.FileSnapshotInfrastructure, 2.0.0"
// Install Scand.StormPetrel.FileSnapshotInfrastructure as a Cake Addin #addin nuget:?package=Scand.StormPetrel.FileSnapshotInfrastructure&version=2.0.0 // Install Scand.StormPetrel.FileSnapshotInfrastructure as a Cake Tool #tool nuget:?package=Scand.StormPetrel.FileSnapshotInfrastructure&version=2.0.0
Scand Storm Petrel File Snapshot Infrastructure
Overview
.NET library that implements Scand.StormPetrel.Generator.Abstraction to rewrite expected baseline files with actual snapshots (HTML, JSON, XML, images, or other bytes). This can be utilized in Snapshot Unit Testing when snapshots are stored as individual files in the file system.
Use Cases
By Configuration
Default Configuration
Rewrites expected baseline files as demonstrated by CalculatorSnapshotTest against the default baseline file structure. Initial baseline files like AddTest.json must exist before StormPetrel auto-generated tests and their origin tests execution because the default appsettings.StormPetrel.json does not specify snapshot file extensions.
Default Configuration With Custom Options
Similar to the Default Configuration, but explicitly specifies the json
extension and custom baseline file structure on test assembly initialization in ModuleInitializer. Initial baseline files may not exist before StormPetrel auto-generated tests and their origin tests execution in this case.
Custom Configuration
Rewrites expected baseline files as demonstrated by CalculatorSnapshotTest against a custom baseline file structure. Initial baseline files may not exist before StormPetrel auto-generated tests and their origin tests execution because the custom configuration may specify snapshot file extensions as indicated in CustomSnapshotOptions. See other files in CustomSnapshotInfrastructure for detailed examples of custom configurations.
By Snapshot Read Kind
Text
See ReadAllText
method call examples in CalculatorSnapshotTest and other tests.
Binary
See ReadAllBytes
method call examples in CalculatorSnapshotTest and other tests.
Stream
See OpenReadWithShareReadWrite
method call examples in CalculatorSnapshotTest and other tests.
By StormPetrel Use Cases
StormPetrel supports many use cases based on test framework attributes. All these use cases are supported by the File Snapshot Infrastructure package. Some of them are demonstrated in DefaultConfiguration/CalculatorSnapshotTest and CustomConfiguration/CalculatorSnapshotTest.
By Test Method Use Case Id
Use Case Id in Test Method Parameters
If a test method has useCaseId
parameter name or a method parameter marked by UseCaseIdAttribute, then the parameter value is transferred to/from File Snapshot Infrastructure code to get the appropriate snapshot baseline file or folder name. Find useCaseId
in DefaultConfiguration/CalculatorSnapshotTest or CustomConfiguration/CalculatorSnapshotTest for more details.
No Use Case Id in Test Method Parameters
If a test method does not have useCaseId
parameter name and no method parameter marked by UseCaseIdAttribute, then File Snapshot Infrastructure code treats useCaseId
as empty in snapshot baseline file or folder names.
Getting Started
To utilize File Snapshot Infrastructure in a test .NET project:
- Add the Scand.StormPetrel.Generator NuGet package to the project.
- Add the Scand.StormPetrel.FileSnapshotInfrastructure NuGet package to the project.
- Add an
appsettings.StormPetrel.json
file withBuild Action
set toC# analyzer additional file
according to Scand.StormPetrel.Generator Configuration. The file should reference File Snapshot Infrastructure classes like below:
{
"GeneratorConfig":
{
"DumperExpression": "new Scand.StormPetrel.FileSnapshotInfrastructure.SnapshotDumper()", //Use SnapshotDumper to dump string/binary/stream snapshots stored in actual/expected test variables.
"RewriterExpression": "new Scand.StormPetrel.FileSnapshotInfrastructure.SnapshotRewriter()" //Use SnapshotRewriter to rewrite snapshot files with actual values.
},
"IgnoreInvocationExpressionRegex": "SnapshotProvider", //Ignore SnapshotProvider expressions in Storm Petrel flow.
"Serilog": null //Optionally disable the logging.
}
See this and other configuration examples in DefaultConfiguration, DefaultConfigurationWithCustomOptions, and CustomConfiguration test projects.
Supported Software
The same as in Scand.StormPetrel.Generator.
CHANGELOG
References
At SCAND, we specialize in building advanced .NET solutions to help businesses develop new or modernize their legacy applications. If you need help getting started with Storm Petrel or support with implementation, we're ready to assist. Whether you're refactoring or rewriting, our team can help solve any challenges you might face. Visit our page to learn more, or reach out for hands-on guidance.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Scand.StormPetrel.Generator.Abstraction (>= 2.0.0 && < 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 83 | 10/31/2024 |
See CHANGELOG file referenced in README.