64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public members surfaced by commentchecker — resolves 5,847 of 5,869 issues (99.6%) across three /fixdocs passes.
61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
using Serilog;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Client.CLI.Commands;
|
|
using ZB.MOM.WW.OtOpcUa.Client.CLI.Tests.Fakes;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression test for Client.CLI-007: ConfigureLogging must dispose the previously assigned
|
|
/// Log.Logger before replacing it, so repeated CLI invocations do not leak sinks.
|
|
/// </summary>
|
|
public class LoggerLifecycleTests
|
|
{
|
|
/// <summary>Verifies that ConfigureLogging disposes previous logger before reassigning.</summary>
|
|
[Fact]
|
|
public async Task ConfigureLogging_DisposesPreviousLogger_BeforeReassigning()
|
|
{
|
|
// Install a tracker logger before the command runs.
|
|
var trackerSink = new DisposeTrackingSink();
|
|
var trackerLogger = new LoggerConfiguration()
|
|
.WriteTo.Sink(trackerSink)
|
|
.CreateLogger();
|
|
Log.Logger = trackerLogger;
|
|
|
|
try
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new ConnectCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
await command.ExecuteAsync(console);
|
|
|
|
// The command's ConfigureLogging should have disposed the tracker logger we installed.
|
|
trackerSink.Disposed.ShouldBeTrue(
|
|
"Previous Log.Logger should be disposed via Log.CloseAndFlush() before ConfigureLogging assigns a new one.");
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
|
|
private sealed class DisposeTrackingSink : ILogEventSink, IDisposable
|
|
{
|
|
/// <summary>Gets a value indicating whether the sink has been disposed.</summary>
|
|
public bool Disposed { get; private set; }
|
|
/// <summary>Emits a log event.</summary>
|
|
/// <param name="logEvent">The log event to emit.</param>
|
|
public void Emit(LogEvent logEvent) { }
|
|
/// <summary>Disposes the sink and marks it as disposed.</summary>
|
|
public void Dispose() => Disposed = true;
|
|
}
|
|
}
|