BbQ.MockLite 2.0.1

dotnet add package BbQ.MockLite --version 2.0.1
                    
NuGet\Install-Package BbQ.MockLite -Version 2.0.1
                    
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="BbQ.MockLite" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BbQ.MockLite" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="BbQ.MockLite" />
                    
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 BbQ.MockLite --version 2.0.1
                    
#r "nuget: BbQ.MockLite, 2.0.1"
                    
#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 BbQ.MockLite@2.0.1
                    
#: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=BbQ.MockLite&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=BbQ.MockLite&version=2.0.1
                    
Install as a Cake Tool

MockLite

Your interfaces. Your testing API. Generated.

Turn application contracts into test doubles with setup, callbacks and verification tailored to every member. MockLite's C# source generator creates concrete mock classes during your build, so you can discover the testing API in IntelliSense, write typed behavior and inspect the generated implementation.

Less time maintaining handwritten fakes. More time describing how your application should behave.

Try your first generated mock · Explore the generated API · Upgrade to 2.x

MockLite source-generation walkthrough: an IPriceFeed contract becomes a MockPriceFeed with member-specific setup, typed callbacks and argument-aware verification.

Illustrated code walkthrough. The same API calls appear below as selectable text.

A testing workflow built around your contracts

What you need to do What the generator gives you
Find the right setup without memorizing a framework Member-specific methods such as SetupGetPrice and GetPriceReturns, discoverable in IntelliSense
React to a call using real argument types Callbacks and return factories whose parameters are inferred from the interface signature
Check the interaction that matters Methods such as VerifyGetPrice, with typed predicates and Times counts
Keep test doubles aligned as contracts evolve Concrete implementations regenerated at build time; references to changed generated members receive normal C# compiler feedback
Understand what runs in your test Generated C# you can inspect, with no DispatchProxy on the generated invocation path

The package pairs source generation with Roslyn diagnostics and code fixes for recognized setup mistakes. See which diagnostics are implemented.

Try it in a test project

Add both packages to the project that will compile your generated mocks:

dotnet add package BbQ.MockLite
dotnet add package BbQ.MockLite.Generators

The core package contains the shared runtime; the generator package supplies source generation, analyzers and code fixes. The repository builds with .NET 8 and .NET 10 SDKs; the generator targets .NET 8. Use a current SDK and C# language version supported by your project.

1. Select a contract

Keep the generation declaration in your test project. This also works for interfaces from referenced assemblies, so you can leave application contracts untouched:

using BbQ.MockLite;

[GenerateMock<IPriceFeed>]
public partial class TestDoubles { }

// Example contract; normally imported from your application.
public interface IPriceFeed
{
    decimal GetPrice(string sku);
}

Build the project. MockLite generates MockPriceFeed in the interface's namespace. For an interface you want to annotate directly, [GenerateMock] on that interface is also supported.

2. Describe the scenario

var prices = new MockPriceFeed();

prices.SetupGetPrice(sku => sku == "SKU-42")
    .Callback(sku => Console.WriteLine($"Looked up {sku}"))
    .Returns(19.95m);

sku is a string, inferred from the contract. The predicate filters both the callback and the configured return behavior. The setup API is generated for this method, so incompatible callback signatures and return types receive C# compiler feedback.

3. Exercise the behavior and verify it

IPriceFeed feed = prices; // Pass this interface to your system under test.
decimal price = feed.GetPrice("SKU-42"); // 19.95m

prices.VerifyGetPrice(sku => sku == "SKU-42", Times.Once);

In a real test, call the service that consumes IPriceFeed, assert its result with your test framework, then verify the interaction. Construct MockPriceFeed directly to access its generated setup and verification members; Mock.Of<IPriceFeed>() returns the interface type.

Start with one dependency

Try a generated mock in one new test or replace one handwritten fake. Existing tests can continue using their current tools while you evaluate the workflow.

Scenario Starting point
Configure a generated mock with member-specific helpers new MockPriceFeed()
Generate a mock for an interface you cannot annotate [GenerateMock<IExternalService>] on a class in your test project
Use an expression-based runtime mock without generation Mock.Create<IPriceFeed>(), then pass its .Object to your service

Generated mocks support methods, properties, typed matching, callbacks, async return shapes and invocation recording. There are boundaries: generic interface methods do not receive generated setup/returns helpers; overloaded methods use signature-qualified helper names. Check the API reference for naming and supported shapes before choosing a contract.

For measured comparisons and reproducible commands, see the wiki benchmarks and benchmark project.

Go further in the wiki

Upgrading from 1.x? In 2.x, runtime Verify(expression, times) honors expression arguments, setup callbacks inherit matching, and the newest matching setup wins. Use VerifyAnyArguments for an intentional method-wide count.

Questions or an interface shape that needs support? Open an issue.

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

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on BbQ.MockLite:

Package Downloads
BbQ.MockLite.Generators

Source generator and analyzers for BbQ.MockLite - generates optimized mock implementations at compile time with diagnostic analyzers and code fix providers.

BbQ.MockLite.AutoFixture

Freeze MockLite test doubles for injection by AutoFixture.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 93 11/19/2026
2.0.0 172 10/4/2026
1.1.0 367 8/4/2026
1.0.12 264 3/20/2026
1.0.11 158 3/19/2026
1.0.10 152 3/18/2026
1.0.9 143 3/18/2026
1.0.8 163 3/17/2026
1.0.7 153 3/6/2026
1.0.6 1,934 12/27/2025
1.0.5 1,419 12/3/2025
1.0.4 727 12/2/2025
1.0.3 761 12/2/2025
1.0.2 738 12/2/2025
1.0.1 739 12/2/2025
1.0.0 672 12/1/2025