From 374c45cadb1b609be23a25fbba074ba9d55a0086 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 30 Mar 2021 18:23:27 -0700 Subject: [PATCH 1/2] Add ToString() to Testing's log WriteContext --- src/Testing/src/Logging/WriteContext.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Testing/src/Logging/WriteContext.cs b/src/Testing/src/Logging/WriteContext.cs index 0ecfc8f1a9a7..1f4ad768ba34 100644 --- a/src/Testing/src/Logging/WriteContext.cs +++ b/src/Testing/src/Logging/WriteContext.cs @@ -29,5 +29,10 @@ public string Message return Formatter(State, Exception); } } + + public override string ToString() + { + return $"{LogLevel} {LoggerName}: {Message}"; + } } -} \ No newline at end of file +} From fc769ae37a0484e15fce6cf67f99d3b375ea98a2 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Tue, 30 Mar 2021 18:36:44 -0700 Subject: [PATCH 2/2] Update StrictTestServerTests to only show unexpected log --- .../IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs b/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs index a7a657354619..d04b68af5dc0 100644 --- a/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs +++ b/src/Servers/IIS/IIS/test/IIS.Tests/StrictTestServerTests.cs @@ -1,11 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Testing; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; using Xunit; +using Xunit.Sdk; namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests { @@ -14,7 +16,11 @@ public class StrictTestServerTests: LoggedTest public override void Dispose() { base.Dispose(); - Assert.DoesNotContain(TestSink.Writes, w => w.LogLevel > LogLevel.Information); + + if (TestSink.Writes.FirstOrDefault(w => w.LogLevel > LogLevel.Information) is WriteContext writeContext) + { + throw new XunitException($"Unexpected log: {writeContext}"); + } } protected static TaskCompletionSource CreateTaskCompletionSource()