mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 17:25:51 +00:00
c0a353a4de
* Preparation to enforce formatting and style in CI - enabled IDE0055 to enforce formatting on build - disabled SA1137 and SA1025 because they are already covered by IDE0055 - disabled SA1021 because it conflicts with csharp_space_after_cast * Cleanup formatting and style on codebase This commit has no manual changes, it is the result of running "dotnet format whitespace" and "dotnet format style" * new formatting fixes after merge * appveyor: set git autocrlf as suggested by sharwell to hopefully fix Windows CI. * use autocrlf input to hopefully fix Linux tests * fix formatting * use autocrlf input for Linux only * set csharp_space_after_cast to false * Revert SA1021 suppression --------- Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
108 lines
3.3 KiB
C#
108 lines
3.3 KiB
C#
using System;
|
|
using System.Threading;
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using Moq;
|
|
|
|
using Renci.SshNet.Messages.Transport;
|
|
|
|
namespace Renci.SshNet.Tests.Classes
|
|
{
|
|
[TestClass]
|
|
public class BaseClientTest_Disconnected_KeepAliveInterval_NotNegativeOne : BaseClientTestBase
|
|
{
|
|
private BaseClient _client;
|
|
private ConnectionInfo _connectionInfo;
|
|
private TimeSpan _keepAliveInterval;
|
|
|
|
protected override void SetupData()
|
|
{
|
|
_connectionInfo = new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "pwd"));
|
|
_keepAliveInterval = TimeSpan.FromMilliseconds(50d);
|
|
}
|
|
|
|
protected override void SetupMocks()
|
|
{
|
|
ServiceFactoryMock.Setup(p => p.CreateSocketFactory())
|
|
.Returns(SocketFactoryMock.Object);
|
|
ServiceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object))
|
|
.Returns(SessionMock.Object);
|
|
SessionMock.Setup(p => p.Connect());
|
|
SessionMock.Setup(p => p.IsConnected).Returns(false);
|
|
SessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
|
|
.Returns(true);
|
|
}
|
|
|
|
protected override void Arrange()
|
|
{
|
|
base.Arrange();
|
|
|
|
_client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
|
|
_client.Connect();
|
|
}
|
|
|
|
protected override void TearDown()
|
|
{
|
|
if (_client != null)
|
|
{
|
|
SessionMock.Setup(p => p.OnDisconnecting());
|
|
SessionMock.Setup(p => p.Dispose());
|
|
_client.Dispose();
|
|
}
|
|
}
|
|
|
|
protected override void Act()
|
|
{
|
|
_client.KeepAliveInterval = _keepAliveInterval;
|
|
|
|
// allow keep-alive to be sent a few times
|
|
Thread.Sleep(195);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void KeepAliveIntervalShouldReturnConfiguredValue()
|
|
{
|
|
Assert.AreEqual(_keepAliveInterval, _client.KeepAliveInterval);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
|
|
{
|
|
ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
|
|
{
|
|
ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
|
|
Times.Once);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ConnectOnSessionShouldBeInvokedOnce()
|
|
{
|
|
SessionMock.Verify(p => p.Connect(), Times.Once);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void IsConnectedOnSessionShouldBeInvokedOnce()
|
|
{
|
|
SessionMock.Verify(p => p.IsConnected, Times.Once);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SendMessageOnSessionShouldNeverBeInvoked()
|
|
{
|
|
SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Never);
|
|
}
|
|
|
|
private class MyClient : BaseClient
|
|
{
|
|
public MyClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory) : base(connectionInfo, ownsConnectionInfo, serviceFactory)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|