Skip to content

Fix 406: Adds tests for disabling source generators#407

Merged
Keboo merged 5 commits intomasterfrom
fix406
Dec 5, 2025
Merged

Fix 406: Adds tests for disabling source generators#407
Keboo merged 5 commits intomasterfrom
fix406

Conversation

@Keboo
Copy link
Collaborator

@Keboo Keboo commented Dec 5, 2025

Summary

Introduces a new test project to thoroughly verify the functionality of disabling individual Moq.AutoMocker source generators via MSBuild properties.

Motivation

Ensures that consumers of the Moq.AutoMock NuGet package can successfully opt-out of specific source generator features by setting dedicated MSBuild properties. This provides flexibility and control over the code generation process.

Changes

  • Introduces a new test project (GeneratorTests/Moq.AutoMock.Generator.DisableTests) configured to build with all Moq.AutoMocker generators explicitly disabled.
  • Adds reflection-based Xunit tests within the new project to confirm the absence of generated extension methods when generators are disabled.
  • Includes a build/Moq.AutoMock.props file within the Moq.AutoMock NuGet package to make generator disable properties visible to the Roslyn compiler during package consumption.
  • Updates the CI workflow (dotnetcore.yml) to integrate and run these new generator disable tests.
  • Adds Microsoft.Extensions.DependencyInjection.Abstractions to Directory.Packages.props for the new test project.
  • Increments the Moq.AutoMock package version.

Fixes #406

Introduces a new test project, `Moq.AutoMock.Generator.DisableTests`, to verify that individual source generators can be correctly disabled using MSBuild properties.

These tests assert that when a generator is explicitly disabled via properties like `EnableMoqAutoMockerOptionsGenerator=false`, its associated generated extension methods are not present in the consuming assembly.

A `Moq.AutoMock.props` file is included in the package to make these disable properties visible to the Roslyn compiler, enabling generators to respect them.

The CI workflow is updated to build and run these new tests, ensuring continuous validation of the generator disable functionality. `Microsoft.Extensions.DependencyInjection.Abstractions` is also added as a package dependency.
@Keboo Keboo enabled auto-merge (squash) December 5, 2025 19:09
Keboo added 4 commits December 5, 2025 11:12
Updates the `dotnet test` command in the build workflow to explicitly use the `--project` flag, improving command reliability. Also, corrects the configuration key from `target` to `applyTo` in the source generator documentation agent.

Fixes #406
Uses `VersionOverride` for the local `Moq.AutoMock` package reference to bypass Central Package Management. This ensures that locally-built packages, especially those with CI version suffixes, are correctly resolved in the test project without interference from CPM.

Fixes #406
Adjusts NuGet configuration to prioritize local `Moq.AutoMock` package sources, ensuring generator tests consistently use locally-built versions. This setup is crucial for validating generator behavior against specific development builds.

Updates the `PackageReference` `VersionOverride` to `*` to reliably match any local package version, including prerelease suffixes often used in CI builds.

Fixes #406
Updates the `VersionOverride` for the `Moq.AutoMock` package reference from `*` to `*-*`.
This improves matching for both stable and prerelease versions (e.g., `3.6.2-ci0123`) when consuming a locally-built package in CI and local development environments.

Fixes #406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Are you sure EnableMoqAutoMockerOptionsGenerator switch (and any other) really works?

1 participant