Skip to content

Commit

Permalink
Adding LogsShouldNotContainErrorsAsync()
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Nov 10, 2024
1 parent 1fbb8c5 commit 264d6ce
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Lombiq.Tests.UI/Extensions/WebApplicationInstanceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lombiq.Tests.UI.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Shouldly;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -54,6 +55,28 @@ public static Task LogsShouldContainAsync(
CancellationToken cancellationToken = default) =>
AssertLogsAsync(webApplicationInstance, logEntryPredicate, ShouldBeEnumerableTestExtensions.ShouldContain, cancellationToken);

/// <summary>
/// Asserts that the logs should NOT contain any entries with <see cref="LogLevel.Error"/> and above. If the
/// assertion fails, the Shouldly exception will contain all log entries.
/// </summary>
/// <remarks>
/// <para>
/// If you want to inspect the logs in a more structured way, message by message, consider using <see
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> directly instead. Alternatively, set log
/// filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// configuration (see the samples).
/// </para>
/// </remarks>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can cancel the log retrieval.</param>
public static Task LogsShouldNotContainErrorsAsync(
this IWebApplicationInstance webApplicationInstance,
CancellationToken cancellationToken = default) =>
AssertLogsAsync(
webApplicationInstance,
logEntry => logEntry.Level > LogLevel.Error,
ShouldBeEnumerableTestExtensions.ShouldNotContain,
cancellationToken);

/// <summary>
/// Asserts that the logs should NOT contain any entries matching the given predicate. If the assertion fails, the
/// Shouldly exception will contain all log entries.
Expand Down

0 comments on commit 264d6ce

Please sign in to comment.