From 85546c48c5b3fce77dcc83c6b71cd849e6504124 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 00:26:18 +0000 Subject: [PATCH] Add unit tests for LoggerFactoryProxy Tests verify: - CreateLogger before SetLoggerFactory is called throws InvalidOperationException - SetLoggerFactory with null throws ArgumentNullException - CreateLogger after initialization delegates to the inner factory Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Logging/LoggerFactoryProxyTests.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryProxyTests.cs diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryProxyTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryProxyTests.cs new file mode 100644 index 0000000000..43abce1894 --- /dev/null +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggerFactoryProxyTests.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Testing.Platform.Logging; + +using Moq; + +namespace Microsoft.Testing.Platform.UnitTests; + +[TestClass] +public sealed class LoggerFactoryProxyTests +{ + [TestMethod] + public void CreateLogger_WhenNotInitialized_ThrowsInvalidOperationException() + { + LoggerFactoryProxy proxy = new(); + + Assert.ThrowsExactly(() => proxy.CreateLogger("test")); + } + + [TestMethod] + public void SetLoggerFactory_WithNull_ThrowsArgumentNullException() + { + LoggerFactoryProxy proxy = new(); + + Assert.ThrowsExactly(() => proxy.SetLoggerFactory(null!)); + } + + [TestMethod] + public void CreateLogger_WhenInitialized_DelegatesToInnerFactory() + { + Mock mockLogger = new(); + Mock mockFactory = new(); + mockFactory.Setup(f => f.CreateLogger("category")).Returns(mockLogger.Object); + + LoggerFactoryProxy proxy = new(); + proxy.SetLoggerFactory(mockFactory.Object); + + ILogger result = proxy.CreateLogger("category"); + + Assert.AreSame(mockLogger.Object, result); + mockFactory.Verify(f => f.CreateLogger("category"), Times.Once); + } +}