Class HasLoggedShorthandExtensions
- Namespace
- TUnit.Assertions.Extensions
- Assembly
- LogAssertions.TUnit.dll
Top-level shorthand entry points that wrap the most common HasLogged()... chains.
Each shorthand is equivalent to spelling out the underlying chain: they exist purely to
reduce ceremony for high-frequency assertions.
public static class HasLoggedShorthandExtensions
- Inheritance
-
HasLoggedShorthandExtensions
- Inherited Members
Remarks
Lives in TUnit.Assertions.Extensions (where TUnit's source generator emits the
core entry-point extension methods like HasLogged()) so consumers do not need a
second using directive to discover these shorthands. If you can call
Assert.That(collector).HasLogged() in a file, you can also call
Assert.That(collector).HasLoggedOnce() there: same auto-import path.
All shorthands return a HasLoggedAssertion, so additional filters can still
be chained after the shorthand: HasLoggedExactly(3).AtLevel(LogLevel.Warning)
asserts "exactly 3 records, all matching the supplied filter set".
Methods
HasLoggedAtLeast<TActual>(IAssertionSource<TActual>, int)
Shorthand for HasLogged().AtLeast(count): at least count matching records.
public static HasLoggedAssertion HasLoggedAtLeast<TActual>(this IAssertionSource<TActual> source, int count) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
countintThe minimum match count. Must be non-negative.
Returns
- HasLoggedAssertion
The assertion, configured for the minimum count.
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedAtMost<TActual>(IAssertionSource<TActual>, int)
Shorthand for HasLogged().AtMost(count): at most count matching records.
public static HasLoggedAssertion HasLoggedAtMost<TActual>(this IAssertionSource<TActual> source, int count) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
countintThe maximum match count. Must be non-negative.
Returns
- HasLoggedAssertion
The assertion, configured for the maximum count.
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedBetween<TActual>(IAssertionSource<TActual>, int, int)
Shorthand for HasLogged().Between(min, max): between min and
max matching records (inclusive).
public static HasLoggedAssertion HasLoggedBetween<TActual>(this IAssertionSource<TActual> source, int min, int max) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
minintThe minimum match count (inclusive). Must be non-negative.
maxintThe maximum match count (inclusive). Must be greater than or equal to
min.
Returns
- HasLoggedAssertion
The assertion, configured for the range.
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedErrorOrAbove<TActual>(IAssertionSource<TActual>)
Shorthand for HasLogged().AtLevelOrAbove(LogLevel.Error): any record at Error or
Critical. Pre-configured for the most common "did anything fail" assertion.
public static HasLoggedAssertion HasLoggedErrorOrAbove<TActual>(this IAssertionSource<TActual> source) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
Returns
- HasLoggedAssertion
The assertion, with the level filter applied.
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedExactly<TActual>(IAssertionSource<TActual>, int)
Shorthand for HasLogged().Exactly(count): exactly count matching records.
public static HasLoggedAssertion HasLoggedExactly<TActual>(this IAssertionSource<TActual> source, int count) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
countintThe required match count. Must be non-negative.
Returns
- HasLoggedAssertion
The assertion, configured for the exact count.
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedNothing<TActual>(IAssertionSource<TActual>)
Shorthand for HasNotLogged() with no filters: asserts the collector has no records
at all. Reads cleaner than HasNotLogged() for the "produced zero log output" case.
public static HasNotLoggedAssertion HasLoggedNothing<TActual>(this IAssertionSource<TActual> source) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
Returns
- HasNotLoggedAssertion
The negative assertion (no further filters needed).
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedOnce<TActual>(IAssertionSource<TActual>)
Shorthand for HasLogged().Once(): exactly one matching record.
public static HasLoggedAssertion HasLoggedOnce<TActual>(this IAssertionSource<TActual> source) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
Returns
- HasLoggedAssertion
The assertion, configured for an exact count of 1.
Type Parameters
TActualThe actual type carried by the assertion source.
HasLoggedWarningOrAbove<TActual>(IAssertionSource<TActual>)
Shorthand for HasLogged().AtLevelOrAbove(LogLevel.Warning): any record at Warning,
Error, or Critical. Pre-configured for the most common "did anything go wrong" assertion.
public static HasLoggedAssertion HasLoggedWarningOrAbove<TActual>(this IAssertionSource<TActual> source) where TActual : FakeLogCollector
Parameters
sourceIAssertionSource<TActual>The assertion source over a Microsoft.Extensions.Logging.Testing.FakeLogCollector.
Returns
- HasLoggedAssertion
The assertion, with the level filter applied.
Type Parameters
TActualThe actual type carried by the assertion source.