Nzr.Snapshot.Xunit.Extensions 1.1.0

dotnet add package Nzr.Snapshot.Xunit.Extensions --version 1.1.0                
NuGet\Install-Package Nzr.Snapshot.Xunit.Extensions -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nzr.Snapshot.Xunit.Extensions" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nzr.Snapshot.Xunit.Extensions --version 1.1.0                
#r "nuget: Nzr.Snapshot.Xunit.Extensions, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Nzr.Snapshot.Xunit.Extensions as a Cake Addin
#addin nuget:?package=Nzr.Snapshot.Xunit.Extensions&version=1.1.0

// Install Nzr.Snapshot.Xunit.Extensions as a Cake Tool
#tool nuget:?package=Nzr.Snapshot.Xunit.Extensions&version=1.1.0                

Nzr.Snapshot.Xunit.Extensions

NuGet Version NuGet Downloads GitHub last commit GitHub Actions Workflow Status GitHub License

Nzr.Snapshot.Xunit.Extensions is a simple extension library for integrating Snapshooter with xUnit. It enables custom folder organization for snapshots based on test attributes and allows for flexible snapshot management in unit tests.

Features

  • Custom Folder Organization: Automatically organize snapshots into custom folders based on the SnapshotFolder attribute applied to xUnit test methods.
  • Class Name Exclusion: Optionally exclude the class name from the snapshot file path.

Installation

You can install Nzr.Snapshot.Xunit.Extensions via NuGet Package Manager:

Install-Package Nzr.Snapshot.Xunit.Extensions
dotnet add package Nzr.Snapshot.Xunit.Extensions

Usage

To use this package, simply include it in your xUnit test project and apply the extension methods to match the snapshots of objects during tests.

Example Usage

using FluentAssertions;
using Snapshooter;
using Nzr.Snapshot.Xunit.Extensions;

public class SnapshotTests
{
    [Fact]
    public void Match_Without_SnapshotFolderAttribute_Should_Snapshot_Folder_In_The_Same_Folder()
    {
        // Arrange
        var currentResult = new { City = "Nova Lima", CreatedAt = DateTimeOffset.Now };

        // Assert
        currentResult.Should().Match();
    }

    [SnapshotFolder("SnapshotExtensions")]
    [Fact]
    public void Match_With_SnapshotFolderAttribute_Should_Snapshot_Folder_In_Specified_Folder()
    {
        // Arrange
        var currentResult = new { City = "Lisbon", CreatedAt = DateTimeOffset.Now };

        // Assert
        currentResult.Should().Match();
    }

    [SnapshotFolder("Shared", excludeClassName: false)]
    [Fact]
    public void Match_With_SnapshotFolderAttribute_Keeping_ClassName_Should_Snapshot_Folder_In_Specified_Folder()
    {
        // Arrange
        var currentResult = new { City = "Berlin", CreatedAt = DateTimeOffset.Now };

        // Assert
        currentResult.Should().Match();
    }
}

SnapshotFolderAttribute

The SnapshotFolderAttribute is used to define custom folder paths for your snapshots. You can optionally specify whether to exclude the class name from the snapshot file name.

Parameters:
  • Name: Specifies the folder name for snapshots.
  • ExcludeClassName: Optional boolean to exclude the class name from the snapshot filename.
[SnapshotFolder("FolderName", excludeClassName: true)]

Contributing

We welcome contributions! If you'd like to contribute to this project, please fork the repository and submit a pull request. Please ensure that your code passes all tests and includes relevant documentation for new features or changes.

Steps for Contribution

  1. Give a start for this repository!
  2. Fork the repository.
  3. Clone the forked repository to your local machine.
  4. Create a new branch.
  5. Implement your changes.
  6. Run tests to ensure everything works.
  7. Commit your changes and create a pull request.

Acknowledgements

  • Snapshooter for snapshot testing.
  • xUnit for providing a great testing framework.
  • The open-source community for their contributions and feedback.

License

Nzr.Snapshot.Xunit.Extensions is licensed under the Apache License, Version 2.0, January 2004. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Disclaimer

This project is provided "as-is" without any warranty or guarantee of its functionality. The author assumes no responsibility or liability for any issues, damages, or consequences arising from the use of this code, whether direct or indirect. By using this project, you agree that you are solely responsible for any risks associated with its use, and you will not hold the author accountable for any loss, injury, or legal ramifications that may occur.

Please ensure that you understand the code and test it thoroughly before using it in any production environment.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.0 49 1/22/2025
1.0.7 156 1/19/2025
1.0.6 58 1/19/2025
1.0.5 60 1/19/2025
1.0.4 60 1/19/2025