From c0dbd997e7fc505837a45f8728b24dd5e28c9f12 Mon Sep 17 00:00:00 2001 From: Dennis Dyall Date: Tue, 13 Aug 2024 20:08:43 +0200 Subject: [PATCH] Fix tests that would fail if run together --- .../tests/Yubico/Core/Logging/LogTests.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs b/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs index 138c3ce9..b443b7c5 100644 --- a/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs +++ b/Yubico.Core/tests/Yubico/Core/Logging/LogTests.cs @@ -11,21 +11,33 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + +using System; using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace Yubico.Core.Logging { - public class LogTests + public class LogTests : IDisposable { + private readonly ILoggerFactory _originalFactory = Log.Instance; + +#pragma warning disable CA1816 + public void Dispose() +#pragma warning restore CA1816 + { + // Reset to the original factory after each test + Log.Instance = _originalFactory; + } + // Ensure that the default LoggerFactory is created when no configuration is provided. [Fact] public void DefaultLoggerFactory_IsCreated_WhenNoConfigurationProvided() { // Act ILoggerFactory loggerFactory = Log.Instance; - + // Assert Assert.NotNull(loggerFactory); ILogger logger = loggerFactory.CreateLogger(); @@ -39,10 +51,10 @@ public void ManualLoggerFactory_SettingInstance_OverridesDefaultFactory() // Arrange var mockLoggerFactory = new Mock(); Log.Instance = mockLoggerFactory.Object; - + // Act ILoggerFactory actualFactory = Log.Instance; - + // Assert Assert.Same(mockLoggerFactory.Object, actualFactory); }