From 264d6ce93889689b92ef7654dc1ed53effda24af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sun, 10 Nov 2024 20:51:37 +0100 Subject: [PATCH] Adding LogsShouldNotContainErrorsAsync() --- .../WebApplicationInstanceExtensions.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Lombiq.Tests.UI/Extensions/WebApplicationInstanceExtensions.cs b/Lombiq.Tests.UI/Extensions/WebApplicationInstanceExtensions.cs index 2e699330f..2dda322b2 100644 --- a/Lombiq.Tests.UI/Extensions/WebApplicationInstanceExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/WebApplicationInstanceExtensions.cs @@ -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; @@ -54,6 +55,28 @@ public static Task LogsShouldContainAsync( CancellationToken cancellationToken = default) => AssertLogsAsync(webApplicationInstance, logEntryPredicate, ShouldBeEnumerableTestExtensions.ShouldContain, cancellationToken); + /// + /// Asserts that the logs should NOT contain any entries with and above. If the + /// assertion fails, the Shouldly exception will contain all log entries. + /// + /// + /// + /// If you want to inspect the logs in a more structured way, message by message, consider using 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). + /// + /// + /// A that can cancel the log retrieval. + public static Task LogsShouldNotContainErrorsAsync( + this IWebApplicationInstance webApplicationInstance, + CancellationToken cancellationToken = default) => + AssertLogsAsync( + webApplicationInstance, + logEntry => logEntry.Level > LogLevel.Error, + ShouldBeEnumerableTestExtensions.ShouldNotContain, + cancellationToken); + /// /// 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.