mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
252c732c5e
* GeneratePackageOnBuild IncludeSymbols * Add packages to artifacts * Update src/Renci.SshNet/Renci.SshNet.csproj Co-authored-by: Rob Hague <rob.hague00@gmail.com> * Update Renci.SshNet.csproj Co-authored-by: Rob Hague <rob.hague00@gmail.com> * Delete build/nuget/SSH.NET.nuspec * Delete SSH.NET.nuspec from .sln file * Update Renci.SshNet.csproj * Update build.proj * init nbgv * Include version.json in "Solution Items" * Update Directory.Build.props * define publicReleaseRefSpec * update version.json * update version.json * set cloud build number * fix https://github.com/sshnet/SSH.NET/issues/1292 * remove unexpected code format * Delete version from csproj * move nbgv from Directory.Build.props to Renci.SshNet.csproj as only this particular project needs versioning. include package version in ThisAssembly and use nuget package version for the SSH client version. Since we define the precision of nuget package to "build", it has 3 digits. Nuget package version is unique which should be suffient. * Use package from CI feed * Bump version to 2024.0.1; Update version precision * Some tweaks: - Remove the "release" section. I don't think we will use that for now - Remove the "cloudBuild" section. Changing the CI build number doesn't seem that useful - In the "nugetPackageVersion" section: - Remove "precision". It defaults to build - Add "semVer"=2. This makes the package version e.g. 2024.1.1-prerelease.1 instead of 2024.1.1-prerelease-0001 - In "assemblyVersion" change "precision" to revision. Doesn't seem to change anything, I was just copying nbgv's setup: https://github.com/dotnet/Nerdbank.GitVersioning/blob/main/version.json - Make sure there are no '-' in the softwareversion string (change the test to a regex) * Revert unnecessary test changes; remove unnecessary tests --------- Co-authored-by: Rob Hague <rob.hague00@gmail.com> Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
228 lines
6.8 KiB
C#
228 lines
6.8 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Threading;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Messages.Transport;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class SessionTest_NotConnected : SessionTestBase
|
|
{
|
|
private ConnectionInfo _connectionInfo;
|
|
private Session _session;
|
|
|
|
protected override void SetupData()
|
|
{
|
|
var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
|
|
_connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5));
|
|
}
|
|
|
|
protected override void Act()
|
|
{
|
|
_session = new Session(_connectionInfo, ServiceFactoryMock.Object, SocketFactoryMock.Object);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
|
|
{
|
|
Assert.AreSame(_connectionInfo, _session.ConnectionInfo);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void DisconnectShouldNotThrowException()
|
|
{
|
|
_session.Disconnect();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void DisposeShouldNotThrowException()
|
|
{
|
|
_session.Dispose();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsConnectedShouldReturnFalse()
|
|
{
|
|
Assert.IsFalse(_session.IsConnected);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SendMessageShouldThrowSshConnectionException()
|
|
{
|
|
try
|
|
{
|
|
_session.SendMessage(new IgnoreMessage());
|
|
Assert.Fail();
|
|
}
|
|
catch (SshConnectionException ex)
|
|
{
|
|
Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason);
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("Client not connected.", ex.Message);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SessionIdShouldReturnNull()
|
|
{
|
|
Assert.IsNull(_session.SessionId);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ServerVersionShouldReturnNull()
|
|
{
|
|
Assert.IsNull(_session.ServerVersion);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void WaitOnHandle_WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull()
|
|
{
|
|
const WaitHandle waitHandle = null;
|
|
|
|
try
|
|
{
|
|
_session.WaitOnHandle(waitHandle);
|
|
Assert.Fail();
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("waitHandle", ex.ParamName);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void WaitOnHandle_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull()
|
|
{
|
|
const WaitHandle waitHandle = null;
|
|
var timeout = TimeSpan.FromMinutes(5);
|
|
|
|
try
|
|
{
|
|
_session.WaitOnHandle(waitHandle, timeout);
|
|
Assert.Fail();
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("waitHandle", ex.ParamName);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_TryWait_WaitHandleAndTimeout_ShouldReturnDisconnected()
|
|
{
|
|
var session = (ISession)_session;
|
|
var waitHandle = new ManualResetEvent(false);
|
|
|
|
var result = session.TryWait(waitHandle, Timeout.InfiniteTimeSpan);
|
|
|
|
Assert.AreEqual(WaitResult.Disconnected, result);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_TryWait_WaitHandleAndTimeoutAndException_ShouldReturnDisconnected()
|
|
{
|
|
var session = (ISession)_session;
|
|
var waitHandle = new ManualResetEvent(false);
|
|
|
|
var result = session.TryWait(waitHandle, Timeout.InfiniteTimeSpan, out var exception);
|
|
|
|
Assert.AreEqual(WaitResult.Disconnected, result);
|
|
Assert.IsNull(exception);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor()
|
|
{
|
|
var session = (ISession)_session;
|
|
Assert.AreSame(_connectionInfo, session.ConnectionInfo);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_MessageListenerCompletedShouldBeSignaled()
|
|
{
|
|
var session = (ISession)_session;
|
|
|
|
Assert.IsNotNull(session.MessageListenerCompleted);
|
|
Assert.IsTrue(session.MessageListenerCompleted.WaitOne(0));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_SendMessageShouldThrowSshConnectionException()
|
|
{
|
|
var session = (ISession)_session;
|
|
|
|
try
|
|
{
|
|
session.SendMessage(new IgnoreMessage());
|
|
Assert.Fail();
|
|
}
|
|
catch (SshConnectionException ex)
|
|
{
|
|
Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason);
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("Client not connected.", ex.Message);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_TrySendMessageShouldReturnFalse()
|
|
{
|
|
var session = (ISession)_session;
|
|
|
|
var actual = session.TrySendMessage(new IgnoreMessage());
|
|
|
|
Assert.IsFalse(actual);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull()
|
|
{
|
|
const WaitHandle waitHandle = null;
|
|
var session = (ISession)_session;
|
|
|
|
try
|
|
{
|
|
session.WaitOnHandle(waitHandle);
|
|
Assert.Fail();
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("waitHandle", ex.ParamName);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ISession_WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull()
|
|
{
|
|
const WaitHandle waitHandle = null;
|
|
var session = (ISession)_session;
|
|
|
|
try
|
|
{
|
|
session.WaitOnHandle(waitHandle, Timeout.InfiniteTimeSpan);
|
|
Assert.Fail();
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
Assert.IsNull(ex.InnerException);
|
|
Assert.AreEqual("waitHandle", ex.ParamName);
|
|
}
|
|
}
|
|
|
|
private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout)
|
|
{
|
|
return new ConnectionInfo(serverEndPoint.Address.ToString(), serverEndPoint.Port, "eric", new NoneAuthenticationMethod("eric"))
|
|
{
|
|
Timeout = timeout
|
|
};
|
|
}
|
|
}
|
|
}
|