BbQ.MockLite.Generators
2.0.1
dotnet add package BbQ.MockLite.Generators --version 2.0.1
NuGet\Install-Package BbQ.MockLite.Generators -Version 2.0.1
<PackageReference Include="BbQ.MockLite.Generators" Version="2.0.1" />
<PackageVersion Include="BbQ.MockLite.Generators" Version="2.0.1" />
<PackageReference Include="BbQ.MockLite.Generators" />
paket add BbQ.MockLite.Generators --version 2.0.1
#r "nuget: BbQ.MockLite.Generators, 2.0.1"
#:package BbQ.MockLite.Generators@2.0.1
#addin nuget:?package=BbQ.MockLite.Generators&version=2.0.1
#tool nuget:?package=BbQ.MockLite.Generators&version=2.0.1
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
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
- Generated and runtime API reference — signatures, matching and verification.
- Getting started and source generators.
- Benchmarks — commands and historical measurements.
- Sample application — more complete scenarios.
- Callback guide and quick reference.
- Analyzer status — active and reserved diagnostics.
- 2.x migration guide — interaction changes for existing users.
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 | Versions 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 was computed. 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. |
-
net8.0
- BbQ.MockLite (>= 2.0.1)
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.1 | 57 | 11/19/2026 |
| 2.0.0 | 149 | 10/4/2026 |
| 1.1.0 | 197 | 8/4/2026 |
| 1.0.12 | 160 | 3/20/2026 |
| 1.0.11 | 150 | 3/19/2026 |
| 1.0.10 | 148 | 3/18/2026 |
| 1.0.9 | 136 | 3/18/2026 |
| 1.0.8 | 147 | 3/17/2026 |
| 1.0.7 | 147 | 3/6/2026 |
| 1.0.6 | 172 | 12/27/2025 |
| 1.0.5 | 729 | 12/3/2025 |
| 1.0.4 | 716 | 12/2/2025 |
| 1.0.3 | 717 | 12/2/2025 |
| 1.0.2 | 710 | 12/2/2025 |
| 1.0.1 | 733 | 12/2/2025 |
| 1.0.0 | 651 | 12/1/2025 |