From cd391cb666e867e5fe9fd55db1fc91edeb4abe7d Mon Sep 17 00:00:00 2001 From: Marius Thesing Date: Tue, 15 Jul 2025 20:49:18 +0200 Subject: [PATCH] fix IDE0031 https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0031 --- src/Renci.SshNet/NetConfClient.cs | 7 ++--- src/Renci.SshNet/Netconf/NetConfSession.cs | 14 +++------- src/Renci.SshNet/Session.cs | 14 +++------- src/Renci.SshNet/SshClient.cs | 7 ++--- ...pose_SessionIsConnectedAndChannelIsOpen.cs | 14 +++------- ...pose_SessionIsConnectedAndChannelIsOpen.cs | 21 ++++---------- ...nelIsOpen_EofNotReceived_SendEofInvoked.cs | 7 ++--- ...IsConnectedAndChannelIsOpen_EofReceived.cs | 21 ++++---------- ...ectionClosedByServer_NoDataSentByServer.cs | 7 ++--- ...est_ServerResponseContainsNullCharacter.cs | 7 ++--- ...entificationOnlyContainsProtocolVersion.cs | 7 ++--- ...changeTest_ServerResponseValid_Comments.cs | 7 ++--- ...erverResponseValid_EmptySoftwareVersion.cs | 7 ++--- ...angeTest_ServerResponseValid_NoComments.cs | 7 ++--- ...rminatedByLineFeedWithoutCarriageReturn.cs | 7 ++--- ...Test_TimeoutReadingIdentificationString.cs | 14 +++------- ...dedPortDynamicTest_Dispose_PortDisposed.cs | 7 ++--- ...ortDynamicTest_Dispose_PortNeverStarted.cs | 7 ++--- ...icTest_Dispose_PortStarted_ChannelBound.cs | 28 ++++++------------- ...est_Dispose_PortStarted_ChannelNotBound.cs | 14 +++------- ...rdedPortDynamicTest_Dispose_PortStopped.cs | 7 ++--- ...cTest_SessionErrorOccurred_ChannelBound.cs | 28 ++++++------------- ...ardedPortDynamicTest_Start_PortDisposed.cs | 7 ++--- ...dPortDynamicTest_Start_PortNeverStarted.cs | 7 ++--- ...wardedPortDynamicTest_Start_PortStarted.cs | 7 ++--- ...wardedPortDynamicTest_Start_PortStopped.cs | 7 ++--- ...wardedPortDynamicTest_Start_SessionNull.cs | 7 ++--- ...t_Started_SocketSendShutdownImmediately.cs | 7 ++--- ...cTest_Started_SocketVersionNotSupported.cs | 14 +++------- ...wardedPortDynamicTest_Stop_PortDisposed.cs | 7 ++--- ...edPortDynamicTest_Stop_PortNeverStarted.cs | 7 ++--- ...namicTest_Stop_PortStarted_ChannelBound.cs | 28 ++++++------------- ...icTest_Stop_PortStarted_ChannelNotBound.cs | 14 +++------- ...rwardedPortDynamicTest_Stop_PortStopped.cs | 7 ++--- ...ardedPortLocalTest_Dispose_PortDisposed.cs | 7 ++--- ...lTest_Dispose_PortDisposed_NeverStarted.cs | 7 ++--- ...dPortLocalTest_Dispose_PortNeverStarted.cs | 7 ++--- ...alTest_Dispose_PortStarted_ChannelBound.cs | 28 ++++++------------- ...est_Dispose_PortStarted_ChannelNotBound.cs | 7 ++--- ...wardedPortLocalTest_Dispose_PortStopped.cs | 7 ++--- ...rwardedPortLocalTest_Start_PortDisposed.cs | 7 ++--- ...dedPortLocalTest_Start_PortNeverStarted.cs | 7 ++--- ...orwardedPortLocalTest_Start_PortStarted.cs | 7 ++--- ...orwardedPortLocalTest_Start_PortStopped.cs | 7 ++--- ...orwardedPortLocalTest_Stop_PortDisposed.cs | 7 ++--- ...LocalTest_Stop_PortStarted_ChannelBound.cs | 28 ++++++------------- ...alTest_Stop_PortStarted_ChannelNotBound.cs | 7 ++--- ...ForwardedPortLocalTest_Stop_PortStopped.cs | 7 ++--- ...rdedPortRemoteTest_Dispose_PortDisposed.cs | 7 ++--- ...PortRemoteTest_Dispose_PortNeverStarted.cs | 7 ++--- ...teTest_Dispose_PortStarted_ChannelBound.cs | 21 ++++---------- ...ardedPortRemoteTest_Dispose_PortStopped.cs | 7 ++--- ...wardedPortRemoteTest_Start_PortDisposed.cs | 7 ++--- ...rwardedPortRemoteTest_Start_SessionNull.cs | 7 ++--- ...rwardedPortRemoteTest_Stop_PortDisposed.cs | 7 ++--- .../Classes/SessionTest_ConnectedBase.cs | 28 ++++++------------- .../Classes/SessionTest_ConnectingBase.cs | 21 ++++---------- .../Common/AsyncSocketListener.cs | 7 ++--- 58 files changed, 182 insertions(+), 455 deletions(-) diff --git a/src/Renci.SshNet/NetConfClient.cs b/src/Renci.SshNet/NetConfClient.cs index e4b66ad9..5b509dc5 100644 --- a/src/Renci.SshNet/NetConfClient.cs +++ b/src/Renci.SshNet/NetConfClient.cs @@ -299,11 +299,8 @@ namespace Renci.SshNet if (disposing) { - if (_netConfSession != null) - { - _netConfSession.Dispose(); - _netConfSession = null; - } + _netConfSession?.Dispose(); + _netConfSession = null; } } diff --git a/src/Renci.SshNet/Netconf/NetConfSession.cs b/src/Renci.SshNet/Netconf/NetConfSession.cs index 2044a785..60edc2d8 100644 --- a/src/Renci.SshNet/Netconf/NetConfSession.cs +++ b/src/Renci.SshNet/Netconf/NetConfSession.cs @@ -213,17 +213,11 @@ namespace Renci.SshNet.NetConf if (disposing) { - if (_serverCapabilitiesConfirmed != null) - { - _serverCapabilitiesConfirmed.Dispose(); - _serverCapabilitiesConfirmed = null; - } + _serverCapabilitiesConfirmed?.Dispose(); + _serverCapabilitiesConfirmed = null; - if (_rpcReplyReceived != null) - { - _rpcReplyReceived.Dispose(); - _rpcReplyReceived = null; - } + _rpcReplyReceived?.Dispose(); + _rpcReplyReceived = null; } } } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index ec3eac87..e94ebeb2 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -1570,17 +1570,11 @@ namespace Renci.SshNet disposableClientCipher.Dispose(); } - if (_serverMac != null) - { - _serverMac.Dispose(); - _serverMac = null; - } + _serverMac?.Dispose(); + _serverMac = null; - if (_clientMac != null) - { - _clientMac.Dispose(); - _clientMac = null; - } + _clientMac?.Dispose(); + _clientMac = null; // Update negotiated algorithms _serverCipher = _keyExchange.CreateServerCipher(out _serverAead); diff --git a/src/Renci.SshNet/SshClient.cs b/src/Renci.SshNet/SshClient.cs index 3051074e..05508462 100644 --- a/src/Renci.SshNet/SshClient.cs +++ b/src/Renci.SshNet/SshClient.cs @@ -325,11 +325,8 @@ namespace Renci.SshNet if (disposing) { - if (_inputStream != null) - { - _inputStream.Dispose(); - _inputStream = null; - } + _inputStream?.Dispose(); + _inputStream = null; _isDisposed = true; } diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs index 332f3cfe..8e4c13ea 100644 --- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs +++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs @@ -47,17 +47,11 @@ namespace Renci.SshNet.Tests.Classes.Channels [TestCleanup] public void CleanUp() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } + _client?.Dispose(); + _client = null; - if (_listener != null) - { - _listener.Stop(); - _listener = null; - } + _listener?.Stop(); + _listener = null; } private void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs index 8617aba3..4fcf476f 100644 --- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs +++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Dispose_SessionIsConnectedAndChannelIsOpen.cs @@ -47,23 +47,14 @@ namespace Renci.SshNet.Tests.Classes.Channels [TestCleanup] public void CleanUp() { - if (_remoteListener != null) - { - _remoteListener.Stop(); - _remoteListener = null; - } + _remoteListener?.Stop(); + _remoteListener = null; - if (_channelThread != null) - { - _channelThread.Join(); - _channelThread = null; - } + _channelThread?.Join(); + _channelThread = null; - if (_channel != null) - { - _channel.Dispose(); - _channel = null; - } + _channel?.Dispose(); + _channel = null; } private void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs index f6eb2933..ed2946e4 100644 --- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs +++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs @@ -31,11 +31,8 @@ namespace Renci.SshNet.Tests.Classes.Channels [TestCleanup] public void TearDown() { - if (_channelClosedEventHandlerCompleted != null) - { - _channelClosedEventHandlerCompleted.Dispose(); - _channelClosedEventHandlerCompleted = null; - } + _channelClosedEventHandlerCompleted?.Dispose(); + _channelClosedEventHandlerCompleted = null; } protected override void SetupData() diff --git a/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs b/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs index 4f11009b..c03bfea1 100644 --- a/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs +++ b/test/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Dispose_SessionIsConnectedAndChannelIsOpen_EofReceived.cs @@ -91,23 +91,14 @@ namespace Renci.SshNet.Tests.Classes.Channels [TestCleanup] public void TearDown() { - if (_channelClosedReceived != null) - { - _channelClosedReceived.Dispose(); - _channelClosedReceived = null; - } + _channelClosedReceived?.Dispose(); + _channelClosedReceived = null; - if (_raiseChannelCloseReceivedThread != null) - { - _raiseChannelCloseReceivedThread.Join(); - _raiseChannelCloseReceivedThread = null; - } + _raiseChannelCloseReceivedThread?.Join(); + _raiseChannelCloseReceivedThread = null; - if (_channelClosedEventHandlerCompleted != null) - { - _channelClosedEventHandlerCompleted.Dispose(); - _channelClosedEventHandlerCompleted = null; - } + _channelClosedEventHandlerCompleted?.Dispose(); + _channelClosedEventHandlerCompleted = null; } protected override void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs index 43aa9a3b..b6ba2dbe 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ConnectionClosedByServer_NoDataSentByServer.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs index 164cb6a7..4d55fba2 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseContainsNullCharacter.cs @@ -38,11 +38,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs index 3b064951..b68588ec 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseInvalid_SshIdentificationOnlyContainsProtocolVersion.cs @@ -38,11 +38,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs index 2af8062b..3835e651 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_Comments.cs @@ -37,11 +37,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_EmptySoftwareVersion.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_EmptySoftwareVersion.cs index c7daaf14..141bf418 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_EmptySoftwareVersion.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_EmptySoftwareVersion.cs @@ -38,11 +38,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs index 36596720..ce80d99d 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_NoComments.cs @@ -37,11 +37,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs index 2c35bce5..ad495378 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_ServerResponseValid_TerminatedByLineFeedWithoutCarriageReturn.cs @@ -37,11 +37,8 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; if (_client != null) { diff --git a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs index 3710e206..3917c9b2 100644 --- a/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs +++ b/test/Renci.SshNet.Tests/Classes/Connection/ProtocolVersionExchangeTest_TimeoutReadingIdentificationString.cs @@ -37,17 +37,11 @@ namespace Renci.SshNet.Tests.Classes.Connection [TestCleanup] public void Cleanup() { - if (_server != null) - { - _server.Dispose(); - _server = null; - } + _server?.Dispose(); + _server = null; - if (_client != null) - { - _client.Close(); - _client = null; - } + _client?.Close(); + _client = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs index d39a91fa..8da9eee6 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs @@ -24,11 +24,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs index a9ce2b49..adacc6c7 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs @@ -32,11 +32,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs index 692afe88..76e819d5 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs @@ -46,26 +46,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - if (_channelBindStarted != null) - { - _channelBindStarted.Dispose(); - _channelBindStarted = null; - } - if (_channelBindCompleted != null) - { - _channelBindCompleted.Dispose(); - _channelBindCompleted = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; + _channelBindStarted?.Dispose(); + _channelBindStarted = null; + _channelBindCompleted?.Dispose(); + _channelBindCompleted = null; } private void CreateMocks() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs index 5804f6db..ba949c2c 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs @@ -38,16 +38,10 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs index 85ef70f8..5a847d72 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs @@ -32,11 +32,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs index c98784ed..dd26b91d 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_SessionErrorOccurred_ChannelBound.cs @@ -47,26 +47,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - if (_channelBindStarted != null) - { - _channelBindStarted.Dispose(); - _channelBindStarted = null; - } - if (_channelBindCompleted != null) - { - _channelBindCompleted.Dispose(); - _channelBindCompleted = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; + _channelBindStarted?.Dispose(); + _channelBindStarted = null; + _channelBindCompleted?.Dispose(); + _channelBindCompleted = null; } private void CreateMocks() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs index 2ceac31e..394be33e 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs @@ -25,11 +25,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs index adc55951..32d70787 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs @@ -34,11 +34,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs index d39263b5..922897a4 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs index ad71d804..bffee25f 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs @@ -34,11 +34,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs index c326c00d..7c97f2aa 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs @@ -28,11 +28,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs index e58bf3d9..597b0a0e 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs @@ -59,11 +59,8 @@ namespace Renci.SshNet.Tests.Classes } } - if (_channelDisposed != null) - { - _channelDisposed.Dispose(); - _channelDisposed = null; - } + _channelDisposed?.Dispose(); + _channelDisposed = null; } private void SetupData() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs index d28c311b..850f6fcf 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs @@ -45,17 +45,11 @@ namespace Renci.SshNet.Tests.Classes _forwardedPort.Stop(); } - if (_client != null) - { - _client.Close(); - _client = null; - } + _client?.Close(); + _client = null; - if (_exceptionFired != null) - { - _exceptionFired.Dispose(); - _exceptionFired = null; - } + _exceptionFired?.Dispose(); + _exceptionFired = null; } private void SetupData() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs index 58b02032..aa99838a 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs @@ -27,11 +27,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs index 118b075e..1125acde 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs @@ -27,11 +27,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs index fcfc88a0..cfda2a20 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs @@ -45,26 +45,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - if (_channelBindStarted != null) - { - _channelBindStarted.Dispose(); - _channelBindStarted = null; - } - if (_channelBindCompleted != null) - { - _channelBindCompleted.Dispose(); - _channelBindCompleted = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; + _channelBindStarted?.Dispose(); + _channelBindStarted = null; + _channelBindCompleted?.Dispose(); + _channelBindCompleted = null; } private void CreateMocks() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs index fa716b6b..6a3e0839 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs @@ -38,16 +38,10 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs index dbc73880..a976733b 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs @@ -32,11 +32,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs index 66cc6d57..7ae63cb4 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs @@ -30,11 +30,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs index fb74e217..9a12182e 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs @@ -24,11 +24,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs index 22a1ae9f..82c22062 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs @@ -33,11 +33,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs index 6980d366..5f3ab59c 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs @@ -40,26 +40,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - if (_channelBindStarted != null) - { - _channelBindStarted.Dispose(); - _channelBindStarted = null; - } - if (_channelBindCompleted != null) - { - _channelBindCompleted.Dispose(); - _channelBindCompleted = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; + _channelBindStarted?.Dispose(); + _channelBindStarted = null; + _channelBindCompleted?.Dispose(); + _channelBindCompleted = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs index 0f3b0a57..f684f9ed 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs index a9dacf9a..c17165b9 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs @@ -33,11 +33,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs index 6d841b9c..d49b3219 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs @@ -28,11 +28,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs index 9d003ff1..4a884631 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs index 60718f7b..d3b4f489 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs @@ -36,11 +36,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs index c7d13ec3..0c61346c 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs index 2806ec54..e62ac1cd 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs @@ -24,11 +24,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs index a6432f38..440a6f41 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs @@ -40,26 +40,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - if (_channelBound != null) - { - _channelBound.Dispose(); - _channelBound = null; - } - if (_channelBindCompleted != null) - { - _channelBindCompleted.Dispose(); - _channelBindCompleted = null; - } + _client?.Dispose(); + _client = null; + _forwardedPort?.Dispose(); + _forwardedPort = null; + _channelBound?.Dispose(); + _channelBound = null; + _channelBindCompleted?.Dispose(); + _channelBindCompleted = null; } private void CreateMocks() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs index b8e893db..08c4e6cc 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs index 7ec8bde3..54b2594d 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs @@ -33,11 +33,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs index 2cedfbe5..a8e2bd1b 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs @@ -27,11 +27,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs index 37f526e4..f559fec5 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs @@ -35,11 +35,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs index eea751b1..eb08449a 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs @@ -49,23 +49,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (ForwardedPort != null) - { - ForwardedPort.Dispose(); - ForwardedPort = null; - } + ForwardedPort?.Dispose(); + ForwardedPort = null; - if (_channelBindStarted != null) - { - _channelBindStarted.Dispose(); - _channelBindStarted = null; - } + _channelBindStarted?.Dispose(); + _channelBindStarted = null; - if (_channelBindCompleted != null) - { - _channelBindCompleted.Dispose(); - _channelBindCompleted = null; - } + _channelBindCompleted?.Dispose(); + _channelBindCompleted = null; } private void CreateMocks() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs index ecb1a2ac..fddcd680 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs @@ -37,11 +37,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (ForwardedPort != null) - { - ForwardedPort.Dispose(); - ForwardedPort = null; - } + ForwardedPort?.Dispose(); + ForwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs index 8b0b0511..ee7ee869 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs @@ -28,11 +28,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs index 9cd3a304..7428b365 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs @@ -28,11 +28,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs index 796bdda4..53df6703 100644 --- a/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs +++ b/test/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs @@ -27,11 +27,8 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void Cleanup() { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } + _forwardedPort?.Dispose(); + _forwardedPort = null; } protected void Arrange() diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs index 24291fe7..c8ff510e 100644 --- a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs +++ b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs @@ -66,23 +66,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void TearDown() { - if (ServerListener != null) - { - ServerListener.Dispose(); - ServerListener = null; - } + ServerListener?.Dispose(); + ServerListener = null; - if (ServerSocket != null) - { - ServerSocket.Dispose(); - ServerSocket = null; - } + ServerSocket?.Dispose(); + ServerSocket = null; - if (Session != null) - { - Session.Dispose(); - Session = null; - } + Session?.Dispose(); + Session = null; if (ClientSocket != null && ClientSocket.Connected) { @@ -90,11 +81,8 @@ namespace Renci.SshNet.Tests.Classes ClientSocket.Dispose(); } - if (FirstKexReceived != null) - { - FirstKexReceived.Dispose(); - FirstKexReceived = null; - } + FirstKexReceived?.Dispose(); + FirstKexReceived = null; } protected virtual void SetupData() diff --git a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs index e8bb7bd7..957bf2ec 100644 --- a/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs +++ b/test/Renci.SshNet.Tests/Classes/SessionTest_ConnectingBase.cs @@ -79,23 +79,14 @@ namespace Renci.SshNet.Tests.Classes [TestCleanup] public void TearDown() { - if (ServerListener != null) - { - ServerListener.Dispose(); - ServerListener = null; - } + ServerListener?.Dispose(); + ServerListener = null; - if (ServerSocket != null) - { - ServerSocket.Dispose(); - ServerSocket = null; - } + ServerSocket?.Dispose(); + ServerSocket = null; - if (Session != null) - { - Session.Dispose(); - Session = null; - } + Session?.Dispose(); + Session = null; if (ClientSocket != null && ClientSocket.Connected) { diff --git a/test/Renci.SshNet.Tests/Common/AsyncSocketListener.cs b/test/Renci.SshNet.Tests/Common/AsyncSocketListener.cs index 23e48799..575d3716 100644 --- a/test/Renci.SshNet.Tests/Common/AsyncSocketListener.cs +++ b/test/Renci.SshNet.Tests/Common/AsyncSocketListener.cs @@ -90,11 +90,8 @@ namespace Renci.SshNet.Tests.Common _listener?.Dispose(); - if (_receiveThread != null) - { - _receiveThread.Join(); - _receiveThread = null; - } + _receiveThread?.Join(); + _receiveThread = null; } public void Dispose()