Przeglądaj źródła

Round 2 of analyzer fixes and general cleanup. (#1132)

Gert Driesen 2 lat temu
rodzic
commit
c04cdbcb97
100 zmienionych plików z 1441 dodań i 1232 usunięć
  1. 11 0
      .editorconfig
  2. 0 2
      Directory.Build.props
  3. 32 0
      src/Renci.SshNet.Tests/.editorconfig
  4. 6 6
      src/Renci.SshNet.Tests/Classes/BaseClientTestBase.cs
  5. 15 15
      src/Renci.SshNet.Tests/Classes/BaseClientTest_Connect_OnConnectedThrowsException.cs
  6. 21 18
      src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAliveInterval_NegativeOne.cs
  7. 15 15
      src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAliveInterval_NotNegativeOne.cs
  8. 11 11
      src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs
  9. 15 15
      src/Renci.SshNet.Tests/Classes/BaseClientTest_Disconnected_Connect.cs
  10. 15 15
      src/Renci.SshNet.Tests/Classes/BaseClientTest_Disconnected_KeepAliveInterval_NotNegativeOne.cs
  11. 10 10
      src/Renci.SshNet.Tests/Classes/BaseClientTest_NotConnected_KeepAliveInterval_NotNegativeOne.cs
  12. 70 58
      src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs
  13. 80 50
      src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
  14. 61 52
      src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs
  15. 4 1
      src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs
  16. 21 1
      src/Renci.SshNet.Tests/Classes/Channels/ChannelStub.cs
  17. 3 5
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs
  18. 2 1
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs
  19. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs
  20. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs
  21. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs
  22. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs
  23. 5 4
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs
  24. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs
  25. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs
  26. 3 2
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs
  27. 5 3
      src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs
  28. 26 1
      src/Renci.SshNet.Tests/Classes/Channels/ClientChannelStub.cs
  29. 5 4
      src/Renci.SshNet.Tests/Classes/CipherInfoTest.cs
  30. 2 1
      src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInAlternateBranch.cs
  31. 62 44
      src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs
  32. 1 1
      src/Renci.SshNet.Tests/Classes/CommandAsyncResultTest.cs
  33. 19 23
      src/Renci.SshNet.Tests/Classes/Common/AsyncResultTest.cs
  34. 3 3
      src/Renci.SshNet.Tests/Classes/Common/AuthenticationPasswordChangeEventArgsTest.cs
  35. 4 4
      src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptEventArgsTest.cs
  36. 10 11
      src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptTest.cs
  37. 112 115
      src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs
  38. 2 2
      src/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs
  39. 43 30
      src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest.cs
  40. 4 4
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs
  41. 5 4
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Pad.cs
  42. 2 4
      src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_ToBigInteger2.cs
  43. 2 2
      src/Renci.SshNet.Tests/Classes/Common/PacketDumpTest.cs
  44. 10 8
      src/Renci.SshNet.Tests/Classes/Common/PipeStreamTest.cs
  45. 1 1
      src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingRead.cs
  46. 1 1
      src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingWrite.cs
  47. 2 2
      src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_BytesRemainingAfterRead.cs
  48. 1 1
      src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_NoBytesRemainingAfterRead.cs
  49. 3 3
      src/Renci.SshNet.Tests/Classes/Common/PortForwardEventArgsTest.cs
  50. 2 2
      src/Renci.SshNet.Tests/Classes/Common/PosixPathTest_CreateAbsoluteOrRelativeFilePath.cs
  51. 1 1
      src/Renci.SshNet.Tests/Classes/Common/PosixPathTest_GetDirectoryName.cs
  52. 1 1
      src/Renci.SshNet.Tests/Classes/Common/PosixPathTest_GetFileName.cs
  53. 5 6
      src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs
  54. 13 11
      src/Renci.SshNet.Tests/Classes/Common/SshConnectionExceptionTest.cs
  55. 7 9
      src/Renci.SshNet.Tests/Classes/Compression/ZlibOpenSshTest.cs
  56. 11 10
      src/Renci.SshNet.Tests/Classes/Compression/ZlibStreamTest.cs
  57. 1 1
      src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs
  58. 10 12
      src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionRefusedByServer.cs
  59. 11 17
      src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionSucceeded.cs
  60. 4 4
      src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs
  61. 12 13
      src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs
  62. 11 11
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ConnectionToProxyRefused.cs
  63. 10 15
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent.cs
  64. 1 1
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyHostInvalid.cs
  65. 22 19
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsEmpty.cs
  66. 14 14
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsNull.cs
  67. 19 16
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine.cs
  68. 21 18
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine.cs
  69. 21 18
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent.cs
  70. 12 12
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders.cs
  71. 19 16
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIsNot200.cs
  72. 21 23
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsEmpty.cs
  73. 18 16
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty.cs
  74. 20 18
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNull.cs
  75. 16 14
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs
  76. 24 26
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs
  77. 19 21
      src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs
  78. 11 7
      src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs
  79. 14 10
      src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs
  80. 10 7
      src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs
  81. 4 3
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs
  82. 15 33
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionRejectedByProxy.cs
  83. 15 19
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs
  84. 10 12
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionToProxyRefused.cs
  85. 5 8
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs
  86. 16 20
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress.cs
  87. 15 19
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyCode.cs
  88. 6 13
      src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion.cs
  89. 4 3
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTestBase.cs
  90. 10 13
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ConnectionToProxyRefused.cs
  91. 7 10
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_NoAuthentication_ConnectionSucceeded.cs
  92. 15 19
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported.cs
  93. 12 13
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs
  94. 8 15
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed.cs
  95. 16 16
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded.cs
  96. 7 14
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength.cs
  97. 26 32
      src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength.cs
  98. 4 4
      src/Renci.SshNet.Tests/Classes/Connection/SshIdentificationTest.cs
  99. 119 31
      src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs
  100. 3 1
      src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs

+ 11 - 0
.editorconfig_soon → .editorconfig

@@ -535,6 +535,11 @@ dotnet_diagnostic.IDE0045.severity = none
 # Configured using 'dotnet_style_prefer_conditional_expression_over_return'
 dotnet_diagnostic.IDE0046.severity = suggestion
 
+# IDE0047: Remove unnecessary parentheses
+# 
+# Removing "unnecessary" parentheses is not always a clear win for readability.
+dotnet_diagnostic.IDE0047.severity = suggestion
+
 # IDE0055: Fix formatting
 #
 # When enabled, diagnostics are reported for indented object initializers.
@@ -547,6 +552,12 @@ dotnet_diagnostic.IDE0046.severity = suggestion
 # There are no settings to configure this correctly, unless https://github.com/dotnet/roslyn/issues/63256 (or similar) is ever implemented.
 dotnet_diagnostic.IDE0055.severity = none
 
+# IDE0130: Namespace does not match folder structure
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0130
+#
+# TODO: Remove when https://github.com/sshnet/SSH.NET/issues/1129 is fixed
+dotnet_diagnostic.IDE0130.severity = none
+
 # IDE0270: Null check can be simplified
 # 
 # var inputPath = originalDossierPathList.Find(x => x.id == updatedPath.id);

+ 0 - 2
Directory.Build.props

@@ -9,10 +9,8 @@
         <AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\Renci.SshNet.snk</AssemblyOriginatorKeyFile>
         <GenerateDocumentationFile>true</GenerateDocumentationFile>
         <LangVersion>latest</LangVersion>
-        <!--
         <WarningLevel>9999</WarningLevel>
         <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
-        -->
         <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
     </PropertyGroup>
 

+ 32 - 0
src/Renci.SshNet.Tests/.editorconfig

@@ -0,0 +1,32 @@
+[*.cs]
+
+#### SYSLIB diagnostics ####
+
+# SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time
+#
+# TODO: Remove this when https://github.com/sshnet/SSH.NET/issues/1131 is implemented.
+dotnet_diagnostic.SYSLIB1045.severity = none
+
+### StyleCop Analyzers rules ###
+
+#### .NET Compiler Platform analysers rules ####
+
+# IDE0007: Use var instead of explicit type
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0007
+dotnet_diagnostic.IDE0007.severity = suggestion
+
+# IDE0028: Use collection initializers
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0028
+dotnet_diagnostic.IDE0028.severity = suggestion
+
+# IDE0058: Remove unnecessary expression value
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0058
+dotnet_diagnostic.IDE0058.severity = suggestion
+
+# IDE0059: Remove unnecessary value assignment
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0059
+dotnet_diagnostic.IDE0059.severity = suggestion
+
+# IDE0230: Use UTF-8 string literal
+# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0230
+dotnet_diagnostic.IDE0230.severity = suggestion

+ 6 - 6
src/Renci.SshNet.Tests/Classes/BaseClientTestBase.cs

@@ -6,15 +6,15 @@ namespace Renci.SshNet.Tests.Classes
 {
     public abstract class BaseClientTestBase : TripleATestBase
     {
-        internal Mock<IServiceFactory> _serviceFactoryMock { get; private set; }
-        internal Mock<ISocketFactory> _socketFactoryMock { get; private set; }
-        internal Mock<ISession> _sessionMock { get; private set; }
+        internal Mock<IServiceFactory> ServiceFactoryMock { get; private set; }
+        internal Mock<ISocketFactory> SocketFactoryMock { get; private set; }
+        internal Mock<ISession> SessionMock { get; private set; }
 
         protected virtual void CreateMocks()
         {
-            _serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
-            _socketFactoryMock = new Mock<ISocketFactory>(MockBehavior.Strict);
-            _sessionMock = new Mock<ISession>(MockBehavior.Strict);
+            ServiceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
+            SocketFactoryMock = new Mock<ISocketFactory>(MockBehavior.Strict);
+            SessionMock = new Mock<ISession>(MockBehavior.Strict);
         }
 
         protected virtual void SetupData()

+ 15 - 15
src/Renci.SshNet.Tests/Classes/BaseClientTest_Connect_OnConnectedThrowsException.cs

@@ -24,20 +24,20 @@ namespace Renci.SshNet.Tests.Classes
 
         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.Dispose());
+            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.Dispose());
         }
 
         protected override void TearDown()
         {
             if (_client != null)
             {
-                _sessionMock.Setup(p => p.OnDisconnecting());
-                _sessionMock.Setup(p => p.Dispose());
+                SessionMock.Setup(p => p.OnDisconnecting());
+                SessionMock.Setup(p => p.Dispose());
                 _client.Dispose();
             }
         }
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object)
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object)
                 {
                     OnConnectedException = _onConnectException
                 };
@@ -75,26 +75,26 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
+            ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
         }
 
         [TestMethod]
         public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object),
+            ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
                                        Times.Once);
         }
 
         [TestMethod]
         public void ConnectOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.Connect(), Times.Once);
+            SessionMock.Verify(p => p.Connect(), Times.Once);
         }
 
         [TestMethod]
         public void DisposeOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.Dispose(), Times.Once);
+            SessionMock.Verify(p => p.Dispose(), Times.Once);
         }
 
         [TestMethod]
@@ -104,7 +104,7 @@ namespace Renci.SshNet.Tests.Classes
 
             _client.ErrorOccurred += (sender, args) => Interlocked.Increment(ref errorOccurredSignalCount);
 
-            _sessionMock.Raise(p => p.ErrorOccured += null, new ExceptionEventArgs(new Exception()));
+            SessionMock.Raise(p => p.ErrorOccured += null, new ExceptionEventArgs(new Exception()));
 
             Assert.AreEqual(0, errorOccurredSignalCount);
         }
@@ -116,7 +116,7 @@ namespace Renci.SshNet.Tests.Classes
 
             _client.HostKeyReceived += (sender, args) => Interlocked.Increment(ref hostKeyReceivedSignalCount);
 
-            _sessionMock.Raise(p => p.HostKeyReceived += null, new HostKeyEventArgs(GetKeyHostAlgorithm()));
+            SessionMock.Raise(p => p.HostKeyReceived += null, new HostKeyEventArgs(GetKeyHostAlgorithm()));
 
             Assert.AreEqual(0, hostKeyReceivedSignalCount);
         }

+ 21 - 18
src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAliveInterval_NegativeOne.cs

@@ -1,8 +1,10 @@
 using System;
 using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
-using Renci.SshNet.Connection;
+
 using Renci.SshNet.Messages.Transport;
 
 namespace Renci.SshNet.Tests.Classes
@@ -24,22 +26,23 @@ namespace Renci.SshNet.Tests.Classes
 
         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(true);
-            _sessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
-                        .Returns(true)
-                        .Callback(() => Interlocked.Increment(ref _keepAliveCount));
+            _ = 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(true);
+            _ = SessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
+                            .Returns(true)
+                            .Callback(() => Interlocked.Increment(ref _keepAliveCount));
         }
 
         protected override void Arrange()
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
             _client.Connect();
             _client.KeepAliveInterval = _keepAliveInterval;
         }
@@ -48,8 +51,8 @@ namespace Renci.SshNet.Tests.Classes
         {
             if (_client != null)
             {
-                _sessionMock.Setup(p => p.OnDisconnecting());
-                _sessionMock.Setup(p => p.Dispose());
+                SessionMock.Setup(p => p.OnDisconnecting());
+                SessionMock.Setup(p => p.Dispose());
                 _client.Dispose();
             }
         }
@@ -72,25 +75,25 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
+            ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
         }
 
         [TestMethod]
         public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object), Times.Once);
+            ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object), Times.Once);
         }
 
         [TestMethod]
         public void ConnectOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.Connect(), Times.Once);
+            SessionMock.Verify(p => p.Connect(), Times.Once);
         }
 
         [TestMethod]
         public void IsConnectedOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.IsConnected, Times.Once);
+            SessionMock.Verify(p => p.IsConnected, Times.Once);
         }
 
         [TestMethod]
@@ -99,7 +102,7 @@ namespace Renci.SshNet.Tests.Classes
             // allow keep-alive to be sent once
             Thread.Sleep(100);
 
-            _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(1));
+            SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(1));
         }
 
         private class MyClient : BaseClient

+ 15 - 15
src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAliveInterval_NotNegativeOne.cs

@@ -23,13 +23,13 @@ namespace Renci.SshNet.Tests.Classes
 
         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(true);
-            _sessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
+            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(true);
+            SessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
                         .Returns(true)
                         .Callback(() => Interlocked.Increment(ref _keepAliveCount));
         }
@@ -38,7 +38,7 @@ namespace Renci.SshNet.Tests.Classes
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
             _client.Connect();
         }
 
@@ -46,8 +46,8 @@ namespace Renci.SshNet.Tests.Classes
         {
             if (_client != null)
             {
-                _sessionMock.Setup(p => p.OnDisconnecting());
-                _sessionMock.Setup(p => p.Dispose());
+                SessionMock.Setup(p => p.OnDisconnecting());
+                SessionMock.Setup(p => p.Dispose());
                 _client.Dispose();
             }
         }
@@ -74,32 +74,32 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
+            ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
         }
 
         [TestMethod]
         public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object),
+            ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
                                        Times.Once);
         }
 
         [TestMethod]
         public void ConnectOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.Connect(), Times.Once);
+            SessionMock.Verify(p => p.Connect(), Times.Once);
         }
 
         [TestMethod]
         public void IsConnectedOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.IsConnected, Times.Once);
+            SessionMock.Verify(p => p.IsConnected, Times.Once);
         }
 
         [TestMethod]
         public void SendMessageOnSessionShouldBeInvokedThreeTimes()
         {
-            _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(3));
+            SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(3));
         }
 
         private class MyClient : BaseClient

+ 11 - 11
src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs

@@ -24,15 +24,15 @@ namespace Renci.SshNet.Tests.Classes
         {
             _mockSequence = new MockSequence();
 
-            _serviceFactoryMock.InSequence(_mockSequence)
+            ServiceFactoryMock.InSequence(_mockSequence)
                                .Setup(p => p.CreateSocketFactory())
-                               .Returns(_socketFactoryMock.Object);
-            _serviceFactoryMock.InSequence(_mockSequence)
-                               .Setup(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object))
-                               .Returns(_sessionMock.Object);
-            _sessionMock.InSequence(_mockSequence)
+                               .Returns(SocketFactoryMock.Object);
+            ServiceFactoryMock.InSequence(_mockSequence)
+                               .Setup(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object))
+                               .Returns(SessionMock.Object);
+            SessionMock.InSequence(_mockSequence)
                         .Setup(p => p.Connect());
-            _sessionMock.InSequence(_mockSequence)
+            SessionMock.InSequence(_mockSequence)
                         .Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
                         .Returns(true)
                         .Callback(() =>
@@ -46,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object)
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object)
                 {
                     KeepAliveInterval = TimeSpan.FromMilliseconds(50d)
                 };
@@ -57,8 +57,8 @@ namespace Renci.SshNet.Tests.Classes
         {
             if (_client != null)
             {
-                _sessionMock.InSequence(_mockSequence).Setup(p => p.OnDisconnecting());
-                _sessionMock.InSequence(_mockSequence).Setup(p => p.Dispose());
+                SessionMock.InSequence(_mockSequence).Setup(p => p.OnDisconnecting());
+                SessionMock.InSequence(_mockSequence).Setup(p => p.Dispose());
                 _client.Dispose();
             }
         }
@@ -79,7 +79,7 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void SendMessageOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Once);
+            SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Once);
         }
 
         private class MyClient : BaseClient

+ 15 - 15
src/Renci.SshNet.Tests/Classes/BaseClientTest_Disconnected_Connect.cs

@@ -29,22 +29,22 @@ namespace Renci.SshNet.Tests.Classes
         {
             var sequence = new MockSequence();
 
-            _serviceFactoryMock.InSequence(sequence)
+            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)
+                               .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)
+            SessionMock.InSequence(sequence)
                         .Setup(p => p.OnDisconnecting());
-            _sessionMock.InSequence(sequence)
+            SessionMock.InSequence(sequence)
                         .Setup(p => p.Dispose());
-            _serviceFactoryMock.InSequence(sequence)
+            ServiceFactoryMock.InSequence(sequence)
                                .Setup(p => p.CreateSocketFactory())
                                .Returns(_socketFactory2Mock.Object);
-            _serviceFactoryMock.InSequence(sequence)
+            ServiceFactoryMock.InSequence(sequence)
                                .Setup(p => p.CreateSession(_connectionInfo, _socketFactory2Mock.Object))
                                .Returns(_session2Mock.Object);
             _session2Mock.InSequence(sequence)
@@ -55,7 +55,7 @@ namespace Renci.SshNet.Tests.Classes
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
             _client.Connect();
             _client.Disconnect();
         }
@@ -78,22 +78,22 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedTwic()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Exactly(2));
+            ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Exactly(2));
         }
 
         [TestMethod]
         public void CreateSessionOnServiceFactoryShouldBeInvokedTwice()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object),
+            ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
                                        Times.Once);
-            _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactory2Mock.Object),
+            ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactory2Mock.Object),
                                        Times.Once);
         }
 
         [TestMethod]
         public void ConnectOnSessionShouldBeInvokedTwice()
         {
-            _sessionMock.Verify(p => p.Connect(), Times.Once);
+            SessionMock.Verify(p => p.Connect(), Times.Once);
             _session2Mock.Verify(p => p.Connect(), Times.Once);
         }
 

+ 15 - 15
src/Renci.SshNet.Tests/Classes/BaseClientTest_Disconnected_KeepAliveInterval_NotNegativeOne.cs

@@ -21,13 +21,13 @@ namespace Renci.SshNet.Tests.Classes
 
         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>()))
+            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);
         }
 
@@ -35,7 +35,7 @@ namespace Renci.SshNet.Tests.Classes
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
             _client.Connect();
         }
 
@@ -43,8 +43,8 @@ namespace Renci.SshNet.Tests.Classes
         {
             if (_client != null)
             {
-                _sessionMock.Setup(p => p.OnDisconnecting());
-                _sessionMock.Setup(p => p.Dispose());
+                SessionMock.Setup(p => p.OnDisconnecting());
+                SessionMock.Setup(p => p.Dispose());
                 _client.Dispose();
             }
         }
@@ -66,32 +66,32 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
+            ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
         }
 
         [TestMethod]
         public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
         {
-            _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object),
+            ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
                                        Times.Once);
         }
 
         [TestMethod]
         public void ConnectOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.Connect(), Times.Once);
+            SessionMock.Verify(p => p.Connect(), Times.Once);
         }
 
         [TestMethod]
         public void IsConnectedOnSessionShouldBeInvokedOnce()
         {
-            _sessionMock.Verify(p => p.IsConnected, Times.Once);
+            SessionMock.Verify(p => p.IsConnected, Times.Once);
         }
 
         [TestMethod]
         public void SendMessageOnSessionShouldNeverBeInvoked()
         {
-            _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Never);
+            SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Never);
         }
 
         private class MyClient : BaseClient

+ 10 - 10
src/Renci.SshNet.Tests/Classes/BaseClientTest_NotConnected_KeepAliveInterval_NotNegativeOne.cs

@@ -25,15 +25,15 @@ namespace Renci.SshNet.Tests.Classes
         {
             base.Arrange();
 
-            _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
+            _client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
         }
 
         protected override void TearDown()
         {
             if (_client != null)
             {
-                _sessionMock.Setup(p => p.OnDisconnecting());
-                _sessionMock.Setup(p => p.Dispose());
+                SessionMock.Setup(p => p.OnDisconnecting());
+                SessionMock.Setup(p => p.Dispose());
                 _client.Dispose();
             }
         }
@@ -55,12 +55,12 @@ namespace Renci.SshNet.Tests.Classes
         [TestMethod]
         public void ConnectShouldActivateKeepAliveIfSessionIs()
         {
-            _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.TrySendMessage(It.IsAny<IgnoreMessage>()))
+            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.TrySendMessage(It.IsAny<IgnoreMessage>()))
                         .Returns(true)
                         .Callback(() => Interlocked.Increment(ref _keepAliveCount));
 
@@ -70,7 +70,7 @@ namespace Renci.SshNet.Tests.Classes
             Thread.Sleep(250);
 
             // Exactly two keep-alives should be sent
-            _sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(2));
+            SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(2));
         }
 
         private class MyClient : BaseClient

+ 70 - 58
src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs

@@ -3,8 +3,11 @@ using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
+
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages;
@@ -53,16 +56,17 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void SocketShouldBeClosedAndBindShouldEndWhenForwardedPortSignalsClosingEvent()
         {
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.Setup(p => p.SendMessage(It.IsAny<ChannelOpenMessage>()))
-                        .Callback<Message>(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null,
+            _ = _sessionMock.Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.Setup(p => p.SendMessage(It.IsAny<ChannelOpenMessage>()))
+                            .Callback<Message>(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null,
                                                                    new MessageEventArgs<ChannelOpenConfirmationMessage>(
                                                                        new ChannelOpenConfirmationMessage(((ChannelOpenMessage) m).LocalChannelNumber,
                                                                                                           _remoteWindowSize,
                                                                                                           _remotePacketSize,
                                                                                                           _remoteChannelNumber))));
-            _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
-                        .Callback<WaitHandle>(p => p.WaitOne(Session.Infinite));
+            _ = _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
+                            .Callback<WaitHandle>(p => p.WaitOne(Session.Infinite));
 
             var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
             using (var localPortListener = new AsyncSocketListener(localPortEndPoint))
@@ -108,16 +112,17 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void SocketShouldBeClosedAndBindShouldEndWhenOnErrorOccurredIsInvoked()
         {
-            _sessionMock.Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.Setup(p => p.SendMessage(It.IsAny<ChannelOpenMessage>()))
-                        .Callback<Message>(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null,
+            _ = _sessionMock.Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.Setup(p => p.SendMessage(It.IsAny<ChannelOpenMessage>()))
+                            .Callback<Message>(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null,
                                                                    new MessageEventArgs<ChannelOpenConfirmationMessage>(
                                                                        new ChannelOpenConfirmationMessage(((ChannelOpenMessage) m).LocalChannelNumber,
                                                                                                           _remoteWindowSize,
                                                                                                           _remotePacketSize,
                                                                                                           _remoteChannelNumber))));
-            _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
-                        .Callback<WaitHandle>(p => p.WaitOne(Session.Infinite));
+            _ = _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
+                            .Callback<WaitHandle>(p => p.WaitOne(Session.Infinite));
 
             var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122);
             using (var localPortListener = new AsyncSocketListener(localPortEndPoint))
@@ -166,46 +171,53 @@ namespace Renci.SshNet.Tests.Classes.Channels
         {
             var sequence = new MockSequence();
 
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.SendMessage(It.IsAny<ChannelOpenMessage>()))
-                        .Callback<Message>(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null,
+            _ = _sessionMock.InSequence(sequence).Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.SendMessage(It.IsAny<ChannelOpenMessage>()))
+                            .Callback<Message>(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null,
                                                                    new MessageEventArgs<ChannelOpenConfirmationMessage>(
                                                                        new ChannelOpenConfirmationMessage(((ChannelOpenMessage) m).LocalChannelNumber,
                                                                                                           _remoteWindowSize,
                                                                                                           _remotePacketSize,
                                                                                                           _remoteChannelNumber))));
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
-                        .Callback<WaitHandle>(p => p.WaitOne(Session.Infinite));
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.TrySendMessage(It.IsAny<ChannelEofMessage>()))
-                        .Returns(true)
-                        .Callback<Message>(
-                            m => new Thread(() =>
-                            {
-                                Thread.Sleep(50);
-                                _sessionMock.Raise(s => s.ChannelEofReceived += null,
-                                                   new MessageEventArgs<ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
-                            }).Start());
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.TrySendMessage(It.IsAny<ChannelCloseMessage>()))
-                        .Returns(true)
-                        .Callback<Message>(
-                            m => new Thread(() =>
-                            {
-                                Thread.Sleep(50);
-                                _sessionMock.Raise(s => s.ChannelCloseReceived += null,
-                                                   new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
-                            }).Start());
-            _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
-            _connectionInfoMock.InSequence(sequence).Setup(p => p.ChannelCloseTimeout).Returns(_channelCloseTimeout);
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.TryWait(It.IsAny<EventWaitHandle>(), _channelCloseTimeout))
-                        .Callback<WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) => waitHandle.WaitOne())
-                        .Returns(WaitResult.Success);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.WaitOnHandle(It.IsAny<EventWaitHandle>()))
+                            .Callback<WaitHandle>(p => p.WaitOne(Session.Infinite));
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TrySendMessage(It.IsAny<ChannelEofMessage>()))
+                            .Returns(true)
+                            .Callback<Message>(m => new Thread(() =>
+                                {
+                                    Thread.Sleep(50);
+                                    _sessionMock.Raise(s => s.ChannelEofReceived += null,
+                                                       new MessageEventArgs<ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
+                                }).Start());
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TrySendMessage(It.IsAny<ChannelCloseMessage>()))
+                            .Returns(true)
+                            .Callback<Message>(m => new Thread(() =>
+                                {
+                                    Thread.Sleep(50);
+                                    _sessionMock.Raise(s => s.ChannelCloseReceived += null,
+                                                       new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
+                                }).Start());
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.ConnectionInfo)
+                            .Returns(_connectionInfoMock.Object);
+            _ = _connectionInfoMock.InSequence(sequence)
+                                   .Setup(p => p.ChannelCloseTimeout)
+                                   .Returns(_channelCloseTimeout);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TryWait(It.IsAny<EventWaitHandle>(), _channelCloseTimeout))
+                            .Callback<WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) => waitHandle.WaitOne())
+                            .Returns(WaitResult.Success);
 
             var channelBindFinishedWaitHandle = new ManualResetEvent(false);
             Socket handler = null;
@@ -217,26 +229,26 @@ namespace Renci.SshNet.Tests.Classes.Channels
                 localPortListener.Start();
 
                 localPortListener.Connected += socket =>
-                {
-                    channel = new ChannelDirectTcpip(_sessionMock.Object,
-                                                     _localChannelNumber,
-                                                     _localWindowSize,
-                                                     _localPacketSize);
-                    channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket);
-                    channel.Bind();
-                    channel.Dispose();
+                    {
+                        channel = new ChannelDirectTcpip(_sessionMock.Object,
+                                                         _localChannelNumber,
+                                                         _localWindowSize,
+                                                         _localPacketSize);
+                        channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket);
+                        channel.Bind();
+                        channel.Dispose();
 
-                    handler = socket;
+                        handler = socket;
 
-                    channelBindFinishedWaitHandle.Set();
-                };
+                        _ = channelBindFinishedWaitHandle.Set();
+                    };
 
                 var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                 client.Connect(localPortEndPoint);
                 client.Shutdown(SocketShutdown.Send);
                 Assert.IsFalse(client.Connected);
 
-                channelBindFinishedWaitHandle.WaitOne();
+                _ = channelBindFinishedWaitHandle.WaitOne();
 
                 Assert.IsNotNull(handler);
                 Assert.IsFalse(handler.Connected);
@@ -251,4 +263,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             }
         }
     }
-}
+}

+ 80 - 50
src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs

@@ -79,45 +79,53 @@ namespace Renci.SshNet.Tests.Classes.Channels
             _forwardedPortMock = new Mock<IForwardedPort>(MockBehavior.Strict);
 
             var sequence = new MockSequence();
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                .Setup(p => p.SendMessage(It.Is<ChannelOpenMessage>(m => AssertExpectedMessage(m))));
-            _sessionMock.InSequence(sequence)
-                .Setup(p => p.WaitOnHandle(It.IsNotNull<WaitHandle>()))
-                .Callback<WaitHandle>(
-                    w =>
-                    {
-                        _sessionMock.Raise(
-                            s => s.ChannelOpenConfirmationReceived += null,
-                            new MessageEventArgs<ChannelOpenConfirmationMessage>(
-                                new ChannelOpenConfirmationMessage(
-                                    _localChannelNumber,
-                                    _remoteWindowSize,
-                                    _remotePacketSize,
-                                    _remoteChannelNumber)));
-                        w.WaitOne();
-                    });
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                .Setup(
-                    p => p.TrySendMessage(It.Is<ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
-                .Returns(true);
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                .Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
-                .Returns(true);
-            _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
-            _connectionInfoMock.InSequence(sequence).Setup(p => p.ChannelCloseTimeout).Returns(_channelCloseTimeout);
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.TryWait(It.IsAny<EventWaitHandle>(), _channelCloseTimeout))
-                        .Callback<WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) =>
-                        {
-                            _sessionMock.Raise(
-                                s => s.ChannelCloseReceived += null,
-                                new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
-                            waitHandle.WaitOne();
-                        })
-                        .Returns(WaitResult.Success);
+
+            _ = _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.SendMessage(It.Is<ChannelOpenMessage>(m => AssertExpectedMessage(m))));
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.WaitOnHandle(It.IsNotNull<WaitHandle>()))
+                            .Callback<WaitHandle>(
+                                w =>
+                                {
+                                    _sessionMock.Raise(
+                                        s => s.ChannelOpenConfirmationReceived += null,
+                                        new MessageEventArgs<ChannelOpenConfirmationMessage>(
+                                            new ChannelOpenConfirmationMessage(
+                                                _localChannelNumber,
+                                                _remoteWindowSize,
+                                                _remotePacketSize,
+                                                _remoteChannelNumber)));
+                                    _ = w.WaitOne();
+                                });
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TrySendMessage(It.Is<ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.ConnectionInfo)
+                            .Returns(_connectionInfoMock.Object);
+            _ = _connectionInfoMock.InSequence(sequence)
+                                   .Setup(p => p.ChannelCloseTimeout)
+                                   .Returns(_channelCloseTimeout);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TryWait(It.IsAny<EventWaitHandle>(), _channelCloseTimeout))
+                            .Callback<WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) =>
+                                {
+                                    _sessionMock.Raise(
+                                        s => s.ChannelCloseReceived += null,
+                                        new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
+                                    _ = waitHandle.WaitOne();
+                                })
+                            .Returns(WaitResult.Success);
 
             var localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122);
             _listener = new AsyncSocketListener(localEndpoint);
@@ -138,7 +146,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
                     }
                     finally
                     {
-                        _channelBindFinishedWaitHandle.Set();
+                        _ = _channelBindFinishedWaitHandle.Set();
                     }
                 };
             _listener.Start();
@@ -154,7 +162,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
                         if (bytesReceived == 0)
                         {
                             _client.Shutdown(SocketShutdown.Send);
-                            _clientReceivedFinishedWaitHandle.Set();
+                            _ = _clientReceivedFinishedWaitHandle.Set();
                         }
                     }
                 );
@@ -166,17 +174,14 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         private void Act()
         {
-            if (_channel != null)
-            {
-                _channel.Dispose();
-            }
+            _channel?.Dispose();
         }
 
         [TestMethod]
         public void BindShouldHaveFinishedWithoutException()
         {
             Assert.IsTrue(_channelBindFinishedWaitHandle.WaitOne(0));
-            Assert.IsNull(_channelException, _channelException != null ? _channelException.ToString() : null);
+            Assert.IsNull(_channelException, _channelException?.ToString());
         }
 
         [TestMethod]
@@ -206,29 +211,54 @@ namespace Renci.SshNet.Tests.Classes.Channels
         private bool AssertExpectedMessage(ChannelOpenMessage channelOpenMessage)
         {
             if (channelOpenMessage == null)
+            {
                 return false;
+            }
+
             if (channelOpenMessage.LocalChannelNumber != _localChannelNumber)
+            {
                 return false;
+            }
+
             if (channelOpenMessage.InitialWindowSize != _localWindowSize)
+            {
                 return false;
+            }
+
             if (channelOpenMessage.MaximumPacketSize != _localPacketSize)
+            {
                 return false;
+            }
 
-            var directTcpipChannelInfo = channelOpenMessage.Info as DirectTcpipChannelInfo;
-            if (directTcpipChannelInfo == null)
+            if (channelOpenMessage.Info is not DirectTcpipChannelInfo directTcpipChannelInfo)
+            {
                 return false;
+            }
+
             if (directTcpipChannelInfo.HostToConnect != _remoteHost)
+            {
                 return false;
+            }
+
             if (directTcpipChannelInfo.PortToConnect != _port)
+            {
                 return false;
+            }
 
-            var clientEndpoint = _client.LocalEndPoint as IPEndPoint;
-            if (clientEndpoint == null)
+            if (_client.LocalEndPoint is not IPEndPoint clientEndpoint)
+            {
                 return false;
+            }
+
             if (directTcpipChannelInfo.OriginatorAddress != clientEndpoint.Address.ToString())
+            {
                 return false;
+            }
+
             if (directTcpipChannelInfo.OriginatorPort != clientEndpoint.Port)
+            {
                 return false;
+            }
 
             return true;
         }

+ 61 - 52
src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs

@@ -1,11 +1,13 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
+
 using Renci.SshNet.Channels;
 using Renci.SshNet.Messages.Connection;
 using Renci.SshNet.Tests.Common;
@@ -53,10 +55,10 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
             if (_channelThread != null)
             {
-                if (_channelThread.IsAlive)
-                    _channelThread.Abort();
+                _channelThread.Join();
                 _channelThread = null;
             }
+
             if (_channel != null)
             {
                 _channel.Dispose();
@@ -87,56 +89,63 @@ namespace Renci.SshNet.Tests.Classes.Channels
             _forwardedPortMock = new Mock<IForwardedPort>(MockBehavior.Strict);
 
             var sequence = new MockSequence();
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
-            _connectionInfoMock.InSequence(sequence).Setup(p => p.Timeout).Returns(_connectionInfoTimeout);
-            _sessionMock.InSequence(sequence).Setup(
-                p => p.SendMessage(
-                    It.Is<ChannelOpenConfirmationMessage>(
-                        m => m.LocalChannelNumber == _remoteChannelNumber
-                             &&
-                             m.InitialWindowSize == _localWindowSize
-                             &&
-                             m.MaximumPacketSize == _localPacketSize
-                             &&
-                             m.RemoteChannelNumber == _localChannelNumber)
-                    ));
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                .Setup(
-                    p => p.TrySendMessage(It.Is<ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
-                .Returns(true);
-            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
-            _sessionMock.InSequence(sequence)
-                .Setup(
-                    p => p.TrySendMessage(It.Is<ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
-                .Returns(true);
-            _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
-            _connectionInfoMock.InSequence(sequence).Setup(p => p.ChannelCloseTimeout).Returns(_channelCloseTimeout);
-            _sessionMock.InSequence(sequence)
-                        .Setup(p => p.TryWait(It.IsAny<EventWaitHandle>(), _channelCloseTimeout))
-                        .Callback<WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) =>
-                        {
-                            _sessionMock.Raise(
-                                s => s.ChannelCloseReceived += null,
-                                new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
-                            waitHandle.WaitOne();
-                        })
-                        .Returns(WaitResult.Success);
+
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.ConnectionInfo)
+                            .Returns(_connectionInfoMock.Object);
+            _ = _connectionInfoMock.InSequence(sequence)
+                                   .Setup(p => p.Timeout)
+                                   .Returns(_connectionInfoTimeout);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.SendMessage(It.Is<ChannelOpenConfirmationMessage>(m =>
+                                    m.LocalChannelNumber == _remoteChannelNumber &&
+                                    m.InitialWindowSize == _localWindowSize &&
+                                    m.MaximumPacketSize == _localPacketSize &&
+                                    m.RemoteChannelNumber == _localChannelNumber)));
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TrySendMessage(It.Is<ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.IsConnected)
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TrySendMessage(It.Is<ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber)))
+                            .Returns(true);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.ConnectionInfo)
+                            .Returns(_connectionInfoMock.Object);
+            _ = _connectionInfoMock.InSequence(sequence)
+                                   .Setup(p => p.ChannelCloseTimeout)
+                                   .Returns(_channelCloseTimeout);
+            _ = _sessionMock.InSequence(sequence)
+                            .Setup(p => p.TryWait(It.IsAny<EventWaitHandle>(), _channelCloseTimeout))
+                            .Callback<WaitHandle, TimeSpan>((waitHandle, channelCloseTimeout) =>
+                                {
+                                    _sessionMock.Raise(
+                                        s => s.ChannelCloseReceived += null,
+                                        new MessageEventArgs<ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
+                                    _ = waitHandle.WaitOne();
+                                })
+                            .Returns(WaitResult.Success);
 
             _remoteListener = new AsyncSocketListener(_remoteEndpoint);
-            _remoteListener.Connected += socket => _connectedRegister.Add(socket);
-            _remoteListener.Disconnected += socket => _disconnectedRegister.Add(socket);
+            _remoteListener.Connected += _connectedRegister.Add;
+            _remoteListener.Disconnected += _disconnectedRegister.Add;
             _remoteListener.Start();
 
-            _channel = new ChannelForwardedTcpip(
-                _sessionMock.Object,
-                _localChannelNumber,
-                _localWindowSize,
-                _localPacketSize,
-                _remoteChannelNumber,
-                _remoteWindowSize,
-                _remotePacketSize);
+            _channel = new ChannelForwardedTcpip(_sessionMock.Object,
+                                                 _localChannelNumber,
+                                                 _localWindowSize,
+                                                 _localPacketSize,
+                                                 _remoteChannelNumber,
+                                                 _remoteWindowSize,
+                                                 _remotePacketSize);
 
             _channelThread = new Thread(() =>
                 {
@@ -150,7 +159,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
                     }
                     finally
                     {
-                        _channelBindFinishedWaitHandle.Set();
+                        _ = _channelBindFinishedWaitHandle.Set();
                     }
                 });
             _channelThread.Start();
@@ -175,7 +184,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
         [TestMethod]
         public void BindShouldHaveFinishedWithoutException()
         {
-            Assert.IsNull(_channelException, _channelException != null ? _channelException.ToString() : null);
+            Assert.IsNull(_channelException, _channelException?.ToString());
             Assert.IsTrue(_channelBindFinishedWaitHandle.WaitOne(0));
         }
 
@@ -197,4 +206,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.IsFalse(_channel.IsOpen);
         }
     }
-}
+}

+ 4 - 1
src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Dispose_Disposed.cs

@@ -1,8 +1,11 @@
 using System;
 using System.Collections.Generic;
 using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
+
 using Renci.SshNet.Channels;
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
@@ -144,4 +147,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.IsFalse(_channel.IsOpen);
         }
     }
-}
+}

+ 21 - 1
src/Renci.SshNet.Tests/Classes/Channels/ChannelStub.cs

@@ -54,7 +54,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize)
         {
-            base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
+            InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
         }
 
         protected override void OnClose()
@@ -62,7 +62,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnClose();
 
             if (OnCloseException != null)
+            {
                 throw OnCloseException;
+            }
         }
 
         protected override void OnData(byte[] data)
@@ -70,7 +72,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnData(data);
 
             if (OnDataException != null)
+            {
                 throw OnDataException;
+            }
         }
 
         protected override void OnDisconnected()
@@ -78,7 +82,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnDisconnected();
 
             if (OnDisconnectedException != null)
+            {
                 throw OnDisconnectedException;
+            }
         }
 
         protected override void OnEof()
@@ -86,7 +92,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnEof();
 
             if (OnEofException != null)
+            {
                 throw OnEofException;
+            }
         }
 
         protected override void OnExtendedData(byte[] data, uint dataTypeCode)
@@ -94,7 +102,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnExtendedData(data, dataTypeCode);
 
             if (OnExtendedDataException != null)
+            {
                 throw OnExtendedDataException;
+            }
         }
 
         protected override void OnErrorOccured(Exception exp)
@@ -102,7 +112,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             OnErrorOccurredInvocations.Add(exp);
 
             if (OnErrorOccurredException != null)
+            {
                 throw OnErrorOccurredException;
+            }
         }
 
         protected override void OnFailure()
@@ -110,7 +122,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnFailure();
 
             if (OnFailureException != null)
+            {
                 throw OnFailureException;
+            }
         }
 
         protected override void OnRequest(RequestInfo info)
@@ -118,7 +132,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnRequest(info);
 
             if (OnRequestException != null)
+            {
                 throw OnRequestException;
+            }
         }
 
         protected override void OnSuccess()
@@ -126,7 +142,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnSuccess();
 
             if (OnSuccessException != null)
+            {
                 throw OnSuccessException;
+            }
         }
 
         protected override void OnWindowAdjust(uint bytesToAdd)
@@ -134,7 +152,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnWindowAdjust(bytesToAdd);
 
             if (OnWindowAdjustException != null)
+            {
                 throw OnWindowAdjustException;
+            }
         }
     }
 }

+ 3 - 5
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs

@@ -94,12 +94,10 @@ namespace Renci.SshNet.Tests.Classes.Channels
                 _channelClosedReceived = null;
             }
 
-            if (_raiseChannelCloseReceivedThread != null && _raiseChannelCloseReceivedThread.IsAlive)
+            if (_raiseChannelCloseReceivedThread != null)
             {
-                if (!_raiseChannelCloseReceivedThread.Join(1000))
-                {
-                    _raiseChannelCloseReceivedThread.Abort();
-                }
+                _raiseChannelCloseReceivedThread.Join();
+                _raiseChannelCloseReceivedThread = null;
             }
 
             if (_channelClosedEventHandlerCompleted != null)

+ 2 - 1
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -61,4 +62,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onDataException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -69,4 +70,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onEofException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -61,4 +62,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onExtendedDataException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -61,4 +62,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onFailureException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 5 - 4
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -32,8 +33,8 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         protected override void SetupMocks()
         {
-            SessionMock.Setup(p => p.ConnectionInfo)
-                        .Returns(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "password")));
+            _ = SessionMock.Setup(p => p.ConnectionInfo)
+                           .Returns(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "password")));
         }
 
         protected override void Arrange()
@@ -65,4 +66,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onRequestException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -61,4 +62,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onSuccessException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Connection;
 
@@ -70,4 +71,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onWindowAdjustException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 3 - 2
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
@@ -59,4 +60,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreSame(_onDisconnectedException, _channel.OnErrorOccurredInvocations[0]);
         }
     }
-}
+}

+ 5 - 3
src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
+
 using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes.Channels
@@ -35,7 +36,8 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         protected override void SetupMocks()
         {
-            SessionMock.Setup(p => p.IsConnected).Returns(true);
+            _ = SessionMock.Setup(p => p.IsConnected)
+                           .Returns(true);
         }
 
         protected override void Arrange()
@@ -72,4 +74,4 @@ namespace Renci.SshNet.Tests.Classes.Channels
             Assert.AreEqual(0, _channelExceptionRegister.Count);
         }
     }
-}
+}

+ 26 - 1
src/Renci.SshNet.Tests/Classes/Channels/ClientChannelStub.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+
 using Renci.SshNet.Channels;
 using Renci.SshNet.Messages.Connection;
 
@@ -58,7 +59,7 @@ namespace Renci.SshNet.Tests.Classes.Channels
 
         public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize)
         {
-            base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
+            InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize);
         }
 
         protected override void OnClose()
@@ -66,7 +67,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnClose();
 
             if (OnCloseException != null)
+            {
                 throw OnCloseException;
+            }
         }
 
         protected override void OnData(byte[] data)
@@ -74,7 +77,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnData(data);
 
             if (OnDataException != null)
+            {
                 throw OnDataException;
+            }
         }
 
         protected override void OnDisconnected()
@@ -82,7 +87,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnDisconnected();
 
             if (OnDisconnectedException != null)
+            {
                 throw OnDisconnectedException;
+            }
         }
 
         protected override void OnEof()
@@ -90,7 +97,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnEof();
 
             if (OnEofException != null)
+            {
                 throw OnEofException;
+            }
         }
 
         protected override void OnExtendedData(byte[] data, uint dataTypeCode)
@@ -98,7 +107,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnExtendedData(data, dataTypeCode);
 
             if (OnExtendedDataException != null)
+            {
                 throw OnExtendedDataException;
+            }
         }
 
         protected override void OnErrorOccured(Exception exp)
@@ -106,7 +117,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             OnErrorOccurredInvocations.Add(exp);
 
             if (OnErrorOccurredException != null)
+            {
                 throw OnErrorOccurredException;
+            }
         }
 
         protected override void OnFailure()
@@ -114,7 +127,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnFailure();
 
             if (OnFailureException != null)
+            {
                 throw OnFailureException;
+            }
         }
 
         protected override void OnRequest(RequestInfo info)
@@ -122,7 +137,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnRequest(info);
 
             if (OnRequestException != null)
+            {
                 throw OnRequestException;
+            }
         }
 
         protected override void OnSuccess()
@@ -130,7 +147,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnSuccess();
 
             if (OnSuccessException != null)
+            {
                 throw OnSuccessException;
+            }
         }
 
         protected override void OnWindowAdjust(uint bytesToAdd)
@@ -138,7 +157,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnWindowAdjust(bytesToAdd);
 
             if (OnWindowAdjustException != null)
+            {
                 throw OnWindowAdjustException;
+            }
         }
 
         protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize)
@@ -146,7 +167,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize);
 
             if (OnOpenConfirmationException != null)
+            {
                 throw OnOpenConfirmationException;
+            }
         }
 
         protected override void OnOpenFailure(uint reasonCode, string description, string language)
@@ -154,7 +177,9 @@ namespace Renci.SshNet.Tests.Classes.Channels
             base.OnOpenFailure(reasonCode, description, language);
 
             if (OnOpenFailureException != null)
+            {
                 throw OnOpenFailureException;
+            }
         }
     }
 }

+ 5 - 4
src/Renci.SshNet.Tests/Classes/CipherInfoTest.cs

@@ -1,7 +1,8 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Renci.SshNet.Common;
+
 using Renci.SshNet.Security.Cryptography;
 using Renci.SshNet.Tests.Common;
+
 using System;
 
 namespace Renci.SshNet.Tests.Classes
@@ -19,10 +20,10 @@ namespace Renci.SshNet.Tests.Classes
         [Ignore] // placeholder
         public void CipherInfoConstructorTest()
         {
-            int keySize = 0; // TODO: Initialize to an appropriate value
+            var keySize = 0; // TODO: Initialize to an appropriate value
             Func<byte[], byte[], Cipher> cipher = null; // TODO: Initialize to an appropriate value
-            CipherInfo target = new CipherInfo(keySize, cipher);
+            var target = new CipherInfo(keySize, cipher);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
     }
-}
+}

+ 2 - 1
src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PartialSuccessLimitReachedFollowedBySuccessInAlternateBranch.cs

@@ -1,7 +1,8 @@
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
-using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes
 {

+ 62 - 44
src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs

@@ -1,5 +1,7 @@
 using System.Collections.Generic;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
 
 namespace Renci.SshNet.Tests.Classes
@@ -19,52 +21,68 @@ namespace Renci.SshNet.Tests.Classes
         {
             var seq = new MockSequence();
 
-            SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
-            SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
-            SessionMock.InSequence(seq).Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"));
-
-            ConnectionInfoMock.InSequence(seq).Setup(p => p.CreateNoneAuthenticationMethod())
-                              .Returns(NoneAuthenticationMethodMock.Object);
-
-            NoneAuthenticationMethodMock.InSequence(seq)
-                                        .Setup(p => p.Authenticate(SessionMock.Object))
-                                        .Returns(AuthenticationResult.Failure);
-            ConnectionInfoMock.InSequence(seq)
-                              .Setup(p => p.AuthenticationMethods)
-                              .Returns(new List<IAuthenticationMethod>
-                                  {
-                                      KeyboardInteractiveAuthenticationMethodMock.Object,
-                                      PasswordAuthenticationMethodMock.Object,
-                                      PublicKeyAuthenticationMethodMock.Object
-                                  });
-            NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password" });
-            KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
-            PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
-            PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
-
-            PasswordAuthenticationMethodMock.InSequence(seq)
+            _ = SessionMock.InSequence(seq)
+                           .Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
+            _ = SessionMock.InSequence(seq)
+                           .Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
+            _ = SessionMock.InSequence(seq)
+                .Setup(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"));
+            _ = ConnectionInfoMock.InSequence(seq)
+                                  .Setup(p => p.CreateNoneAuthenticationMethod())
+                                  .Returns(NoneAuthenticationMethodMock.Object);
+            _ = NoneAuthenticationMethodMock.InSequence(seq)
                                             .Setup(p => p.Authenticate(SessionMock.Object))
-                                            .Returns(AuthenticationResult.PartialSuccess);
-            PasswordAuthenticationMethodMock.InSequence(seq)
+                                            .Returns(AuthenticationResult.Failure);
+            _ = ConnectionInfoMock.InSequence(seq)
+                                  .Setup(p => p.AuthenticationMethods)
+                                  .Returns(new List<IAuthenticationMethod>
+                                      {
+                                          KeyboardInteractiveAuthenticationMethodMock.Object,
+                                          PasswordAuthenticationMethodMock.Object,
+                                          PublicKeyAuthenticationMethodMock.Object
+                                      });
+            _ = NoneAuthenticationMethodMock.InSequence(seq)
                                             .Setup(p => p.AllowedAuthentications)
-                                            .Returns(new[] {"password", "publickey"});
-            KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive");
-            PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password");
-            PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey");
-
-            PublicKeyAuthenticationMethodMock.InSequence(seq)
-                                             .Setup(p => p.Authenticate(SessionMock.Object))
-                                             .Returns(AuthenticationResult.Failure);
-            PublicKeyAuthenticationMethodMock.InSequence(seq)
-                                             .Setup(p => p.Name)
-                                             .Returns("publickey");
-            PasswordAuthenticationMethodMock.InSequence(seq)
-                                            .Setup(p => p.Authenticate(SessionMock.Object))
-                                            .Returns(AuthenticationResult.Success);
-
-            SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
-            SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
-            SessionMock.InSequence(seq).Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"));
+                                            .Returns(new[] { "password" });
+            _ = KeyboardInteractiveAuthenticationMethodMock.InSequence(seq)
+                                                           .Setup(p => p.Name)
+                                                           .Returns("keyboard-interactive");
+            _ = PasswordAuthenticationMethodMock.InSequence(seq)
+                                                .Setup(p => p.Name)
+                                                .Returns("password");
+            _ = PublicKeyAuthenticationMethodMock.InSequence(seq)
+                                                 .Setup(p => p.Name)
+                                                 .Returns("publickey");
+            _ = PasswordAuthenticationMethodMock.InSequence(seq)
+                                                .Setup(p => p.Authenticate(SessionMock.Object))
+                                                .Returns(AuthenticationResult.PartialSuccess);
+            _ = PasswordAuthenticationMethodMock.InSequence(seq)
+                                                .Setup(p => p.AllowedAuthentications)
+                                                .Returns(new[] {"password", "publickey"});
+            _ = KeyboardInteractiveAuthenticationMethodMock.InSequence(seq)
+                                                           .Setup(p => p.Name)
+                                                           .Returns("keyboard-interactive");
+            _ = PasswordAuthenticationMethodMock.InSequence(seq)
+                                                .Setup(p => p.Name)
+                                                .Returns("password");
+            _ = PublicKeyAuthenticationMethodMock.InSequence(seq)
+                                                 .Setup(p => p.Name)
+                                                 .Returns("publickey");
+            _ = PublicKeyAuthenticationMethodMock.InSequence(seq)
+                                                 .Setup(p => p.Authenticate(SessionMock.Object))
+                                                 .Returns(AuthenticationResult.Failure);
+            _ = PublicKeyAuthenticationMethodMock.InSequence(seq)
+                                                 .Setup(p => p.Name)
+                                                 .Returns("publickey");
+            _ = PasswordAuthenticationMethodMock.InSequence(seq)
+                                                .Setup(p => p.Authenticate(SessionMock.Object))
+                                                .Returns(AuthenticationResult.Success);
+            _ = SessionMock.InSequence(seq)
+                           .Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"));
+            _ = SessionMock.InSequence(seq)
+                           .Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"));
+            _ = SessionMock.InSequence(seq)
+                           .Setup(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"));
         }
 
         protected override void Arrange()

+ 1 - 1
src/Renci.SshNet.Tests/Classes/CommandAsyncResultTest.cs

@@ -11,7 +11,7 @@ namespace Renci.SshNet.Tests.Classes
         public void BytesSentTest()
         {
             var target = new CommandAsyncResult();
-            int expected = new Random().Next();
+            var expected = new Random().Next();
 
             target.BytesSent = expected;
 

+ 19 - 23
src/Renci.SshNet.Tests/Classes/Common/AsyncResultTest.cs

@@ -1,6 +1,7 @@
 using System;
-using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Tests.Common;
 
@@ -19,10 +20,9 @@ namespace Renci.SshNet.Tests.Classes.Common
         ///</summary>
         public void EndInvokeTest1Helper<TResult>()
         {
-            AsyncResult<TResult> target = CreateAsyncResult<TResult>(); // TODO: Initialize to an appropriate value
-            TResult expected = default(TResult); // TODO: Initialize to an appropriate value
-            TResult actual;
-            actual = target.EndInvoke();
+            var target = CreateAsyncResult<TResult>(); // TODO: Initialize to an appropriate value
+            var expected = default(TResult); // TODO: Initialize to an appropriate value
+            var actual = target.EndInvoke();
             Assert.AreEqual(expected, actual);
             Assert.Inconclusive("Verify the correctness of this test method.");
         }
@@ -45,9 +45,9 @@ namespace Renci.SshNet.Tests.Classes.Common
         ///</summary>
         public void SetAsCompletedTest1Helper<TResult>()
         {
-            AsyncResult<TResult> target = CreateAsyncResult<TResult>(); // TODO: Initialize to an appropriate value
-            TResult result = default(TResult); // TODO: Initialize to an appropriate value
-            bool completedSynchronously = false; // TODO: Initialize to an appropriate value
+            var target = CreateAsyncResult<TResult>(); // TODO: Initialize to an appropriate value
+            TResult result = default; // TODO: Initialize to an appropriate value
+            var completedSynchronously = false; // TODO: Initialize to an appropriate value
             target.SetAsCompleted(result, completedSynchronously);
             Assert.Inconclusive("A method that does not return a value cannot be verified.");
         }
@@ -71,7 +71,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void EndInvokeTest()
         {
-            AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
+            var target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
             target.EndInvoke();
             Assert.Inconclusive("A method that does not return a value cannot be verified.");
         }
@@ -82,9 +82,9 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void SetAsCompletedTest()
         {
-            AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
+            var target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
             Exception exception = null; // TODO: Initialize to an appropriate value
-            bool completedSynchronously = false; // TODO: Initialize to an appropriate value
+            var completedSynchronously = false; // TODO: Initialize to an appropriate value
             target.SetAsCompleted(exception, completedSynchronously);
             Assert.Inconclusive("A method that does not return a value cannot be verified.");
         }
@@ -95,9 +95,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void AsyncStateTest()
         {
-            AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
-            object actual;
-            actual = target.AsyncState;
+            var target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
+            var actual = target.AsyncState;
             Assert.Inconclusive("Verify the correctness of this test method.");
         }
 
@@ -107,9 +106,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void AsyncWaitHandleTest()
         {
-            AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
-            WaitHandle actual;
-            actual = target.AsyncWaitHandle;
+            var target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
+            var actual = target.AsyncWaitHandle;
             Assert.Inconclusive("Verify the correctness of this test method.");
         }
 
@@ -119,9 +117,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void CompletedSynchronouslyTest()
         {
-            AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.CompletedSynchronously;
+            var target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
+            var actual = target.CompletedSynchronously;
             Assert.Inconclusive("Verify the correctness of this test method.");
         }
 
@@ -131,9 +128,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void IsCompletedTest()
         {
-            AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.IsCompleted;
+            var target = CreateAsyncResult(); // TODO: Initialize to an appropriate value
+            var actual = target.IsCompleted;
             Assert.Inconclusive("Verify the correctness of this test method.");
         }
     }

+ 3 - 3
src/Renci.SshNet.Tests/Classes/Common/AuthenticationPasswordChangeEventArgsTest.cs

@@ -19,8 +19,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void AuthenticationPasswordChangeEventArgsConstructorTest()
         {
-            string username = string.Empty; // TODO: Initialize to an appropriate value
-            AuthenticationPasswordChangeEventArgs target = new AuthenticationPasswordChangeEventArgs(username);
+            var username = string.Empty; // TODO: Initialize to an appropriate value
+            var target = new AuthenticationPasswordChangeEventArgs(username);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -31,7 +31,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void NewPasswordTest()
         {
             string username = string.Empty; // TODO: Initialize to an appropriate value
-            AuthenticationPasswordChangeEventArgs target = new AuthenticationPasswordChangeEventArgs(username); // TODO: Initialize to an appropriate value
+            var target = new AuthenticationPasswordChangeEventArgs(username); // TODO: Initialize to an appropriate value
             byte[] expected = null; // TODO: Initialize to an appropriate value
             byte[] actual;
             target.NewPassword = expected;

+ 4 - 4
src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptEventArgsTest.cs

@@ -20,11 +20,11 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void AuthenticationPromptEventArgsConstructorTest()
         {
-            string username = string.Empty; // TODO: Initialize to an appropriate value
-            string instruction = string.Empty; // TODO: Initialize to an appropriate value
-            string language = string.Empty; // TODO: Initialize to an appropriate value
+            var username = string.Empty; // TODO: Initialize to an appropriate value
+            var instruction = string.Empty; // TODO: Initialize to an appropriate value
+            var language = string.Empty; // TODO: Initialize to an appropriate value
             IEnumerable<AuthenticationPrompt> prompts = null; // TODO: Initialize to an appropriate value
-            AuthenticationPromptEventArgs target = new AuthenticationPromptEventArgs(username, instruction, language, prompts);
+            var target = new AuthenticationPromptEventArgs(username, instruction, language, prompts);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
     }

+ 10 - 11
src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptTest.cs

@@ -17,10 +17,10 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void AuthenticationPromptConstructorTest()
         {
-            int id = 0; // TODO: Initialize to an appropriate value
-            bool isEchoed = false; // TODO: Initialize to an appropriate value
-            string request = string.Empty; // TODO: Initialize to an appropriate value
-            AuthenticationPrompt target = new AuthenticationPrompt(id, isEchoed, request);
+            var id = 0; // TODO: Initialize to an appropriate value
+            var isEchoed = false; // TODO: Initialize to an appropriate value
+            var request = string.Empty; // TODO: Initialize to an appropriate value
+            var target = new AuthenticationPrompt(id, isEchoed, request);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -30,14 +30,13 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void ResponseTest()
         {
-            int id = 0; // TODO: Initialize to an appropriate value
-            bool isEchoed = false; // TODO: Initialize to an appropriate value
-            string request = string.Empty; // TODO: Initialize to an appropriate value
-            AuthenticationPrompt target = new AuthenticationPrompt(id, isEchoed, request); // TODO: Initialize to an appropriate value
-            string expected = string.Empty; // TODO: Initialize to an appropriate value
-            string actual;
+            var id = 0; // TODO: Initialize to an appropriate value
+            var isEchoed = false; // TODO: Initialize to an appropriate value
+            var request = string.Empty; // TODO: Initialize to an appropriate value
+            var target = new AuthenticationPrompt(id, isEchoed, request); // TODO: Initialize to an appropriate value
+            var expected = string.Empty; // TODO: Initialize to an appropriate value
             target.Response = expected;
-            actual = target.Response;
+            var actual = target.Response;
             Assert.AreEqual(expected, actual);
             Assert.Inconclusive("Verify the correctness of this test method.");
         }

Plik diff jest za duży
+ 112 - 115
src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs


+ 2 - 2
src/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs

@@ -4,10 +4,10 @@ using Renci.SshNet.Tests.Common;
 namespace Renci.SshNet.Tests.Classes.Common
 {
     /// <summary>
-    /// Provides data for <see cref="Renci.SshNet.Channels.Channel.OpenFailed"/> event.
+    /// Provides data for <see cref="SshNet.Channels.ClientChannel.OpenFailed"/> event.
     /// </summary>
     [TestClass]
     public class ChannelOpenFailedEventArgsTest : TestBase
     {
     }
-}
+}

+ 43 - 30
src/Renci.SshNet.Tests/Classes/Common/CountdownEventTest.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Diagnostics;
 using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace Renci.SshNet.Tests.Classes.Common
@@ -71,7 +72,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                countdownEvent.Signal();
+                _ = countdownEvent.Signal();
                 Assert.Fail();
             }
             catch (InvalidOperationException)
@@ -95,7 +96,9 @@ namespace Renci.SshNet.Tests.Classes.Common
             var expectedSignalCount = _random.Next(5, 20);
 
             for (var i = 0; i < (expectedSignalCount - 1); i++)
+            {
                 countdownEvent.AddCount();
+            }
 
             var threads = new Thread[expectedSignalCount];
             for (var i = 0; i < expectedSignalCount; i++)
@@ -103,8 +106,8 @@ namespace Renci.SshNet.Tests.Classes.Common
                 threads[i] = new Thread(() =>
                     {
                         Thread.Sleep(sleep);
-                        Interlocked.Increment(ref signalCount);
-                        countdownEvent.Signal();
+                        _ = Interlocked.Increment(ref signalCount);
+                        _ = countdownEvent.Signal();
                     });
                 threads[i].Start();
             }
@@ -135,17 +138,19 @@ namespace Renci.SshNet.Tests.Classes.Common
             var expectedSignalCount = _random.Next(5, 20);
 
             for (var i = 0; i < (expectedSignalCount - 1); i++)
+            {
                 countdownEvent.AddCount();
+            }
 
             var threads = new Thread[expectedSignalCount];
             for (var i = 0; i < expectedSignalCount; i++)
             {
                 threads[i] = new Thread(() =>
-                {
-                    Thread.Sleep(sleep);
-                    Interlocked.Increment(ref signalCount);
-                    countdownEvent.Signal();
-                });
+                    {
+                        Thread.Sleep(sleep);
+                        _ = Interlocked.Increment(ref signalCount);
+                        _ = countdownEvent.Signal();
+                    });
                 threads[i].Start();
             }
 
@@ -175,17 +180,19 @@ namespace Renci.SshNet.Tests.Classes.Common
             var expectedSignalCount = _random.Next(5, 20);
 
             for (var i = 0; i < (expectedSignalCount - 1); i++)
+            {
                 countdownEvent.AddCount();
+            }
 
             var threads = new Thread[expectedSignalCount];
             for (var i = 0; i < expectedSignalCount; i++)
             {
                 threads[i] = new Thread(() =>
-                {
-                    Thread.Sleep(sleep);
-                    countdownEvent.Signal();
-                    Interlocked.Increment(ref signalCount);
-                });
+                    {
+                        Thread.Sleep(sleep);
+                        _ = countdownEvent.Signal();
+                        _ = Interlocked.Increment(ref signalCount);
+                    });
                 threads[i].Start();
             }
 
@@ -198,7 +205,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             Assert.IsFalse(countdownEvent.IsSet);
             Assert.IsFalse(countdownEvent.WaitHandle.WaitOne(0));
 
-            countdownEvent.Wait(Session.InfiniteTimeSpan);
+            _ = countdownEvent.Wait(Session.InfiniteTimeSpan);
             countdownEvent.Dispose();
         }
 
@@ -225,17 +232,19 @@ namespace Renci.SshNet.Tests.Classes.Common
             var expectedSignalCount = _random.Next(5, 20);
 
             for (var i = 0; i < (expectedSignalCount - 1); i++)
+            {
                 countdownEvent.AddCount();
+            }
 
             var threads = new Thread[expectedSignalCount];
             for (var i = 0; i < expectedSignalCount; i++)
             {
                 threads[i] = new Thread(() =>
-                {
-                    Thread.Sleep(sleep);
-                    Interlocked.Increment(ref signalCount);
-                    countdownEvent.Signal();
-                });
+                    {
+                        Thread.Sleep(sleep);
+                        _ = Interlocked.Increment(ref signalCount);
+                        _ = countdownEvent.Signal();
+                    });
                 threads[i].Start();
             }
 
@@ -265,17 +274,19 @@ namespace Renci.SshNet.Tests.Classes.Common
             var expectedSignalCount = _random.Next(5, 20);
 
             for (var i = 0; i < (expectedSignalCount - 1); i++)
+            {
                 countdownEvent.AddCount();
+            }
 
             var threads = new Thread[expectedSignalCount];
             for (var i = 0; i < expectedSignalCount; i++)
             {
                 threads[i] = new Thread(() =>
-                {
-                    Thread.Sleep(sleep);
-                    Interlocked.Increment(ref signalCount);
-                    countdownEvent.Signal();
-                });
+                    {
+                        Thread.Sleep(sleep);
+                        _ = Interlocked.Increment(ref signalCount);
+                        _ = countdownEvent.Signal();
+                    });
                 threads[i].Start();
             }
 
@@ -305,17 +316,19 @@ namespace Renci.SshNet.Tests.Classes.Common
             var expectedSignalCount = _random.Next(5, 20);
 
             for (var i = 0; i < (expectedSignalCount - 1); i++)
+            {
                 countdownEvent.AddCount();
+            }
 
             var threads = new Thread[expectedSignalCount];
             for (var i = 0; i < expectedSignalCount; i++)
             {
                 threads[i] = new Thread(() =>
-                {
-                    Thread.Sleep(sleep);
-                    countdownEvent.Signal();
-                    Interlocked.Increment(ref signalCount);
-                });
+                    {
+                        Thread.Sleep(sleep);
+                        _ = countdownEvent.Signal();
+                        _ = Interlocked.Increment(ref signalCount);
+                    });
                 threads[i].Start();
             }
 
@@ -328,7 +341,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             Assert.IsFalse(countdownEvent.IsSet);
             Assert.IsFalse(countdownEvent.WaitHandle.WaitOne(0));
 
-            countdownEvent.Wait(Session.InfiniteTimeSpan);
+            _ = countdownEvent.Wait(Session.InfiniteTimeSpan);
             countdownEvent.Dispose();
         }
 

+ 4 - 4
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_IsEqualTo_ByteArray.cs

@@ -26,7 +26,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                Extensions.IsEqualTo(left, right);
+                _ = Extensions.IsEqualTo(left, right);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -44,7 +44,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                Extensions.IsEqualTo(left, right);
+                _ = Extensions.IsEqualTo(left, right);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -62,7 +62,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                Extensions.IsEqualTo(left, right);
+                _ = Extensions.IsEqualTo(left, right);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -157,7 +157,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             for (var i = 0; i < runs; i++)
             {
-                Extensions.IsEqualTo(left, right);
+                _ = Extensions.IsEqualTo(left, right);
             }
 
             GC.Collect();

+ 5 - 4
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_Pad.cs

@@ -1,6 +1,7 @@
-using System;
-using System.Diagnostics.CodeAnalysis;
+using System.Diagnostics.CodeAnalysis;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
@@ -13,7 +14,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void ShouldReturnNotPadded()
         {
             byte[] value = {0x0a, 0x0d};
-            byte[] padded = value.Pad(2);
+            var padded = value.Pad(2);
             Assert.AreEqual(value, padded);
             Assert.AreEqual(value.Length, padded.Length);
         }
@@ -22,7 +23,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         public void ShouldReturnPadded()
         {
             byte[] value = { 0x0a, 0x0d };
-            byte[] padded = value.Pad(3);
+            var padded = value.Pad(3);
             Assert.AreEqual(value.Length + 1, padded.Length);
             Assert.AreEqual(0x00, padded[0]);
             Assert.AreEqual(0x0a, padded[1]);

+ 2 - 4
src/Renci.SshNet.Tests/Classes/Common/ExtensionsTest_ToBigInteger2.cs

@@ -1,12 +1,10 @@
-using System;
-using System.Diagnostics.CodeAnalysis;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
 {
     [TestClass]
-    [SuppressMessage("ReSharper", "InvokeAsExtensionMethod")]
     public class ExtensionsTest_ToBigInteger2
     {
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Common/PacketDumpTest.cs

@@ -15,7 +15,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                PacketDump.Create(data, 0);
+                _ = PacketDump.Create(data, 0);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                PacketDump.Create(data, -1);
+                _ =PacketDump.Create(data, -1);
                 Assert.Fail();
             }
             catch (ArgumentOutOfRangeException ex)

+ 10 - 8
src/Renci.SshNet.Tests/Classes/Common/PipeStreamTest.cs

@@ -1,7 +1,9 @@
 using System;
 using System.IO;
 using System.Threading;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Tests.Common;
 
@@ -25,7 +27,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
                 Assert.AreEqual(stream.Length, testBuffer.Length);
 
-                stream.Read(outputBuffer, 0, outputBuffer.Length);
+                _ = stream.Read(outputBuffer, 0, outputBuffer.Length);
 
                 Assert.AreEqual(stream.Length, 0);
 
@@ -44,9 +46,9 @@ namespace Renci.SshNet.Tests.Classes.Common
             {
                 stream.Write(testBuffer, 0, testBuffer.Length);
                 Assert.AreEqual(stream.Length, testBuffer.Length);
-                stream.ReadByte();
+                _ = stream.ReadByte();
                 Assert.AreEqual(stream.Length, testBuffer.Length - 1);
-                stream.ReadByte();
+                _ = stream.ReadByte();
                 Assert.AreEqual(stream.Length, testBuffer.Length - 2);
             }
         }
@@ -92,7 +94,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                target.Seek(offset, origin);
+                _ = target.Seek(offset, origin);
                 Assert.Fail();
             }
             catch (NotSupportedException)
@@ -169,9 +171,9 @@ namespace Renci.SshNet.Tests.Classes.Common
             Assert.AreEqual(2L, target.Length);
             target.WriteByte(0x0a);
             Assert.AreEqual(3L, target.Length);
-            target.Read(new byte[2], 0, 2);
+            _ = target.Read(new byte[2], 0, 2);
             Assert.AreEqual(1L, target.Length);
-            target.ReadByte();
+            _ = target.ReadByte();
             Assert.AreEqual(0L, target.Length);
         }
 
@@ -195,7 +197,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             Assert.AreEqual(0, target.Position);
             target.WriteByte(0x0a);
             Assert.AreEqual(0, target.Position);
-            target.ReadByte();
+            _ = target.ReadByte();
             Assert.AreEqual(0, target.Position);
         }
 
@@ -214,4 +216,4 @@ namespace Renci.SshNet.Tests.Classes.Common
             }
         }
     }
-}
+}

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingRead.cs

@@ -34,7 +34,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             _pipeStream.Close();
 
             // give async read time to complete
-            _readThread.Join(100);
+            _ = _readThread.Join(100);
         }
 
         [TestMethod]

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Close_BlockingWrite.cs

@@ -45,7 +45,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             _pipeStream.Close();
 
             // give write time to complete
-            _writehread.Join(100);
+            _ = _writehread.Join(100);
         }
 
         [TestMethod]

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_BytesRemainingAfterRead.cs

@@ -30,7 +30,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             _readThread.Start();
 
             // ensure we've started reading
-            _readThread.Join(50);
+            _ = _readThread.Join(50);
         }
 
         protected override void Act()
@@ -38,7 +38,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             _pipeStream.Flush();
 
             // give async read time to complete
-            _readThread.Join(100);
+            _ = _readThread.Join(100);
         }
 
         [TestMethod]

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Common/PipeStream_Flush_NoBytesRemainingAfterRead.cs

@@ -34,7 +34,7 @@ namespace Renci.SshNet.Tests.Classes.Common
             _pipeStream.Flush();
 
             // give async read time to complete
-            _readThread.Join(100);
+            _ = _readThread.Join(100);
         }
 
         [TestMethod]

+ 3 - 3
src/Renci.SshNet.Tests/Classes/Common/PortForwardEventArgsTest.cs

@@ -18,7 +18,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         {
             try
             {
-                new PortForwardEventArgs(null, 80);
+                _ = new PortForwardEventArgs(null, 80);
             }
             catch (ArgumentNullException ex)
             {
@@ -54,7 +54,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                new PortForwardEventArgs(Resources.HOST, port);
+                _ = new PortForwardEventArgs(Resources.HOST, port);
                 Assert.Fail();
             }
             catch (ArgumentOutOfRangeException ex)
@@ -64,4 +64,4 @@ namespace Renci.SshNet.Tests.Classes.Common
             }
         }
     }
-}
+}

+ 2 - 2
src/Renci.SshNet.Tests/Classes/Common/PosixPathTest_CreateAbsoluteOrRelativeFilePath.cs

@@ -15,7 +15,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                PosixPath.CreateAbsoluteOrRelativeFilePath(path);
+                _ = PosixPath.CreateAbsoluteOrRelativeFilePath(path);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -32,7 +32,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                PosixPath.CreateAbsoluteOrRelativeFilePath(path);
+                _ = PosixPath.CreateAbsoluteOrRelativeFilePath(path);
                 Assert.Fail();
             }
             catch (ArgumentException ex)

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Common/PosixPathTest_GetDirectoryName.cs

@@ -14,7 +14,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                PosixPath.GetDirectoryName(path);
+                _ = PosixPath.GetDirectoryName(path);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Common/PosixPathTest_GetFileName.cs

@@ -14,7 +14,7 @@ namespace Renci.SshNet.Tests.Classes.Common
 
             try
             {
-                PosixPath.GetFileName(path);
+                _ = PosixPath.GetFileName(path);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)

+ 5 - 6
src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs

@@ -67,12 +67,11 @@ namespace Renci.SshNet.Tests.Classes.Common
             
             Assert.IsTrue(watch.ElapsedMilliseconds < 50);
 
-            var releaseThread = new Thread(
-                () =>
-                    {
-                        Thread.Sleep(sleepTime);
-                        target.Release();
-                    });
+            var releaseThread = new Thread(() =>
+                {
+                    Thread.Sleep(sleepTime);
+                    _ = target.Release();
+                });
             releaseThread.Start();
 
             target.Wait();

+ 13 - 11
src/Renci.SshNet.Tests/Classes/Common/SshConnectionExceptionTest.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Runtime.Serialization;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Renci.SshNet.Common;
 using Renci.SshNet.Messages.Transport;
 using Renci.SshNet.Tests.Common;
@@ -20,7 +22,7 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void SshConnectionExceptionConstructorTest()
         {
-            SshConnectionException target = new SshConnectionException();
+            var target = new SshConnectionException();
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -30,8 +32,8 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void SshConnectionExceptionConstructorTest1()
         {
-            string message = string.Empty; // TODO: Initialize to an appropriate value
-            SshConnectionException target = new SshConnectionException(message);
+            var message = string.Empty; // TODO: Initialize to an appropriate value
+            var target = new SshConnectionException(message);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -41,9 +43,9 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void SshConnectionExceptionConstructorTest2()
         {
-            string message = string.Empty; // TODO: Initialize to an appropriate value
-            DisconnectReason disconnectReasonCode = new DisconnectReason(); // TODO: Initialize to an appropriate value
-            SshConnectionException target = new SshConnectionException(message, disconnectReasonCode);
+            var message = string.Empty; // TODO: Initialize to an appropriate value
+            var disconnectReasonCode = new DisconnectReason(); // TODO: Initialize to an appropriate value
+            var target = new SshConnectionException(message, disconnectReasonCode);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -53,10 +55,10 @@ namespace Renci.SshNet.Tests.Classes.Common
         [TestMethod]
         public void SshConnectionExceptionConstructorTest3()
         {
-            string message = string.Empty; // TODO: Initialize to an appropriate value
-            DisconnectReason disconnectReasonCode = new DisconnectReason(); // TODO: Initialize to an appropriate value
+            var message = string.Empty; // TODO: Initialize to an appropriate value
+            var disconnectReasonCode = new DisconnectReason(); // TODO: Initialize to an appropriate value
             Exception inner = null; // TODO: Initialize to an appropriate value
-            SshConnectionException target = new SshConnectionException(message, disconnectReasonCode, inner);
+            var target = new SshConnectionException(message, disconnectReasonCode, inner);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -67,9 +69,9 @@ namespace Renci.SshNet.Tests.Classes.Common
         [Ignore] // placeholder for actual test
         public void GetObjectDataTest()
         {
-            SshConnectionException target = new SshConnectionException(); // TODO: Initialize to an appropriate value
+            var target = new SshConnectionException(); // TODO: Initialize to an appropriate value
             SerializationInfo info = null; // TODO: Initialize to an appropriate value
-            StreamingContext context = new StreamingContext(); // TODO: Initialize to an appropriate value
+            var context = new StreamingContext(); // TODO: Initialize to an appropriate value
             target.GetObjectData(info, context);
             Assert.Inconclusive("A method that does not return a value cannot be verified.");
         }

+ 7 - 9
src/Renci.SshNet.Tests/Classes/Compression/ZlibOpenSshTest.cs

@@ -1,7 +1,6 @@
-using Renci.SshNet.Compression;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using Renci.SshNet;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Renci.SshNet.Compression;
 using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Compression
@@ -20,7 +19,7 @@ namespace Renci.SshNet.Tests.Classes.Compression
         [TestMethod()]
         public void ZlibOpenSshConstructorTest()
         {
-            ZlibOpenSsh target = new ZlibOpenSsh();
+            var target = new ZlibOpenSsh();
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -30,7 +29,7 @@ namespace Renci.SshNet.Tests.Classes.Compression
         [TestMethod()]
         public void InitTest()
         {
-            ZlibOpenSsh target = new ZlibOpenSsh(); // TODO: Initialize to an appropriate value
+            var target = new ZlibOpenSsh(); // TODO: Initialize to an appropriate value
             Session session = null; // TODO: Initialize to an appropriate value
             target.Init(session);
             Assert.Inconclusive("A method that does not return a value cannot be verified.");
@@ -42,9 +41,8 @@ namespace Renci.SshNet.Tests.Classes.Compression
         [TestMethod()]
         public void NameTest()
         {
-            ZlibOpenSsh target = new ZlibOpenSsh(); // TODO: Initialize to an appropriate value
-            string actual;
-            actual = target.Name;
+            var target = new ZlibOpenSsh(); // TODO: Initialize to an appropriate value
+            var actual = target.Name;
             Assert.Inconclusive("Verify the correctness of this test method.");
         }
     }

+ 11 - 10
src/Renci.SshNet.Tests/Classes/Compression/ZlibStreamTest.cs

@@ -1,11 +1,12 @@
-using Renci.SshNet.Compression;
+using System.IO;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using System.IO;
+
+using Renci.SshNet.Compression;
 using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Compression
-{   
+{
     /// <summary>
     ///This is a test class for ZlibStreamTest and is intended
     ///to contain all ZlibStreamTest Unit Tests
@@ -21,8 +22,8 @@ namespace Renci.SshNet.Tests.Classes.Compression
         public void ZlibStreamConstructorTest()
         {
             Stream stream = null; // TODO: Initialize to an appropriate value
-            CompressionMode mode = new CompressionMode(); // TODO: Initialize to an appropriate value
-            ZlibStream target = new ZlibStream(stream, mode);
+            var mode = new CompressionMode(); // TODO: Initialize to an appropriate value
+            var target = new ZlibStream(stream, mode);
             Assert.Inconclusive("TODO: Implement code to verify target");
         }
 
@@ -34,11 +35,11 @@ namespace Renci.SshNet.Tests.Classes.Compression
         public void WriteTest()
         {
             Stream stream = null; // TODO: Initialize to an appropriate value
-            CompressionMode mode = new CompressionMode(); // TODO: Initialize to an appropriate value
-            ZlibStream target = new ZlibStream(stream, mode); // TODO: Initialize to an appropriate value
+            var mode = new CompressionMode(); // TODO: Initialize to an appropriate value
+            var target = new ZlibStream(stream, mode); // TODO: Initialize to an appropriate value
             byte[] buffer = null; // TODO: Initialize to an appropriate value
-            int offset = 0; // TODO: Initialize to an appropriate value
-            int count = 0; // TODO: Initialize to an appropriate value
+            var offset = 0; // TODO: Initialize to an appropriate value
+            var count = 0; // TODO: Initialize to an appropriate value
             target.Write(buffer, offset, count);
             Assert.Inconclusive("A method that does not return a value cannot be verified.");
         }

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTestBase.cs

@@ -1,7 +1,7 @@
 using Moq;
+
 using Renci.SshNet.Connection;
 using Renci.SshNet.Tests.Common;
-using System.Net;
 
 namespace Renci.SshNet.Tests.Classes.Connection
 {

+ 10 - 12
src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionRefusedByServer.cs

@@ -1,11 +1,12 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Net;
 using System.Net.Sockets;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -30,18 +31,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -50,7 +48,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SocketException ex)
@@ -86,7 +84,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 11 - 17
src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_ConnectionSucceeded.cs

@@ -1,12 +1,13 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Net;
 using System.Net.Sockets;
-using System.Threading;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
 
 namespace Renci.SshNet.Tests.Classes.Connection
 {
@@ -41,23 +42,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_server != null)
-            {
-                _server.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _server?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()

+ 4 - 4
src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_HostNameInvalid.cs

@@ -1,6 +1,6 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using System.Net.Sockets;
+using System.Net.Sockets;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace Renci.SshNet.Tests.Classes.Connection
 {
@@ -22,7 +22,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SocketException ex)

+ 12 - 13
src/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs

@@ -1,13 +1,15 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,18 +36,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -54,7 +53,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -91,7 +90,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 11 - 11
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ConnectionToProxyRefused.cs

@@ -1,6 +1,7 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
-using Renci.SshNet.Common;
+
 using System;
 using System.Diagnostics;
 using System.Net;
@@ -28,8 +29,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(5000);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(5000)
+                };
             _stopWatch = new Stopwatch();
             _actualException = null;
 
@@ -38,18 +41,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -58,7 +58,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SocketException ex)
@@ -94,7 +94,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 10 - 15
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyClosesConnectionBeforeStatusLineIsSent.cs

@@ -30,8 +30,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(100)
+                };
             _actualException = null;
 
             _clientSocket = SocketFactory.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@@ -47,30 +49,23 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -101,7 +96,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 1 - 1
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyHostInvalid.cs

@@ -29,7 +29,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SocketException ex)

+ 22 - 19
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsEmpty.cs

@@ -1,7 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Net;
@@ -9,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,8 +37,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  string.Empty,
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic cHJveHlVc2VyOg=={2}{2}",
                                                  _connectionInfo.Host,
@@ -49,13 +54,14 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _proxyServer.Disconnected += (socket) => _disconnected = true;
             _proxyServer.Connected += socket =>
                 {
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
-                        socket.Shutdown(SocketShutdown.Send);
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+
+                    socket.Shutdown(SocketShutdown.Send);
                 };
             _proxyServer.BytesReceived += (bytesReceived, socket) =>
                 {
@@ -66,18 +72,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 14 - 14
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyPasswordIsNull.cs

@@ -34,8 +34,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  null,
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic cHJveHlVc2VyOg=={2}{2}",
                                                  _connectionInfo.Host,
@@ -49,12 +51,13 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _proxyServer.Disconnected += (socket) => _disconnected = true;
             _proxyServer.Connected += socket =>
             {
-                socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
-                socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+                _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+                _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+
                 socket.Shutdown(SocketShutdown.Send);
             };
             _proxyServer.BytesReceived += (bytesReceived, socket) =>
@@ -66,18 +69,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 19 - 16
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseDoesNotContainHttpStatusLine.cs

@@ -1,14 +1,17 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -33,8 +36,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(100)
+                };
             _bytesReceivedByProxy = new List<byte>();
             _actualException = null;
 
@@ -46,7 +51,8 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     if (_bytesReceivedByProxy.Count == 0)
                     {
-                        socket.Send(Encoding.ASCII.GetBytes("Whatever\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Whatever\r\n"));
+
                         socket.Shutdown(SocketShutdown.Send);
                     }
 
@@ -57,25 +63,22 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -106,7 +109,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 21 - 18
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_ExtraTextBeforeStatusLine.cs

@@ -1,7 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Net;
@@ -9,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,8 +37,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
                                                  _connectionInfo.Host,
@@ -56,12 +61,13 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 // it sends the CONNECT request
                 if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
                 {
-                    socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+
                     socket.Shutdown(SocketShutdown.Send);
                 }
             };
@@ -70,18 +76,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 21 - 18
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_HeadersAndContent.cs

@@ -1,7 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Net;
@@ -9,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,8 +37,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
                                                  _connectionInfo.Host,
@@ -56,12 +61,13 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     // it sends the CONNECT request
                     if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
                     {
-                        socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("TEEN_BYTES"));
-                        socket.Send(Encoding.ASCII.GetBytes("!666!"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("TEEN_BYTES"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("!666!"));
+                        
                         socket.Shutdown(SocketShutdown.Send);
                     }
                 };
@@ -70,18 +76,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 12 - 12
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIs200_OnlyHeaders.cs

@@ -34,8 +34,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
                                                  _connectionInfo.Host,
@@ -56,10 +58,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     // it sends the CONNECT request
                     if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
                     {
-                        socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+
                         socket.Shutdown(SocketShutdown.Send);
                     }
                 };
@@ -68,18 +71,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 19 - 16
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyResponseStatusIsNot200.cs

@@ -1,14 +1,17 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -33,8 +36,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(100);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(100)
+                };
             _bytesReceivedByProxy = new List<byte>();
             _actualException = null;
 
@@ -46,7 +51,8 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     if (_bytesReceivedByProxy.Count == 0)
                     {
-                        socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 404 I searched everywhere, really...\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 404 I searched everywhere, really...\r\n"));
+
                         socket.Shutdown(SocketShutdown.Send);
                     }
 
@@ -57,25 +63,22 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -106,7 +109,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 21 - 23
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsEmpty.cs

@@ -1,7 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Net;
@@ -9,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,8 +37,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  string.Empty,
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}{2}",
                                                  _connectionInfo.Host,
                                                  _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
@@ -55,12 +60,12 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     // it sends the CONNECT request
                     if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
                     {
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
                     }
                 };
             _proxyServer.Start();
@@ -68,23 +73,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Close();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Close();
         }
 
         protected override void Act()

+ 18 - 16
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNotNullAndNotEmpty.cs

@@ -1,7 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Net;
@@ -9,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,8 +37,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "user",
                                                  "pwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic dXNlcjpwd2Q={2}{2}",
                                                  _connectionInfo.Host,
@@ -48,10 +53,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _proxyServer = new AsyncSocketListener(new IPEndPoint(IPAddress.Loopback, _connectionInfo.ProxyPort));
             _proxyServer.Connected += (socket) =>
                 {
-                    socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
                 };
             _proxyServer.Disconnected += (socket) => _disconnected = true;
             _proxyServer.BytesReceived += (bytesReceived, socket) =>
@@ -63,18 +68,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 20 - 18
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_ProxyUserNameIsNull.cs

@@ -1,7 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Net;
@@ -9,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,8 +37,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  null,
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(20);
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(20)
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}{2}",
                                                  _connectionInfo.Host,
                                                  _connectionInfo.Port.ToString(CultureInfo.InvariantCulture),
@@ -55,12 +60,12 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 // it sends the CONNECT request
                 if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
                 {
-                    socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                    socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH.NET\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                    _ = socket.Send(Encoding.ASCII.GetBytes("SSH4EVER"));
                 }
             };
             _proxyServer.Start();
@@ -68,8 +73,8 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
@@ -82,10 +87,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 _clientSocket.Close();
             }
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()

+ 16 - 14
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs

@@ -1,12 +1,15 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -31,8 +34,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200))
+                };
             _stopWatch = new Stopwatch();
             _actualException = null;
 
@@ -41,18 +46,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -61,7 +63,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -98,7 +100,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 24 - 26
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingHttpContent.cs

@@ -1,9 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Globalization;
@@ -12,6 +7,14 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -41,8 +44,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200))
+                };
             _expectedHttpRequest = string.Format("CONNECT {0}:{1} HTTP/1.0{2}" +
                                                  "Proxy-Authorization: Basic cHJveHlVc2VyOnByb3h5UHdk{2}{2}",
                                                  _connectionInfo.Host,
@@ -63,11 +68,11 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     // Force a timeout by sending less content than indicated by Content-Length header
                     if (_bytesReceivedByProxy.Count == _expectedHttpRequest.Length)
                     {
-                        socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("\r\n"));
-                        socket.Send(Encoding.ASCII.GetBytes("TOO_FEW"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Content-Length: 10\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("\r\n"));
+                        _ = socket.Send(Encoding.ASCII.GetBytes("TOO_FEW"));
                     }
                 };
             _proxyServer.Start();
@@ -78,23 +83,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_server != null)
-            {
-                _server.Dispose();
-            }
-
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _server?.Dispose();
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
@@ -103,7 +101,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -156,7 +154,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 19 - 21
src/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutReadingStatusLine.cs

@@ -1,15 +1,18 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -37,8 +40,10 @@ namespace Renci.SshNet.Tests.Classes.Connection
                                                  8122,
                                                  "proxyUser",
                                                  "proxyPwd",
-                                                 new KeyboardInteractiveAuthenticationMethod("user"));
-            _connectionInfo.Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200));
+                                                 new KeyboardInteractiveAuthenticationMethod("user"))
+                {
+                    Timeout = TimeSpan.FromMilliseconds(random.Next(50, 200))
+                };
             _stopWatch = new Stopwatch();
             _actualException = null;
 
@@ -54,23 +59,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_server != null)
-            {
-                _server.Dispose();
-            }
-
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _server?.Dispose();
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
@@ -79,7 +77,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -126,7 +124,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 11 - 7
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs

@@ -1,8 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
@@ -10,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -63,7 +65,9 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _server.BytesReceived += (bytes, socket) =>
                 {
                     _dataReceivedByServer.AddRange(bytes);
-                    socket.Send(_serverIdentification);
+
+                    _ = socket.Send(_serverIdentification);
+
                     socket.Shutdown(SocketShutdown.Send);
                 };
             _server.Disconnected += (socket) => _clientDisconnected = true;
@@ -78,7 +82,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _protocolVersionExchange.Start(_clientVersion, _client, _timeout);
+                _ = _protocolVersionExchange.Start(_clientVersion, _client, _timeout);
                 Assert.Fail();
             }
             catch (SshConnectionException ex)

+ 14 - 10
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs

@@ -1,8 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
@@ -10,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -61,11 +63,13 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _server = new AsyncSocketListener(_serverEndPoint);
             _server.Start();
             _server.BytesReceived += (bytes, socket) =>
-            {
-                _dataReceivedByServer.AddRange(bytes);
-                socket.Send(_serverIdentification);
-                socket.Shutdown(SocketShutdown.Send);
-            };
+                {
+                    _dataReceivedByServer.AddRange(bytes);
+
+                    _ = socket.Send(_serverIdentification);
+
+                    socket.Shutdown(SocketShutdown.Send);
+                };
             _server.Disconnected += (socket) => _clientDisconnected = true;
 
             _client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

+ 10 - 7
src/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs

@@ -1,8 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
@@ -10,6 +6,12 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -61,7 +63,8 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _server.BytesReceived += (bytes, socket) =>
                 {
                     _dataReceivedByServer.AddRange(bytes);
-                    socket.Send(Encoding.UTF8.GetBytes("Welcome!\r\n"));
+
+                    _ = socket.Send(Encoding.UTF8.GetBytes("Welcome!\r\n"));
                 };
             _server.Disconnected += (socket) => _clientDisconnected = true;
 
@@ -75,7 +78,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _protocolVersionExchange.Start(_clientVersion, _client, _timeout);
+                _ = _protocolVersionExchange.Start(_clientVersion, _client, _timeout);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)

+ 4 - 3
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTestBase.cs

@@ -1,8 +1,9 @@
-using Moq;
+using System.Net;
+
+using Moq;
+
 using Renci.SshNet.Connection;
 using Renci.SshNet.Tests.Common;
-using System.Net;
-using System.Threading;
 
 namespace Renci.SshNet.Tests.Classes.Connection
 {

+ 15 - 33
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionRejectedByProxy.cs

@@ -1,13 +1,16 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -36,7 +39,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     if (_bytesReceivedByProxy.Count == 0)
                     {
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                 // Reply version (null byte)
                                 0x00,
@@ -52,30 +55,23 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -106,7 +102,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)
@@ -120,19 +116,5 @@ namespace Renci.SshNet.Tests.Classes.Connection
             SocketFactoryMock.Verify(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp),
                                      Times.Once());
         }
-
-        private static byte GetNotSupportedSocksVersion()
-        {
-            var random = new Random();
-
-            while (true)
-            {
-                var socksVersion = random.Next(1, 255);
-                if (socksVersion != 4)
-                {
-                    return (byte) socksVersion;
-                }
-            }
-        }
     }
 }

+ 15 - 19
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionSucceeded.cs

@@ -1,15 +1,18 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -43,7 +46,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     if (_bytesReceivedByProxy.Count == bytesReceived.Length)
                     {
                         // Send SOCKS response
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                 // Reply version (null byte)
                                 0x00,
@@ -60,7 +63,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                             });
 
                         // Send extra byte to allow us to verify that connector did not consume too much
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                 0xfe
                             });
@@ -71,23 +74,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()

+ 10 - 12
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_ConnectionToProxyRefused.cs

@@ -1,10 +1,11 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Net.Sockets;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -29,18 +30,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -49,7 +47,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SocketException ex)
@@ -85,7 +83,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 5 - 8
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs

@@ -31,18 +31,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -51,7 +48,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -88,7 +85,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 16 - 20
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingDestinationAddress.cs

@@ -1,15 +1,18 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -40,7 +43,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _proxyServer.Disconnected += socket => _disconnected = true;
             _proxyServer.Connected += socket =>
             {
-                socket.Send(new byte[]
+                _ = socket.Send(new byte[]
                     {
                             // Reply version (null byte)
                             0x00,
@@ -58,23 +61,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_server != null)
-            {
-                _server.Dispose();
-            }
-
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _server?.Dispose();
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
@@ -83,7 +79,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -130,7 +126,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 15 - 19
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyCode.cs

@@ -1,15 +1,18 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Connection;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Connection;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -40,7 +43,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _proxyServer.Disconnected += socket => _disconnected = true;
             _proxyServer.Connected += socket =>
                 {
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                             // Reply version (null byte)
                             0x00
@@ -54,23 +57,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_server != null)
-            {
-                _server.Dispose();
-            }
-
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _server?.Dispose();
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
@@ -79,7 +75,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)

+ 6 - 13
src/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutReadingReplyVersion.cs

@@ -46,23 +46,16 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_server != null)
-            {
-                _server.Dispose();
-            }
-
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _server?.Dispose();
+            _proxyServer?.Dispose();
         }
 
         protected override void Act()
@@ -71,7 +64,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -118,7 +111,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 4 - 3
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTestBase.cs

@@ -1,10 +1,11 @@
 using Moq;
+
 using Renci.SshNet.Connection;
 using Renci.SshNet.Tests.Common;
+
 using System;
 using System.Net;
 using System.Text;
-using System.Threading;
 
 namespace Renci.SshNet.Tests.Classes.Connection
 {
@@ -59,8 +60,8 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             for (var i = 0; i < length; i++)
             {
-                var @char = (char) random.Next(offset, offset + 26);
-                sb.Append(@char);
+                var c = (char) random.Next(offset, offset + 26);
+                _ = sb.Append(c);
             }
 
             return sb.ToString();

+ 10 - 13
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ConnectionToProxyRefused.cs

@@ -1,11 +1,11 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using System;
+using System;
 using System.Diagnostics;
-using System.Net;
 using System.Net.Sockets;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -30,18 +30,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -50,7 +47,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SocketException ex)
@@ -86,7 +83,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 7 - 10
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_NoAuthentication_ConnectionSucceeded.cs

@@ -39,7 +39,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     // We received the greeting
 
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                                     // SOCKS version
                                     0x05,
@@ -51,7 +51,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     // We received the connection request
 
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                                     // SOCKS version
                                     0x05,
@@ -62,7 +62,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                         });
 
                     // Send server bound address
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                                     // IPv6
                                     0x04,
@@ -89,7 +89,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                         });
 
                     // Send extra byte to allow us to verify that connector did not consume too much
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                                 0xff
                         });
@@ -100,18 +100,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 15 - 19
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_ProxySocksVersionIsNotSupported.cs

@@ -1,12 +1,15 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -34,37 +37,30 @@ namespace Renci.SshNet.Tests.Classes.Connection
             _proxyServer.Disconnected += socket => _disconnected = true;
             _proxyServer.BytesReceived += (bytesReceived, socket) =>
                 {
-                    socket.Send(new byte[] { _proxySocksVersion });
+                    _ = socket.Send(new byte[] { _proxySocksVersion });
                 };
             _proxyServer.Start();
         }
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -95,7 +91,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 12 - 13
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs

@@ -1,12 +1,14 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using System;
+using System;
 using System.Diagnostics;
 using System.Globalization;
-using System.Net;
 using System.Net.Sockets;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -33,18 +35,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
@@ -53,7 +52,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (SshOperationTimeoutException ex)
@@ -90,7 +89,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 8 - 15
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_AuthenticationFailed.cs

@@ -42,7 +42,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     // We received the greeting
 
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                             // SOCKS version
                             0x05,
@@ -54,7 +54,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 {
                     // We received the username/password authentication request
 
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                             // Authentication version
                             0x01,
@@ -68,30 +68,23 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -163,7 +156,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 16 - 16
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_ConnectionSucceeded.cs

@@ -1,8 +1,4 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
@@ -10,6 +6,13 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -40,7 +43,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     {
                         // We received the greeting
 
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                     // SOCKS version
                                     0x05,
@@ -52,7 +55,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     {
                         // We received the username/password authentication request
 
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                     // Authentication version
                                     0x01,
@@ -64,7 +67,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     {
                         // We received the connection request
 
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                     // SOCKS version
                                     0x05,
@@ -75,7 +78,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                             });
 
                         // Send server bound address
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                     // IPv4
                                     0x01,
@@ -90,7 +93,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                             });
 
                         // Send extra byte to allow us to verify that connector did not consume too much
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                 0xfe
                             });
@@ -101,18 +104,15 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
+            _proxyServer?.Dispose();
 
             if (_clientSocket != null)
             {

+ 7 - 14
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_PasswordExceedsMaximumLength.cs

@@ -41,7 +41,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                 // Wait until we received the greeting
                 if (_bytesReceivedByProxy.Count == 4)
                 {
-                    socket.Send(new byte[]
+                    _ = socket.Send(new byte[]
                         {
                                 // SOCKS version
                                 0x05,
@@ -55,30 +55,23 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -135,7 +128,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 26 - 32
src/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_UserNamePasswordAuthentication_UserNameExceedsMaximumLength.cs

@@ -1,14 +1,17 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using Renci.SshNet.Common;
-using Renci.SshNet.Tests.Common;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Tests.Common;
+
 namespace Renci.SshNet.Tests.Classes.Connection
 {
     [TestClass]
@@ -41,7 +44,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
                     // Wait until we received the greeting
                     if (_bytesReceivedByProxy.Count == 4)
                     {
-                        socket.Send(new byte[]
+                        _ = socket.Send(new byte[]
                             {
                                 // SOCKS version
                                 0x05,
@@ -55,30 +58,23 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
         protected override void SetupMocks()
         {
-            SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
-                             .Returns(_clientSocket);
+            _ = SocketFactoryMock.Setup(p => p.Create(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
+                                 .Returns(_clientSocket);
         }
 
         protected override void TearDown()
         {
             base.TearDown();
 
-            if (_proxyServer != null)
-            {
-                _proxyServer.Dispose();
-            }
-
-            if (_clientSocket != null)
-            {
-                _clientSocket.Dispose();
-            }
+            _proxyServer?.Dispose();
+            _clientSocket?.Dispose();
         }
 
         protected override void Act()
         {
             try
             {
-                Connector.Connect(_connectionInfo);
+                _ = Connector.Connect(_connectionInfo);
                 Assert.Fail();
             }
             catch (ProxyException ex)
@@ -101,20 +97,18 @@ namespace Renci.SshNet.Tests.Classes.Connection
         [TestMethod]
         public void ProxyShouldHaveReceivedExpectedSocksRequest()
         {
-            var expectedSocksRequest = new List<byte>();
-
-            //
             // Client greeting
-            //
-
-            // SOCKS version
-            expectedSocksRequest.Add(0x05);
-            // Number of authentication methods supported
-            expectedSocksRequest.Add(0x02);
-            // No authentication
-            expectedSocksRequest.Add(0x00);
-            // Username/password
-            expectedSocksRequest.Add(0x02);
+            var expectedSocksRequest = new List<byte>
+            {
+                // SOCKS version
+                0x05,
+                // Number of authentication methods supported
+                0x02,
+                // No authentication
+                0x00,
+                // Username/password
+                0x02
+            };
 
             var errorText = string.Format("Expected:{0}{1}{0}but was:{0}{2}",
                                           Environment.NewLine,
@@ -135,7 +129,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
         {
             try
             {
-                _clientSocket.Receive(new byte[0]);
+                _ = _clientSocket.Receive(new byte[0]);
                 Assert.Fail();
             }
             catch (ObjectDisposedException)

+ 4 - 4
src/Renci.SshNet.Tests/Classes/Connection/SshIdentificationTest.cs

@@ -27,7 +27,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                new SshIdentification(protocolVersion, softwareVersion);
+                _ = new SshIdentification(protocolVersion, softwareVersion);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -45,7 +45,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                new SshIdentification(protocolVersion, softwareVersion);
+                _ = new SshIdentification(protocolVersion, softwareVersion);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -90,7 +90,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                new SshIdentification(protocolVersion, softwareVersion, comments);
+                _ = new SshIdentification(protocolVersion, softwareVersion, comments);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -109,7 +109,7 @@ namespace Renci.SshNet.Tests.Classes.Connection
 
             try
             {
-                new SshIdentification(protocolVersion, softwareVersion, comments);
+                _ = new SshIdentification(protocolVersion, softwareVersion, comments);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)

+ 119 - 31
src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs

@@ -33,9 +33,15 @@ namespace Renci.SshNet.Tests.Classes
         {
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.Http, null,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
-                    new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       ProxyTypes.Http,
+                                       null,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -51,8 +57,14 @@ namespace Renci.SshNet.Tests.Classes
         {
             var proxyHost = string.Empty;
 
-            var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME,
-                ProxyTypes.Http, string.Empty, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
+            var connectionInfo = new ConnectionInfo(Resources.HOST,
+                                                    int.Parse(Resources.PORT),
+                                                    Resources.USERNAME,
+                                                    ProxyTypes.Http,
+                                                    string.Empty,
+                                                    int.Parse(Resources.PORT),
+                                                    Resources.USERNAME,
+                                                    Resources.PASSWORD,
                 new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
 
             Assert.AreSame(proxyHost, connectionInfo.ProxyHost);
@@ -66,7 +78,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.Http, Resources.HOST, ++maxPort, Resources.USERNAME, Resources.PASSWORD, null);
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       ProxyTypes.Http,
+                                       Resources.HOST,
+                                       ++maxPort,
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       null);
                 Assert.Fail();
             }
             catch (ArgumentOutOfRangeException ex)
@@ -84,7 +104,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.Http, Resources.HOST, --minPort, Resources.USERNAME, Resources.PASSWORD, null);
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       ProxyTypes.Http,
+                                       Resources.HOST,
+                                       --minPort,
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       null);
                 Assert.Fail();
             }
             catch (ArgumentOutOfRangeException ex)
@@ -126,8 +154,15 @@ namespace Renci.SshNet.Tests.Classes
         {
             try
             {
-                new ConnectionInfo(null, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
+                _ = new ConnectionInfo(null,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       ProxyTypes.None,
+                                       Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       null);
             }
             catch (ArgumentNullException ex)
             {
@@ -183,8 +218,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, port, Resources.USERNAME, ProxyTypes.None, Resources.HOST,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
+                _ = new ConnectionInfo(Resources.HOST,
+                                       port,
+                                       Resources.USERNAME,
+                                       ProxyTypes.None,
+                                       Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       null);
                 Assert.Fail();
             }
             catch (ArgumentOutOfRangeException ex)
@@ -202,8 +244,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, port, Resources.USERNAME, ProxyTypes.None, Resources.HOST,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
+                _ = new ConnectionInfo(Resources.HOST,
+                                       port,
+                                       Resources.USERNAME,
+                                       ProxyTypes.None,
+                                       Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       null);
                 Assert.Fail();
             }
             catch (ArgumentOutOfRangeException ex)
@@ -234,9 +283,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), username, ProxyTypes.Http, Resources.USERNAME,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
-                    new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       username,
+                                       ProxyTypes.Http,
+                                       Resources.USERNAME,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -254,9 +309,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), username, ProxyTypes.Http, Resources.USERNAME,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
-                    new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       username,
+                                       ProxyTypes.Http,
+                                       Resources.USERNAME,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
                 Assert.Fail();
             }
             catch (ArgumentException ex)
@@ -275,9 +336,15 @@ namespace Renci.SshNet.Tests.Classes
 
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), username, ProxyTypes.Http, Resources.USERNAME,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
-                    new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       username,
+                                       ProxyTypes.Http,
+                                       Resources.USERNAME,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
                 Assert.Fail();
             }
             catch (ArgumentException ex)
@@ -294,8 +361,15 @@ namespace Renci.SshNet.Tests.Classes
         {
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, null);
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       ProxyTypes.None,
+                                       Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       null);
                 Assert.Fail();
             }
             catch (ArgumentNullException ex)
@@ -311,8 +385,15 @@ namespace Renci.SshNet.Tests.Classes
         {
             try
             {
-                new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, Resources.HOST,
-                    int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, new AuthenticationMethod[0]);
+                _ = new ConnectionInfo(Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       ProxyTypes.None,
+                                       Resources.HOST,
+                                       int.Parse(Resources.PORT),
+                                       Resources.USERNAME,
+                                       Resources.PASSWORD,
+                                       new AuthenticationMethod[0]);
                 Assert.Fail();
             }
             catch (ArgumentException ex)
@@ -326,11 +407,18 @@ namespace Renci.SshNet.Tests.Classes
         [TestCategory("ConnectionInfo")]
         public void AuthenticateShouldThrowArgumentNullExceptionWhenServiceFactoryIsNull()
         {
-            var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None,
-                Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD,
-                new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
+            var connectionInfo = new ConnectionInfo(Resources.HOST,
+                                                    int.Parse(Resources.PORT),
+                                                    Resources.USERNAME,
+                                                    ProxyTypes.None,
+                                                    Resources.HOST,
+                                                    int.Parse(Resources.PORT),
+                                                    Resources.USERNAME,
+                                                    Resources.PASSWORD,
+                                                    new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME));
+
             var session = new Mock<ISession>(MockBehavior.Strict).Object;
-            IServiceFactory serviceFactory = null;
+            const IServiceFactory serviceFactory = null;
 
             try
             {
@@ -344,4 +432,4 @@ namespace Renci.SshNet.Tests.Classes
             }
         }
    }
-}
+}

+ 3 - 1
src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs

@@ -2,9 +2,11 @@
 using System.Collections.Generic;
 using System.Net;
 using System.Net.Sockets;
+
 using Microsoft.VisualStudio.TestTools.UnitTesting;
+
 using Moq;
-using Renci.SshNet.Channels;
+
 using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików