Repository navigation
v0.13.0
·
53 commits
to main
since this release
Immutable
release. Only release title and notes can be modified.
[0.13.0] - 2026-11-01: wait for a log from background work, a discarding logger factory
Minor release. Event-driven waits return once background work has logged a matching record, without polling; LogCollectorBuilder.CreateDiscarding gives an enabled logger that keeps nothing; the sequence and When configurators take expression lambdas. One source-breaking edge (see Changed).
Added
FakeLogCollector.WaitForLogAsync(ILogRecordFilter filter, CancellationToken cancellationToken)waits until the collector holds a record that matches the filter and returns it. It is built onFakeLogCollector.GetLogsAsync, so it wakes on each new record, with no polling interval and no real-time delay; records logged before the call count. On cancellation theOperationCanceledExceptionsays how many records arrived and how many matched.FakeLogCollector.WaitForLogAsync(Func<FakeLogRecord, bool> predicate, CancellationToken cancellationToken)is the predicate form.FakeLogCollector.WaitForLogsAsync(ILogRecordFilter filter, int count, CancellationToken cancellationToken)waits forcountmatching records and returns them in the order they were logged.LogCollectorBuilder.CreateDiscarding(LogLevel minimumLevel = LogLevel.Trace)returns anILoggerFactorywhose loggers are enabled atminimumLeveland above but keep nothing, so code guarded bylogger.IsEnabled(...)runs its logging branch under coverage without a collector that grows in a long-lived host. It replaces the discarding provider the README used to show.HasLoggedSequence().ThenAnyOrder(params Func<HasLoggedSequenceAssertion, HasLoggedSequenceAssertion>[])andWhen(bool, Func<TSelf, TSelf>)(on everyHasLogged/HasNotLogged/HasLoggedSequencechain) take configurators that return the assertion, which is what an expression lambda such ass => s.Containing("x", StringComparison.Ordinal)does. Such lambdas now bind to these overloads, so the awaitable assertion they return is observed instead of discarded, and analyzers that require awaitables to be observed (Meziantou.Analyzer MA0134 from 3.0.318, Microsoft.VisualStudio.Threading.Analyzers VSTHRD110 from 18.12) no longer report every configurator. Statement-lambda configurators keep binding to the existingActionoverloads, with the same semantics. AThenAnyOrdercall that mixes a statement lambda with expression lambdas binds as a whole to theActionoverload, so its expression lambdas still discard their result; write every sub-step of such a call as an expression lambda.
Changed
- BREAKING:
ThenAnyOrder()with no argument no longer compiles; passArray.Empty<Action<HasLoggedSequenceAssertion>>()instead.ThenAnyOrder(null)andWhen(condition, null)with a barenullneed a cast to theActionorFunctype to choose an overload. Calls that pass lambdas are unaffected. TUnit.AssertionsandTUnit.Coreminimum versions raised from 1.58.0 to 1.77.0, andMicrosoft.Extensions.Diagnostics.Testingfrom 10.7.0 to 10.11.0 (GetLogsAsync, which the waits build on, needs 10.9.0 or later).- README: waiting for a log from background work uses
WaitForLogAsyncinstead of polling withEventually; theHasLoggedOnlysection frames the gate as an audit that is expected to fail the first time and points to counts; the snapshot section recommends a scrubber set and explains migrating from a hand-rolled renderer;TUnit.Mocks.Loggingis compared with collector capture.