-
Notifications
You must be signed in to change notification settings - Fork 0
feat(nsubstitute): milestone 5 phase 1 - Compono.NSubstitute package #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ncipollina
merged 3 commits into
main
from
feat/milestone-5-phase-1-nsubstitute-package
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
bd2f72b
feat(nsubstitute): milestone 5 phase 1 - Compono.NSubstitute package
ncipollina bd47a90
docs(xunitv3): shorten PrivateAssets comment on Compono reference
ncipollina d04fa41
docs(nsubstitute): stop describing Compono.NSubstitute as not impleme…
ncipollina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <LangVersion>latest</LangVersion> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <TargetFrameworks>net10.0;net11.0</TargetFrameworks> | ||
| <Description>NSubstitute integration for Compono - a test-double provider composing interface, delegate, and (optionally) abstract-class parameters as real NSubstitute substitutes. See docs/adr/0024-public-provider-extensibility-model.md and docs/adr/0025-compono-nsubstitute-package-design.md.</Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- Compono packs its source generator as an analyzer asset. PrivateAssets="none" allows | ||
| that analyzer to flow through this integration package to consumers that reference | ||
| only Compono.NSubstitute. --> | ||
| <ProjectReference Include="..\Compono\Compono.csproj" PrivateAssets="none" /> | ||
| <PackageReference Include="NSubstitute" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <InternalsVisibleTo Include="Compono.NSubstitute.Tests" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace Compono; | ||
|
|
||
| /// <summary> | ||
| /// Activates <see cref="NSubstituteProvider"/> on a <see cref="CompositionBuilder"/>. See | ||
| /// <c>docs/adr/0025-compono-nsubstitute-package-design.md</c>. | ||
| /// </summary> | ||
| public static class CompositionBuilderExtensions | ||
| { | ||
| extension(CompositionBuilder builder) | ||
| { | ||
| /// <summary> | ||
| /// Registers an <see cref="NSubstituteProvider"/> with default <see cref="NSubstituteOptions"/>. | ||
| /// </summary> | ||
| public CompositionBuilder UseNSubstitute() => builder.UseNSubstitute(static _ => { }); | ||
|
|
||
| /// <summary> | ||
| /// Registers an <see cref="NSubstituteProvider"/>, configured by <paramref name="configure"/>. | ||
| /// </summary> | ||
| /// <param name="configure">Sets the provider's <see cref="NSubstituteOptions"/>.</param> | ||
| public CompositionBuilder UseNSubstitute(Action<NSubstituteOptions> configure) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(configure); | ||
| var options = new NSubstituteOptions(); | ||
| configure(options); | ||
| return builder.AddTestDoubleProvider(new NSubstituteProvider(options)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace Compono; | ||
|
|
||
| /// <summary> | ||
| /// Configuration for <see cref="NSubstituteProvider"/>, set via | ||
| /// <c>CompositionBuilderExtensions.UseNSubstitute(Action{NSubstituteOptions})</c>. See | ||
| /// <c>docs/adr/0025-compono-nsubstitute-package-design.md</c>. | ||
| /// </summary> | ||
| public sealed class NSubstituteOptions | ||
| { | ||
| /// <summary> | ||
| /// Whether an unsealed abstract class is substitutable, in addition to every interface and | ||
| /// delegate type. Defaults to <see langword="true"/>. | ||
| /// </summary> | ||
| public bool SubstituteAbstractClasses { get; set; } = true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| using NSubstitute; | ||
|
|
||
| namespace Compono; | ||
|
|
||
| /// <summary> | ||
| /// A stage-6 test-double provider that composes an interface, delegate, or (when | ||
| /// <see cref="NSubstituteOptions.SubstituteAbstractClasses"/> allows it) unsealed abstract-class | ||
| /// request as a real NSubstitute substitute, via <see cref="Substitute.For(Type[], object[])"/>. | ||
| /// Registered via <c>CompositionBuilderExtensions.UseNSubstitute()</c>. See | ||
| /// <c>docs/adr/0025-compono-nsubstitute-package-design.md</c> (Amendment 1 for the corrected shape | ||
| /// below). | ||
| /// </summary> | ||
| public sealed class NSubstituteProvider : ICompositionValueProvider | ||
| { | ||
| private readonly bool _substituteAbstractClasses; | ||
|
|
||
| /// <summary> | ||
| /// Creates an <see cref="NSubstituteProvider"/>, snapshotting <paramref name="options"/>'s | ||
| /// current values - the provider never retains the caller-owned <see cref="NSubstituteOptions"/> | ||
| /// instance itself, so a caller mutating it after construction can't change this | ||
| /// already-registered provider's behavior (ADR-0024's immutable-provider-registration guarantee). | ||
| /// </summary> | ||
| /// <param name="options">The options to snapshot.</param> | ||
| public NSubstituteProvider(NSubstituteOptions options) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(options); | ||
| _substituteAbstractClasses = options.SubstituteAbstractClasses; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public CompositionProviderResult TryProvide(in CompositionProviderRequest request, ICompositionContext context) | ||
| { | ||
| if (!IsSubstitutable(request.RequestedType, _substituteAbstractClasses)) | ||
| return CompositionProviderResult.NotHandled; | ||
|
|
||
| return CompositionProviderResult.Handled(Substitute.For([request.RequestedType], [])); | ||
| } | ||
|
|
||
| // ADR-0025 Amendment 1: IsSubclassOf(typeof(MulticastDelegate)), not | ||
| // typeof(Delegate).IsAssignableFrom(requestedType) - the latter wrongly matches the | ||
| // non-substitutable Delegate/MulticastDelegate framework base types themselves. | ||
| internal static bool IsSubstitutable(Type requestedType, bool substituteAbstractClasses) => | ||
| requestedType.IsInterface | ||
| || requestedType.IsSubclassOf(typeof(MulticastDelegate)) | ||
| || (substituteAbstractClasses && requestedType.IsAbstract && !requestedType.IsSealed && !requestedType.IsInterface); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking Phase 1 done while leaving
docs/public-api.md:425-427anddocs/mvp.md:270-276saying thatCompono.NSubstituteis “not yet implemented” makes the API and roadmap documentation contradict the packable project and public entry points added by this commit. This affects readers immediately after the change lands, even if verification remains pending in Phase 2; update those statements to distinguish implemented package code from pending tests rather than deferring the correction to Phase 3.AGENTS.md reference: AGENTS.md:L156-L157
Useful? React with 👍 / 👎.