Sample: ASP.NET API¶
A realistic but tightly scoped ASP.NET Core minimal-API application demonstrating all four Compono packages working together — enough ASP.NET structure to host the scenario, not an architecture showcase; Compono usage stays the dominant content. Real, buildable code: samples/Compono.Samples.AspNetApi (the app) and samples/Compono.Samples.AspNetApi.Tests (the tests).
What it demonstrates¶
- A reusable profile (
ApiTestProfile) applyingUseNSubstitute()andUseBogus()together, exactly like an application's ownProgram.cswould. - A
[Shared]NSubstitute substitute (IOrderRepository) injected into the system under test, with explicit setup (Returns(...)) layered on top of the composed substitute, then verified withReceived(...)— see theCompono.NSubstitutePackage Guide. - A
Compono.Bogus-generatedCustomer(FirstName/LastName/Emailmatched by member-name convention) composed alongside the NSubstitute substitute with zero interaction between the two packages — see theCompono.BogusPackage Guide. - Inline plus composed theory values in the same row (
[Compose(5)]fixing one parameter while the rest still compose). - One integration-style endpoint test: a real ASP.NET Core host (
WebApplicationFactory<Program>), with the composed[Shared]substitute swapped in for the app's own repository registration — the request travels through real minimal-API routing and model binding, not a direct method call. - Deterministic seed reproduction for the composed
Customerdata.
Packages¶
Compono, Compono.XunitV3, Compono.NSubstitute, Compono.Bogus.
Running it¶
git clone https://github.com/LayeredCraft/compono.git
cd compono
dotnet test samples/Compono.Samples.AspNetApi.Tests/Compono.Samples.AspNetApi.Tests.csproj
Next¶
- Haven't seen the simpler, core-only workflow yet? → Basic Usage.
- Deciding whether to install
Compono.NSubstitute/Compono.Bogusat all? → Package Guides. - One narrow, copy/paste answer instead of a full project? → Cookbook.