From af6136cfc4e67ea0a13227c97920369b16e8e98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D0=BD=D0=B8=D0=BD=20=D0=A1=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B0=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 16 Jul 2026 10:47:34 +0300 Subject: [PATCH 1/2] feat(xunit logging): TestOutputHelperWireMockLogger allow to provide current test output helper --- .../TestOutputHelperWireMockLogger.cs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs b/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs index bda59781d..60d84ab02 100644 --- a/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs +++ b/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs @@ -1,6 +1,5 @@ // Copyright © WireMock.Net -using System; using Newtonsoft.Json; using Stef.Validation; using WireMock.Admin.Requests; @@ -14,51 +13,61 @@ namespace WireMock.Net.Xunit; /// public sealed class TestOutputHelperWireMockLogger : IWireMockLogger { - private readonly ITestOutputHelper _testOutputHelper; + private readonly Func _testOutputHelperFactory; /// /// Create a new instance on the . /// /// Represents a class which can be used to provide test output. - public TestOutputHelperWireMockLogger(ITestOutputHelper testOutputHelper) + public TestOutputHelperWireMockLogger(ITestOutputHelper testOutputHelper) : + this(() => testOutputHelper) { - _testOutputHelper = Guard.NotNull(testOutputHelper); + Guard.NotNull(testOutputHelper); + } + + /// + /// Create a new instance on the . + /// + /// Represents a factory to provide current test output. + public TestOutputHelperWireMockLogger(Func testOutputHelperFactory) + { + _testOutputHelperFactory = Guard.NotNull(testOutputHelperFactory); } /// public void Debug(string formatString, params object[] args) { - _testOutputHelper.WriteLine(Format("Debug", formatString, args)); + _testOutputHelperFactory()?.WriteLine(Format("Debug", formatString, args)); } /// public void Info(string formatString, params object[] args) { - _testOutputHelper.WriteLine(Format("Info", formatString, args)); + _testOutputHelperFactory()?.WriteLine(Format("Info", formatString, args)); } /// public void Warn(string formatString, params object[] args) { - _testOutputHelper.WriteLine(Format("Warning", formatString, args)); + _testOutputHelperFactory()?.WriteLine(Format("Warning", formatString, args)); } /// public void Error(string formatString, params object[] args) { - _testOutputHelper.WriteLine(Format("Error", formatString, args)); + _testOutputHelperFactory()?.WriteLine(Format("Error", formatString, args)); } /// public void Error(string message, Exception exception) { - _testOutputHelper.WriteLine(Format("Error", $"{message} {{0}}", exception)); + _testOutputHelperFactory()?.WriteLine(Format("Error", $"{message} {{0}}", exception)); if (exception is AggregateException ae) { ae.Handle(ex => { - _testOutputHelper.WriteLine(Format("Error", "Exception {0}", ex)); + _testOutputHelperFactory()?.WriteLine(Format("Error", "Exception {0}", ex)); return true; }); } @@ -72,7 +81,7 @@ public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminReques Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }); - _testOutputHelper.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); + _testOutputHelperFactory()?.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); } private static string Format(string level, string formatString, params object[] args) From 0eccdf3d0a2ea5e098185e898b8e8befa33aba6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D0=BD=D0=B8=D0=BD=20=D0=A1=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B0=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 16 Jul 2026 11:13:48 +0300 Subject: [PATCH 2/2] fix(ctor): TestOutputHelperWireMockLogger made factory return nullable --- src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs b/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs index 60d84ab02..bfedd2ed8 100644 --- a/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs +++ b/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs @@ -13,7 +13,7 @@ namespace WireMock.Net.Xunit; /// public sealed class TestOutputHelperWireMockLogger : IWireMockLogger { - private readonly Func _testOutputHelperFactory; + private readonly Func _testOutputHelperFactory; /// /// Create a new instance on the . @@ -29,7 +29,7 @@ public TestOutputHelperWireMockLogger(ITestOutputHelper testOutputHelper) : /// Create a new instance on the . /// /// Represents a factory to provide current test output. - public TestOutputHelperWireMockLogger(Func testOutputHelperFactory) + public TestOutputHelperWireMockLogger(Func testOutputHelperFactory) { _testOutputHelperFactory = Guard.NotNull(testOutputHelperFactory); }