mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
d40bc43ac1
* 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>
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Moq;
|
|
|
|
using Renci.SshNet.Tests.Properties;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class ConnectionInfoTest_Authenticate_Success
|
|
{
|
|
private Mock<IServiceFactory> _serviceFactoryMock;
|
|
private Mock<IClientAuthentication> _clientAuthenticationMock;
|
|
private Mock<ISession> _sessionMock;
|
|
private ConnectionInfo _connectionInfo;
|
|
|
|
[TestInitialize]
|
|
public void Init()
|
|
{
|
|
Arrange();
|
|
Act();
|
|
}
|
|
|
|
protected void Arrange()
|
|
{
|
|
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
|
|
_clientAuthenticationMock = new Mock<IClientAuthentication>(MockBehavior.Strict);
|
|
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
|
|
_sessionMock.Setup(p => p.SessionLoggerFactory).Returns(NullLoggerFactory.Instance);
|
|
|
|
_connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None,
|
|
Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
|
|
new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
|
|
|
|
_serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Returns(_clientAuthenticationMock.Object);
|
|
_clientAuthenticationMock.Setup(p => p.Authenticate(_connectionInfo, _sessionMock.Object));
|
|
}
|
|
|
|
protected void Act()
|
|
{
|
|
_connectionInfo.Authenticate(_sessionMock.Object, _serviceFactoryMock.Object);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsAuthenticatedShouldReturnTrue()
|
|
{
|
|
Assert.IsTrue(_connectionInfo.IsAuthenticated);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CreateClientAuthenticationOnServiceFactoryShouldBeInvokedOnce()
|
|
{
|
|
_serviceFactoryMock.Verify(p => p.CreateClientAuthentication(), Times.Once);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void AuthenticateOnClientAuthenticationShouldBeInvokedOnce()
|
|
{
|
|
_clientAuthenticationMock.Verify(p => p.Authenticate(_connectionInfo, _sessionMock.Object), Times.Once);
|
|
}
|
|
}
|
|
}
|