Table of Contents

Class MeasurementSetAssertions

Namespace
MetricsAssertions.TUnit
Assembly
MetricsAssertions.TUnit.dll

TUnit-native fluent Assert.That(set).Has* assertions over a MeasurementSet: counter totals, measurement counts, emptiness, histogram sample sum / average / range, exact and order-insensitive sample sets, and tag-consistency. Narrow first with Tagged(string, object?) / ForInstrument(string) to assert a dimension. Generated via the TUnit [GenerateAssertion] source generator (AOT-clean).

public static class MeasurementSetAssertions
Inheritance
MeasurementSetAssertions
Inherited Members

Methods

HasAllSamplesInRange(MeasurementSet, double, double)

Asserts every sample lies within the inclusive range [min, max].

[GenerateAssertion]
public static AssertionResult HasAllSamplesInRange(this MeasurementSet value, double min, double max)

Parameters

value MeasurementSet

The measurement set.

min double

The inclusive lower bound.

max double

The inclusive upper bound.

Returns

AssertionResult

A passing assertion when every sample is in range; otherwise a failing one.

Exceptions

ArgumentNullException

value is null.

HasCounterTotal(MeasurementSet, long)

Asserts the net total of the values equals expected.

[GenerateAssertion]
public static AssertionResult HasCounterTotal(this MeasurementSet value, long expected)

Parameters

value MeasurementSet

The measurement set.

expected long

The expected net total.

Returns

AssertionResult

A passing assertion when the total matches; otherwise a failing one naming both values.

Exceptions

ArgumentNullException

value is null.

HasCounterTotalAtLeast(MeasurementSet, long)

Asserts the net total of the values is at least expected.

[GenerateAssertion]
public static AssertionResult HasCounterTotalAtLeast(this MeasurementSet value, long expected)

Parameters

value MeasurementSet

The measurement set.

expected long

The minimum expected net total.

Returns

AssertionResult

A passing assertion when the total is at least the expected; otherwise a failing one.

Exceptions

ArgumentNullException

value is null.

HasEveryMeasurementTagged(MeasurementSet, string)

Asserts every measurement carries a tag with key tagKey.

[GenerateAssertion]
public static AssertionResult HasEveryMeasurementTagged(this MeasurementSet value, string tagKey)

Parameters

value MeasurementSet

The measurement set.

tagKey string

The tag key that must be present on every measurement.

Returns

AssertionResult

A passing assertion when every measurement is tagged; otherwise a failing one.

Exceptions

ArgumentNullException

value or tagKey is null.

HasMeasurementCount(MeasurementSet, int)

Asserts the number of measurements equals expected.

[GenerateAssertion]
public static AssertionResult HasMeasurementCount(this MeasurementSet value, int expected)

Parameters

value MeasurementSet

The measurement set.

expected int

The expected measurement count.

Returns

AssertionResult

A passing assertion when the count matches; otherwise a failing one naming both counts.

Exceptions

ArgumentNullException

value is null.

HasNoMeasurements(MeasurementSet)

Asserts the set is empty.

[GenerateAssertion]
public static AssertionResult HasNoMeasurements(this MeasurementSet value)

Parameters

value MeasurementSet

The measurement set.

Returns

AssertionResult

A passing assertion when the set is empty; otherwise a failing one naming the count.

Exceptions

ArgumentNullException

value is null.

HasSampleAverage(MeasurementSet, double, double)

Asserts the mean of the histogram samples equals expected (within tolerance).

[GenerateAssertion]
public static AssertionResult HasSampleAverage(this MeasurementSet value, double expected, double tolerance = 0)

Parameters

value MeasurementSet

The measurement set.

expected double

The expected average.

tolerance double

The allowed absolute difference (exact by default).

Returns

AssertionResult

A passing assertion when the average is within tolerance; otherwise a failing one.

Exceptions

ArgumentNullException

value is null.

HasSampleSum(MeasurementSet, double, double)

Asserts the sum of the histogram samples equals expected (within tolerance).

[GenerateAssertion]
public static AssertionResult HasSampleSum(this MeasurementSet value, double expected, double tolerance = 0)

Parameters

value MeasurementSet

The measurement set.

expected double

The expected sum.

tolerance double

The allowed absolute difference (exact by default).

Returns

AssertionResult

A passing assertion when the sum is within tolerance; otherwise a failing one.

Exceptions

ArgumentNullException

value is null.

HasSamples(MeasurementSet, IReadOnlyList<double>, double)

Asserts the samples equal expected in order, each within tolerance (absolute), the tolerant counterpart of HasSamples(MeasurementSet, params double[]) for samples fed computed doubles.

[GenerateAssertion]
public static AssertionResult HasSamples(this MeasurementSet value, IReadOnlyList<double> expected, double tolerance)

Parameters

value MeasurementSet

The measurement set.

expected IReadOnlyList<double>

The expected samples, in order.

tolerance double

The allowed absolute difference per sample.

Returns

AssertionResult

A passing assertion when the samples match in order within tolerance; otherwise a failing one.

Exceptions

ArgumentNullException

value or expected is null.

ArgumentOutOfRangeException

tolerance is negative or non-finite.

HasSamples(MeasurementSet, params double[])

Asserts the samples equal expected in order.

[GenerateAssertion]
public static AssertionResult HasSamples(this MeasurementSet value, params double[] expected)

Parameters

value MeasurementSet

The measurement set.

expected double[]

The expected samples, in order.

Returns

AssertionResult

A passing assertion when the samples match in order; otherwise a failing one.

Exceptions

ArgumentNullException

value or expected is null.

HasSamplesInAnyOrder(MeasurementSet, IReadOnlyList<double>, double)

Asserts the samples equal expected regardless of order, each within tolerance (absolute), the tolerant counterpart of HasSamplesInAnyOrder(MeasurementSet, params double[]) for samples fed computed doubles.

[GenerateAssertion]
public static AssertionResult HasSamplesInAnyOrder(this MeasurementSet value, IReadOnlyList<double> expected, double tolerance)

Parameters

value MeasurementSet

The measurement set.

expected IReadOnlyList<double>

The expected samples, in any order.

tolerance double

The allowed absolute difference per sample.

Returns

AssertionResult

A passing assertion when the samples match in any order within tolerance; otherwise a failing one.

Exceptions

ArgumentNullException

value or expected is null.

ArgumentOutOfRangeException

tolerance is negative or non-finite.

HasSamplesInAnyOrder(MeasurementSet, params double[])

Asserts the samples equal expected regardless of order.

[GenerateAssertion]
public static AssertionResult HasSamplesInAnyOrder(this MeasurementSet value, params double[] expected)

Parameters

value MeasurementSet

The measurement set.

expected double[]

The expected samples, in any order.

Returns

AssertionResult

A passing assertion when the samples match in any order; otherwise a failing one.

Exceptions

ArgumentNullException

value or expected is null.

HasTaggedMeasurement(MeasurementSet, string, object?)

Asserts at least one measurement carries a tag tagKey equal to tagValue.

[GenerateAssertion]
public static AssertionResult HasTaggedMeasurement(this MeasurementSet value, string tagKey, object? tagValue)

Parameters

value MeasurementSet

The measurement set.

tagKey string

The tag key to match.

tagValue object

The tag value to match.

Returns

AssertionResult

A passing assertion when a matching measurement exists; otherwise a failing one.

Exceptions

ArgumentNullException

value or tagKey is null.