Files
ssh.net/test/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.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

115 lines
4.0 KiB
C#

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Renci.SshNet.Tests.Classes
{
[TestClass]
public class NetConfClientTest_Dispose_Connected : NetConfClientTestBase
{
private NetConfClient _netConfClient;
private ConnectionInfo _connectionInfo;
private int _operationTimeout;
protected override void SetupData()
{
_connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
_operationTimeout = new Random().Next(1000, 10000);
_netConfClient = new NetConfClient(_connectionInfo, false, ServiceFactoryMock.Object)
{
OperationTimeout = TimeSpan.FromMilliseconds(_operationTimeout)
};
}
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());
_ = ServiceFactoryMock.InSequence(sequence)
.Setup(p => p.CreateNetConfSession(SessionMock.Object, _operationTimeout))
.Returns(NetConfSessionMock.Object);
_ = NetConfSessionMock.InSequence(sequence)
.Setup(p => p.Connect());
_ = SessionMock.InSequence(sequence)
.Setup(p => p.OnDisconnecting());
_ = NetConfSessionMock.InSequence(sequence)
.Setup(p => p.Disconnect());
_ = SessionMock.InSequence(sequence)
.Setup(p => p.Dispose());
_ = NetConfSessionMock.InSequence(sequence)
.Setup(p => p.Dispose());
}
protected override void Arrange()
{
base.Arrange();
_netConfClient.Connect();
}
protected override void Act()
{
_netConfClient.Dispose();
}
[TestMethod]
public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce()
{
ServiceFactoryMock.Verify(p => p.CreateNetConfSession(SessionMock.Object, _operationTimeout), Times.Once);
}
[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 DisconnectOnNetConfSessionShouldBeInvokedOnce()
{
NetConfSessionMock.Verify(p => p.Disconnect(), Times.Once);
}
[TestMethod]
public void DisconnectOnSessionShouldNeverBeInvoked()
{
SessionMock.Verify(p => p.Disconnect(), Times.Never);
}
[TestMethod]
public void DisposeOnNetConfSessionShouldBeInvokedOnce()
{
NetConfSessionMock.Verify(p => p.Dispose(), Times.Once);
}
[TestMethod]
public void DisposeOnSessionShouldBeInvokedOnce()
{
SessionMock.Verify(p => p.Dispose(), Times.Once);
}
[TestMethod]
public void OnDisconnectingOnSessionShouldBeInvokedOnce()
{
SessionMock.Verify(p => p.OnDisconnecting(), Times.Once);
}
}
}