SweetMock.SourceGenerator 0.9.41

dotnet add package SweetMock.SourceGenerator --version 0.9.41
                    
NuGet\Install-Package SweetMock.SourceGenerator -Version 0.9.41
                    
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="SweetMock.SourceGenerator" Version="0.9.41">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SweetMock.SourceGenerator" Version="0.9.41" />
                    
Directory.Packages.props
<PackageReference Include="SweetMock.SourceGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SweetMock.SourceGenerator --version 0.9.41
                    
#r "nuget: SweetMock.SourceGenerator, 0.9.41"
                    
#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.
#:package SweetMock.SourceGenerator@0.9.41
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SweetMock.SourceGenerator&version=0.9.41
                    
Install as a Cake Addin
#tool nuget:?package=SweetMock.SourceGenerator&version=0.9.41
                    
Install as a Cake Tool

Icon Sweet Mock

A source generator for creating mocks and fixtures for testing. SweetMock automatically generates fixture and mock implementations of interfaces or classes to help in unit testing by providing a way to simulate the behavior of complex dependencies.

[Fixture<ShoppingBasket>]
[Fact]
public async Task TheGuideShouldAlwaysBeAvailable()
{
    // Arrange
    var userGuid = Guid.NewGuid();

    var fixture = Fixture.ShoppingBasket(config =>
    {
        config.user.Id(userGuid);
        var basket1 = Mock.IBasket(c => c.Add());
        config.basketRepo
            .TryGetUserBasket(Task.FromResult(true), basket1)
            .Save();
        config.bookRepo
            .IsAvailable(true)
            .InStock(42)
            .GetByISBN(new Book("isbn 0-434-00348-4", "The Hitch Hiker's Guide to the Galaxy", "Douglas Adams"));
        config.messageBroker.SendMessage();
    });

    var sut = fixture.CreateShoppingBasket();

    // Act
    await sut.AddBookToBasket("isbn 0-434-00348-4", CancellationToken.None);

    // Assert
    var sendMessage = Assert.Single(fixture.Calls.messageBroker.SendMessage(arguments => arguments.userId == userGuid));
    Assert.Equal("The book The Hitch Hiker's Guide to the Galaxy by Douglas Adams was added to your basket", sendMessage.message);
}

For more details see the documentation

Installation

Install the package via NuGet:

dotnet add package SweetMock

Features

SweetMock offers a comprehensive set of features designed to streamline unit testing in C# projects. Its source generator code simplifies security scanning and ensures that mock implementations are both fast, reliable and maintainable.

The fixture system enables bulk creation of mock dependencies, making it easy to set up complex test scenarios while direct access to creating individual mock object allows for more advanced scenarios.

SweetMock supports both interface and class mocking, providing flexibility for a wide range of dependency types. Built-in mocks cover common scenarios, reducing the need for custom implementations.

Extensive logging features allow for detailed assertions, helping you verify interactions and outcomes with precision.

Additionally, SweetMock is test framework agnostic, working seamlessly with XUnit, NUnit, TUnit, and other popular frameworks.

Requirements

  • C# 12.0 (.net 8 and above)

License

This project is licensed under MIT License

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SweetMock.SourceGenerator:

Package Downloads
SweetMock

Source generator for creating mocks and fixtures for testing. SweetMock is a tool that automatically generates test fixtures and mock implementations of interfaces or classes helping in unit testing by providing a way to simulate the behavior of complex dependencies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.41 250 5/22/2026
0.9.40 248 5/19/2026
0.9.39 232 4/29/2026
0.9.38 219 4/21/2026
0.9.37 155 3/24/2026
0.9.37-RC1 156 3/13/2026
0.9.36 197 1/15/2026
Loading failed