Nzr.Snapshot.Xunit.Extensions 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Nzr.Snapshot.Xunit.Extensions --version 1.0.5                
NuGet\Install-Package Nzr.Snapshot.Xunit.Extensions -Version 1.0.5                
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.0.5" />                
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.0.5                
#r "nuget: Nzr.Snapshot.Xunit.Extensions, 1.0.5"                
#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.0.5

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

Nzr.Snapshot.Xunit.Extensions

GitHub last commit NuGet Downloads

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:

dotnet add package Nzr.Snapshot.Xunit.Extensions

Or, via the NuGet package page.

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)]

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

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.

For more information on how to use this project, please refer to the documentation.

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