Mockolate is a source-generated mocking library for .NET. Users write IFoo.CreateMock(); a Roslyn incremental generator emits the mock at compile time, analyzers validate the usage, and the runtime library records interactions, evaluates setups and answers verifications. Read the docs under References only when a task needs them.
- Use the SDK pinned in
global.json(currently .NET 11,rollForward: latestPatch). Tests also run on .NET 10 and .NET 8, and on .NET Framework 4.8 on Windows only. The test projects compile with C# 15 on every framework, butTests/Directory.Build.propssetsMockolateDisableUnionParametersfor all exceptnet11.0, so the union-typed setup surface is exercised on .NET 11 and the classic one on the others. - Build from the root with
dotnet build Mockolate.slnx. Shared settings live in the rootDirectory.Build.props(strong naming,MinimumRoslynVersion),Source/Directory.Build.props(target frameworks, warnings as errors, AOT and trimming flags) andTests/Directory.Build.props(test frameworks, TUnit, aweXpect). - Package versions belong only in
Directory.Packages.props.VersionOverrideis used only to pin Roslyn packages to$(MinimumRoslynVersion).
Correctness is a must. The other goals are strong defaults and win in this order when they conflict: generated code compiles in every consumer, stable and compatible (including the generated surface), AOT and trimming by construction, errors at compile time, one consistent API under sut.Mock, an allocation-free hot path, extensible, documented. Docs/agents/design-goals.md explains each goal and the checks before a commit; Docs/agents/conventions.md lists the concrete rules for the library, the generator, the analyzers, the tests and the docs.
- Target frameworks:
Mockolateshipsnetstandard2.0,net8.0,net10.0andnet11.0. The generator, analyzers and code fixers targetnetstandard2.0only. Code compiled fornetstandard2.0ornet48has noIsExternalInit,System.IndexorSystem.Rangeunless polyfilled, so records,initand list patterns need care:MockolatepolyfillsIsExternalInit,Mockolate.Testsdoes not, and guards such code with#if NET8_0_OR_GREATER. - Roslyn version: the generator, analyzers and code fixers compile against
MinimumRoslynVersion(5.0.0), the oldest compiler they must load in. Never use a newer Roslyn API. It cannot drop below 5.0 because the emittedMock.g.csuses a C# 14 extension block. - Generated code runs inside every consumer's compilation. Keep it reflection-free, fully qualified with
global::, clash-free with user member names, valid under nullable and warnings-as-errors, and deterministic. The generator reports no diagnostics: it skips what it cannot mock andMockabilityAnalyzerreports it, so mockability rules change in both. Keep the generator incremental: pipeline entities must have value equality (EquatableArray, records) so caching works;MockGenerator.EqualityTestscovers this. - Arity: the library hand-writes setup and verification types for up to four parameters; the generator emits the same shapes for more. A change to one arity applies to every arity in both places.
- Analyzers: rule IDs are
MockolateNNNN. Add the descriptor inRules.cs, its texts inResources.resx, the row inAnalyzerReleases.Unshipped.mdand the user docs inDocs/pages/10-analyzers.md. - AOT and trimming: the runtime library sets
IsAotCompatibleandIsTrimmablefornet8.0+ with warnings as errors. Do not add reflection-based dispatch to the library or the generated code. - Performance: recording, setup matching and verification are hot paths with allocation-free fast paths (
FastMockInteractions, the*Recordstypes). Measure hot-path changes with the benchmarks before and after. - Public API: every change to the public surface of
Mockolateshows up in the API snapshots. Document new public members with XML comments. Mark breaking changes with!in the PR title (feat!:,refactor!:). - Strong naming: all assemblies are signed with
strongname.snk; anInternalsVisibleToneedsPublicKey="$(PublicKey)". - Style: follow
.editorconfig: tabs, explicit types instead ofvar, nothis.,Systemusings first; private fields are_camelCase. New extension members use C# 14extensionblocks. Tests use TUnit with aweXpect (await That(...)) and are preferably named<Subject>_Should<Outcome>.
- Run the tests for what you changed before pushing; see workflows.
- Generator output changes must update the snapshots in
Tests/Mockolate.SourceGenerators.Tests/Snapshot/MockGenerationSnapshotTests: run the tests withAWEXPECT_ACCEPT_SNAPSHOTS=alland review the diff. New generator special cases go intoTests/Mockolate.Tests/GeneratorCoverage, which both test projects share. - Public API changes must update
Tests/Mockolate.Api.Tests/ApiApprovalTests/Mockolate/*.awexpect-snapshot.cs(one per target framework). Never commit*.awexpect-snapshot.pending.*. - Analyzer and code fix changes need tests in
Tests/Mockolate.Analyzers.Tests. - Changes in
Pipeline/BenchmarkReport.csneedTests/Build.Tests. - Coverage must stay above 90% and SonarCloud must report no issues.
- Files are stored with LF and checked out with CRLF on Windows (
.gitattributestext=auto,.editorconfigend_of_line = crlf). Raw string literals take the file's line endings, so compare multi-line strings with.IgnoringNewlineStyle(). - Some files start with a UTF-8 BOM and most do not. Keep each file's encoding: prefer the edit tools over PowerShell rewrites (
Set-Content,Out-File), which add or drop the BOM depending on version and-Encoding, and checkgit difffor a changed U+FEFF. - User docs live in
Docs/pages/and are published to https://docs.testably.org/Mockolate/. Update them for user-visible changes. The README is the NuGet landing page and links there; update it only when the features or the getting started steps change.
Pages under Docs/pages are published on docs.testably.org and follow the docs style guide. The key rules:
- US English, sentence case for headings and labels, no em dashes, one line per paragraph.
- A
descriptionin the front matter of every page; the H1 is the title; order with uniqueNN-prefixes. - Relative file links within the repository, site-absolute
/Library/...links across libraries. - Install instructions only through
<PackageInstall package="..." />, never hand-written commands or NuGet badges. - Examples check results with
await That(...); complete examples use TUnit[Test].
The Mockolate-specific documentation rules are in Conventions.
- Branch from
mainand open a pull request. PRs are squash-merged, so the PR title becomes the commit subject and must follow conventional commits (feat:,fix:,refactor:,test:,docs:,ci:,chore:). - Commit messages: the subject is the PR title, the body explains why (not what or how), each paragraph is a single line, and there are no co-author or attribution trailers.
- Never commit
.claude/,Artifacts/,TestResults/or pending snapshots. - Dependabot PRs use
chore:and are auto-merged by Mergify once unit and API tests pass. Pushing avX.Y.Ztag publishes to nuget.org; do not create tags unless asked. - Check review findings against the code before acting on them.
- Design goals: the goals for every change, in priority order, and the checks before a commit.
- Conventions: API shape, hot path, exceptions and messages, generator, analyzer, test and docs rules.
- Workflows: build, test, snapshot, benchmark, mutation, AOT and documentation commands, the Fallout targets in
Pipeline/and the CI workflows. - Project structure: projects, architecture and where code lives.