Files
ssh.net/test/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs
mus65 c0a353a4de Cleanup formatting and style and enforce it in CI (#1380)
* 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>
2024-05-17 22:34:27 +02:00

79 lines
2.5 KiB
C#

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Renci.SshNet.Tests.Classes
{
[TestClass]
public class SshClientTest_Dispose_Disconnected : BaseClientTestBase
{
private SshClient _sshClient;
private ConnectionInfo _connectionInfo;
protected override void SetupData()
{
_connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
}
protected override void SetupMocks()
{
var sequence = new MockSequence();
ServiceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSocketFactory())
.Returns(SocketFactoryMock.Object);
ServiceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object))
.Returns(SessionMock.Object);
SessionMock.InSequence(sequence).Setup(p => p.Connect());
SessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
SessionMock.InSequence(sequence).Setup(p => p.Dispose());
}
protected override void Arrange()
{
base.Arrange();
_sshClient = new SshClient(_connectionInfo, false, ServiceFactoryMock.Object);
_sshClient.Connect();
_sshClient.Disconnect();
}
protected override void Act()
{
_sshClient.Dispose();
}
[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 DisconnectOnSessionShouldNeverBeInvoked()
{
SessionMock.Verify(p => p.Disconnect(), Times.Never);
}
[TestMethod]
public void DisposeOnSessionShouldBeInvokedOnce()
{
SessionMock.Verify(p => p.Dispose(), Times.Once);
}
[TestMethod]
public void OnDisconnectingOnSessionShouldBeInvokedOnce()
{
SessionMock.Verify(p => p.OnDisconnecting(), Times.Once);
}
}
}