Namespace MetricsAssertions
Classes
- CapturedMeasurement
A single captured metric measurement, normalized for assertions: the instrument it came from, its numeric value (any instrument value type, projected to double for uniform querying), the tags attached to it, and the time it was collected.
- InstrumentCapture
A single-instrument measurement capture, built on the first-party Microsoft.Extensions.Diagnostics.Metrics.Testing.MetricCollector<T> primitive (strongly typed, with built-in async waiting and an injectable TimeProvider). The generic value type is erased behind a uniform MeasurementSet surface so heterogeneous instruments share one assertion vocabulary and bundle into a MeterCapture.
Construct via Of<T>(Instrument<T>, TimeProvider?) (when the instrument is referenceable), OfObservable<T>(ObservableInstrument<T>, TimeProvider?), or OfName<T>(string, string, TimeProvider?) (by meter + instrument name - the primitive attaches even to a plain static Meter). For observable instruments, call RecordObservable() before reading. Dispose to release.
- MeasurementSet
An immutable, queryable set of captured measurements - the core unit assertions are written against. Produced by an InstrumentCapture or MeterCapture and narrowed with Tagged(string, object?) / ForInstrument(string). Exposes counter-style aggregates (Total), histogram-style aggregates (Sum/Min/Max/ Average), the raw Values and All measurements, and a deterministic ToSnapshotString() projection for snapshot-style baselines.
- MeterCapture
A meter-wide measurement capture composed from a bundle of per-instrument InstrumentCapture (each backed by a Microsoft.Extensions.Diagnostics.Metrics.Testing.MetricCollector<T>). Built fluently for a known instrument set - strongly typed at construction, uniform to query and assert - for tests that need to assert across several instruments of one meter at once (e.g. an observable-gauge scrape).
Build with For(string) +
Add*; query per instrument via the indexer or CounterTotal(string) / Samples(string) / MeasurementCount(string), or across all via Measurements. Call RecordObservable() before reading observable gauges.
- MeterInspector
Discovery helper for the one thing Microsoft.Extensions.Diagnostics.Metrics.Testing.MetricCollector<T> cannot answer: which instruments a meter actually publishes (a registry question, not a measurement one). Uses a short-lived MeterListener - the only mechanism that enumerates a meter's instruments without knowing their names or value types up front.
Structs
- MeasurementBaseline
An opaque marker for a point in an InstrumentCapture's measurement stream, taken with Snapshot() and passed to Since(MeasurementBaseline) to assert only the measurements recorded after it (the delta produced by an action, independent of whatever a long-lived static meter accumulated before). A baseline is bound to the capture that produced it; passing it to a different capture's Since(MeasurementBaseline) throws.