Files
Bart Vries d40bc43ac1 Refactor logging to allow a loggerfactory per session (#1673)
* Refactor logging to allow a loggerfactory per session specified in the ConnectionInfo.

This commit introduces an `ILoggerFactory` to various classes, replacing the static logger factory with an instance-based approach for more flexible and session-specific logging. These changes improve the logging framework's flexibility and maintainability and allow unit testing of logging.

* Improvements bases on feedback. Fixed tests. Added documentation.

* Update src/Renci.SshNet/ConnectionInfo.cs

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2025-07-26 21:24:48 +02:00

41 lines
1.0 KiB
C#

using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Renci.SshNet.Tests.Classes.Channels
{
public abstract class ChannelSessionTestBase
{
internal Mock<ISession> SessionMock { get; private set; }
internal Mock<IConnectionInfo> ConnectionInfoMock { get; private set; }
[TestInitialize]
public void Initialize()
{
Arrange();
Act();
}
protected abstract void SetupData();
protected void CreateMocks()
{
SessionMock = new Mock<ISession>(MockBehavior.Strict);
SessionMock.Setup(p => p.SessionLoggerFactory).Returns(NullLoggerFactory.Instance);
ConnectionInfoMock = new Mock<IConnectionInfo>(MockBehavior.Strict);
}
protected abstract void SetupMocks();
protected virtual void Arrange()
{
SetupData();
CreateMocks();
SetupMocks();
}
protected abstract void Act();
}
}