mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
933613e31c
* Update to MSTest 4 * fix TestMethodForPlatformAttribute replace Execute with ExecuteAsync and fix MSTEST0057 https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0057 (link currently dead) * fix compilation error * fix MSTEST0037 https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0037 * fix MSTEST0052 https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0052 * fix MSTEST0045 Fixing this properly would require the tests to respect testContext.CancellationToken. I'm not sure this is worth fixing or how to even do it for the sync methods. https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0045 * fix MSTEST0001 I assume that parallelization would break a lot of stuff. https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0001 * Workaround for new Sonar warnings because of MSTest4 * revert analyzer fixes in OrderedDictionaryTest * use custom sync console logger for MSTest to work around https://github.com/microsoft/testfx/issues/6457 * remove redundant args --------- Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com> Co-authored-by: Rob Hague <rob.hague00@gmail.com>
87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Moq;
|
|
|
|
using Renci.SshNet.Channels;
|
|
using Renci.SshNet.Common;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class SubsystemSession_OnSessionErrorOccurred_Disposed
|
|
{
|
|
private Mock<ISession> _sessionMock;
|
|
private Mock<IChannelSession> _channelMock;
|
|
private string _subsystemName;
|
|
private SubsystemSessionStub _subsystemSession;
|
|
private int _operationTimeout;
|
|
private IList<EventArgs> _disconnectedRegister;
|
|
private IList<ExceptionEventArgs> _errorOccurredRegister;
|
|
private ExceptionEventArgs _errorOccurredEventArgs;
|
|
|
|
[TestInitialize]
|
|
public void Setup()
|
|
{
|
|
Arrange();
|
|
Act();
|
|
}
|
|
|
|
protected void Arrange()
|
|
{
|
|
var random = new Random();
|
|
_subsystemName = random.Next().ToString(CultureInfo.InvariantCulture);
|
|
_operationTimeout = 30000;
|
|
_disconnectedRegister = new List<EventArgs>();
|
|
_errorOccurredRegister = new List<ExceptionEventArgs>();
|
|
_errorOccurredEventArgs = new ExceptionEventArgs(new SystemException());
|
|
|
|
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
|
|
_sessionMock.Setup(p => p.SessionLoggerFactory).Returns(NullLoggerFactory.Instance);
|
|
_channelMock = new Mock<IChannelSession>(MockBehavior.Strict);
|
|
|
|
var sequence = new MockSequence();
|
|
_sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object);
|
|
_channelMock.InSequence(sequence).Setup(p => p.Open());
|
|
_channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true);
|
|
_channelMock.InSequence(sequence).Setup(p => p.Dispose());
|
|
|
|
_subsystemSession = new SubsystemSessionStub(
|
|
_sessionMock.Object,
|
|
_subsystemName,
|
|
_operationTimeout);
|
|
_subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args);
|
|
_subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args);
|
|
_subsystemSession.Connect();
|
|
_subsystemSession.Dispose();
|
|
}
|
|
|
|
protected void Act()
|
|
{
|
|
_sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void DisconnectHasNeverFired()
|
|
{
|
|
Assert.IsEmpty(_disconnectedRegister);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ErrorOccurredHasNeverFired()
|
|
{
|
|
Assert.IsEmpty(_errorOccurredRegister);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsOpenShouldReturnFalse()
|
|
{
|
|
Assert.IsFalse(_subsystemSession.IsOpen);
|
|
}
|
|
}
|
|
}
|