Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/cookbook/vary-composed-configuration-per-theory-row.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,33 @@ receives, `builder.Register(() => config)`, and add a composed `TConfig`
parameter after the row values. It resolves to that row's own instance.
See [Reading the row's `TConfig`](../packages/compono-xunitv3.md#per-row-configuration).

**Optional: a consumer-side base profile.** If many profiles repeat that
line, you can reduce the boilerplate with your own small base type — this
is a convenience in your test project, not a Compono type or API, and
Compono won't ship it:

```csharp
public abstract class ConfigProfile<TConfig>(TConfig config) : ICompositionProfile
where TConfig : class
{
protected TConfig Config => config;

public void Configure(CompositionBuilder builder)
{
builder.Register(() => config);
ConfigureCore(builder);
}

protected abstract void ConfigureCore(CompositionBuilder builder);
}
```

`PricingProfile` could derive from `ConfigProfile<PricingConfig>` and put
only its own registrations in `ConfigureCore`. A derived profile must not
also call `Register(() => config)` for `TConfig` — that's a duplicate
registration and fails composition (a `CompositionException` wrapping a
`CompositionConfigurationException`).

**`[Shared]` still works.** Mark a parameter `[Shared]` and, when a row
supplies a value at that position, that value becomes the single instance
every other parameter in the row resolving that type receives; otherwise
Expand Down
4 changes: 4 additions & 0 deletions docs/packages/compono-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ composition to work. There is no separate MSBuild opt-in to remember, no
"How this actually runs," below, for what "on by default" means
mechanically and how to opt back out.

**Forgot `UseLogging()`?** A composition failure naming `ILogger` or
`ILogger<T>` usually means it wasn't registered — see [Runtime composition
failures](../troubleshooting/common-errors.md#runtime-composition-failures).

## What it gives you

```csharp
Expand Down
28 changes: 24 additions & 4 deletions docs/packages/compono-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ not `Microsoft.Extensions.Diagnostics`, not
`Microsoft.Extensions.Diagnostics.Testing`, not
`Microsoft.Extensions.DependencyInjection.Abstractions`.

**No MSBuild opt-in.** Unlike `Compono.TestDoubles`, there is nothing to
enable — `Compono.Metrics` ships no generator, analyzer, or props asset.
`UseMetrics()` works as soon as the package is referenced.
**No generation opt-in.** Unlike `Compono.TestDoubles`, there is nothing to
enable: `Compono.Metrics` ships no generator or analyzer, and `UseMetrics()`
works as soon as the package is referenced. The package includes a
`build`/`buildTransitive` props asset that defaults
`ComponoMetricsOwnsMeterFactory` to `true`, so `Compono.Generators` never
emits a `Compono.TestDoubles` double for `IMeterFactory`; consumers can
override that property (set it to `false`) but don't need to configure it
themselves. See
[Registration order and misuse](#registration-order-and-misuse).

**Forgot `UseMetrics()`?** A composition failure naming `IMeterFactory`
usually means it wasn't registered — see [Runtime composition
failures](../troubleshooting/common-errors.md#runtime-composition-failures).

## What it gives you

Expand All @@ -55,7 +65,7 @@ var service = composer.Create<OrderService>(); // OrderService(IMeterFactory m
public sealed class MetricsProfile : ICompositionProfile
{
public void Configure(CompositionBuilder builder) =>
builder.UseMetrics().Share<IMeterFactory>();
builder.UseMetrics();
}

[Theory]
Expand All @@ -71,6 +81,16 @@ public void PlacingAnOrderCountsIt([Shared] IMeterFactory meters, OrderService s
}
```

**`[Shared]` and `Share<IMeterFactory>()` — use one or the other.** The
parameter above is `[Shared]`, so the test and the SUT receive the same
factory with no `Share<T>()` needed; `[Shared]` resolves first, whatever
its parameter position. Use `Share<IMeterFactory>()` in the profile
instead for profile-wide intent — an undecorated `IMeterFactory` parameter,
or several consumers in one `Composer.Create` graph. Declaring both is
redundant but harmless. What matters is the sharing, not the mechanism:
each `CapturingMeterFactory` captures only the meters it created, so a
test observing a different instance sees no measurements.

```csharp
var placed = meters.GetMeasurements<long>("Shop.Orders", "shop.orders.placed");
Assert.Equal(1, placed.Sum(m => m.Value)); // value math via LINQ
Expand Down
10 changes: 10 additions & 0 deletions docs/packages/compono-xunitv3-aot.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ unchanged on this package. See [`Compono.XunitV3`'s per-row
configuration](compono-xunitv3.md#per-row-configuration) and
[Use Profiles](../how-to/use-profiles.md#a-profile-whose-constructor-takes-runtime-objects).

**Failure granularity is the same whole-theory contract** (ADR-0070 item 9):
all rows are composed before any row runs, so one row's composition failure
stops the rest — including rows that would have passed — and the theory
reports a single failed result instead of one per row, so the reported test
count can drop while the failure is present. Every data attribute on the
method, including `[InlineData]` rows, is affected. Fix the failing row and
every row runs and is counted again. On AOT, an unsupported row/shape is
usually a compile-time `CMP` diagnostic instead of this runtime failure — see
[ComposeData diagnostics on Native AOT](#composedata-diagnostics-on-native-aot).

## Not yet supported

`Compono.XunitV3.Aot.ComposeAttribute`'s three forms don't support inline
Expand Down
22 changes: 20 additions & 2 deletions docs/packages/compono-xunitv3.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ This works the same on `Compono.XunitV3.Aot`. Both engines are proven by
([RESEARCH-0040](../research/0040-issue-161-1-4-dogfood-follow-up.md)
finding 2).

**Optional consumer-side base profile.** If many profiles repeat
`builder.Register(() => config)`, you can write your own
`ConfigProfile<TConfig>` base to hold that one line — see [Vary Composed
Configuration per Theory
Row](../cookbook/vary-composed-configuration-per-theory-row.md#solution).
It's a convenience type in your test project, not a Compono API. A derived
profile must not also register `TConfig` (that's a duplicate
registration).

### Shared dependencies and `[Shared]`

A `[Shared]` parameter works the same as under `[Compose]`: it names the one
Expand Down Expand Up @@ -455,8 +464,17 @@ Every failure — reading the member, building one row's profile, or composing a
row — throws a `CompositionException` that names the member (`Type.Member`). A
row failure also names the **zero-based row index** and the row's label when it
has one, and (per the rule below) a seed; a member-level failure has no row
index. The whole theory fails as a unit: there are no placeholder rows
and no custom invoker to keep the other rows running. The original cause is
index.

The whole theory fails as a unit: there are no placeholder rows and no custom
invoker to keep the other rows running. Composition happens when the theory
runs, and **all** rows are built before any row executes. A composition
failure in one row therefore stops the rest: no row of that theory executes,
including rows that would have passed. The theory then reports a **single**
failed result instead of one result per row, so the suite's reported test
count can drop while the failure is present. Every data attribute on the same
method is affected, including its `[InlineData]` rows. Once the composition
error is fixed, every row runs and is counted again. The original cause is
preserved as the exception's `InnerException`, and any `Diagnostic` is carried
through.

Expand Down
Loading
Loading