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>
65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Moq;
|
|
|
|
using Renci.SshNet.Tests.Common;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class SshCommandTest_EndExecute_AsyncResultIsNull : TestBase
|
|
{
|
|
private Mock<ISession> _sessionMock;
|
|
private string _commandText;
|
|
private Encoding _encoding;
|
|
private SshCommand _sshCommand;
|
|
private IAsyncResult _asyncResult;
|
|
private ArgumentNullException _actualException;
|
|
|
|
protected override void OnInit()
|
|
{
|
|
base.OnInit();
|
|
|
|
Arrange();
|
|
Act();
|
|
}
|
|
|
|
private void Arrange()
|
|
{
|
|
_sessionMock = new Mock<ISession>();
|
|
_sessionMock.Setup(p => p.SessionLoggerFactory).Returns(NullLoggerFactory.Instance);
|
|
_commandText = new Random().Next().ToString(CultureInfo.InvariantCulture);
|
|
_encoding = Encoding.UTF8;
|
|
_asyncResult = null;
|
|
|
|
_sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding);
|
|
}
|
|
|
|
private void Act()
|
|
{
|
|
try
|
|
{
|
|
_sshCommand.EndExecute(_asyncResult);
|
|
Assert.Fail();
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
_actualException = ex;
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EndExecuteShouldHaveThrownArgumentNullException()
|
|
{
|
|
Assert.IsNotNull(_actualException);
|
|
Assert.IsNull(_actualException.InnerException);
|
|
Assert.AreEqual("asyncResult", _actualException.ParamName);
|
|
}
|
|
}
|
|
}
|