From 2d1d45ade650e37e4544ee14414737d9de14846c Mon Sep 17 00:00:00 2001 From: trebor-salim Date: Mon, 20 Jun 2016 10:26:08 +0200 Subject: [PATCH 1/3] Update PseudoTerminalInfo.cs --- .../Messages/Connection/ChannelRequest/PseudoTerminalInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renci.SshNet/Messages/Connection/ChannelRequest/PseudoTerminalInfo.cs b/src/Renci.SshNet/Messages/Connection/ChannelRequest/PseudoTerminalInfo.cs index 597cfac5..4adfafa8 100644 --- a/src/Renci.SshNet/Messages/Connection/ChannelRequest/PseudoTerminalInfo.cs +++ b/src/Renci.SshNet/Messages/Connection/ChannelRequest/PseudoTerminalInfo.cs @@ -132,7 +132,7 @@ namespace Renci.SshNet.Messages.Connection Write(EnvironmentVariable); Write(Columns); Write(Rows); - Write(Rows); + Write(PixelWidth); Write(PixelHeight); if (TerminalModeValues != null) From 1eb4574e379a0ae56d55786a5c0bf043a9d8087a Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Tue, 21 Jun 2016 06:15:57 +0200 Subject: [PATCH 2/3] Add CI build badge Add CI build badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 48b5fe2d..f7924187 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ SSH.NET SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism. [![Version](https://img.shields.io/nuget/vpre/SSH.NET.svg)](https://www.nuget.org/packages/SSH.NET) +[![Build status](https://ci.appveyor.com/api/projects/status/ih77qu6tap3o92gu/branch/develop?svg=true)](https://ci.appveyor.com/api/projects/status/ih77qu6tap3o92gu/branch/develop) ##Introduction This project was inspired by **Sharp.SSH** library which was ported from java and it seems like was not supported for quite some time. This library is a complete rewrite, without any third party dependencies, using parallelism to achieve the best performance possible. From d43423896c2fe5542096ccc7ec5c7e9a14f3e54a Mon Sep 17 00:00:00 2001 From: Matthew Vukomanovic Date: Wed, 22 Jun 2016 18:48:59 +0800 Subject: [PATCH 3/3] Actually normallise the End of Lines Really reset the eol's in the repository by following the info at git-scm.com/docs/gitattributes Following the example there the following commands were run: rm .git/index git reset git add -u git commit --- .gitattributes | 8 +- src/References/X.690-0207.txt | 4 +- .../Common/Extensions.NET35.cs | 132 +- .../Properties/AssemblyInfo.cs | 14 +- .../Renci.SshNet.NET35.csproj | 1904 +++++----- src/Renci.SshNet.NET35/Session.NET35.cs | 124 +- .../Common/Extensions.SilverlightShared.cs | 106 +- .../Properties/AssemblyInfo.cs | 8 +- .../Session.SilverlightBrowser.cs | 24 +- .../Session.SilverlightShared.cs | 32 +- .../Properties/AssemblyInfo.cs | 8 +- .../Renci.SshNet.Silverlight5.csproj | 1854 ++++----- .../Classes/ForwardedPortLocal.NET35.cs | 26 +- .../Classes/ForwardedPortRemote.NET35.cs | 26 +- .../Classes/SshCommandTest.NET35.cs | 26 +- .../Properties/AssemblyInfo.cs | 8 +- .../Properties/Resources.Designer.cs | 412 +- .../Properties/Resources.resx | 486 +-- .../Renci.SshNet.Tests.NET35.csproj | 2566 ++++++------- src/Renci.SshNet.Tests.NET35/packages.config | 6 +- ...Connected_KeepAlivesNotSentConcurrently.cs | 138 +- .../Channels/ChannelDirectTcpipTest.cs | 448 +-- ...lose_SessionIsConnectedAndChannelIsOpen.cs | 390 +- .../ChannelSessionTest_Close_Closed.cs | 286 +- ...Received_SendChannelCloseMessageFailure.cs | 262 +- ...Received_SendChannelCloseMessageSuccess.cs | 262 +- ...Received_SendChannelCloseMessageFailure.cs | 256 +- ...Received_SendChannelCloseMessageSuccess.cs | 256 +- ...Received_SendChannelCloseMessageFailure.cs | 254 +- ...Received_SendChannelCloseMessageSuccess.cs | 276 +- ...Open_NoChannelCloseOrChannelEofReceived.cs | 282 +- ...ofReceived_SendChannelEofMessageFailure.cs | 282 +- ...sOpen_ChannelCloseAndChannelEofReceived.cs | 254 +- ...edAndChannelIsOpen_ChannelCloseReceived.cs | 248 +- ...Open_NoChannelCloseOrChannelEofReceived.cs | 238 +- .../ChannelSessionTest_Disposed_Closed.cs | 26 +- ...ived_SessionIsConnectedAndChannelIsOpen.cs | 252 +- ...Open_ExceptionWaitingOnOpenConfirmation.cs | 226 +- ...nOpenFailureReceived_NoRetriesAvailable.cs | 276 +- ...n_OnOpenFailureReceived_RetriesAvalable.cs | 302 +- .../Classes/Channels/ChannelStub.cs | 280 +- ...e_SessionIsConnectedAndChannelIsNotOpen.cs | 152 +- ...onnectedAndChannelIsOpen_EofNotReceived.cs | 274 +- ...nelIsOpen_EofNotReceived_SendEofInvoked.cs | 274 +- ...IsConnectedAndChannelIsOpen_EofReceived.cs | 278 +- ...essionIsNotConnectedAndChannelIsNotOpen.cs | 152 +- ...e_SessionIsNotConnectedAndChannelIsOpen.cs | 152 +- ...nChannelCloseReceived_OnClose_Exception.cs | 128 +- ...onnectedAndChannelIsOpen_EofNotReceived.cs | 206 +- ...IsConnectedAndChannelIsOpen_EofReceived.cs | 216 +- ...ionChannelDataReceived_OnData_Exception.cs | 128 +- ...ssionChannelEofReceived_OnEof_Exception.cs | 144 +- ...edDataReceived_OnExtendedData_Exception.cs | 128 +- ...nnelFailureReceived_OnFailure_Exception.cs | 128 +- ...nnelRequestReceived_OnRequest_Exception.cs | 136 +- ...nnelSuccessReceived_OnSuccess_Exception.cs | 128 +- ...AdjustReceived_OnWindowAdjust_Exception.cs | 146 +- ...onDisconnected_OnDisconnected_Exception.cs | 124 +- ...cted_SessionIsConnectedAndChannelIsOpen.cs | 152 +- ...ErrorOccurred_OnErrorOccurred_Exception.cs | 128 +- .../ChannelTest_SendEof_ChannelIsNotOpen.cs | 182 +- .../ChannelTest_SendEof_ChannelIsOpen.cs | 170 +- .../Classes/Channels/ClientChannelStub.cs | 320 +- ...onReceived_OnOpenConfirmation_Exception.cs | 136 +- ...FailureReceived_OnOpenFailure_Exception.cs | 130 +- .../Classes/CipherInfoTest.cs | 52 +- .../Classes/ClientAuthenticationTest.cs | 108 +- .../Classes/ClientAuthenticationTestBase.cs | 162 +- ...e_SingleList_AuthenticationMethodFailed.cs | 140 +- ...eList_AuthenticationMethodNotConfigured.cs | 126 +- ...lowedAuthenticationsAfterPartialSuccess.cs | 110 +- ...stponePartialAccessAuthenticationMethod.cs | 114 +- ...lowedAuthenticationsAfterPartialSuccess.cs | 122 +- ...ultiList_SkipFailedAuthenticationMethod.cs | 110 +- ...llowedAuthenticationAfterPartialSuccess.cs | 106 +- .../Classes/CommandAsyncResultTest.cs | 64 +- .../Classes/Common/ASCIIEncodingTest.cs | 472 +-- .../Classes/Common/AsyncResultTest.cs | 280 +- .../AuthenticationBannerEventArgsTest.cs | 60 +- ...thenticationPasswordChangeEventArgsTest.cs | 88 +- .../AuthenticationPromptEventArgsTest.cs | 64 +- .../Common/AuthenticationPromptTest.cs | 92 +- .../Classes/Common/BigIntegerTest.cs | 3308 ++++++++--------- .../Common/ChannelDataEventArgsTest.cs | 24 +- .../Classes/Common/ChannelEventArgsTest.cs | 24 +- .../Common/ChannelOpenFailedEventArgsTest.cs | 24 +- .../Common/ChannelRequestEventArgsTest.cs | 24 +- .../Classes/Common/DerDataTest.cs | 348 +- .../Classes/Common/ExceptionEventArgsTest.cs | 52 +- .../Classes/Common/HostKeyEventArgsTest.cs | 88 +- .../Common/NetConfServerExceptionTest.cs | 96 +- .../Classes/Common/ObjectIdentifierTest.cs | 54 +- .../Classes/Common/PipeStreamTest.cs | 510 +-- .../Common/PortForwardEventArgsTest.cs | 132 +- .../Common/ProxyExceptionTest.NET40.cs | 14 +- .../Classes/Common/ProxyExceptionTest.cs | 96 +- .../Common/ScpDownloadEventArgsTest.cs | 56 +- .../Classes/Common/ScpExceptionTest.cs | 96 +- .../Classes/Common/ScpUploadEventArgsTest.cs | 56 +- .../Classes/Common/SemaphoreLightTest.cs | 188 +- .../Common/SftpPathNotFoundExceptionTest.cs | 96 +- .../SftpPermissionDeniedExceptionTest.cs | 96 +- .../Classes/Common/ShellDataEventArgsTest.cs | 72 +- .../Common/SshAuthenticationExceptionTest.cs | 94 +- .../Common/SshConnectionExceptionTest.cs | 154 +- .../Classes/Common/SshDataTest.cs | 116 +- .../Classes/Common/SshExceptionTest.cs | 126 +- .../SshOperationTimeoutExceptionTest.cs | 96 +- .../SshPassPhraseNullOrEmptyExceptionTest.cs | 96 +- .../Classes/Compression/CompressorTest.cs | 154 +- .../Classes/Compression/ZlibOpenSshTest.cs | 102 +- .../Classes/Compression/ZlibStreamTest.cs | 88 +- .../Classes/Compression/ZlibTest.cs | 24 +- .../Classes/ConnectionInfoTest.cs | 692 ++-- ...ConnectionInfoTest_Authenticate_Failure.cs | 156 +- ...ConnectionInfoTest_Authenticate_Success.cs | 118 +- .../Classes/ExpectActionTest.cs | 72 +- .../Classes/ForwardedPortDynamicTest.cs | 66 +- ...dedPortDynamicTest_Dispose_PortDisposed.cs | 120 +- ...ortDynamicTest_Dispose_PortNeverStarted.cs | 194 +- ...icTest_Dispose_PortStarted_ChannelBound.cs | 442 +-- ...est_Dispose_PortStarted_ChannelNotBound.cs | 298 +- ...rdedPortDynamicTest_Dispose_PortStopped.cs | 200 +- ...ardedPortDynamicTest_Start_PortDisposed.cs | 152 +- ...dPortDynamicTest_Start_PortNeverStarted.cs | 186 +- ...wardedPortDynamicTest_Start_PortStarted.cs | 220 +- ...wardedPortDynamicTest_Start_PortStopped.cs | 194 +- ...rtDynamicTest_Start_SessionNotConnected.cs | 224 +- ...wardedPortDynamicTest_Start_SessionNull.cs | 202 +- ...wardedPortDynamicTest_Stop_PortDisposed.cs | 204 +- ...edPortDynamicTest_Stop_PortNeverStarted.cs | 170 +- ...namicTest_Stop_PortStarted_ChannelBound.cs | 414 +-- ...icTest_Stop_PortStarted_ChannelNotBound.cs | 298 +- ...rwardedPortDynamicTest_Stop_PortStopped.cs | 200 +- .../Classes/ForwardedPortLocalTest.NET40.cs | 204 +- .../Classes/ForwardedPortLocalTest.cs | 380 +- ...ardedPortLocalTest_Dispose_PortDisposed.cs | 160 +- ...lTest_Dispose_PortDisposed_NeverStarted.cs | 120 +- ...dPortLocalTest_Dispose_PortNeverStarted.cs | 204 +- ...alTest_Dispose_PortStarted_ChannelBound.cs | 388 +- ...est_Dispose_PortStarted_ChannelNotBound.cs | 214 +- ...wardedPortLocalTest_Dispose_PortStopped.cs | 210 +- ...rwardedPortLocalTest_Start_PortDisposed.cs | 168 +- ...dedPortLocalTest_Start_PortNeverStarted.cs | 218 +- ...orwardedPortLocalTest_Start_PortStarted.cs | 252 +- ...orwardedPortLocalTest_Start_PortStopped.cs | 226 +- ...PortLocalTest_Start_SessionNotConnected.cs | 234 +- ...orwardedPortLocalTest_Start_SessionNull.cs | 232 +- ...orwardedPortLocalTest_Stop_PortDisposed.cs | 164 +- ...rdedPortLocalTest_Stop_PortNeverStarted.cs | 198 +- ...LocalTest_Stop_PortStarted_ChannelBound.cs | 386 +- ...alTest_Stop_PortStarted_ChannelNotBound.cs | 214 +- ...ForwardedPortLocalTest_Stop_PortStopped.cs | 212 +- .../Classes/ForwardedPortRemote.NET40.cs | 100 +- .../Classes/ForwardedPortRemoteTest.cs | 298 +- ...rdedPortRemoteTest_Dispose_PortDisposed.cs | 144 +- ...PortRemoteTest_Dispose_PortNeverStarted.cs | 220 +- ...teTest_Dispose_PortStarted_ChannelBound.cs | 444 +-- ...ardedPortRemoteTest_Dispose_PortStopped.cs | 282 +- ...wardedPortRemoteTest_Start_PortDisposed.cs | 164 +- ...edPortRemoteTest_Start_PortNeverStarted.cs | 290 +- ...rwardedPortRemoteTest_Start_PortStarted.cs | 324 +- ...rwardedPortRemoteTest_Start_PortStopped.cs | 322 +- ...ortRemoteTest_Start_SessionNotConnected.cs | 254 +- ...rwardedPortRemoteTest_Start_SessionNull.cs | 186 +- .../ForwardedPortRemoteTest_Started.cs | 408 +- ...rwardedPortRemoteTest_Stop_PortDisposed.cs | 176 +- ...dedPortRemoteTest_Stop_PortNeverStarted.cs | 270 +- ...emoteTest_Stop_PortStarted_ChannelBound.cs | 26 +- ...orwardedPortRemoteTest_Stop_PortStopped.cs | 26 +- ...oardInteractiveAuthenticationMethodTest.cs | 176 +- .../KeyboardInteractiveConnectionInfoTest.cs | 388 +- .../Classes/MessageEventArgsTest.cs | 58 +- .../Authentication/BannerMessageTest.cs | 50 +- .../Authentication/FailureMessageTest.cs | 80 +- .../InformationRequestMessageTest.cs | 24 +- .../InformationResponseMessageTest.cs | 24 +- .../PasswordChangeRequiredMessageTest.cs | 24 +- .../Authentication/PublicKeyMessageTest.cs | 24 +- .../Authentication/RequestMessageHostTest.cs | 20 +- .../RequestMessageKeyboardInteractiveTest.cs | 24 +- .../Authentication/RequestMessageNoneTest.cs | 20 +- .../RequestMessagePasswordTest.cs | 24 +- .../RequestMessagePublicKeyTest.cs | 160 +- .../Authentication/SuccessMessageTest.cs | 50 +- .../Connection/ChannelCloseMessageTest.cs | 72 +- .../Connection/ChannelDataMessageTest.cs | 304 +- .../Connection/ChannelEofMessageTest.cs | 72 +- .../ChannelExtendedDataMessageTest.cs | 72 +- .../Connection/ChannelFailureMessageTest.cs | 72 +- .../Messages/Connection/ChannelMessageTest.cs | 74 +- .../ChannelOpen/ChannelOpenMessageTest.cs | 502 +-- .../ChannelOpen/DirectTcpipChannelInfoTest.cs | 24 +- .../ForwardedTcpipChannelInfoTest.cs | 24 +- .../ChannelOpen/SessionChannelOpenInfoTest.cs | 24 +- .../ChannelOpen/X11ChannelOpenInfoTest.cs | 24 +- .../ChannelOpenConfirmationMessageTest.cs | 78 +- .../ChannelOpenFailureMessageTest.cs | 76 +- .../Connection/ChannelOpenInfoTest.cs | 70 +- .../ChannelRequest/BreakRequestInfoTest.cs | 24 +- .../ChannelRequestMessageTest.cs | 70 +- .../EndOfWriteRequestInfoTest.cs | 74 +- .../EnvironmentVariableRequestInfoTest.cs | 24 +- .../ChannelRequest/ExecRequestInfoTest.cs | 24 +- .../ExitSignalRequestInfoTest.cs | 24 +- .../ExitStatusRequestInfoTest.cs | 24 +- .../KeepAliveRequestInfoTest.cs | 74 +- .../ChannelRequest/PseudoTerminalInfoTest.cs | 24 +- .../ChannelRequest/ShellRequestInfoTest.cs | 24 +- .../ChannelRequest/SignalRequestInfoTest.cs | 24 +- .../SubsystemRequestInfoTest.cs | 24 +- .../WindowChangeRequestInfoTest.cs | 24 +- .../X11ForwardingRequestInfoTest.cs | 24 +- .../ChannelRequest/XonXoffRequestInfoTest.cs | 24 +- .../Connection/ChannelSuccessMessageTest.cs | 72 +- .../ChannelWindowAdjustMessageTest.cs | 74 +- .../Connection/GlobalRequestMessageTest.cs | 78 +- .../Connection/RequestFailureMessageTest.cs | 50 +- .../Messages/Connection/RequestInfoTest.cs | 70 +- .../Connection/RequestSuccessMessageTest.cs | 72 +- .../Classes/Messages/MessageAttributeTest.cs | 122 +- .../Classes/Messages/MessageTest.cs | 102 +- .../Messages/Transport/DebugMessageTest.cs | 50 +- .../Transport/DisconnectMessageTest.cs | 74 +- .../Messages/Transport/IgnoreMessageTest.cs | 190 +- .../KeyExchangeDhGroupExchangeGroupBuilder.cs | 64 +- .../KeyExchangeDhGroupExchangeGroupTest.cs | 50 +- .../KeyExchangeDhGroupExchangeInitTest.cs | 24 +- .../KeyExchangeDhGroupExchangeReplyBuilder.cs | 104 +- .../KeyExchangeDhGroupExchangeReplyTest.cs | 60 +- .../KeyExchangeDhGroupExchangeRequestTest.cs | 138 +- .../Transport/KeyExchangeDhInitMessageTest.cs | 24 +- .../KeyExchangeDhReplyMessageTest.cs | 50 +- .../Transport/KeyExchangeInitMessageTest.cs | 514 +-- .../Messages/Transport/NewKeysMessageTest.cs | 50 +- .../Transport/ServiceAcceptMessageTest.cs | 48 +- .../Transport/ServiceRequestMessageTest.cs | 52 +- .../Transport/UnimplementedMessageTest.cs | 50 +- .../Classes/NetConfClientTest.cs | 392 +- .../NetConfClientTest_Dispose_Connected.cs | 204 +- .../NetConfClientTest_Dispose_Disconnected.cs | 208 +- .../NetConfClientTest_Dispose_Disposed.cs | 206 +- .../NetConfClientTest_Finalize_Connected.cs | 142 +- .../Classes/NoneAuthenticationMethodTest.cs | 186 +- .../PasswordAuthenticationMethodTest.cs | 320 +- .../Classes/PasswordConnectionInfoTest.cs | 960 ++--- .../PrivateKeyAuthenticationMethodTest.cs | 210 +- .../Classes/PrivateKeyConnectionInfoTest.cs | 432 +-- .../Classes/PrivateKeyFileTest.cs | 1006 ++--- .../Classes/Security/AlgorithmTest.cs | 68 +- .../Security/CertificateHostAlgorithmTest.cs | 148 +- .../Security/Cryptography/BlockCipherTest.cs | 154 +- .../CipherDigitalSignatureTest.cs | 108 +- .../Security/Cryptography/CipherTest.cs | 106 +- .../Cryptography/Ciphers/AesCipherTest.cs | 476 +-- .../Cryptography/Ciphers/Arc4CipherTest.cs | 352 +- .../Ciphers/BlowfishCipherTest.cs | 214 +- .../Cryptography/Ciphers/CastCipherTest.cs | 210 +- .../Cryptography/Ciphers/CipherModeTest.cs | 122 +- .../Cryptography/Ciphers/CipherPaddingTest.cs | 76 +- .../Cryptography/Ciphers/DesCipherTest.cs | 144 +- .../Ciphers/Modes/CbcCipherModeTest.cs | 134 +- .../Ciphers/Modes/CfbCipherModeTest.cs | 136 +- .../Ciphers/Modes/CtrCipherModeTest.cs | 136 +- .../Ciphers/Modes/OfbCipherModeTest.cs | 136 +- .../Ciphers/Paddings/PKCS5PaddingTest.cs | 82 +- .../Ciphers/Paddings/PKCS7PaddingTest.cs | 82 +- .../Cryptography/Ciphers/RsaCipherTest.cs | 118 +- .../Cryptography/Ciphers/SerpentCipherTest.cs | 144 +- .../Ciphers/TripleDesCipherTest.cs | 210 +- .../Cryptography/Ciphers/TwofishCipherTest.cs | 144 +- .../Cryptography/DigitalSignatureTest.cs | 108 +- .../Cryptography/DsaDigitalSignatureTest.cs | 146 +- .../Security/Cryptography/DsaKeyTest.cs | 302 +- .../Classes/Security/Cryptography/HMacTest.cs | 270 +- .../Cryptography/RsaDigitalSignatureTest.cs | 78 +- .../Security/Cryptography/RsaKeyTest.cs | 24 +- .../Cryptography/SymmetricCipherTest.cs | 124 +- .../Classes/Security/HostAlgorithmTest.cs | 134 +- ...KeyExchangeDiffieHellmanGroup14Sha1Test.cs | 24 +- .../KeyExchangeDiffieHellmanGroup1Sha1Test.cs | 98 +- ...hangeDiffieHellmanGroupExchangeSha1Test.cs | 24 +- ...ngeDiffieHellmanGroupExchangeSha256Test.cs | 126 +- .../KeyExchangeDiffieHellmanGroupSha1Test.cs | 124 +- .../Security/KeyExchangeDiffieHellmanTest.cs | 72 +- .../Classes/Security/KeyExchangeTest.cs | 32 +- .../Classes/Security/KeyHostAlgorithmTest.cs | 244 +- .../Classes/Security/KeyTest.cs | 168 +- .../Classes/SessionTest.HttpProxy.cs | 526 +-- src/Renci.SshNet.Tests/Classes/SessionTest.cs | 724 ++-- .../Classes/SessionTest_Connected.cs | 338 +- .../Classes/SessionTest_ConnectedBase.cs | 384 +- .../SessionTest_Connected_ConnectionReset.cs | 336 +- .../SessionTest_Connected_Disconnect.cs | 296 +- ...sionTest_Connected_ServerSendsBadPacket.cs | 328 +- ..._Connected_ServerSendsDisconnectMessage.cs | 336 +- ...endsDisconnectMessageAndShutsDownSocket.cs | 344 +- ...ionTest_Connected_ServerShutsDownSocket.cs | 322 +- .../Classes/SessionTest_NotConnected.cs | 382 +- ...est_SocketConnected_BadPacketAndDispose.cs | 190 +- .../ExtendedRequests/FStatVfsRequestTest.cs | 244 +- .../ExtendedRequests/HardLinkRequestTest.cs | 230 +- .../PosixRenameRequestTest.cs | 238 +- .../ExtendedRequests/StatVfsRequestTest.cs | 256 +- .../Sftp/Requests/SftpBlockRequestTest.cs | 202 +- .../Sftp/Requests/SftpCloseRequestTest.cs | 172 +- .../Sftp/Requests/SftpFSetStatRequestTest.cs | 190 +- .../Sftp/Requests/SftpFStatRequestTest.cs | 216 +- .../Sftp/Requests/SftpInitRequestTest.cs | 18 +- .../Sftp/Requests/SftpLStatRequestTest.cs | 228 +- .../Sftp/Requests/SftpLinkRequestTest.cs | 218 +- .../Sftp/Requests/SftpMkDirRequestTest.cs | 202 +- .../Sftp/Requests/SftpOpenDirRequestTest.cs | 228 +- .../Sftp/Requests/SftpOpenRequestTest.cs | 284 +- .../Sftp/Requests/SftpReadDirRequestTest.cs | 218 +- .../Sftp/Requests/SftpReadLinkRequestTest.cs | 254 +- .../Sftp/Requests/SftpReadRequestTest.cs | 268 +- .../Sftp/Requests/SftpRealPathRequestTest.cs | 284 +- .../Sftp/Requests/SftpRemoveRequestTest.cs | 184 +- .../Sftp/Requests/SftpRenameRequestTest.cs | 208 +- .../Sftp/Requests/SftpRmDirRequestTest.cs | 190 +- .../Sftp/Requests/SftpSetStatRequestTest.cs | 212 +- .../Sftp/Requests/SftpStatRequestTest.cs | 224 +- .../Sftp/Requests/SftpSymLinkRequestTest.cs | 244 +- .../Sftp/Requests/SftpUnblockRequestTest.cs | 192 +- .../Sftp/Requests/SftpWriteRequestTest.cs | 224 +- .../ExtendedReplies/StatVfsReplyInfoTest.cs | 178 +- .../Sftp/Responses/SftpAttrsResponseTest.cs | 146 +- .../Sftp/Responses/SftpDataResponseTest.cs | 120 +- .../SftpExtendedReplyResponseTest.cs | 204 +- .../Sftp/Responses/SftpHandleResponseTest.cs | 120 +- .../Sftp/Responses/SftpNameResponseTest.cs | 18 +- .../Sftp/Responses/SftpStatusResponseTest.cs | 18 +- .../Sftp/Responses/SftpVersionResponseTest.cs | 18 +- .../Sftp/SftpDownloadAsyncResultTest.cs | 54 +- .../Classes/Sftp/SftpFileAttributesTest.cs | 474 +-- ...treamTest_CanRead_Closed_FileAccessRead.cs | 148 +- ...Test_CanRead_Closed_FileAccessReadWrite.cs | 148 +- ...reamTest_CanRead_Closed_FileAccessWrite.cs | 148 +- ...eamTest_CanRead_Disposed_FileAccessRead.cs | 148 +- ...st_CanRead_Disposed_FileAccessReadWrite.cs | 148 +- ...amTest_CanRead_Disposed_FileAccessWrite.cs | 148 +- ...Test_CanRead_SessionOpen_FileAccessRead.cs | 146 +- ...CanRead_SessionOpen_FileAccessReadWrite.cs | 146 +- ...est_CanRead_SessionOpen_FileAccessWrite.cs | 146 +- ...reamTest_CanWrite_Closed_FileAccessRead.cs | 148 +- ...est_CanWrite_Closed_FileAccessReadWrite.cs | 148 +- ...eamTest_CanWrite_Closed_FileAccessWrite.cs | 148 +- ...amTest_CanWrite_Disposed_FileAccessRead.cs | 148 +- ...t_CanWrite_Disposed_FileAccessReadWrite.cs | 148 +- ...mTest_CanWrite_Disposed_FileAccessWrite.cs | 148 +- ...est_CanWrite_SessionOpen_FileAccessRead.cs | 146 +- ...anWrite_SessionOpen_FileAccessReadWrite.cs | 146 +- ...st_CanWrite_SessionOpen_FileAccessWrite.cs | 146 +- .../Sftp/SftpFileStreamTest_Close_Closed.cs | 158 +- .../Sftp/SftpFileStreamTest_Close_Disposed.cs | 158 +- ...SftpFileStreamTest_Close_SessionNotOpen.cs | 152 +- .../SftpFileStreamTest_Close_SessionOpen.cs | 156 +- .../Sftp/SftpFileStreamTest_Dispose_Closed.cs | 158 +- .../SftpFileStreamTest_Dispose_Disposed.cs | 158 +- ...tpFileStreamTest_Dispose_SessionNotOpen.cs | 156 +- .../SftpFileStreamTest_Dispose_SessionOpen.cs | 156 +- ...SftpFileStreamTest_Finalize_SessionOpen.cs | 160 +- .../SftpFileStreamTest_SetLength_Closed.cs | 180 +- .../SftpFileStreamTest_SetLength_Disposed.cs | 180 +- ...FileStreamTest_SetLength_SessionNotOpen.cs | 192 +- ...st_SetLength_SessionOpen_FIleAccessRead.cs | 178 +- ...tLength_SessionOpen_FIleAccessReadWrite.cs | 198 +- ...t_SetLength_SessionOpen_FIleAccessWrite.cs | 198 +- .../Sftp/SftpFileSystemInformationTest.cs | 120 +- .../Sftp/SftpListDirectoryAsyncResultTest.cs | 54 +- .../SftpSessionTest_Connected_RequestRead.cs | 278 +- ...ftpSessionTest_Connected_RequestStatVfs.cs | 512 +-- ...tpSynchronizeDirectoriesAsyncResultTest.cs | 54 +- .../Classes/Sftp/SftpUploadAsyncResultTest.cs | 54 +- .../Sftp/SftpVersionResponseBuilder.cs | 106 +- .../Classes/SftpClientTest.Connect.cs | 90 +- .../Classes/SftpClientTest.DeleteFile.cs | 48 +- .../Classes/SftpClientTest.cs | 2542 ++++++------- .../SftpClientTest_Dispose_Connected.cs | 216 +- .../SftpClientTest_Dispose_Disconnected.cs | 218 +- .../SftpClientTest_Dispose_Disposed.cs | 218 +- .../SftpClientTest_Finalize_Connected.cs | 150 +- src/Renci.SshNet.Tests/Classes/ShellStream.cs | 24 +- .../Classes/ShellStreamTest.cs | 234 +- .../Classes/ShellTestTest.cs | 162 +- .../Classes/SshClientTest.cs | 1888 +++++----- ...entTest_Disconnect_ForwardedPortStarted.cs | 164 +- .../SshClientTest_Dispose_Connected.cs | 146 +- .../SshClientTest_Dispose_Disconnected.cs | 148 +- .../Classes/SshClientTest_Dispose_Disposed.cs | 148 +- ...ClientTest_Dispose_ForwardedPortStarted.cs | 194 +- .../Classes/SshCommandTest.NET40.cs | 198 +- .../Classes/SshCommandTest.cs | 1268 +++---- .../Classes/SshCommandTest_EndExecute.cs | 144 +- .../Classes/SubsystemSessionStub.cs | 90 +- .../SubsystemSession_Connect_Connected.cs | 254 +- .../SubsystemSession_Connect_Disconnected.cs | 256 +- .../SubsystemSession_Connect_Disposed.cs | 194 +- ...SubsystemSession_Connect_NeverConnected.cs | 22 +- .../SubsystemSession_Disconnect_Connected.cs | 192 +- .../SubsystemSession_Disconnect_Disposed.cs | 192 +- ...systemSession_Disconnect_NeverConnected.cs | 144 +- .../SubsystemSession_Dispose_Connected.cs | 190 +- .../SubsystemSession_Dispose_Disconnected.cs | 192 +- .../SubsystemSession_Dispose_Disposed.cs | 192 +- ...SubsystemSession_Dispose_NeverConnected.cs | 146 +- ...Session_OnChannelDataReceived_Connected.cs | 242 +- ...mSession_OnChannelDataReceived_Disposed.cs | 188 +- ...elDataReceived_OnDataReceived_Exception.cs | 184 +- ...temSession_OnChannelException_Connected.cs | 222 +- ...stemSession_OnChannelException_Disposed.cs | 178 +- ...Session_OnSessionDisconnected_Connected.cs | 216 +- ...mSession_OnSessionDisconnected_Disposed.cs | 168 +- ...ession_OnSessionErrorOccurred_Connected.cs | 222 +- ...Session_OnSessionErrorOccurred_Disposed.cs | 172 +- .../SubsystemSession_SendData_Connected.cs | 212 +- .../SubsystemSession_SendData_Disconnected.cs | 22 +- .../SubsystemSession_SendData_Disposed.cs | 200 +- ...ubsystemSession_SendData_NeverConnected.cs | 212 +- .../Common/AsyncSocketListener.cs | 322 +- .../Common/HttpProxyStub.cs | 336 +- src/Renci.SshNet.Tests/Common/HttpRequest.cs | 34 +- src/Renci.SshNet.Tests/Common/TestBase.cs | 110 +- .../Key.RSA.Encrypted.Aes.128.CBC.12345.txt | 58 +- .../Key.RSA.Encrypted.Aes.192.CBC.12345.txt | 58 +- .../Key.RSA.Encrypted.Aes.256.CBC.12345.txt | 58 +- .../Data/Key.RSA.Encrypted.Des.CBC.12345.txt | 60 +- .../Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt | 58 +- ....RSA.Encrypted.Des.Ede3.CFB.1234567890.txt | 34 +- src/Renci.SshNet.Tests/Data/Key.RSA.txt | 52 +- .../Properties/AssemblyInfo.cs | 10 +- .../Properties/Resources.Designer.cs | 412 +- .../Properties/Resources.resx | 486 +-- .../Renci.SshNet.Tests.csproj | 1130 +++--- src/Renci.SshNet.Tests/packages.config | 6 +- .../Properties/AssemblyInfo.cs | 10 +- src/Renci.SshNet.WindowsPhone/Session.WP.cs | 154 +- .../Properties/AssemblyInfo.cs | 14 +- .../Renci.SshNet.WindowsPhone8.csproj | 1894 +++++----- src/Renci.SshNet/AuthenticationMethod.cs | 126 +- src/Renci.SshNet/AuthenticationResult.cs | 42 +- src/Renci.SshNet/Channels/Channel.cs | 1830 ++++----- .../Channels/ChannelDirectTcpip.cs | 690 ++-- .../Channels/ChannelForwardedTcpip.cs | 424 +-- src/Renci.SshNet/Channels/ChannelSession.cs | 858 ++--- src/Renci.SshNet/Channels/ChannelTypes.cs | 52 +- src/Renci.SshNet/Channels/ClientChannel.cs | 254 +- src/Renci.SshNet/Channels/IChannel.cs | 216 +- .../Channels/IChannelDirectTcpip.cs | 104 +- .../Channels/IChannelForwardedTcpip.cs | 58 +- src/Renci.SshNet/Channels/IChannelSession.cs | 310 +- src/Renci.SshNet/Channels/ServerChannel.cs | 66 +- src/Renci.SshNet/CipherInfo.cs | 70 +- 454 files changed, 47715 insertions(+), 47715 deletions(-) diff --git a/.gitattributes b/.gitattributes index be6d9e66..700825a7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,10 +2,10 @@ *.cs text *.xaml text -*.sln text eol=crlf -*.csproj text eol=crlf -*.shproj text eol=crlf -*.appxmanifest text eol=crlf +*.sln eol=crlf +*.csproj eol=crlf +*.shproj eol=crlf +*.appxmanifest eol=crlf *.png binary *.jpg binary diff --git a/src/References/X.690-0207.txt b/src/References/X.690-0207.txt index d4bcf732..597e199e 100644 --- a/src/References/X.690-0207.txt +++ b/src/References/X.690-0207.txt @@ -1,3 +1,3 @@ -Source = http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf -Code = .\Renci.SshNet\Common\DerData.cs +Source = http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf +Code = .\Renci.SshNet\Common\DerData.cs Wiki = http://en.wikipedia.org/wiki/Distinguished_Encoding_Rules \ No newline at end of file diff --git a/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs b/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs index 7eda0945..98900f67 100644 --- a/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs +++ b/src/Renci.SshNet.NET35/Common/Extensions.NET35.cs @@ -1,66 +1,66 @@ -using System; -using System.Diagnostics; -using System.Net.Sockets; -using System.Security.Cryptography; -using System.Text; -using System.Threading; - -namespace Renci.SshNet -{ - /// - /// Collection of different extension method specific for .NET 3.5 - /// - internal static partial class Extensions - { - /// - /// Disposes the specified socket. - /// - /// The socket. - [DebuggerNonUserCode] - internal static void Dispose(this Socket socket) - { - if (socket == null) - throw new NullReferenceException(); - - socket.Close(); - } - - /// - /// Disposes the specified handle. - /// - /// The handle. - [DebuggerNonUserCode] - internal static void Dispose(this WaitHandle handle) - { - if (handle == null) - throw new NullReferenceException(); - - handle.Close(); - } - - /// - /// Disposes the specified algorithm. - /// - /// The algorithm. - [DebuggerNonUserCode] - internal static void Dispose(this HashAlgorithm algorithm) - { - if (algorithm == null) - throw new NullReferenceException(); - - algorithm.Clear(); - } - - /// - /// Clears the contents of the string builder. - /// - /// - /// The to clear. - /// - public static void Clear(this StringBuilder value) - { - value.Length = 0; - value.Capacity = 16; - } - } -} +using System; +using System.Diagnostics; +using System.Net.Sockets; +using System.Security.Cryptography; +using System.Text; +using System.Threading; + +namespace Renci.SshNet +{ + /// + /// Collection of different extension method specific for .NET 3.5 + /// + internal static partial class Extensions + { + /// + /// Disposes the specified socket. + /// + /// The socket. + [DebuggerNonUserCode] + internal static void Dispose(this Socket socket) + { + if (socket == null) + throw new NullReferenceException(); + + socket.Close(); + } + + /// + /// Disposes the specified handle. + /// + /// The handle. + [DebuggerNonUserCode] + internal static void Dispose(this WaitHandle handle) + { + if (handle == null) + throw new NullReferenceException(); + + handle.Close(); + } + + /// + /// Disposes the specified algorithm. + /// + /// The algorithm. + [DebuggerNonUserCode] + internal static void Dispose(this HashAlgorithm algorithm) + { + if (algorithm == null) + throw new NullReferenceException(); + + algorithm.Clear(); + } + + /// + /// Clears the contents of the string builder. + /// + /// + /// The to clear. + /// + public static void Clear(this StringBuilder value) + { + value.Length = 0; + value.Capacity = 16; + } + } +} diff --git a/src/Renci.SshNet.NET35/Properties/AssemblyInfo.cs b/src/Renci.SshNet.NET35/Properties/AssemblyInfo.cs index ee4133c8..9b3fcd24 100644 --- a/src/Renci.SshNet.NET35/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.NET35/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET .NET 3.5")] -[assembly: Guid("a9698831-4993-469b-81f1-aed4e5379252")] -[assembly: InternalsVisibleTo("Renci.SshNet.Tests.NET35, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f9194e1eb66b7e2575aaee115ee1d27bc100920e7150e43992d6f668f9737de8b9c7ae892b62b8a36dd1d57929ff1541665d101dc476d6e02390846efae7e5186eec409710fdb596e3f83740afef0d4443055937649bc5a773175b61c57615dac0f0fd10f52b52fedf76c17474cc567b3f7a79de95dde842509fb39aaf69c6c2")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET .NET 3.5")] +[assembly: Guid("a9698831-4993-469b-81f1-aed4e5379252")] +[assembly: InternalsVisibleTo("Renci.SshNet.Tests.NET35, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f9194e1eb66b7e2575aaee115ee1d27bc100920e7150e43992d6f668f9737de8b9c7ae892b62b8a36dd1d57929ff1541665d101dc476d6e02390846efae7e5186eec409710fdb596e3f83740afef0d4443055937649bc5a773175b61c57615dac0f0fd10f52b52fedf76c17474cc567b3f7a79de95dde842509fb39aaf69c6c2")] [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj b/src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj index cdd01c56..13c104cd 100644 --- a/src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj +++ b/src/Renci.SshNet.NET35/Renci.SshNet.NET35.csproj @@ -1,953 +1,953 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A} - Library - Properties - Renci.SshNet - Renci.SshNet - v3.5 - 512 - - - true - full - false - bin\Debug\ - TRACE;DEBUG;FEATURE_RNG_CSP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_POLL;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_MD5;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HASH_SHA384;FEATURE_HASH_SHA512;FEATURE_HASH_RIPEMD160;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII - prompt - 4 - true - bin\Debug\Renci.SshNet.xml - - - none - true - bin\Release\ - TRACE;FEATURE_RNG_CSP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_POLL;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_MD5;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HASH_SHA384;FEATURE_HASH_SHA512;FEATURE_HASH_RIPEMD160;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII - prompt - 4 - bin\Release\Renci.SshNet.xml - - - true - - - true - - - ..\Renci.SshNet.snk - - - - - - - - - - - - Abstractions\CryptoAbstraction.cs - - - Abstractions\DiagnosticAbstraction.cs - - - Abstractions\DnsAbstraction.cs - - - Abstractions\ReflectionAbstraction.cs - - - Abstractions\SocketAbstraction.cs - - - Abstractions\ThreadAbstraction.cs - - - AuthenticationMethod.cs - - - AuthenticationResult.cs - - - BaseClient.cs - - - Channels\Channel.cs - - - Channels\ChannelDirectTcpip.cs - - - Channels\ChannelForwardedTcpip.cs - - - Channels\ChannelSession.cs - - - Channels\ChannelTypes.cs - - - Channels\ClientChannel.cs - - - Channels\IChannel.cs - - - Channels\IChannelDirectTcpip.cs - - - Channels\IChannelForwardedTcpip.cs - - - Channels\IChannelSession.cs - - - Channels\ServerChannel.cs - - - CipherInfo.cs - - - ClientAuthentication.cs - - - CommandAsyncResult.cs - - - Common\Array.cs - - - Common\ASCIIEncoding.cs - - - Common\AsyncResult.cs - - - Common\AuthenticationBannerEventArgs.cs - - - Common\AuthenticationEventArgs.cs - - - Common\AuthenticationPasswordChangeEventArgs.cs - - - Common\AuthenticationPrompt.cs - - - Common\AuthenticationPromptEventArgs.cs - - - Common\BigInteger.cs - - - Common\ChannelDataEventArgs.cs - - - Common\ChannelEventArgs.cs - - - Common\ChannelExtendedDataEventArgs.cs - - - Common\ChannelOpenConfirmedEventArgs.cs - - - Common\ChannelOpenFailedEventArgs.cs - - - Common\ChannelRequestEventArgs.cs - - - Common\DerData.cs - - - Common\ExceptionEventArgs.cs - - - Common\Extensions.cs - - - Common\HostKeyEventArgs.cs - - - Common\NetConfServerException.cs - - - Common\NetConfServerException.NET40.cs - - - Common\ObjectIdentifier.cs - - - Common\PipeStream.cs - - - Common\PortForwardEventArgs.cs - - - Common\ProxyException.cs - - - Common\ScpDownloadEventArgs.cs - - - Common\ScpException.cs - - - Common\ScpException.NET40.cs - - - Common\ScpUploadEventArgs.cs - - - Common\SemaphoreLight.cs - - - Common\SftpPathNotFoundException.cs - - - Common\SftpPathNotFoundException.NET40.cs - - - Common\SftpPermissionDeniedException.cs - - - Common\SftpPermissionDeniedException.NET40.cs - - - Common\ShellDataEventArgs.cs - - - Common\SshAuthenticationException.cs - - - Common\SshAuthenticationException.NET40.cs - - - Common\SshConnectionException.cs - - - Common\SshConnectionException.NET40.cs - - - Common\SshData.cs - - - Common\SshDataStream.cs - - - Common\SshException.cs - - - Common\SshException.NET40.cs - - - Common\SshOperationTimeoutException.cs - - - Common\SshOperationTimeoutException.NET40.cs - - - Common\SshPassPhraseNullOrEmptyException.cs - - - Common\SshPassPhraseNullOrEmptyException.NET40.cs - - - Common\TerminalModes.cs - - - Compression\CompressionMode.cs - - - Compression\Compressor.cs - - - Compression\Zlib.cs - - - Compression\ZlibOpenSsh.cs - - - Compression\ZlibStream.cs - - - ConnectionInfo.cs - - - ExpectAction.cs - - - ExpectAsyncResult.cs - - - ForwardedPort.cs - - - ForwardedPortDynamic.cs - - - ForwardedPortDynamic.NET.cs - - - ForwardedPortLocal.cs - - - ForwardedPortLocal.NET.cs - - - ForwardedPortRemote.cs - - - HashInfo.cs - - - IAuthenticationMethod.cs - - - IClientAuthentication.cs - - - IConnectionInfo.cs - - - IForwardedPort.cs - - - IServiceFactory.cs - - - IServiceFactory.NET.cs - - - ISession.cs - - - ISubsystemSession.cs - - - KeyboardInteractiveAuthenticationMethod.cs - - - KeyboardInteractiveConnectionInfo.cs - - - MessageEventArgs.cs - - - Messages\Authentication\BannerMessage.cs - - - Messages\Authentication\FailureMessage.cs - - - Messages\Authentication\InformationRequestMessage.cs - - - Messages\Authentication\InformationResponseMessage.cs - - - Messages\Authentication\PasswordChangeRequiredMessage.cs - - - Messages\Authentication\PublicKeyMessage.cs - - - Messages\Authentication\RequestMessage.cs - - - Messages\Authentication\RequestMessageHost.cs - - - Messages\Authentication\RequestMessageKeyboardInteractive.cs - - - Messages\Authentication\RequestMessageNone.cs - - - Messages\Authentication\RequestMessagePassword.cs - - - Messages\Authentication\RequestMessagePublicKey.cs - - - Messages\Authentication\SuccessMessage.cs - - - Messages\Connection\ChannelCloseMessage.cs - - - Messages\Connection\ChannelDataMessage.cs - - - Messages\Connection\ChannelEofMessage.cs - - - Messages\Connection\ChannelExtendedDataMessage.cs - - - Messages\Connection\ChannelFailureMessage.cs - - - Messages\Connection\ChannelMessage.cs - - - Messages\Connection\ChannelOpenConfirmationMessage.cs - - - Messages\Connection\ChannelOpenFailureMessage.cs - - - Messages\Connection\ChannelOpenFailureReasons.cs - - - Messages\Connection\ChannelOpen\ChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\ChannelOpenMessage.cs - - - Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs - - - Messages\Connection\ChannelRequest\BreakRequestInfo.cs - - - Messages\Connection\ChannelRequest\ChannelRequestMessage.cs - - - Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs - - - Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExecRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs - - - Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs - - - Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs - - - Messages\Connection\ChannelRequest\RequestInfo.cs - - - Messages\Connection\ChannelRequest\ShellRequestInfo.cs - - - Messages\Connection\ChannelRequest\SignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs - - - Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs - - - Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs - - - Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs - - - Messages\Connection\ChannelSuccessMessage.cs - - - Messages\Connection\ChannelWindowAdjustMessage.cs - - - Messages\Connection\GlobalRequestMessage.cs - - - Messages\Connection\GlobalRequestName.cs - - - Messages\Connection\RequestFailureMessage.cs - - - Messages\Connection\RequestSuccessMessage.cs - - - Messages\Message.cs - - - Messages\MessageAttribute.cs - - - Messages\ServiceName.cs - - - Messages\Transport\DebugMessage.cs - - - Messages\Transport\DisconnectMessage.cs - - - Messages\Transport\DisconnectReason.cs - - - Messages\Transport\IgnoreMessage.cs - - - Messages\Transport\IKeyExchangedAllowed.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeInit.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeReply.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs - - - Messages\Transport\KeyExchangeDhInitMessage.cs - - - Messages\Transport\KeyExchangeDhReplyMessage.cs - - - Messages\Transport\KeyExchangeEcdhInitMessage.cs - - - Messages\Transport\KeyExchangeEcdhReplyMessage.cs - - - Messages\Transport\KeyExchangeInitMessage.cs - - - Messages\Transport\NewKeysMessage.cs - - - Messages\Transport\ServiceAcceptMessage.cs - - - Messages\Transport\ServiceRequestMessage.cs - - - Messages\Transport\UnimplementedMessage.cs - - - NetConfClient.cs - - - Netconf\INetConfSession.cs - - - Netconf\NetConfSession.cs - - - NoneAuthenticationMethod.cs - - - PasswordAuthenticationMethod.cs - - - PasswordConnectionInfo.cs - - - PrivateKeyAuthenticationMethod.cs - - - PrivateKeyConnectionInfo.cs - - - PrivateKeyFile.cs - - - ProxyTypes.cs - - - ScpClient.cs - - - ScpClient.NET.cs - - - Security\Algorithm.cs - - - Security\CertificateHostAlgorithm.cs - - - Security\Cryptography\AsymmetricCipher.cs - - - Security\Cryptography\BlockCipher.cs - - - Security\Cryptography\Cipher.cs - - - Security\Cryptography\CipherDigitalSignature.cs - - - Security\Cryptography\Ciphers\AesCipher.cs - - - Security\Cryptography\Ciphers\Arc4Cipher.cs - - - Security\Cryptography\Ciphers\BlowfishCipher.cs - - - Security\Cryptography\Ciphers\CastCipher.cs - - - Security\Cryptography\Ciphers\CipherMode.cs - - - Security\Cryptography\Ciphers\CipherPadding.cs - - - Security\Cryptography\Ciphers\DesCipher.cs - - - Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs - - - Security\Cryptography\Ciphers\Paddings\PKCS5Padding.cs - - - Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs - - - Security\Cryptography\Ciphers\RsaCipher.cs - - - Security\Cryptography\Ciphers\SerpentCipher.cs - - - Security\Cryptography\Ciphers\TripleDesCipher.cs - - - Security\Cryptography\Ciphers\TwofishCipher.cs - - - Security\Cryptography\DigitalSignature.cs - - - Security\Cryptography\DsaDigitalSignature.cs - - - Security\Cryptography\DsaKey.cs - - - Security\Cryptography\HMACMD5.cs - - - Security\Cryptography\HMACSHA1.cs - - - Security\Cryptography\HMACSHA256.cs - - - Security\Cryptography\HMACSHA384.cs - - - Security\Cryptography\HMACSHA512.cs - - - Security\Cryptography\Key.cs - - - Security\Cryptography\RsaDigitalSignature.cs - - - Security\Cryptography\RsaKey.cs - - - Security\Cryptography\StreamCipher.cs - - - Security\Cryptography\SymmetricCipher.cs - - - Security\GroupExchangeHashData.cs - - - Security\HostAlgorithm.cs - - - Security\IKeyExchange.cs - - - Security\KeyExchange.cs - - - Security\KeyExchangeDiffieHellman.cs - - - Security\KeyExchangeDiffieHellmanGroup14Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroup1Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs - - - Security\KeyExchangeDiffieHellmanGroupSha1.cs - - - Security\KeyHostAlgorithm.cs - - - ServiceFactory.cs - - - ServiceFactory.NET.cs - - - Session.cs - - - Session.NET.cs - - - SftpClient.cs - - - Sftp\Flags.cs - - - Sftp\ISftpSession.cs - - - Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs - - - Sftp\Requests\ExtendedRequests\HardLinkRequest.cs - - - Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs - - - Sftp\Requests\ExtendedRequests\StatVfsRequest.cs - - - Sftp\Requests\SftpBlockRequest.cs - - - Sftp\Requests\SftpCloseRequest.cs - - - Sftp\Requests\SftpExtendedRequest.cs - - - Sftp\Requests\SftpFSetStatRequest.cs - - - Sftp\Requests\SftpFStatRequest.cs - - - Sftp\Requests\SftpInitRequest.cs - - - Sftp\Requests\SftpLinkRequest.cs - - - Sftp\Requests\SftpLStatRequest.cs - - - Sftp\Requests\SftpMkDirRequest.cs - - - Sftp\Requests\SftpOpenDirRequest.cs - - - Sftp\Requests\SftpOpenRequest.cs - - - Sftp\Requests\SftpReadDirRequest.cs - - - Sftp\Requests\SftpReadLinkRequest.cs - - - Sftp\Requests\SftpReadRequest.cs - - - Sftp\Requests\SftpRealPathRequest.cs - - - Sftp\Requests\SftpRemoveRequest.cs - - - Sftp\Requests\SftpRenameRequest.cs - - - Sftp\Requests\SftpRequest.cs - - - Sftp\Requests\SftpRmDirRequest.cs - - - Sftp\Requests\SftpSetStatRequest.cs - - - Sftp\Requests\SftpStatRequest.cs - - - Sftp\Requests\SftpSymLinkRequest.cs - - - Sftp\Requests\SftpUnblockRequest.cs - - - Sftp\Requests\SftpWriteRequest.cs - - - Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs - - - Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs - - - Sftp\Responses\SftpAttrsResponse.cs - - - Sftp\Responses\SftpDataResponse.cs - - - Sftp\Responses\SftpExtendedReplyResponse.cs - - - Sftp\Responses\SftpHandleResponse.cs - - - Sftp\Responses\SftpNameResponse.cs - - - Sftp\Responses\SftpResponse.cs - - - Sftp\Responses\SftpStatusResponse.cs - - - Sftp\Responses\SftpVersionResponse.cs - - - Sftp\SftpDownloadAsyncResult.cs - - - Sftp\SftpFile.cs - - - Sftp\SftpFileAttributes.cs - - - Sftp\SftpFileStream.cs - - - Sftp\SftpFileSystemInformation.cs - - - Sftp\SftpListDirectoryAsyncResult.cs - - - Sftp\SftpMessage.cs - - - Sftp\SftpMessageTypes.cs - - - Sftp\SftpSession.cs - - - Sftp\SftpSynchronizeDirectoriesAsyncResult.cs - - - Sftp\SftpUploadAsyncResult.cs - - - Sftp\StatusCodes.cs - - - Shell.cs - - - ShellStream.cs - - - SshClient.cs - - - SshCommand.cs - - - SshMessageFactory.cs - - - SubsystemSession.cs - - - - - Properties\CommonAssemblyInfo.cs - - - - - - - Renci.SshNet.snk - - - - - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A} + Library + Properties + Renci.SshNet + Renci.SshNet + v3.5 + 512 + + + true + full + false + bin\Debug\ + TRACE;DEBUG;FEATURE_RNG_CSP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_POLL;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_MD5;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HASH_SHA384;FEATURE_HASH_SHA512;FEATURE_HASH_RIPEMD160;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII + prompt + 4 + true + bin\Debug\Renci.SshNet.xml + + + none + true + bin\Release\ + TRACE;FEATURE_RNG_CSP;FEATURE_SOCKET_SYNC;FEATURE_SOCKET_EAP;FEATURE_SOCKET_POLL;FEATURE_STREAM_APM;FEATURE_DNS_SYNC;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_HASH_MD5;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HASH_SHA384;FEATURE_HASH_SHA512;FEATURE_HASH_RIPEMD160;FEATURE_HMAC_MD5;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256;FEATURE_HMAC_SHA384;FEATURE_HMAC_SHA512;FEATURE_HMAC_RIPEMD160;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_DIAGNOSTICS_TRACESOURCE;FEATURE_ENCODING_ASCII + prompt + 4 + bin\Release\Renci.SshNet.xml + + + true + + + true + + + ..\Renci.SshNet.snk + + + + + + + + + + + + Abstractions\CryptoAbstraction.cs + + + Abstractions\DiagnosticAbstraction.cs + + + Abstractions\DnsAbstraction.cs + + + Abstractions\ReflectionAbstraction.cs + + + Abstractions\SocketAbstraction.cs + + + Abstractions\ThreadAbstraction.cs + + + AuthenticationMethod.cs + + + AuthenticationResult.cs + + + BaseClient.cs + + + Channels\Channel.cs + + + Channels\ChannelDirectTcpip.cs + + + Channels\ChannelForwardedTcpip.cs + + + Channels\ChannelSession.cs + + + Channels\ChannelTypes.cs + + + Channels\ClientChannel.cs + + + Channels\IChannel.cs + + + Channels\IChannelDirectTcpip.cs + + + Channels\IChannelForwardedTcpip.cs + + + Channels\IChannelSession.cs + + + Channels\ServerChannel.cs + + + CipherInfo.cs + + + ClientAuthentication.cs + + + CommandAsyncResult.cs + + + Common\Array.cs + + + Common\ASCIIEncoding.cs + + + Common\AsyncResult.cs + + + Common\AuthenticationBannerEventArgs.cs + + + Common\AuthenticationEventArgs.cs + + + Common\AuthenticationPasswordChangeEventArgs.cs + + + Common\AuthenticationPrompt.cs + + + Common\AuthenticationPromptEventArgs.cs + + + Common\BigInteger.cs + + + Common\ChannelDataEventArgs.cs + + + Common\ChannelEventArgs.cs + + + Common\ChannelExtendedDataEventArgs.cs + + + Common\ChannelOpenConfirmedEventArgs.cs + + + Common\ChannelOpenFailedEventArgs.cs + + + Common\ChannelRequestEventArgs.cs + + + Common\DerData.cs + + + Common\ExceptionEventArgs.cs + + + Common\Extensions.cs + + + Common\HostKeyEventArgs.cs + + + Common\NetConfServerException.cs + + + Common\NetConfServerException.NET40.cs + + + Common\ObjectIdentifier.cs + + + Common\PipeStream.cs + + + Common\PortForwardEventArgs.cs + + + Common\ProxyException.cs + + + Common\ScpDownloadEventArgs.cs + + + Common\ScpException.cs + + + Common\ScpException.NET40.cs + + + Common\ScpUploadEventArgs.cs + + + Common\SemaphoreLight.cs + + + Common\SftpPathNotFoundException.cs + + + Common\SftpPathNotFoundException.NET40.cs + + + Common\SftpPermissionDeniedException.cs + + + Common\SftpPermissionDeniedException.NET40.cs + + + Common\ShellDataEventArgs.cs + + + Common\SshAuthenticationException.cs + + + Common\SshAuthenticationException.NET40.cs + + + Common\SshConnectionException.cs + + + Common\SshConnectionException.NET40.cs + + + Common\SshData.cs + + + Common\SshDataStream.cs + + + Common\SshException.cs + + + Common\SshException.NET40.cs + + + Common\SshOperationTimeoutException.cs + + + Common\SshOperationTimeoutException.NET40.cs + + + Common\SshPassPhraseNullOrEmptyException.cs + + + Common\SshPassPhraseNullOrEmptyException.NET40.cs + + + Common\TerminalModes.cs + + + Compression\CompressionMode.cs + + + Compression\Compressor.cs + + + Compression\Zlib.cs + + + Compression\ZlibOpenSsh.cs + + + Compression\ZlibStream.cs + + + ConnectionInfo.cs + + + ExpectAction.cs + + + ExpectAsyncResult.cs + + + ForwardedPort.cs + + + ForwardedPortDynamic.cs + + + ForwardedPortDynamic.NET.cs + + + ForwardedPortLocal.cs + + + ForwardedPortLocal.NET.cs + + + ForwardedPortRemote.cs + + + HashInfo.cs + + + IAuthenticationMethod.cs + + + IClientAuthentication.cs + + + IConnectionInfo.cs + + + IForwardedPort.cs + + + IServiceFactory.cs + + + IServiceFactory.NET.cs + + + ISession.cs + + + ISubsystemSession.cs + + + KeyboardInteractiveAuthenticationMethod.cs + + + KeyboardInteractiveConnectionInfo.cs + + + MessageEventArgs.cs + + + Messages\Authentication\BannerMessage.cs + + + Messages\Authentication\FailureMessage.cs + + + Messages\Authentication\InformationRequestMessage.cs + + + Messages\Authentication\InformationResponseMessage.cs + + + Messages\Authentication\PasswordChangeRequiredMessage.cs + + + Messages\Authentication\PublicKeyMessage.cs + + + Messages\Authentication\RequestMessage.cs + + + Messages\Authentication\RequestMessageHost.cs + + + Messages\Authentication\RequestMessageKeyboardInteractive.cs + + + Messages\Authentication\RequestMessageNone.cs + + + Messages\Authentication\RequestMessagePassword.cs + + + Messages\Authentication\RequestMessagePublicKey.cs + + + Messages\Authentication\SuccessMessage.cs + + + Messages\Connection\ChannelCloseMessage.cs + + + Messages\Connection\ChannelDataMessage.cs + + + Messages\Connection\ChannelEofMessage.cs + + + Messages\Connection\ChannelExtendedDataMessage.cs + + + Messages\Connection\ChannelFailureMessage.cs + + + Messages\Connection\ChannelMessage.cs + + + Messages\Connection\ChannelOpenConfirmationMessage.cs + + + Messages\Connection\ChannelOpenFailureMessage.cs + + + Messages\Connection\ChannelOpenFailureReasons.cs + + + Messages\Connection\ChannelOpen\ChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\ChannelOpenMessage.cs + + + Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs + + + Messages\Connection\ChannelRequest\BreakRequestInfo.cs + + + Messages\Connection\ChannelRequest\ChannelRequestMessage.cs + + + Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs + + + Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExecRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs + + + Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs + + + Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs + + + Messages\Connection\ChannelRequest\RequestInfo.cs + + + Messages\Connection\ChannelRequest\ShellRequestInfo.cs + + + Messages\Connection\ChannelRequest\SignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs + + + Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs + + + Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs + + + Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs + + + Messages\Connection\ChannelSuccessMessage.cs + + + Messages\Connection\ChannelWindowAdjustMessage.cs + + + Messages\Connection\GlobalRequestMessage.cs + + + Messages\Connection\GlobalRequestName.cs + + + Messages\Connection\RequestFailureMessage.cs + + + Messages\Connection\RequestSuccessMessage.cs + + + Messages\Message.cs + + + Messages\MessageAttribute.cs + + + Messages\ServiceName.cs + + + Messages\Transport\DebugMessage.cs + + + Messages\Transport\DisconnectMessage.cs + + + Messages\Transport\DisconnectReason.cs + + + Messages\Transport\IgnoreMessage.cs + + + Messages\Transport\IKeyExchangedAllowed.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeInit.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeReply.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs + + + Messages\Transport\KeyExchangeDhInitMessage.cs + + + Messages\Transport\KeyExchangeDhReplyMessage.cs + + + Messages\Transport\KeyExchangeEcdhInitMessage.cs + + + Messages\Transport\KeyExchangeEcdhReplyMessage.cs + + + Messages\Transport\KeyExchangeInitMessage.cs + + + Messages\Transport\NewKeysMessage.cs + + + Messages\Transport\ServiceAcceptMessage.cs + + + Messages\Transport\ServiceRequestMessage.cs + + + Messages\Transport\UnimplementedMessage.cs + + + NetConfClient.cs + + + Netconf\INetConfSession.cs + + + Netconf\NetConfSession.cs + + + NoneAuthenticationMethod.cs + + + PasswordAuthenticationMethod.cs + + + PasswordConnectionInfo.cs + + + PrivateKeyAuthenticationMethod.cs + + + PrivateKeyConnectionInfo.cs + + + PrivateKeyFile.cs + + + ProxyTypes.cs + + + ScpClient.cs + + + ScpClient.NET.cs + + + Security\Algorithm.cs + + + Security\CertificateHostAlgorithm.cs + + + Security\Cryptography\AsymmetricCipher.cs + + + Security\Cryptography\BlockCipher.cs + + + Security\Cryptography\Cipher.cs + + + Security\Cryptography\CipherDigitalSignature.cs + + + Security\Cryptography\Ciphers\AesCipher.cs + + + Security\Cryptography\Ciphers\Arc4Cipher.cs + + + Security\Cryptography\Ciphers\BlowfishCipher.cs + + + Security\Cryptography\Ciphers\CastCipher.cs + + + Security\Cryptography\Ciphers\CipherMode.cs + + + Security\Cryptography\Ciphers\CipherPadding.cs + + + Security\Cryptography\Ciphers\DesCipher.cs + + + Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs + + + Security\Cryptography\Ciphers\Paddings\PKCS5Padding.cs + + + Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs + + + Security\Cryptography\Ciphers\RsaCipher.cs + + + Security\Cryptography\Ciphers\SerpentCipher.cs + + + Security\Cryptography\Ciphers\TripleDesCipher.cs + + + Security\Cryptography\Ciphers\TwofishCipher.cs + + + Security\Cryptography\DigitalSignature.cs + + + Security\Cryptography\DsaDigitalSignature.cs + + + Security\Cryptography\DsaKey.cs + + + Security\Cryptography\HMACMD5.cs + + + Security\Cryptography\HMACSHA1.cs + + + Security\Cryptography\HMACSHA256.cs + + + Security\Cryptography\HMACSHA384.cs + + + Security\Cryptography\HMACSHA512.cs + + + Security\Cryptography\Key.cs + + + Security\Cryptography\RsaDigitalSignature.cs + + + Security\Cryptography\RsaKey.cs + + + Security\Cryptography\StreamCipher.cs + + + Security\Cryptography\SymmetricCipher.cs + + + Security\GroupExchangeHashData.cs + + + Security\HostAlgorithm.cs + + + Security\IKeyExchange.cs + + + Security\KeyExchange.cs + + + Security\KeyExchangeDiffieHellman.cs + + + Security\KeyExchangeDiffieHellmanGroup14Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroup1Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs + + + Security\KeyExchangeDiffieHellmanGroupSha1.cs + + + Security\KeyHostAlgorithm.cs + + + ServiceFactory.cs + + + ServiceFactory.NET.cs + + + Session.cs + + + Session.NET.cs + + + SftpClient.cs + + + Sftp\Flags.cs + + + Sftp\ISftpSession.cs + + + Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs + + + Sftp\Requests\ExtendedRequests\HardLinkRequest.cs + + + Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs + + + Sftp\Requests\ExtendedRequests\StatVfsRequest.cs + + + Sftp\Requests\SftpBlockRequest.cs + + + Sftp\Requests\SftpCloseRequest.cs + + + Sftp\Requests\SftpExtendedRequest.cs + + + Sftp\Requests\SftpFSetStatRequest.cs + + + Sftp\Requests\SftpFStatRequest.cs + + + Sftp\Requests\SftpInitRequest.cs + + + Sftp\Requests\SftpLinkRequest.cs + + + Sftp\Requests\SftpLStatRequest.cs + + + Sftp\Requests\SftpMkDirRequest.cs + + + Sftp\Requests\SftpOpenDirRequest.cs + + + Sftp\Requests\SftpOpenRequest.cs + + + Sftp\Requests\SftpReadDirRequest.cs + + + Sftp\Requests\SftpReadLinkRequest.cs + + + Sftp\Requests\SftpReadRequest.cs + + + Sftp\Requests\SftpRealPathRequest.cs + + + Sftp\Requests\SftpRemoveRequest.cs + + + Sftp\Requests\SftpRenameRequest.cs + + + Sftp\Requests\SftpRequest.cs + + + Sftp\Requests\SftpRmDirRequest.cs + + + Sftp\Requests\SftpSetStatRequest.cs + + + Sftp\Requests\SftpStatRequest.cs + + + Sftp\Requests\SftpSymLinkRequest.cs + + + Sftp\Requests\SftpUnblockRequest.cs + + + Sftp\Requests\SftpWriteRequest.cs + + + Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs + + + Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs + + + Sftp\Responses\SftpAttrsResponse.cs + + + Sftp\Responses\SftpDataResponse.cs + + + Sftp\Responses\SftpExtendedReplyResponse.cs + + + Sftp\Responses\SftpHandleResponse.cs + + + Sftp\Responses\SftpNameResponse.cs + + + Sftp\Responses\SftpResponse.cs + + + Sftp\Responses\SftpStatusResponse.cs + + + Sftp\Responses\SftpVersionResponse.cs + + + Sftp\SftpDownloadAsyncResult.cs + + + Sftp\SftpFile.cs + + + Sftp\SftpFileAttributes.cs + + + Sftp\SftpFileStream.cs + + + Sftp\SftpFileSystemInformation.cs + + + Sftp\SftpListDirectoryAsyncResult.cs + + + Sftp\SftpMessage.cs + + + Sftp\SftpMessageTypes.cs + + + Sftp\SftpSession.cs + + + Sftp\SftpSynchronizeDirectoriesAsyncResult.cs + + + Sftp\SftpUploadAsyncResult.cs + + + Sftp\StatusCodes.cs + + + Shell.cs + + + ShellStream.cs + + + SshClient.cs + + + SshCommand.cs + + + SshMessageFactory.cs + + + SubsystemSession.cs + + + + + Properties\CommonAssemblyInfo.cs + + + + + + + Renci.SshNet.snk + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet.NET35/Session.NET35.cs b/src/Renci.SshNet.NET35/Session.NET35.cs index 959beba8..04679746 100644 --- a/src/Renci.SshNet.NET35/Session.NET35.cs +++ b/src/Renci.SshNet.NET35/Session.NET35.cs @@ -1,62 +1,62 @@ -using System.Linq; -using System; -using Renci.SshNet.Messages; -using System.Reflection; -using System.Collections.Generic; -using System.Diagnostics; - -namespace Renci.SshNet -{ - /// - /// Provides functionality to connect and interact with SSH server. - /// - public partial class Session - { - private static readonly Dictionary _handlers; - - static Session() - { - _handlers = new Dictionary(); - - foreach (var method in typeof(Session).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Where(x => x.Name == "HandleMessage")) - { - if (method.IsGenericMethod) continue; - - var args = method.GetParameters(); - if (args.Length != 1) continue; - - var argType = args[0].ParameterType; - if (!argType.IsSubclassOf(typeof(Message))) continue; - - _handlers.Add(argType, method); - } - } - - /// - /// Handles SSH messages. - /// - /// The message. - partial void HandleMessageCore(Message message) - { - Debug.Assert(message != null); - - MethodInfo method; - - if (_handlers.TryGetValue(message.GetType(), out method)) - { - try - { - method.Invoke(this, new object[] { message }); - } - catch (TargetInvocationException ex) - { - throw ex.InnerException ?? ex; - } - } - else - { - HandleMessage(message); - } - } - } -} +using System.Linq; +using System; +using Renci.SshNet.Messages; +using System.Reflection; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Renci.SshNet +{ + /// + /// Provides functionality to connect and interact with SSH server. + /// + public partial class Session + { + private static readonly Dictionary _handlers; + + static Session() + { + _handlers = new Dictionary(); + + foreach (var method in typeof(Session).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).Where(x => x.Name == "HandleMessage")) + { + if (method.IsGenericMethod) continue; + + var args = method.GetParameters(); + if (args.Length != 1) continue; + + var argType = args[0].ParameterType; + if (!argType.IsSubclassOf(typeof(Message))) continue; + + _handlers.Add(argType, method); + } + } + + /// + /// Handles SSH messages. + /// + /// The message. + partial void HandleMessageCore(Message message) + { + Debug.Assert(message != null); + + MethodInfo method; + + if (_handlers.TryGetValue(message.GetType(), out method)) + { + try + { + method.Invoke(this, new object[] { message }); + } + catch (TargetInvocationException ex) + { + throw ex.InnerException ?? ex; + } + } + else + { + HandleMessage(message); + } + } + } +} diff --git a/src/Renci.SshNet.Silverlight/Common/Extensions.SilverlightShared.cs b/src/Renci.SshNet.Silverlight/Common/Extensions.SilverlightShared.cs index 26baf7ff..c69e7c4f 100644 --- a/src/Renci.SshNet.Silverlight/Common/Extensions.SilverlightShared.cs +++ b/src/Renci.SshNet.Silverlight/Common/Extensions.SilverlightShared.cs @@ -1,53 +1,53 @@ -using System; -using System.Net.Sockets; -using System.Threading; -using System.Security.Cryptography; -using System.Diagnostics; - -namespace Renci.SshNet.Common -{ - /// - /// Collection of different extension method specific for Silverlight - /// - internal static partial class Extensions - { - /// - /// Disposes the specified socket. - /// - /// The socket. - [DebuggerNonUserCode] - internal static void Dispose(this Socket socket) - { - if (socket == null) - throw new NullReferenceException(); - - socket.Close(); - } - - /// - /// Disposes the specified handle. - /// - /// The handle. - [DebuggerNonUserCode] - internal static void Dispose(this WaitHandle handle) - { - if (handle == null) - throw new NullReferenceException(); - - handle.Close(); - } - - /// - /// Disposes the specified algorithm. - /// - /// The algorithm. - [DebuggerNonUserCode] - internal static void Dispose(this HashAlgorithm algorithm) - { - if (algorithm == null) - throw new NullReferenceException(); - - algorithm.Clear(); - } - } -} +using System; +using System.Net.Sockets; +using System.Threading; +using System.Security.Cryptography; +using System.Diagnostics; + +namespace Renci.SshNet.Common +{ + /// + /// Collection of different extension method specific for Silverlight + /// + internal static partial class Extensions + { + /// + /// Disposes the specified socket. + /// + /// The socket. + [DebuggerNonUserCode] + internal static void Dispose(this Socket socket) + { + if (socket == null) + throw new NullReferenceException(); + + socket.Close(); + } + + /// + /// Disposes the specified handle. + /// + /// The handle. + [DebuggerNonUserCode] + internal static void Dispose(this WaitHandle handle) + { + if (handle == null) + throw new NullReferenceException(); + + handle.Close(); + } + + /// + /// Disposes the specified algorithm. + /// + /// The algorithm. + [DebuggerNonUserCode] + internal static void Dispose(this HashAlgorithm algorithm) + { + if (algorithm == null) + throw new NullReferenceException(); + + algorithm.Clear(); + } + } +} diff --git a/src/Renci.SshNet.Silverlight/Properties/AssemblyInfo.cs b/src/Renci.SshNet.Silverlight/Properties/AssemblyInfo.cs index 730482b5..f9c8d324 100644 --- a/src/Renci.SshNet.Silverlight/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.Silverlight/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Silverlight 4")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Silverlight 4")] [assembly: Guid("2b3f6251-8079-48aa-a76b-df70e40092e2")] \ No newline at end of file diff --git a/src/Renci.SshNet.Silverlight/Session.SilverlightBrowser.cs b/src/Renci.SshNet.Silverlight/Session.SilverlightBrowser.cs index c6898128..467b875d 100644 --- a/src/Renci.SshNet.Silverlight/Session.SilverlightBrowser.cs +++ b/src/Renci.SshNet.Silverlight/Session.SilverlightBrowser.cs @@ -1,12 +1,12 @@ -using Renci.SshNet.Messages; - -namespace Renci.SshNet -{ - public partial class Session - { - partial void HandleMessageCore(Message message) - { - this.HandleMessage((dynamic) message); - } - } -} +using Renci.SshNet.Messages; + +namespace Renci.SshNet +{ + public partial class Session + { + partial void HandleMessageCore(Message message) + { + this.HandleMessage((dynamic) message); + } + } +} diff --git a/src/Renci.SshNet.Silverlight/Session.SilverlightShared.cs b/src/Renci.SshNet.Silverlight/Session.SilverlightShared.cs index 8e82f1a6..aef28da4 100644 --- a/src/Renci.SshNet.Silverlight/Session.SilverlightShared.cs +++ b/src/Renci.SshNet.Silverlight/Session.SilverlightShared.cs @@ -1,16 +1,16 @@ -using System.Linq; - -namespace Renci.SshNet -{ - public partial class Session - { - /// - /// Gets a value indicating whether the socket is connected. - /// - /// true if the socket is connected; otherwise, false - partial void IsSocketConnected(ref bool isConnected) - { - isConnected = (_socket != null && _socket.Connected); - } - } -} +using System.Linq; + +namespace Renci.SshNet +{ + public partial class Session + { + /// + /// Gets a value indicating whether the socket is connected. + /// + /// true if the socket is connected; otherwise, false + partial void IsSocketConnected(ref bool isConnected) + { + isConnected = (_socket != null && _socket.Connected); + } + } +} diff --git a/src/Renci.SshNet.Silverlight5/Properties/AssemblyInfo.cs b/src/Renci.SshNet.Silverlight5/Properties/AssemblyInfo.cs index b533cf7c..7266e154 100644 --- a/src/Renci.SshNet.Silverlight5/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.Silverlight5/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Silverlight 5")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Silverlight 5")] [assembly: Guid("2b3f6251-8079-48aa-a76b-df70e40092e2")] \ No newline at end of file diff --git a/src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj b/src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj index f40232a8..e4ff0219 100644 --- a/src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj +++ b/src/Renci.SshNet.Silverlight5/Renci.SshNet.Silverlight5.csproj @@ -1,928 +1,928 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {E367F791-C1EC-4181-912A-2943CAC6B3BC} - {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - Renci.SshNet - Renci.SshNet - Silverlight - v5.0 - $(TargetFrameworkVersion) - false - true - true - - - - v3.5 - - - true - full - false - Bin\Debug - TRACE;DEBUG;SILVERLIGHT;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - prompt - 4 - false - Bin\Debug\Renci.SshNet.xml - true - - - none - true - Bin\Release - TRACE;SILVERLIGHT;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - prompt - 4 - false - Bin\Release\Renci.SshNet.xml - - - true - - - true - - - ..\Renci.SshNet.snk - - - - - - False - ..\..\packages\SshNet.Security.Cryptography.1.0.0\lib\sl5\SshNet.Security.Cryptography.dll - True - - - - - - - - - Session.SilverlightBrowser.cs - - - Session.SilverlightShared.cs - - - Abstractions\CryptoAbstraction.cs - - - Abstractions\DiagnosticAbstraction.cs - - - Abstractions\DnsAbstraction.cs - - - Abstractions\ReflectionAbstraction.cs - - - Abstractions\SocketAbstraction.cs - - - Abstractions\ThreadAbstraction.cs - - - AuthenticationMethod.cs - - - AuthenticationResult.cs - - - BaseClient.cs - - - Channels\Channel.cs - - - Channels\ChannelDirectTcpip.cs - - - Channels\ChannelForwardedTcpip.cs - - - Channels\ChannelSession.cs - - - Channels\ChannelTypes.cs - - - Channels\ClientChannel.cs - - - Channels\IChannel.cs - - - Channels\IChannelDirectTcpip.cs - - - Channels\IChannelForwardedTcpip.cs - - - Channels\IChannelSession.cs - - - Channels\ServerChannel.cs - - - CipherInfo.cs - - - ClientAuthentication.cs - - - CommandAsyncResult.cs - - - Common\Array.cs - - - Common\ASCIIEncoding.cs - - - Common\AsyncResult.cs - - - Common\AuthenticationBannerEventArgs.cs - - - Common\AuthenticationEventArgs.cs - - - Common\AuthenticationPasswordChangeEventArgs.cs - - - Common\AuthenticationPrompt.cs - - - Common\AuthenticationPromptEventArgs.cs - - - Common\BigInteger.cs - - - Common\ChannelDataEventArgs.cs - - - Common\ChannelEventArgs.cs - - - Common\ChannelExtendedDataEventArgs.cs - - - Common\ChannelOpenConfirmedEventArgs.cs - - - Common\ChannelOpenFailedEventArgs.cs - - - Common\ChannelRequestEventArgs.cs - - - Common\DerData.cs - - - Common\ExceptionEventArgs.cs - - - Common\Extensions.cs - - - Common\Extensions.SilverlightShared.cs - - - Common\HostKeyEventArgs.cs - - - Common\ObjectIdentifier.cs - - - Common\PipeStream.cs - - - Common\PortForwardEventArgs.cs - - - Common\ProxyException.cs - - - Common\ScpDownloadEventArgs.cs - - - Common\ScpException.cs - - - Common\ScpUploadEventArgs.cs - - - Common\SemaphoreLight.cs - - - Common\SftpPathNotFoundException.cs - - - Common\SftpPermissionDeniedException.cs - - - Common\ShellDataEventArgs.cs - - - Common\SshAuthenticationException.cs - - - Common\SshConnectionException.cs - - - Common\SshData.cs - - - Common\SshDataStream.cs - - - Common\SshException.cs - - - Common\SshOperationTimeoutException.cs - - - Common\SshPassPhraseNullOrEmptyException.cs - - - Common\TerminalModes.cs - - - Compression\CompressionMode.cs - - - Compression\Compressor.cs - - - Compression\Zlib.cs - - - Compression\ZlibOpenSsh.cs - - - Compression\ZlibStream.cs - - - ConnectionInfo.cs - - - ExpectAction.cs - - - ExpectAsyncResult.cs - - - ForwardedPort.cs - - - ForwardedPortDynamic.cs - - - ForwardedPortLocal.cs - - - ForwardedPortRemote.cs - - - HashInfo.cs - - - IAuthenticationMethod.cs - - - IClientAuthentication.cs - - - IConnectionInfo.cs - - - IForwardedPort.cs - - - IServiceFactory.cs - - - ISession.cs - - - ISubsystemSession.cs - - - KeyboardInteractiveAuthenticationMethod.cs - - - KeyboardInteractiveConnectionInfo.cs - - - MessageEventArgs.cs - - - Messages\Authentication\BannerMessage.cs - - - Messages\Authentication\FailureMessage.cs - - - Messages\Authentication\InformationRequestMessage.cs - - - Messages\Authentication\InformationResponseMessage.cs - - - Messages\Authentication\PasswordChangeRequiredMessage.cs - - - Messages\Authentication\PublicKeyMessage.cs - - - Messages\Authentication\RequestMessage.cs - - - Messages\Authentication\RequestMessageHost.cs - - - Messages\Authentication\RequestMessageKeyboardInteractive.cs - - - Messages\Authentication\RequestMessageNone.cs - - - Messages\Authentication\RequestMessagePassword.cs - - - Messages\Authentication\RequestMessagePublicKey.cs - - - Messages\Authentication\SuccessMessage.cs - - - Messages\Connection\ChannelCloseMessage.cs - - - Messages\Connection\ChannelDataMessage.cs - - - Messages\Connection\ChannelEofMessage.cs - - - Messages\Connection\ChannelExtendedDataMessage.cs - - - Messages\Connection\ChannelFailureMessage.cs - - - Messages\Connection\ChannelMessage.cs - - - Messages\Connection\ChannelOpenConfirmationMessage.cs - - - Messages\Connection\ChannelOpenFailureMessage.cs - - - Messages\Connection\ChannelOpenFailureReasons.cs - - - Messages\Connection\ChannelOpen\ChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\ChannelOpenMessage.cs - - - Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs - - - Messages\Connection\ChannelRequest\BreakRequestInfo.cs - - - Messages\Connection\ChannelRequest\ChannelRequestMessage.cs - - - Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs - - - Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExecRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs - - - Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs - - - Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs - - - Messages\Connection\ChannelRequest\RequestInfo.cs - - - Messages\Connection\ChannelRequest\ShellRequestInfo.cs - - - Messages\Connection\ChannelRequest\SignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs - - - Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs - - - Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs - - - Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs - - - Messages\Connection\ChannelSuccessMessage.cs - - - Messages\Connection\ChannelWindowAdjustMessage.cs - - - Messages\Connection\GlobalRequestMessage.cs - - - Messages\Connection\GlobalRequestName.cs - - - Messages\Connection\RequestFailureMessage.cs - - - Messages\Connection\RequestSuccessMessage.cs - - - Messages\Message.cs - - - Messages\MessageAttribute.cs - - - Messages\ServiceName.cs - - - Messages\Transport\DebugMessage.cs - - - Messages\Transport\DisconnectMessage.cs - - - Messages\Transport\DisconnectReason.cs - - - Messages\Transport\IgnoreMessage.cs - - - Messages\Transport\IKeyExchangedAllowed.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeInit.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeReply.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs - - - Messages\Transport\KeyExchangeDhInitMessage.cs - - - Messages\Transport\KeyExchangeDhReplyMessage.cs - - - Messages\Transport\KeyExchangeEcdhInitMessage.cs - - - Messages\Transport\KeyExchangeEcdhReplyMessage.cs - - - Messages\Transport\KeyExchangeInitMessage.cs - - - Messages\Transport\NewKeysMessage.cs - - - Messages\Transport\ServiceAcceptMessage.cs - - - Messages\Transport\ServiceRequestMessage.cs - - - Messages\Transport\UnimplementedMessage.cs - - - NoneAuthenticationMethod.cs - - - PasswordAuthenticationMethod.cs - - - PasswordConnectionInfo.cs - - - PrivateKeyAuthenticationMethod.cs - - - PrivateKeyConnectionInfo.cs - - - PrivateKeyFile.cs - - - ProxyTypes.cs - - - ScpClient.cs - - - Security\Algorithm.cs - - - Security\CertificateHostAlgorithm.cs - - - Security\Cryptography\AsymmetricCipher.cs - - - Security\Cryptography\BlockCipher.cs - - - Security\Cryptography\Cipher.cs - - - Security\Cryptography\CipherDigitalSignature.cs - - - Security\Cryptography\Ciphers\AesCipher.cs - - - Security\Cryptography\Ciphers\Arc4Cipher.cs - - - Security\Cryptography\Ciphers\BlowfishCipher.cs - - - Security\Cryptography\Ciphers\CastCipher.cs - - - Security\Cryptography\Ciphers\CipherMode.cs - - - Security\Cryptography\Ciphers\CipherPadding.cs - - - Security\Cryptography\Ciphers\DesCipher.cs - - - Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs - - - Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs - - - Security\Cryptography\Ciphers\Paddings\PKCS5Padding.cs - - - Security\Cryptography\Ciphers\RsaCipher.cs - - - Security\Cryptography\Ciphers\SerpentCipher.cs - - - Security\Cryptography\Ciphers\TripleDesCipher.cs - - - Security\Cryptography\Ciphers\TwofishCipher.cs - - - Security\Cryptography\DigitalSignature.cs - - - Security\Cryptography\DsaDigitalSignature.cs - - - Security\Cryptography\DsaKey.cs - - - Security\Cryptography\HMACMD5.cs - - - Security\Cryptography\HMACSHA1.cs - - - Security\Cryptography\HMACSHA256.cs - - - Security\Cryptography\HMACSHA384.cs - - - Security\Cryptography\HMACSHA512.cs - - - Security\Cryptography\Key.cs - - - Security\Cryptography\RsaDigitalSignature.cs - - - Security\Cryptography\RsaKey.cs - - - Security\Cryptography\StreamCipher.cs - - - Security\Cryptography\SymmetricCipher.cs - - - Security\GroupExchangeHashData.cs - - - Security\HostAlgorithm.cs - - - Security\IKeyExchange.cs - - - Security\KeyExchange.cs - - - Security\KeyExchangeDiffieHellman.cs - - - Security\KeyExchangeDiffieHellmanGroup14Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroup1Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs - - - Security\KeyExchangeDiffieHellmanGroupSha1.cs - - - Security\KeyHostAlgorithm.cs - - - ServiceFactory.cs - - - Session.cs - - - SftpClient.cs - - - Sftp\Flags.cs - - - Sftp\ISftpSession.cs - - - Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs - - - Sftp\Requests\ExtendedRequests\HardLinkRequest.cs - - - Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs - - - Sftp\Requests\ExtendedRequests\StatVfsRequest.cs - - - Sftp\Requests\SftpBlockRequest.cs - - - Sftp\Requests\SftpCloseRequest.cs - - - Sftp\Requests\SftpExtendedRequest.cs - - - Sftp\Requests\SftpFSetStatRequest.cs - - - Sftp\Requests\SftpFStatRequest.cs - - - Sftp\Requests\SftpInitRequest.cs - - - Sftp\Requests\SftpLinkRequest.cs - - - Sftp\Requests\SftpLStatRequest.cs - - - Sftp\Requests\SftpMkDirRequest.cs - - - Sftp\Requests\SftpOpenDirRequest.cs - - - Sftp\Requests\SftpOpenRequest.cs - - - Sftp\Requests\SftpReadDirRequest.cs - - - Sftp\Requests\SftpReadLinkRequest.cs - - - Sftp\Requests\SftpReadRequest.cs - - - Sftp\Requests\SftpRealPathRequest.cs - - - Sftp\Requests\SftpRemoveRequest.cs - - - Sftp\Requests\SftpRenameRequest.cs - - - Sftp\Requests\SftpRequest.cs - - - Sftp\Requests\SftpRmDirRequest.cs - - - Sftp\Requests\SftpSetStatRequest.cs - - - Sftp\Requests\SftpStatRequest.cs - - - Sftp\Requests\SftpSymLinkRequest.cs - - - Sftp\Requests\SftpUnblockRequest.cs - - - Sftp\Requests\SftpWriteRequest.cs - - - Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs - - - Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs - - - Sftp\Responses\SftpAttrsResponse.cs - - - Sftp\Responses\SftpDataResponse.cs - - - Sftp\Responses\SftpExtendedReplyResponse.cs - - - Sftp\Responses\SftpHandleResponse.cs - - - Sftp\Responses\SftpNameResponse.cs - - - Sftp\Responses\SftpResponse.cs - - - Sftp\Responses\SftpStatusResponse.cs - - - Sftp\Responses\SftpVersionResponse.cs - - - Sftp\SftpDownloadAsyncResult.cs - - - Sftp\SftpFile.cs - - - Sftp\SftpFileAttributes.cs - - - Sftp\SftpFileStream.cs - - - Sftp\SftpFileSystemInformation.cs - - - Sftp\SftpListDirectoryAsyncResult.cs - - - Sftp\SftpMessage.cs - - - Sftp\SftpMessageTypes.cs - - - Sftp\SftpSession.cs - - - Sftp\SftpSynchronizeDirectoriesAsyncResult.cs - - - Sftp\SftpUploadAsyncResult.cs - - - Sftp\StatusCodes.cs - - - Shell.cs - - - ShellStream.cs - - - SshClient.cs - - - SshCommand.cs - - - SshMessageFactory.cs - - - SubsystemSession.cs - - - - Properties\CommonAssemblyInfo.cs - - - - - Renci.SshNet.snk - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {E367F791-C1EC-4181-912A-2943CAC6B3BC} + {A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Renci.SshNet + Renci.SshNet + Silverlight + v5.0 + $(TargetFrameworkVersion) + false + true + true + + + + v3.5 + + + true + full + false + Bin\Debug + TRACE;DEBUG;SILVERLIGHT;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + prompt + 4 + false + Bin\Debug\Renci.SshNet.xml + true + + + none + true + Bin\Release + TRACE;SILVERLIGHT;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + prompt + 4 + false + Bin\Release\Renci.SshNet.xml + + + true + + + true + + + ..\Renci.SshNet.snk + + + + + + False + ..\..\packages\SshNet.Security.Cryptography.1.0.0\lib\sl5\SshNet.Security.Cryptography.dll + True + + + + + + + + + Session.SilverlightBrowser.cs + + + Session.SilverlightShared.cs + + + Abstractions\CryptoAbstraction.cs + + + Abstractions\DiagnosticAbstraction.cs + + + Abstractions\DnsAbstraction.cs + + + Abstractions\ReflectionAbstraction.cs + + + Abstractions\SocketAbstraction.cs + + + Abstractions\ThreadAbstraction.cs + + + AuthenticationMethod.cs + + + AuthenticationResult.cs + + + BaseClient.cs + + + Channels\Channel.cs + + + Channels\ChannelDirectTcpip.cs + + + Channels\ChannelForwardedTcpip.cs + + + Channels\ChannelSession.cs + + + Channels\ChannelTypes.cs + + + Channels\ClientChannel.cs + + + Channels\IChannel.cs + + + Channels\IChannelDirectTcpip.cs + + + Channels\IChannelForwardedTcpip.cs + + + Channels\IChannelSession.cs + + + Channels\ServerChannel.cs + + + CipherInfo.cs + + + ClientAuthentication.cs + + + CommandAsyncResult.cs + + + Common\Array.cs + + + Common\ASCIIEncoding.cs + + + Common\AsyncResult.cs + + + Common\AuthenticationBannerEventArgs.cs + + + Common\AuthenticationEventArgs.cs + + + Common\AuthenticationPasswordChangeEventArgs.cs + + + Common\AuthenticationPrompt.cs + + + Common\AuthenticationPromptEventArgs.cs + + + Common\BigInteger.cs + + + Common\ChannelDataEventArgs.cs + + + Common\ChannelEventArgs.cs + + + Common\ChannelExtendedDataEventArgs.cs + + + Common\ChannelOpenConfirmedEventArgs.cs + + + Common\ChannelOpenFailedEventArgs.cs + + + Common\ChannelRequestEventArgs.cs + + + Common\DerData.cs + + + Common\ExceptionEventArgs.cs + + + Common\Extensions.cs + + + Common\Extensions.SilverlightShared.cs + + + Common\HostKeyEventArgs.cs + + + Common\ObjectIdentifier.cs + + + Common\PipeStream.cs + + + Common\PortForwardEventArgs.cs + + + Common\ProxyException.cs + + + Common\ScpDownloadEventArgs.cs + + + Common\ScpException.cs + + + Common\ScpUploadEventArgs.cs + + + Common\SemaphoreLight.cs + + + Common\SftpPathNotFoundException.cs + + + Common\SftpPermissionDeniedException.cs + + + Common\ShellDataEventArgs.cs + + + Common\SshAuthenticationException.cs + + + Common\SshConnectionException.cs + + + Common\SshData.cs + + + Common\SshDataStream.cs + + + Common\SshException.cs + + + Common\SshOperationTimeoutException.cs + + + Common\SshPassPhraseNullOrEmptyException.cs + + + Common\TerminalModes.cs + + + Compression\CompressionMode.cs + + + Compression\Compressor.cs + + + Compression\Zlib.cs + + + Compression\ZlibOpenSsh.cs + + + Compression\ZlibStream.cs + + + ConnectionInfo.cs + + + ExpectAction.cs + + + ExpectAsyncResult.cs + + + ForwardedPort.cs + + + ForwardedPortDynamic.cs + + + ForwardedPortLocal.cs + + + ForwardedPortRemote.cs + + + HashInfo.cs + + + IAuthenticationMethod.cs + + + IClientAuthentication.cs + + + IConnectionInfo.cs + + + IForwardedPort.cs + + + IServiceFactory.cs + + + ISession.cs + + + ISubsystemSession.cs + + + KeyboardInteractiveAuthenticationMethod.cs + + + KeyboardInteractiveConnectionInfo.cs + + + MessageEventArgs.cs + + + Messages\Authentication\BannerMessage.cs + + + Messages\Authentication\FailureMessage.cs + + + Messages\Authentication\InformationRequestMessage.cs + + + Messages\Authentication\InformationResponseMessage.cs + + + Messages\Authentication\PasswordChangeRequiredMessage.cs + + + Messages\Authentication\PublicKeyMessage.cs + + + Messages\Authentication\RequestMessage.cs + + + Messages\Authentication\RequestMessageHost.cs + + + Messages\Authentication\RequestMessageKeyboardInteractive.cs + + + Messages\Authentication\RequestMessageNone.cs + + + Messages\Authentication\RequestMessagePassword.cs + + + Messages\Authentication\RequestMessagePublicKey.cs + + + Messages\Authentication\SuccessMessage.cs + + + Messages\Connection\ChannelCloseMessage.cs + + + Messages\Connection\ChannelDataMessage.cs + + + Messages\Connection\ChannelEofMessage.cs + + + Messages\Connection\ChannelExtendedDataMessage.cs + + + Messages\Connection\ChannelFailureMessage.cs + + + Messages\Connection\ChannelMessage.cs + + + Messages\Connection\ChannelOpenConfirmationMessage.cs + + + Messages\Connection\ChannelOpenFailureMessage.cs + + + Messages\Connection\ChannelOpenFailureReasons.cs + + + Messages\Connection\ChannelOpen\ChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\ChannelOpenMessage.cs + + + Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs + + + Messages\Connection\ChannelRequest\BreakRequestInfo.cs + + + Messages\Connection\ChannelRequest\ChannelRequestMessage.cs + + + Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs + + + Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExecRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs + + + Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs + + + Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs + + + Messages\Connection\ChannelRequest\RequestInfo.cs + + + Messages\Connection\ChannelRequest\ShellRequestInfo.cs + + + Messages\Connection\ChannelRequest\SignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs + + + Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs + + + Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs + + + Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs + + + Messages\Connection\ChannelSuccessMessage.cs + + + Messages\Connection\ChannelWindowAdjustMessage.cs + + + Messages\Connection\GlobalRequestMessage.cs + + + Messages\Connection\GlobalRequestName.cs + + + Messages\Connection\RequestFailureMessage.cs + + + Messages\Connection\RequestSuccessMessage.cs + + + Messages\Message.cs + + + Messages\MessageAttribute.cs + + + Messages\ServiceName.cs + + + Messages\Transport\DebugMessage.cs + + + Messages\Transport\DisconnectMessage.cs + + + Messages\Transport\DisconnectReason.cs + + + Messages\Transport\IgnoreMessage.cs + + + Messages\Transport\IKeyExchangedAllowed.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeInit.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeReply.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs + + + Messages\Transport\KeyExchangeDhInitMessage.cs + + + Messages\Transport\KeyExchangeDhReplyMessage.cs + + + Messages\Transport\KeyExchangeEcdhInitMessage.cs + + + Messages\Transport\KeyExchangeEcdhReplyMessage.cs + + + Messages\Transport\KeyExchangeInitMessage.cs + + + Messages\Transport\NewKeysMessage.cs + + + Messages\Transport\ServiceAcceptMessage.cs + + + Messages\Transport\ServiceRequestMessage.cs + + + Messages\Transport\UnimplementedMessage.cs + + + NoneAuthenticationMethod.cs + + + PasswordAuthenticationMethod.cs + + + PasswordConnectionInfo.cs + + + PrivateKeyAuthenticationMethod.cs + + + PrivateKeyConnectionInfo.cs + + + PrivateKeyFile.cs + + + ProxyTypes.cs + + + ScpClient.cs + + + Security\Algorithm.cs + + + Security\CertificateHostAlgorithm.cs + + + Security\Cryptography\AsymmetricCipher.cs + + + Security\Cryptography\BlockCipher.cs + + + Security\Cryptography\Cipher.cs + + + Security\Cryptography\CipherDigitalSignature.cs + + + Security\Cryptography\Ciphers\AesCipher.cs + + + Security\Cryptography\Ciphers\Arc4Cipher.cs + + + Security\Cryptography\Ciphers\BlowfishCipher.cs + + + Security\Cryptography\Ciphers\CastCipher.cs + + + Security\Cryptography\Ciphers\CipherMode.cs + + + Security\Cryptography\Ciphers\CipherPadding.cs + + + Security\Cryptography\Ciphers\DesCipher.cs + + + Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs + + + Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs + + + Security\Cryptography\Ciphers\Paddings\PKCS5Padding.cs + + + Security\Cryptography\Ciphers\RsaCipher.cs + + + Security\Cryptography\Ciphers\SerpentCipher.cs + + + Security\Cryptography\Ciphers\TripleDesCipher.cs + + + Security\Cryptography\Ciphers\TwofishCipher.cs + + + Security\Cryptography\DigitalSignature.cs + + + Security\Cryptography\DsaDigitalSignature.cs + + + Security\Cryptography\DsaKey.cs + + + Security\Cryptography\HMACMD5.cs + + + Security\Cryptography\HMACSHA1.cs + + + Security\Cryptography\HMACSHA256.cs + + + Security\Cryptography\HMACSHA384.cs + + + Security\Cryptography\HMACSHA512.cs + + + Security\Cryptography\Key.cs + + + Security\Cryptography\RsaDigitalSignature.cs + + + Security\Cryptography\RsaKey.cs + + + Security\Cryptography\StreamCipher.cs + + + Security\Cryptography\SymmetricCipher.cs + + + Security\GroupExchangeHashData.cs + + + Security\HostAlgorithm.cs + + + Security\IKeyExchange.cs + + + Security\KeyExchange.cs + + + Security\KeyExchangeDiffieHellman.cs + + + Security\KeyExchangeDiffieHellmanGroup14Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroup1Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs + + + Security\KeyExchangeDiffieHellmanGroupSha1.cs + + + Security\KeyHostAlgorithm.cs + + + ServiceFactory.cs + + + Session.cs + + + SftpClient.cs + + + Sftp\Flags.cs + + + Sftp\ISftpSession.cs + + + Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs + + + Sftp\Requests\ExtendedRequests\HardLinkRequest.cs + + + Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs + + + Sftp\Requests\ExtendedRequests\StatVfsRequest.cs + + + Sftp\Requests\SftpBlockRequest.cs + + + Sftp\Requests\SftpCloseRequest.cs + + + Sftp\Requests\SftpExtendedRequest.cs + + + Sftp\Requests\SftpFSetStatRequest.cs + + + Sftp\Requests\SftpFStatRequest.cs + + + Sftp\Requests\SftpInitRequest.cs + + + Sftp\Requests\SftpLinkRequest.cs + + + Sftp\Requests\SftpLStatRequest.cs + + + Sftp\Requests\SftpMkDirRequest.cs + + + Sftp\Requests\SftpOpenDirRequest.cs + + + Sftp\Requests\SftpOpenRequest.cs + + + Sftp\Requests\SftpReadDirRequest.cs + + + Sftp\Requests\SftpReadLinkRequest.cs + + + Sftp\Requests\SftpReadRequest.cs + + + Sftp\Requests\SftpRealPathRequest.cs + + + Sftp\Requests\SftpRemoveRequest.cs + + + Sftp\Requests\SftpRenameRequest.cs + + + Sftp\Requests\SftpRequest.cs + + + Sftp\Requests\SftpRmDirRequest.cs + + + Sftp\Requests\SftpSetStatRequest.cs + + + Sftp\Requests\SftpStatRequest.cs + + + Sftp\Requests\SftpSymLinkRequest.cs + + + Sftp\Requests\SftpUnblockRequest.cs + + + Sftp\Requests\SftpWriteRequest.cs + + + Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs + + + Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs + + + Sftp\Responses\SftpAttrsResponse.cs + + + Sftp\Responses\SftpDataResponse.cs + + + Sftp\Responses\SftpExtendedReplyResponse.cs + + + Sftp\Responses\SftpHandleResponse.cs + + + Sftp\Responses\SftpNameResponse.cs + + + Sftp\Responses\SftpResponse.cs + + + Sftp\Responses\SftpStatusResponse.cs + + + Sftp\Responses\SftpVersionResponse.cs + + + Sftp\SftpDownloadAsyncResult.cs + + + Sftp\SftpFile.cs + + + Sftp\SftpFileAttributes.cs + + + Sftp\SftpFileStream.cs + + + Sftp\SftpFileSystemInformation.cs + + + Sftp\SftpListDirectoryAsyncResult.cs + + + Sftp\SftpMessage.cs + + + Sftp\SftpMessageTypes.cs + + + Sftp\SftpSession.cs + + + Sftp\SftpSynchronizeDirectoriesAsyncResult.cs + + + Sftp\SftpUploadAsyncResult.cs + + + Sftp\StatusCodes.cs + + + Shell.cs + + + ShellStream.cs + + + SshClient.cs + + + SshCommand.cs + + + SshMessageFactory.cs + + + SubsystemSession.cs + + + + Properties\CommonAssemblyInfo.cs + + + + + Renci.SshNet.snk + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortLocal.NET35.cs b/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortLocal.NET35.cs index 034989b6..2eec0336 100644 --- a/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortLocal.NET35.cs +++ b/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortLocal.NET35.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.SshClientTests -{ - public partial class ForwardedPortLocalTest : TestBase - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.SshClientTests +{ + public partial class ForwardedPortLocalTest : TestBase + { + } +} diff --git a/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortRemote.NET35.cs b/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortRemote.NET35.cs index 524b6a07..5b057ba1 100644 --- a/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortRemote.NET35.cs +++ b/src/Renci.SshNet.Tests.NET35/Classes/ForwardedPortRemote.NET35.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.SshClientTests -{ - public partial class ForwardedPortRemoteTest : TestBase - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.SshClientTests +{ + public partial class ForwardedPortRemoteTest : TestBase + { + } +} diff --git a/src/Renci.SshNet.Tests.NET35/Classes/SshCommandTest.NET35.cs b/src/Renci.SshNet.Tests.NET35/Classes/SshCommandTest.NET35.cs index 1f342174..8f95bf3f 100644 --- a/src/Renci.SshNet.Tests.NET35/Classes/SshCommandTest.NET35.cs +++ b/src/Renci.SshNet.Tests.NET35/Classes/SshCommandTest.NET35.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.SshClientTests -{ - public partial class SshCommandTest : TestBase - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.SshClientTests +{ + public partial class SshCommandTest : TestBase + { + } +} diff --git a/src/Renci.SshNet.Tests.NET35/Properties/AssemblyInfo.cs b/src/Renci.SshNet.Tests.NET35/Properties/AssemblyInfo.cs index 8d6f9fc1..01506232 100644 --- a/src/Renci.SshNet.Tests.NET35/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.Tests.NET35/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Tests .NET 3.5")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Tests .NET 3.5")] [assembly: Guid("7c827904-40c1-4fe3-8ed1-8a729b8417a9")] \ No newline at end of file diff --git a/src/Renci.SshNet.Tests.NET35/Properties/Resources.Designer.cs b/src/Renci.SshNet.Tests.NET35/Properties/Resources.Designer.cs index 109a20e4..54bef950 100644 --- a/src/Renci.SshNet.Tests.NET35/Properties/Resources.Designer.cs +++ b/src/Renci.SshNet.Tests.NET35/Properties/Resources.Designer.cs @@ -1,206 +1,206 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.18010 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Renci.SshNet.Tests.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Renci.SshNet.Tests.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///Proc-Type: 4,ENCRYPTED - ///DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 - /// - ///nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva - ///swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI - ///qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 - ///2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP - ///iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd - ///nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm - ///P+lkxKf2RWnh406F [rest of string was truncated]";. - /// - internal static string DSA_KEY_WITH_PASS { - get { - return ResourceManager.GetString("DSA_KEY_WITH_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw - ///fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe - ///bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 - ///UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr - ///u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB - ///xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM - ///HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH - ///4UOFA/UFdQ0TYXXW0 [rest of string was truncated]";. - /// - internal static string DSA_KEY_WITHOUT_PASS { - get { - return ResourceManager.GetString("DSA_KEY_WITHOUT_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to oleg-centos.edc.renci.org. - /// - internal static string HOST { - get { - return ResourceManager.GetString("HOST", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO - ///h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P - ///12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT - ///1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO - ///eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy - ///wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq - ///JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi - ///YTV9H2SWRF6UF+GiR [rest of string was truncated]";. - /// - internal static string INVALID_KEY { - get { - return ResourceManager.GetString("INVALID_KEY", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to tester. - /// - internal static string PASSWORD { - get { - return ResourceManager.GetString("PASSWORD", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 22. - /// - internal static string PORT { - get { - return ResourceManager.GetString("PORT", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org. - /// - internal static string PROXY_HOST { - get { - return ResourceManager.GetString("PROXY_HOST", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 8123. - /// - internal static string PROXY_PORT { - get { - return ResourceManager.GetString("PROXY_PORT", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- - ///Proc-Type: 4,ENCRYPTED - ///DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 - /// - ///Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr - ///uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG - ///FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ - ///OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB - ///nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ - ///bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 - ///SMP7QVfPf5aJIaa8 [rest of string was truncated]";. - /// - internal static string RSA_KEY_WITH_PASS { - get { - return ResourceManager.GetString("RSA_KEY_WITH_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- - ///MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D - ///9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl - ///9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba - ///orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb - ///d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q - ///mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz - ///9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA - ///RW493jlECIBWjd+1a [rest of string was truncated]";. - /// - internal static string RSA_KEY_WITHOUT_PASS { - get { - return ResourceManager.GetString("RSA_KEY_WITHOUT_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to tester. - /// - internal static string USERNAME { - get { - return ResourceManager.GetString("USERNAME", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18010 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Renci.SshNet.Tests.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Renci.SshNet.Tests.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///Proc-Type: 4,ENCRYPTED + ///DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 + /// + ///nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva + ///swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI + ///qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 + ///2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP + ///iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd + ///nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm + ///P+lkxKf2RWnh406F [rest of string was truncated]";. + /// + internal static string DSA_KEY_WITH_PASS { + get { + return ResourceManager.GetString("DSA_KEY_WITH_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw + ///fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe + ///bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 + ///UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr + ///u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB + ///xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM + ///HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH + ///4UOFA/UFdQ0TYXXW0 [rest of string was truncated]";. + /// + internal static string DSA_KEY_WITHOUT_PASS { + get { + return ResourceManager.GetString("DSA_KEY_WITHOUT_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to oleg-centos.edc.renci.org. + /// + internal static string HOST { + get { + return ResourceManager.GetString("HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO + ///h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P + ///12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT + ///1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO + ///eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy + ///wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq + ///JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi + ///YTV9H2SWRF6UF+GiR [rest of string was truncated]";. + /// + internal static string INVALID_KEY { + get { + return ResourceManager.GetString("INVALID_KEY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tester. + /// + internal static string PASSWORD { + get { + return ResourceManager.GetString("PASSWORD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 22. + /// + internal static string PORT { + get { + return ResourceManager.GetString("PORT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org. + /// + internal static string PROXY_HOST { + get { + return ResourceManager.GetString("PROXY_HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 8123. + /// + internal static string PROXY_PORT { + get { + return ResourceManager.GetString("PROXY_PORT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- + ///Proc-Type: 4,ENCRYPTED + ///DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 + /// + ///Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr + ///uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG + ///FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ + ///OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB + ///nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ + ///bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 + ///SMP7QVfPf5aJIaa8 [rest of string was truncated]";. + /// + internal static string RSA_KEY_WITH_PASS { + get { + return ResourceManager.GetString("RSA_KEY_WITH_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- + ///MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D + ///9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl + ///9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba + ///orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb + ///d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q + ///mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz + ///9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA + ///RW493jlECIBWjd+1a [rest of string was truncated]";. + /// + internal static string RSA_KEY_WITHOUT_PASS { + get { + return ResourceManager.GetString("RSA_KEY_WITHOUT_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tester. + /// + internal static string USERNAME { + get { + return ResourceManager.GetString("USERNAME", resourceCulture); + } + } + } +} diff --git a/src/Renci.SshNet.Tests.NET35/Properties/Resources.resx b/src/Renci.SshNet.Tests.NET35/Properties/Resources.resx index 1b97000e..b1605aba 100644 --- a/src/Renci.SshNet.Tests.NET35/Properties/Resources.resx +++ b/src/Renci.SshNet.Tests.NET35/Properties/Resources.resx @@ -1,244 +1,244 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - -----BEGIN DSA PRIVATE KEY----- -MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw -fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe -bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 -UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr -u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB -xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM -HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH -4UOFA/UFdQ0TYXXW0wRX/amynT4iTEXAx0FjxUNK5ryxloeoXiXEH4FK7D8RtJO1 -1UsaRrN+nqWiSTVAehl6tzoMCPargGcWeFlAZZnPGN76OD9J1GiKZj8CFQCl8SkF -GWfS+mH8xhLsxh1nI7rfJw== ------END DSA PRIVATE KEY----- - - - -----BEGIN DSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 - -nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva -swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI -qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 -2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP -iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd -nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm -P+lkxKf2RWnh406FxBvBZzwB3rQeeM7QTg2IcFqGnlf005FIikp6SlyhZ/3M/Nl3 -FW235vuO37jLCL8qosGt4NOWAstXaxDujfIb/Q+IYxUpWZrdiH5tM/mUXARK0Sjf -D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM -7jB0kNVZrz3qUKnoJHIozA== ------END DSA PRIVATE KEY----- - - - oleg-centos.edc.renci.org - - - -----BEGIN DSA PRIVATE KEY----- -MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO -h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P -12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT -1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO -eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy -wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq -JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi -YTV9H2SWRF6UF+GiR5SajChveS106T9O+tepip+7V5YgFfW+ALOxwar+6V8VoUF4 -xNvNTWtaw+wK8xsgxhhYDaWVhVLVhR40QmeQhx/BQm+EYkSSa9kkCQIURGd0R+Zj -tM7dZpB+reWl9L5e2L8= ------END DSA PRIVATE KEY----- - - - tester - - - 22 - - - proxy.oleg-centos.edc.renci.org - - - 8123 - - - -----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D -9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl -9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba -orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb -d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q -mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz -9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA -RW493jlECIBWjd+1aZWPM2vGKJtTp2q802u6DOX9cbgFUcVB899ugFqDjREVxLqU -dBqhtjDJQ0sTPBVy2CBkrsrvLy7AZd4LlaqxpdTdpkD/auUxg4zdThHT/XeQ0V0G -3BS5vGehfqgkDOQpQSm7HexM+9GDJnnzMdNXjmWBPxZU49QAlxujZeZ1M2IgKwMq -eNkWAOnZJidfsfwYluSCi8OHPN2i1s/b7pgn6ffb50S/k2mmhTHxNChDdGTlW91G -6CFLAoGBAPlGA4qzZCG4SLBQicGhhXZlwaKKfTvWNi4xNPZeoJezC0G+yZZT7IIV -zCj83t3dteaRRw15e+7NuIXZx3zl2hANfEpBZwnS4sOekvbS9/S7cEVzOEk53jRU -TOtHRsvNxS2xK3RywqoaqzcPaK2Df917yzbqvEajMRudRPrsTvYdAoGBAPggB/kJ -+VxZf13JqV2KgrFoVvykJpRlw2F5+lkH69ON9gdl976J3TNJDqAmHeWFxBUL+6Lt -9TSpMq3fYueJXg9xaTkSYg177sPRGCmRLO5aneA4nJkIB6KHRXsR71C9D4fJK8Fi -YB5n5dnBUTBhkvaI6KsxcxDzEg2zAJEcn4WNAoGBAOsHf66pI+VHWnpakINdxvqa -dL3TCFz9K8UnFK3G7y/x9Kuz4qOuNsPLaLjua7s+wXL+ASn2MwW6pqoWekKPkxZz -HWqVb8dvEFIKipDyzIepadsU3UxbIfbTI/PG3FnCAw3S7nUbvtrl8eN07arpsxKn -63zr81iLPO4mkX7ezhs/AoGADi23UA8y0hO+Ip3PKeqoYei0g3cYJbysFDLbGwfE -VTtP4ypl7aF6WrO3sWFDiXVbqW5mJpFBNjWN3gzD0rdkdek5NnYUO0jpEoD6EQD7 -QNH6ZJWFSpK+m5Kzg2AcTcGpHbO5W4H23SqCKbNGd8sPtlD3Wj1XCEhnbn9B3GgJ -HZMCgYEAjn9BH4fcobMaM15AV0s6sCEyr/vzn3QBfoIBqqqlipMqOtPDv8oyvGO4 -5tSpMrTKf4e3YAMPA4TXRAiVLjeRYlhdj3He0LkAuZZabrHeRmWqjDruMWd1TcKZ -3o8DLgYbSH7eGXUJ+euM4spKr5OLkBEkmH7Of6Qxss2njvjVNTE= ------END RSA PRIVATE KEY----- - - - -----BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 - -Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr -uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG -FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ -OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB -nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ -bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 -SMP7QVfPf5aJIaa8t+SlpvtIFTIkEhTViOCl+udT04670DGwmJUgrJAV0r+/Ytf7 -Mi+m3DagN7gGmCvYo+7r7EBl1G6e3hCSYm0rFxGOBesmCWriRoeRpxirWnkrns57 -D57pEC1hg90IdycCGpiwqubGDKFljuMLiVd2w0onVhudShPszP+nJAaq18wUB+rE -mtBv+GlpqCITREB4lG2noP4r9P9lgrOTqmKvWjvUTQjfS3u0XO/1aQllKlwe97C7 -mfOxcZQWy5F7+9CiWpDpomW7Eso89ja6uyupw4Q4gsm7EUacqOOaVxHrm3MVhYjE -Bfk9I5agKFqeHdjBUUP0DQ6X7JUEtb/Ri8ZrFnyT8sBG7JYnMTXfjPQqdR493cp2 -hWI5reZLi4CCUqt4Pcmhm2vtwJz5HXChARPYq2C3DhdJHcdhxUr97rfTGE1w8mPY -JcwSFnNN47UBcDg6nvSfY3SJKV0gmmqz9fEw1pBoCrudJKw9U0vQrNoCEJOpEETG -4XojbAMsTr0Ps5fI2X1VbVYWtU1uyZxqF8KaTCTN1Paapmqaq4N+qIFrrXA+PTH+ -dyaMLmYJ263Gy5eNkCZMeWLDFZ9WHX/Zx2ERMXfI6fyGImXkb6E0Dia+bB087BZP -9C5gHAvZIjv+FosZrViFqDfrV5hDXL6bO3+V3zieemRxRCTvMtk+RXUJDd50qIOW -gKNcSbevLPOyQH7eQbR+fU4KtJDUigbTFunSn2MZkDl2GDDlKI35wUAVr5yGsJbE -yiIQe5DgLGZcMiEpqbhuqSfuOw0cUlFVyKeNZ/Hr701HWngLt677IY8ExyuNbBfT -PRaes+hcjJ1QmJoRHZx9rQ3w0IpezCpRkRLRKJzzuQZOuwd95whKFXroFsdeaHxO -hS4PqlLbuSMLiSIaPSZM6Huc4kb5lqCaxg/SBlXTCX17Z/8TFoqV/wCJz17XnkH6 -9WtKAC2TwKxiLZ2Qzwr2XV48lASugIOZkSW2qxM9ui+b1T9ICFKRGLn/UB//pOiG -270hNJDLB/BKRExjS+RXeOpdAIJB5XsAEp8h56ub9emhhf9tCEXOn7PN7HbMCnQh -7k8EpAG0h5StLUhY1HHvynVz2/qyMvZa/bIaaudL2565Z6nDU+iBxed7O1qrbRAH -Vakr7Sa3K5niCyH5kxdyO1t29l1ksBqpDUrj+vViFuLkd3XIiui8IA== ------END RSA PRIVATE KEY----- - - - tester - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + -----BEGIN DSA PRIVATE KEY----- +MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw +fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe +bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 +UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr +u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB +xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM +HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH +4UOFA/UFdQ0TYXXW0wRX/amynT4iTEXAx0FjxUNK5ryxloeoXiXEH4FK7D8RtJO1 +1UsaRrN+nqWiSTVAehl6tzoMCPargGcWeFlAZZnPGN76OD9J1GiKZj8CFQCl8SkF +GWfS+mH8xhLsxh1nI7rfJw== +-----END DSA PRIVATE KEY----- + + + -----BEGIN DSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 + +nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva +swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI +qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 +2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP +iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd +nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm +P+lkxKf2RWnh406FxBvBZzwB3rQeeM7QTg2IcFqGnlf005FIikp6SlyhZ/3M/Nl3 +FW235vuO37jLCL8qosGt4NOWAstXaxDujfIb/Q+IYxUpWZrdiH5tM/mUXARK0Sjf +D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM +7jB0kNVZrz3qUKnoJHIozA== +-----END DSA PRIVATE KEY----- + + + oleg-centos.edc.renci.org + + + -----BEGIN DSA PRIVATE KEY----- +MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO +h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P +12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT +1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO +eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy +wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq +JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi +YTV9H2SWRF6UF+GiR5SajChveS106T9O+tepip+7V5YgFfW+ALOxwar+6V8VoUF4 +xNvNTWtaw+wK8xsgxhhYDaWVhVLVhR40QmeQhx/BQm+EYkSSa9kkCQIURGd0R+Zj +tM7dZpB+reWl9L5e2L8= +-----END DSA PRIVATE KEY----- + + + tester + + + 22 + + + proxy.oleg-centos.edc.renci.org + + + 8123 + + + -----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D +9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl +9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba +orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb +d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q +mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz +9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA +RW493jlECIBWjd+1aZWPM2vGKJtTp2q802u6DOX9cbgFUcVB899ugFqDjREVxLqU +dBqhtjDJQ0sTPBVy2CBkrsrvLy7AZd4LlaqxpdTdpkD/auUxg4zdThHT/XeQ0V0G +3BS5vGehfqgkDOQpQSm7HexM+9GDJnnzMdNXjmWBPxZU49QAlxujZeZ1M2IgKwMq +eNkWAOnZJidfsfwYluSCi8OHPN2i1s/b7pgn6ffb50S/k2mmhTHxNChDdGTlW91G +6CFLAoGBAPlGA4qzZCG4SLBQicGhhXZlwaKKfTvWNi4xNPZeoJezC0G+yZZT7IIV +zCj83t3dteaRRw15e+7NuIXZx3zl2hANfEpBZwnS4sOekvbS9/S7cEVzOEk53jRU +TOtHRsvNxS2xK3RywqoaqzcPaK2Df917yzbqvEajMRudRPrsTvYdAoGBAPggB/kJ ++VxZf13JqV2KgrFoVvykJpRlw2F5+lkH69ON9gdl976J3TNJDqAmHeWFxBUL+6Lt +9TSpMq3fYueJXg9xaTkSYg177sPRGCmRLO5aneA4nJkIB6KHRXsR71C9D4fJK8Fi +YB5n5dnBUTBhkvaI6KsxcxDzEg2zAJEcn4WNAoGBAOsHf66pI+VHWnpakINdxvqa +dL3TCFz9K8UnFK3G7y/x9Kuz4qOuNsPLaLjua7s+wXL+ASn2MwW6pqoWekKPkxZz +HWqVb8dvEFIKipDyzIepadsU3UxbIfbTI/PG3FnCAw3S7nUbvtrl8eN07arpsxKn +63zr81iLPO4mkX7ezhs/AoGADi23UA8y0hO+Ip3PKeqoYei0g3cYJbysFDLbGwfE +VTtP4ypl7aF6WrO3sWFDiXVbqW5mJpFBNjWN3gzD0rdkdek5NnYUO0jpEoD6EQD7 +QNH6ZJWFSpK+m5Kzg2AcTcGpHbO5W4H23SqCKbNGd8sPtlD3Wj1XCEhnbn9B3GgJ +HZMCgYEAjn9BH4fcobMaM15AV0s6sCEyr/vzn3QBfoIBqqqlipMqOtPDv8oyvGO4 +5tSpMrTKf4e3YAMPA4TXRAiVLjeRYlhdj3He0LkAuZZabrHeRmWqjDruMWd1TcKZ +3o8DLgYbSH7eGXUJ+euM4spKr5OLkBEkmH7Of6Qxss2njvjVNTE= +-----END RSA PRIVATE KEY----- + + + -----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 + +Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr +uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG +FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ +OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB +nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ +bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 +SMP7QVfPf5aJIaa8t+SlpvtIFTIkEhTViOCl+udT04670DGwmJUgrJAV0r+/Ytf7 +Mi+m3DagN7gGmCvYo+7r7EBl1G6e3hCSYm0rFxGOBesmCWriRoeRpxirWnkrns57 +D57pEC1hg90IdycCGpiwqubGDKFljuMLiVd2w0onVhudShPszP+nJAaq18wUB+rE +mtBv+GlpqCITREB4lG2noP4r9P9lgrOTqmKvWjvUTQjfS3u0XO/1aQllKlwe97C7 +mfOxcZQWy5F7+9CiWpDpomW7Eso89ja6uyupw4Q4gsm7EUacqOOaVxHrm3MVhYjE +Bfk9I5agKFqeHdjBUUP0DQ6X7JUEtb/Ri8ZrFnyT8sBG7JYnMTXfjPQqdR493cp2 +hWI5reZLi4CCUqt4Pcmhm2vtwJz5HXChARPYq2C3DhdJHcdhxUr97rfTGE1w8mPY +JcwSFnNN47UBcDg6nvSfY3SJKV0gmmqz9fEw1pBoCrudJKw9U0vQrNoCEJOpEETG +4XojbAMsTr0Ps5fI2X1VbVYWtU1uyZxqF8KaTCTN1Paapmqaq4N+qIFrrXA+PTH+ +dyaMLmYJ263Gy5eNkCZMeWLDFZ9WHX/Zx2ERMXfI6fyGImXkb6E0Dia+bB087BZP +9C5gHAvZIjv+FosZrViFqDfrV5hDXL6bO3+V3zieemRxRCTvMtk+RXUJDd50qIOW +gKNcSbevLPOyQH7eQbR+fU4KtJDUigbTFunSn2MZkDl2GDDlKI35wUAVr5yGsJbE +yiIQe5DgLGZcMiEpqbhuqSfuOw0cUlFVyKeNZ/Hr701HWngLt677IY8ExyuNbBfT +PRaes+hcjJ1QmJoRHZx9rQ3w0IpezCpRkRLRKJzzuQZOuwd95whKFXroFsdeaHxO +hS4PqlLbuSMLiSIaPSZM6Huc4kb5lqCaxg/SBlXTCX17Z/8TFoqV/wCJz17XnkH6 +9WtKAC2TwKxiLZ2Qzwr2XV48lASugIOZkSW2qxM9ui+b1T9ICFKRGLn/UB//pOiG +270hNJDLB/BKRExjS+RXeOpdAIJB5XsAEp8h56ub9emhhf9tCEXOn7PN7HbMCnQh +7k8EpAG0h5StLUhY1HHvynVz2/qyMvZa/bIaaudL2565Z6nDU+iBxed7O1qrbRAH +Vakr7Sa3K5niCyH5kxdyO1t29l1ksBqpDUrj+vViFuLkd3XIiui8IA== +-----END RSA PRIVATE KEY----- + + + tester + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj b/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj index d6dc7af9..735b74f7 100644 --- a/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj +++ b/src/Renci.SshNet.Tests.NET35/Renci.SshNet.Tests.NET35.csproj @@ -1,1284 +1,1284 @@ - - - - Debug - AnyCPU - - - 2.0 - {007CE8B3-7827-4AD0-AACD-860505638ABE} - Library - Properties - Renci.SshNet.Tests - Renci.SshNet.Tests.NET35 - v3.5 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - TRACE;DEBUG - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 0 - - - true - - - ..\Renci.SshNet.snk - - - - - ..\..\packages\Moq.4.2.1409.1722\lib\net35\Moq.dll - - - - 3.5 - - - - - - - False - - - - - Classes\Abstraction\CryptoAbstraction_GenerateRandom.cs - - - Classes\Abstraction\DnsAbstraction_GetHostAddresses.cs - - - Classes\Abstraction\ThreadAbstraction_ExecuteThread.cs - - - Classes\Channels\ChannelDirectTcpipTest.cs - - - Classes\Channels\ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs - - - Classes\Channels\ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs - - - Classes\Channels\ChannelSessionTest_Close_Closed.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs - - - Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs - - - Classes\Channels\ChannelSessionTest_Disposed_Closed.cs - - - Classes\Channels\ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs - - - Classes\Channels\ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation.cs - - - Classes\Channels\ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable.cs - - - Classes\Channels\ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable.cs - - - Classes\Channels\ChannelStub.cs - - - Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs - - - Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs - - - Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs - - - Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs - - - Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs - - - Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs - - - Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs - - - Classes\Channels\ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs - - - Classes\Channels\ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs - - - Classes\Channels\ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs - - - Classes\Channels\ClientChannelStub.cs - - - Classes\Channels\ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception.cs - - - Classes\Channels\ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception.cs - - - Classes\CipherInfoTest.cs - - - Classes\ClientAuthenticationTestBase.cs - - - Classes\ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs - - - Classes\ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotConfigured.cs - - - Classes\ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs - - - Classes\ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs - - - Classes\ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod.cs - - - Classes\ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs - - - Classes\CommandAsyncResultTest.cs - - - Classes\Common\ASCIIEncodingTest.cs - - - Classes\Common\AsyncResultTest.cs - - - Classes\Common\AuthenticationBannerEventArgsTest.cs - - - Classes\Common\AuthenticationPasswordChangeEventArgsTest.cs - - - Classes\Common\AuthenticationPromptEventArgsTest.cs - - - Classes\Common\AuthenticationPromptTest.cs - - - Classes\Common\BigIntegerTest.cs - - - Classes\Common\ChannelDataEventArgsTest.cs - - - Classes\Common\ChannelEventArgsTest.cs - - - Classes\Common\ChannelOpenFailedEventArgsTest.cs - - - Classes\Common\ChannelRequestEventArgsTest.cs - - - Classes\Common\DerDataTest.cs - - - Classes\Common\ExceptionEventArgsTest.cs - - - Classes\Common\HostKeyEventArgsTest.cs - - - Classes\Common\NetConfServerExceptionTest.cs - - - Classes\Common\ObjectIdentifierTest.cs - - - Classes\Common\PipeStreamTest.cs - - - Classes\Common\PortForwardEventArgsTest.cs - - - Classes\Common\ProxyExceptionTest.cs - - - Classes\Common\ScpDownloadEventArgsTest.cs - - - Classes\Common\ScpExceptionTest.cs - - - Classes\Common\ScpUploadEventArgsTest.cs - - - Classes\Common\SemaphoreLightTest.cs - - - Classes\Common\SftpPathNotFoundExceptionTest.cs - - - Classes\Common\SftpPermissionDeniedExceptionTest.cs - - - Classes\Common\ShellDataEventArgsTest.cs - - - Classes\Common\SshAuthenticationExceptionTest.cs - - - Classes\Common\SshConnectionExceptionTest.cs - - - Classes\Common\SshDataTest.cs - - - Classes\Common\SshExceptionTest.cs - - - Classes\Common\SshOperationTimeoutExceptionTest.cs - - - Classes\Common\SshPassPhraseNullOrEmptyExceptionTest.cs - - - Classes\Compression\CompressorTest.cs - - - Classes\Compression\ZlibOpenSshTest.cs - - - Classes\Compression\ZlibStreamTest.cs - - - Classes\Compression\ZlibTest.cs - - - Classes\ConnectionInfoTest.cs - - - Classes\ExpectActionTest.cs - - - Classes\ForwardedPortDynamicTest.cs - - - Classes\ForwardedPortDynamicTest_Dispose_PortDisposed.cs - - - Classes\ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs - - - Classes\ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs - - - Classes\ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs - - - Classes\ForwardedPortDynamicTest_Dispose_PortStopped.cs - - - Classes\ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs - - - Classes\ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs - - - Classes\ForwardedPortDynamicTest_Start_PortDisposed.cs - - - Classes\ForwardedPortDynamicTest_Start_PortNeverStarted.cs - - - Classes\ForwardedPortDynamicTest_Start_PortStarted.cs - - - Classes\ForwardedPortDynamicTest_Start_PortStopped.cs - - - Classes\ForwardedPortDynamicTest_Start_SessionNotConnected.cs - - - Classes\ForwardedPortDynamicTest_Start_SessionNull.cs - - - Classes\ForwardedPortDynamicTest_Stop_PortDisposed.cs - - - Classes\ForwardedPortDynamicTest_Stop_PortNeverStarted.cs - - - Classes\ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs - - - Classes\ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs - - - Classes\ForwardedPortDynamicTest_Stop_PortStopped.cs - - - Classes\ForwardedPortLocalTest.cs - - - Classes\ForwardedPortLocalTest_Dispose_PortDisposed.cs - - - Classes\ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs - - - Classes\ForwardedPortLocalTest_Dispose_PortNeverStarted.cs - - - Classes\ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs - - - Classes\ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs - - - Classes\ForwardedPortLocalTest_Dispose_PortStopped.cs - - - Classes\ForwardedPortLocalTest_Start_PortDisposed.cs - - - Classes\ForwardedPortLocalTest_Start_PortNeverStarted.cs - - - Classes\ForwardedPortLocalTest_Start_PortStarted.cs - - - Classes\ForwardedPortLocalTest_Start_PortStopped.cs - - - Classes\ForwardedPortLocalTest_Start_SessionNotConnected.cs - - - Classes\ForwardedPortLocalTest_Start_SessionNull.cs - - - Classes\ForwardedPortLocalTest_Stop_PortDisposed.cs - - - Classes\ForwardedPortLocalTest_Stop_PortNeverStarted.cs - - - Classes\ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs - - - Classes\ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs - - - Classes\ForwardedPortLocalTest_Stop_PortStopped.cs - - - Classes\ForwardedPortRemoteTest.cs - - - Classes\ForwardedPortRemoteTest_Dispose_PortDisposed.cs - - - Classes\ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs - - - Classes\ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs - - - Classes\ForwardedPortRemoteTest_Dispose_PortStopped.cs - - - Classes\ForwardedPortRemoteTest_Started.cs - - - Classes\ForwardedPortRemoteTest_Start_PortDisposed.cs - - - Classes\ForwardedPortRemoteTest_Start_PortNeverStarted.cs - - - Classes\ForwardedPortRemoteTest_Start_PortStarted.cs - - - Classes\ForwardedPortRemoteTest_Start_PortStopped.cs - - - Classes\ForwardedPortRemoteTest_Start_SessionNotConnected.cs - - - Classes\ForwardedPortRemoteTest_Start_SessionNull.cs - - - Classes\ForwardedPortRemoteTest_Stop_PortDisposed.cs - - - Classes\ForwardedPortRemoteTest_Stop_PortNeverStarted.cs - - - Classes\ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound.cs - - - Classes\ForwardedPortRemoteTest_Stop_PortStopped.cs - - - Classes\KeyboardInteractiveAuthenticationMethodTest.cs - - - Classes\KeyboardInteractiveConnectionInfoTest.cs - - - Classes\MessageEventArgsTest.cs - - - Classes\Messages\Authentication\BannerMessageTest.cs - - - Classes\Messages\Authentication\FailureMessageTest.cs - - - Classes\Messages\Authentication\InformationRequestMessageTest.cs - - - Classes\Messages\Authentication\InformationResponseMessageTest.cs - - - Classes\Messages\Authentication\PasswordChangeRequiredMessageTest.cs - - - Classes\Messages\Authentication\PublicKeyMessageTest.cs - - - Classes\Messages\Authentication\RequestMessageHostTest.cs - - - Classes\Messages\Authentication\RequestMessageKeyboardInteractiveTest.cs - - - Classes\Messages\Authentication\RequestMessageNoneTest.cs - - - Classes\Messages\Authentication\RequestMessagePasswordTest.cs - - - Classes\Messages\Authentication\RequestMessagePublicKeyTest.cs - - - Classes\Messages\Authentication\SuccessMessageTest.cs - - - Classes\Messages\Connection\ChannelCloseMessageTest.cs - - - Classes\Messages\Connection\ChannelDataMessageTest.cs - - - Classes\Messages\Connection\ChannelEofMessageTest.cs - - - Classes\Messages\Connection\ChannelExtendedDataMessageTest.cs - - - Classes\Messages\Connection\ChannelFailureMessageTest.cs - - - Classes\Messages\Connection\ChannelMessageTest.cs - - - Classes\Messages\Connection\ChannelOpenConfirmationMessageTest.cs - - - Classes\Messages\Connection\ChannelOpenFailureMessageTest.cs - - - Classes\Messages\Connection\ChannelOpenInfoTest.cs - - - Classes\Messages\Connection\ChannelOpen\ChannelOpenMessageTest.cs - - - Classes\Messages\Connection\ChannelOpen\DirectTcpipChannelInfoTest.cs - - - Classes\Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfoTest.cs - - - Classes\Messages\Connection\ChannelOpen\SessionChannelOpenInfoTest.cs - - - Classes\Messages\Connection\ChannelOpen\X11ChannelOpenInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\BreakRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\ChannelRequestMessageTest.cs - - - Classes\Messages\Connection\ChannelRequest\EndOfWriteRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\ExecRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\ExitSignalRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\ExitStatusRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\KeepAliveRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\PseudoTerminalInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\ShellRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\SignalRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\SubsystemRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\WindowChangeRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\X11ForwardingRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelRequest\XonXoffRequestInfoTest.cs - - - Classes\Messages\Connection\ChannelSuccessMessageTest.cs - - - Classes\Messages\Connection\ChannelWindowAdjustMessageTest.cs - - - Classes\Messages\Connection\GlobalRequestMessageTest.cs - - - Classes\Messages\Connection\RequestFailureMessageTest.cs - - - Classes\Messages\Connection\RequestInfoTest.cs - - - Classes\Messages\Connection\RequestSuccessMessageTest.cs - - - Classes\Messages\MessageAttributeTest.cs - - - Classes\Messages\MessageTest.cs - - - Classes\Messages\Transport\DebugMessageTest.cs - - - Classes\Messages\Transport\DisconnectMessageTest.cs - - - Classes\Messages\Transport\IgnoreMessageTest.cs - - - Classes\Messages\Transport\KeyExchangeDhGroupExchangeGroupTest.cs - - - Classes\Messages\Transport\KeyExchangeDhGroupExchangeInitTest.cs - - - Classes\Messages\Transport\KeyExchangeDhGroupExchangeReplyTest.cs - - - Classes\Messages\Transport\KeyExchangeDhGroupExchangeRequestTest.cs - - - Classes\Messages\Transport\KeyExchangeDhInitMessageTest.cs - - - Classes\Messages\Transport\KeyExchangeDhReplyMessageTest.cs - - - Classes\Messages\Transport\KeyExchangeInitMessageTest.cs - - - Classes\Messages\Transport\NewKeysMessageTest.cs - - - Classes\Messages\Transport\ServiceAcceptMessageTest.cs - - - Classes\Messages\Transport\ServiceRequestMessageTest.cs - - - Classes\Messages\Transport\UnimplementedMessageTest.cs - - - Classes\NetConfClientTest.cs - - - Classes\NoneAuthenticationMethodTest.cs - - - Classes\PasswordAuthenticationMethodTest.cs - - - Classes\PasswordConnectionInfoTest.cs - - - Classes\PrivateKeyAuthenticationMethodTest.cs - - - Classes\PrivateKeyConnectionInfoTest.cs - - - Classes\PrivateKeyFileTest.cs - - - Classes\ScpClientTest.cs - - - Classes\ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs - - - Classes\ScpClientTest_Upload_FileInfoAndPath_Success.cs - - - Classes\Security\CertificateHostAlgorithmTest.cs - - - Classes\Security\Cryptography\Ciphers\AesCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\Arc4CipherTest.cs - - - Classes\Security\Cryptography\Ciphers\BlowfishCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\CastCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\CipherModeTest.cs - - - Classes\Security\Cryptography\Ciphers\CipherPaddingTest.cs - - - Classes\Security\Cryptography\Ciphers\DesCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\Modes\CbcCipherModeTest.cs - - - Classes\Security\Cryptography\Ciphers\Modes\CfbCipherModeTest.cs - - - Classes\Security\Cryptography\Ciphers\Modes\CtrCipherModeTest.cs - - - Classes\Security\Cryptography\Ciphers\Modes\OfbCipherModeTest.cs - - - Classes\Security\Cryptography\Ciphers\Paddings\PKCS5PaddingTest.cs - - - Classes\Security\Cryptography\Ciphers\Paddings\PKCS7PaddingTest.cs - - - Classes\Security\Cryptography\Ciphers\RsaCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\SerpentCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\TripleDesCipherTest.cs - - - Classes\Security\Cryptography\Ciphers\TwofishCipherTest.cs - - - Classes\Security\Cryptography\DsaDigitalSignatureTest.cs - - - Classes\Security\Cryptography\DsaKeyTest.cs - - - Classes\Security\Cryptography\HMacTest.cs - - - Classes\Security\Cryptography\RsaDigitalSignatureTest.cs - - - Classes\Security\Cryptography\RsaKeyTest.cs - - - Classes\Security\KeyExchangeDiffieHellmanGroup14Sha1Test.cs - - - Classes\Security\KeyExchangeDiffieHellmanGroup1Sha1Test.cs - - - Classes\Security\KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs - - - Classes\Security\KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs - - - Classes\Security\KeyHostAlgorithmTest.cs - - - Classes\SessionTest.cs - - - Classes\SessionTest.HttpProxy.cs - - - Classes\SftpClientTest.ChangeDirectory.cs - - - Classes\SftpClientTest.Connect.cs - - - Classes\SftpClientTest.CreateDirectory.cs - - - Classes\SftpClientTest.cs - - - Classes\SftpClientTest.DeleteDirectory.cs - - - Classes\SftpClientTest.DeleteFile.cs - - - Classes\SftpClientTest.Download.cs - - - Classes\SftpClientTest.ListDirectory.cs - - - Classes\SftpClientTest.RenameFile.cs - - - Classes\SftpClientTest.SynchronizeDirectories.cs - - - Classes\SftpClientTest.Upload.cs - - - Classes\Sftp\Requests\ExtendedRequests\FStatVfsRequestTest.cs - - - Classes\Sftp\Requests\ExtendedRequests\HardLinkRequestTest.cs - - - Classes\Sftp\Requests\ExtendedRequests\PosixRenameRequestTest.cs - - - Classes\Sftp\Requests\ExtendedRequests\StatVfsRequestTest.cs - - - Classes\Sftp\Requests\SftpBlockRequestTest.cs - - - Classes\Sftp\Requests\SftpCloseRequestTest.cs - - - Classes\Sftp\Requests\SftpFSetStatRequestTest.cs - - - Classes\Sftp\Requests\SftpFStatRequestTest.cs - - - Classes\Sftp\Requests\SftpInitRequestTest.cs - - - Classes\Sftp\Requests\SftpLinkRequestTest.cs - - - Classes\Sftp\Requests\SftpLStatRequestTest.cs - - - Classes\Sftp\Requests\SftpMkDirRequestTest.cs - - - Classes\Sftp\Requests\SftpOpenDirRequestTest.cs - - - Classes\Sftp\Requests\SftpOpenRequestTest.cs - - - Classes\Sftp\Requests\SftpReadDirRequestTest.cs - - - Classes\Sftp\Requests\SftpReadLinkRequestTest.cs - - - Classes\Sftp\Requests\SftpReadRequestTest.cs - - - Classes\Sftp\Requests\SftpRealPathRequestTest.cs - - - Classes\Sftp\Requests\SftpRemoveRequestTest.cs - - - Classes\Sftp\Requests\SftpRenameRequestTest.cs - - - Classes\Sftp\Requests\SftpRmDirRequestTest.cs - - - Classes\Sftp\Requests\SftpSetStatRequestTest.cs - - - Classes\Sftp\Requests\SftpStatRequestTest.cs - - - Classes\Sftp\Requests\SftpSymLinkRequestTest.cs - - - Classes\Sftp\Requests\SftpUnblockRequestTest.cs - - - Classes\Sftp\Requests\SftpWriteRequestTest.cs - - - Classes\Sftp\Responses\ExtendedReplies\StatVfsReplyInfoTest.cs - - - Classes\Sftp\Responses\SftpAttrsResponseTest.cs - - - Classes\Sftp\Responses\SftpDataResponseTest.cs - - - Classes\Sftp\Responses\SftpExtendedReplyResponseTest.cs - - - Classes\Sftp\Responses\SftpHandleResponseTest.cs - - - Classes\Sftp\Responses\SftpNameResponseTest.cs - - - Classes\Sftp\Responses\SftpStatusResponseTest.cs - - - Classes\Sftp\Responses\SftpVersionResponseTest.cs - - - Classes\Sftp\SftpDownloadAsyncResultTest.cs - - - Classes\Sftp\SftpFileAttributesTest.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs - - - Classes\Sftp\SftpFileStreamTest_Close_Closed.cs - - - Classes\Sftp\SftpFileStreamTest_Close_Disposed.cs - - - Classes\Sftp\SftpFileStreamTest_Close_SessionNotOpen.cs - - - Classes\Sftp\SftpFileStreamTest_Close_SessionOpen.cs - - - Classes\Sftp\SftpFileStreamTest_Dispose_Closed.cs - - - Classes\Sftp\SftpFileStreamTest_Dispose_Disposed.cs - - - Classes\Sftp\SftpFileStreamTest_Dispose_SessionNotOpen.cs - - - Classes\Sftp\SftpFileStreamTest_Dispose_SessionOpen.cs - - - Classes\Sftp\SftpFileStreamTest_Finalize_SessionOpen.cs - - - Classes\Sftp\SftpFileStreamTest_SetLength_Closed.cs - - - Classes\Sftp\SftpFileStreamTest_SetLength_Disposed.cs - - - Classes\Sftp\SftpFileStreamTest_SetLength_SessionNotOpen.cs - - - Classes\Sftp\SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs - - - Classes\Sftp\SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs - - - Classes\Sftp\SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs - - - Classes\Sftp\SftpFileSystemInformationTest.cs - - - Classes\Sftp\SftpFileTest.cs - - - Classes\Sftp\SftpListDirectoryAsyncResultTest.cs - - - Classes\Sftp\SftpSessionTest_Connected_RequestRead.cs - - - Classes\Sftp\SftpSessionTest_Connected_RequestStatVfs.cs - - - Classes\Sftp\SftpSynchronizeDirectoriesAsyncResultTest.cs - - - Classes\Sftp\SftpUploadAsyncResultTest.cs - - - Classes\Sftp\SftpVersionResponseBuilder.cs - - - Classes\ShellStreamTest.cs - - - Classes\ShellTestTest.cs - - - Classes\SshClientTest.cs - - - Classes\SshClientTest_Disconnect_ForwardedPortStarted.cs - - - Classes\SshClientTest_Dispose_ForwardedPortStarted.cs - - - Classes\SshCommandTest.cs - - - Classes\SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs - - - Classes\SshCommandTest_BeginExecute_EndExecuteNotInvokedOnAsyncResultFromPreviousInvocation.cs - - - Classes\SshCommandTest_Dispose.cs - - - Classes\SshCommandTest_EndExecute.cs - - - Classes\SshCommandTest_EndExecute_AsyncResultFromOtherInstance.cs - - - Classes\SshCommandTest_EndExecute_AsyncResultIsNull.cs - - - Classes\SshCommandTest_EndExecute_ChannelOpen.cs - - - Classes\SubsystemSessionStub.cs - - - Classes\SubsystemSession_Connect_Connected.cs - - - Classes\SubsystemSession_Connect_Disconnected.cs - - - Classes\SubsystemSession_Connect_Disposed.cs - - - Classes\SubsystemSession_Connect_NeverConnected.cs - - - Classes\SubsystemSession_Disconnect_Connected.cs - - - Classes\SubsystemSession_Disconnect_Disposed.cs - - - Classes\SubsystemSession_Disconnect_NeverConnected.cs - - - Classes\SubsystemSession_Dispose_Connected.cs - - - Classes\SubsystemSession_Dispose_Disconnected.cs - - - Classes\SubsystemSession_Dispose_Disposed.cs - - - Classes\SubsystemSession_Dispose_NeverConnected.cs - - - Classes\SubsystemSession_OnChannelDataReceived_Connected.cs - - - Classes\SubsystemSession_OnChannelDataReceived_Disposed.cs - - - Classes\SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs - - - Classes\SubsystemSession_OnChannelException_Connected.cs - - - Classes\SubsystemSession_OnChannelException_Disposed.cs - - - Classes\SubsystemSession_OnSessionDisconnected_Connected.cs - - - Classes\SubsystemSession_OnSessionDisconnected_Disposed.cs - - - Classes\SubsystemSession_OnSessionErrorOccurred_Connected.cs - - - Classes\SubsystemSession_OnSessionErrorOccurred_Disposed.cs - - - Classes\SubsystemSession_SendData_Connected.cs - - - Classes\SubsystemSession_SendData_Disconnected.cs - - - Classes\SubsystemSession_SendData_Disposed.cs - - - Classes\SubsystemSession_SendData_NeverConnected.cs - - - Common\AsyncSocketListener.cs - - - Common\HttpProxyStub.cs - - - Common\HttpRequest.cs - - - Common\TestBase.cs - - - - - - - Properties\CommonAssemblyInfo.cs - - - True - True - Resources.resx - - - - - {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A} - Renci.SshNet.NET35 - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - - - Data\Key.RSA.Encrypted.Aes.128.CBC.12345.txt - - - Data\Key.RSA.Encrypted.Aes.192.CBC.12345.txt - - - Data\Key.RSA.Encrypted.Aes.256.CBC.12345.txt - - - Data\Key.RSA.Encrypted.Des.CBC.12345.txt - - - Data\Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt - - - Data\Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt - - - Data\Key.RSA.txt - - - - - Renci.SshNet.snk - - - - - - Data\Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt - - - Data\Key.SSH2.DSA.txt - - - Data\Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt - - - Data\Key.SSH2.RSA.txt - - - - - - - - - + + + + Debug + AnyCPU + + + 2.0 + {007CE8B3-7827-4AD0-AACD-860505638ABE} + Library + Properties + Renci.SshNet.Tests + Renci.SshNet.Tests.NET35 + v3.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + TRACE;DEBUG + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 0 + + + true + + + ..\Renci.SshNet.snk + + + + + ..\..\packages\Moq.4.2.1409.1722\lib\net35\Moq.dll + + + + 3.5 + + + + + + + False + + + + + Classes\Abstraction\CryptoAbstraction_GenerateRandom.cs + + + Classes\Abstraction\DnsAbstraction_GetHostAddresses.cs + + + Classes\Abstraction\ThreadAbstraction_ExecuteThread.cs + + + Classes\Channels\ChannelDirectTcpipTest.cs + + + Classes\Channels\ChannelDirectTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs + + + Classes\Channels\ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs + + + Classes\Channels\ChannelSessionTest_Close_Closed.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs + + + Classes\Channels\ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs + + + Classes\Channels\ChannelSessionTest_Disposed_Closed.cs + + + Classes\Channels\ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs + + + Classes\Channels\ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation.cs + + + Classes\Channels\ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable.cs + + + Classes\Channels\ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable.cs + + + Classes\Channels\ChannelStub.cs + + + Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs + + + Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs + + + Classes\Channels\ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs + + + Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs + + + Classes\Channels\ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs + + + Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs + + + Classes\Channels\ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs + + + Classes\Channels\ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs + + + Classes\Channels\ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs + + + Classes\Channels\ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs + + + Classes\Channels\ClientChannelStub.cs + + + Classes\Channels\ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception.cs + + + Classes\Channels\ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception.cs + + + Classes\CipherInfoTest.cs + + + Classes\ClientAuthenticationTestBase.cs + + + Classes\ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs + + + Classes\ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotConfigured.cs + + + Classes\ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs + + + Classes\ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs + + + Classes\ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod.cs + + + Classes\ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs + + + Classes\CommandAsyncResultTest.cs + + + Classes\Common\ASCIIEncodingTest.cs + + + Classes\Common\AsyncResultTest.cs + + + Classes\Common\AuthenticationBannerEventArgsTest.cs + + + Classes\Common\AuthenticationPasswordChangeEventArgsTest.cs + + + Classes\Common\AuthenticationPromptEventArgsTest.cs + + + Classes\Common\AuthenticationPromptTest.cs + + + Classes\Common\BigIntegerTest.cs + + + Classes\Common\ChannelDataEventArgsTest.cs + + + Classes\Common\ChannelEventArgsTest.cs + + + Classes\Common\ChannelOpenFailedEventArgsTest.cs + + + Classes\Common\ChannelRequestEventArgsTest.cs + + + Classes\Common\DerDataTest.cs + + + Classes\Common\ExceptionEventArgsTest.cs + + + Classes\Common\HostKeyEventArgsTest.cs + + + Classes\Common\NetConfServerExceptionTest.cs + + + Classes\Common\ObjectIdentifierTest.cs + + + Classes\Common\PipeStreamTest.cs + + + Classes\Common\PortForwardEventArgsTest.cs + + + Classes\Common\ProxyExceptionTest.cs + + + Classes\Common\ScpDownloadEventArgsTest.cs + + + Classes\Common\ScpExceptionTest.cs + + + Classes\Common\ScpUploadEventArgsTest.cs + + + Classes\Common\SemaphoreLightTest.cs + + + Classes\Common\SftpPathNotFoundExceptionTest.cs + + + Classes\Common\SftpPermissionDeniedExceptionTest.cs + + + Classes\Common\ShellDataEventArgsTest.cs + + + Classes\Common\SshAuthenticationExceptionTest.cs + + + Classes\Common\SshConnectionExceptionTest.cs + + + Classes\Common\SshDataTest.cs + + + Classes\Common\SshExceptionTest.cs + + + Classes\Common\SshOperationTimeoutExceptionTest.cs + + + Classes\Common\SshPassPhraseNullOrEmptyExceptionTest.cs + + + Classes\Compression\CompressorTest.cs + + + Classes\Compression\ZlibOpenSshTest.cs + + + Classes\Compression\ZlibStreamTest.cs + + + Classes\Compression\ZlibTest.cs + + + Classes\ConnectionInfoTest.cs + + + Classes\ExpectActionTest.cs + + + Classes\ForwardedPortDynamicTest.cs + + + Classes\ForwardedPortDynamicTest_Dispose_PortDisposed.cs + + + Classes\ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs + + + Classes\ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs + + + Classes\ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs + + + Classes\ForwardedPortDynamicTest_Dispose_PortStopped.cs + + + Classes\ForwardedPortDynamicTest_Started_SocketSendShutdownImmediately.cs + + + Classes\ForwardedPortDynamicTest_Started_SocketVersionNotSupported.cs + + + Classes\ForwardedPortDynamicTest_Start_PortDisposed.cs + + + Classes\ForwardedPortDynamicTest_Start_PortNeverStarted.cs + + + Classes\ForwardedPortDynamicTest_Start_PortStarted.cs + + + Classes\ForwardedPortDynamicTest_Start_PortStopped.cs + + + Classes\ForwardedPortDynamicTest_Start_SessionNotConnected.cs + + + Classes\ForwardedPortDynamicTest_Start_SessionNull.cs + + + Classes\ForwardedPortDynamicTest_Stop_PortDisposed.cs + + + Classes\ForwardedPortDynamicTest_Stop_PortNeverStarted.cs + + + Classes\ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs + + + Classes\ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs + + + Classes\ForwardedPortDynamicTest_Stop_PortStopped.cs + + + Classes\ForwardedPortLocalTest.cs + + + Classes\ForwardedPortLocalTest_Dispose_PortDisposed.cs + + + Classes\ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs + + + Classes\ForwardedPortLocalTest_Dispose_PortNeverStarted.cs + + + Classes\ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs + + + Classes\ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs + + + Classes\ForwardedPortLocalTest_Dispose_PortStopped.cs + + + Classes\ForwardedPortLocalTest_Start_PortDisposed.cs + + + Classes\ForwardedPortLocalTest_Start_PortNeverStarted.cs + + + Classes\ForwardedPortLocalTest_Start_PortStarted.cs + + + Classes\ForwardedPortLocalTest_Start_PortStopped.cs + + + Classes\ForwardedPortLocalTest_Start_SessionNotConnected.cs + + + Classes\ForwardedPortLocalTest_Start_SessionNull.cs + + + Classes\ForwardedPortLocalTest_Stop_PortDisposed.cs + + + Classes\ForwardedPortLocalTest_Stop_PortNeverStarted.cs + + + Classes\ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs + + + Classes\ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs + + + Classes\ForwardedPortLocalTest_Stop_PortStopped.cs + + + Classes\ForwardedPortRemoteTest.cs + + + Classes\ForwardedPortRemoteTest_Dispose_PortDisposed.cs + + + Classes\ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs + + + Classes\ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs + + + Classes\ForwardedPortRemoteTest_Dispose_PortStopped.cs + + + Classes\ForwardedPortRemoteTest_Started.cs + + + Classes\ForwardedPortRemoteTest_Start_PortDisposed.cs + + + Classes\ForwardedPortRemoteTest_Start_PortNeverStarted.cs + + + Classes\ForwardedPortRemoteTest_Start_PortStarted.cs + + + Classes\ForwardedPortRemoteTest_Start_PortStopped.cs + + + Classes\ForwardedPortRemoteTest_Start_SessionNotConnected.cs + + + Classes\ForwardedPortRemoteTest_Start_SessionNull.cs + + + Classes\ForwardedPortRemoteTest_Stop_PortDisposed.cs + + + Classes\ForwardedPortRemoteTest_Stop_PortNeverStarted.cs + + + Classes\ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound.cs + + + Classes\ForwardedPortRemoteTest_Stop_PortStopped.cs + + + Classes\KeyboardInteractiveAuthenticationMethodTest.cs + + + Classes\KeyboardInteractiveConnectionInfoTest.cs + + + Classes\MessageEventArgsTest.cs + + + Classes\Messages\Authentication\BannerMessageTest.cs + + + Classes\Messages\Authentication\FailureMessageTest.cs + + + Classes\Messages\Authentication\InformationRequestMessageTest.cs + + + Classes\Messages\Authentication\InformationResponseMessageTest.cs + + + Classes\Messages\Authentication\PasswordChangeRequiredMessageTest.cs + + + Classes\Messages\Authentication\PublicKeyMessageTest.cs + + + Classes\Messages\Authentication\RequestMessageHostTest.cs + + + Classes\Messages\Authentication\RequestMessageKeyboardInteractiveTest.cs + + + Classes\Messages\Authentication\RequestMessageNoneTest.cs + + + Classes\Messages\Authentication\RequestMessagePasswordTest.cs + + + Classes\Messages\Authentication\RequestMessagePublicKeyTest.cs + + + Classes\Messages\Authentication\SuccessMessageTest.cs + + + Classes\Messages\Connection\ChannelCloseMessageTest.cs + + + Classes\Messages\Connection\ChannelDataMessageTest.cs + + + Classes\Messages\Connection\ChannelEofMessageTest.cs + + + Classes\Messages\Connection\ChannelExtendedDataMessageTest.cs + + + Classes\Messages\Connection\ChannelFailureMessageTest.cs + + + Classes\Messages\Connection\ChannelMessageTest.cs + + + Classes\Messages\Connection\ChannelOpenConfirmationMessageTest.cs + + + Classes\Messages\Connection\ChannelOpenFailureMessageTest.cs + + + Classes\Messages\Connection\ChannelOpenInfoTest.cs + + + Classes\Messages\Connection\ChannelOpen\ChannelOpenMessageTest.cs + + + Classes\Messages\Connection\ChannelOpen\DirectTcpipChannelInfoTest.cs + + + Classes\Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfoTest.cs + + + Classes\Messages\Connection\ChannelOpen\SessionChannelOpenInfoTest.cs + + + Classes\Messages\Connection\ChannelOpen\X11ChannelOpenInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\BreakRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\ChannelRequestMessageTest.cs + + + Classes\Messages\Connection\ChannelRequest\EndOfWriteRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\ExecRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\ExitSignalRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\ExitStatusRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\KeepAliveRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\PseudoTerminalInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\ShellRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\SignalRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\SubsystemRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\WindowChangeRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\X11ForwardingRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelRequest\XonXoffRequestInfoTest.cs + + + Classes\Messages\Connection\ChannelSuccessMessageTest.cs + + + Classes\Messages\Connection\ChannelWindowAdjustMessageTest.cs + + + Classes\Messages\Connection\GlobalRequestMessageTest.cs + + + Classes\Messages\Connection\RequestFailureMessageTest.cs + + + Classes\Messages\Connection\RequestInfoTest.cs + + + Classes\Messages\Connection\RequestSuccessMessageTest.cs + + + Classes\Messages\MessageAttributeTest.cs + + + Classes\Messages\MessageTest.cs + + + Classes\Messages\Transport\DebugMessageTest.cs + + + Classes\Messages\Transport\DisconnectMessageTest.cs + + + Classes\Messages\Transport\IgnoreMessageTest.cs + + + Classes\Messages\Transport\KeyExchangeDhGroupExchangeGroupTest.cs + + + Classes\Messages\Transport\KeyExchangeDhGroupExchangeInitTest.cs + + + Classes\Messages\Transport\KeyExchangeDhGroupExchangeReplyTest.cs + + + Classes\Messages\Transport\KeyExchangeDhGroupExchangeRequestTest.cs + + + Classes\Messages\Transport\KeyExchangeDhInitMessageTest.cs + + + Classes\Messages\Transport\KeyExchangeDhReplyMessageTest.cs + + + Classes\Messages\Transport\KeyExchangeInitMessageTest.cs + + + Classes\Messages\Transport\NewKeysMessageTest.cs + + + Classes\Messages\Transport\ServiceAcceptMessageTest.cs + + + Classes\Messages\Transport\ServiceRequestMessageTest.cs + + + Classes\Messages\Transport\UnimplementedMessageTest.cs + + + Classes\NetConfClientTest.cs + + + Classes\NoneAuthenticationMethodTest.cs + + + Classes\PasswordAuthenticationMethodTest.cs + + + Classes\PasswordConnectionInfoTest.cs + + + Classes\PrivateKeyAuthenticationMethodTest.cs + + + Classes\PrivateKeyConnectionInfoTest.cs + + + Classes\PrivateKeyFileTest.cs + + + Classes\ScpClientTest.cs + + + Classes\ScpClientTest_Upload_FileInfoAndPath_SendExecRequestReturnsFalse.cs + + + Classes\ScpClientTest_Upload_FileInfoAndPath_Success.cs + + + Classes\Security\CertificateHostAlgorithmTest.cs + + + Classes\Security\Cryptography\Ciphers\AesCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\Arc4CipherTest.cs + + + Classes\Security\Cryptography\Ciphers\BlowfishCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\CastCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\CipherModeTest.cs + + + Classes\Security\Cryptography\Ciphers\CipherPaddingTest.cs + + + Classes\Security\Cryptography\Ciphers\DesCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\Modes\CbcCipherModeTest.cs + + + Classes\Security\Cryptography\Ciphers\Modes\CfbCipherModeTest.cs + + + Classes\Security\Cryptography\Ciphers\Modes\CtrCipherModeTest.cs + + + Classes\Security\Cryptography\Ciphers\Modes\OfbCipherModeTest.cs + + + Classes\Security\Cryptography\Ciphers\Paddings\PKCS5PaddingTest.cs + + + Classes\Security\Cryptography\Ciphers\Paddings\PKCS7PaddingTest.cs + + + Classes\Security\Cryptography\Ciphers\RsaCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\SerpentCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\TripleDesCipherTest.cs + + + Classes\Security\Cryptography\Ciphers\TwofishCipherTest.cs + + + Classes\Security\Cryptography\DsaDigitalSignatureTest.cs + + + Classes\Security\Cryptography\DsaKeyTest.cs + + + Classes\Security\Cryptography\HMacTest.cs + + + Classes\Security\Cryptography\RsaDigitalSignatureTest.cs + + + Classes\Security\Cryptography\RsaKeyTest.cs + + + Classes\Security\KeyExchangeDiffieHellmanGroup14Sha1Test.cs + + + Classes\Security\KeyExchangeDiffieHellmanGroup1Sha1Test.cs + + + Classes\Security\KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs + + + Classes\Security\KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs + + + Classes\Security\KeyHostAlgorithmTest.cs + + + Classes\SessionTest.cs + + + Classes\SessionTest.HttpProxy.cs + + + Classes\SftpClientTest.ChangeDirectory.cs + + + Classes\SftpClientTest.Connect.cs + + + Classes\SftpClientTest.CreateDirectory.cs + + + Classes\SftpClientTest.cs + + + Classes\SftpClientTest.DeleteDirectory.cs + + + Classes\SftpClientTest.DeleteFile.cs + + + Classes\SftpClientTest.Download.cs + + + Classes\SftpClientTest.ListDirectory.cs + + + Classes\SftpClientTest.RenameFile.cs + + + Classes\SftpClientTest.SynchronizeDirectories.cs + + + Classes\SftpClientTest.Upload.cs + + + Classes\Sftp\Requests\ExtendedRequests\FStatVfsRequestTest.cs + + + Classes\Sftp\Requests\ExtendedRequests\HardLinkRequestTest.cs + + + Classes\Sftp\Requests\ExtendedRequests\PosixRenameRequestTest.cs + + + Classes\Sftp\Requests\ExtendedRequests\StatVfsRequestTest.cs + + + Classes\Sftp\Requests\SftpBlockRequestTest.cs + + + Classes\Sftp\Requests\SftpCloseRequestTest.cs + + + Classes\Sftp\Requests\SftpFSetStatRequestTest.cs + + + Classes\Sftp\Requests\SftpFStatRequestTest.cs + + + Classes\Sftp\Requests\SftpInitRequestTest.cs + + + Classes\Sftp\Requests\SftpLinkRequestTest.cs + + + Classes\Sftp\Requests\SftpLStatRequestTest.cs + + + Classes\Sftp\Requests\SftpMkDirRequestTest.cs + + + Classes\Sftp\Requests\SftpOpenDirRequestTest.cs + + + Classes\Sftp\Requests\SftpOpenRequestTest.cs + + + Classes\Sftp\Requests\SftpReadDirRequestTest.cs + + + Classes\Sftp\Requests\SftpReadLinkRequestTest.cs + + + Classes\Sftp\Requests\SftpReadRequestTest.cs + + + Classes\Sftp\Requests\SftpRealPathRequestTest.cs + + + Classes\Sftp\Requests\SftpRemoveRequestTest.cs + + + Classes\Sftp\Requests\SftpRenameRequestTest.cs + + + Classes\Sftp\Requests\SftpRmDirRequestTest.cs + + + Classes\Sftp\Requests\SftpSetStatRequestTest.cs + + + Classes\Sftp\Requests\SftpStatRequestTest.cs + + + Classes\Sftp\Requests\SftpSymLinkRequestTest.cs + + + Classes\Sftp\Requests\SftpUnblockRequestTest.cs + + + Classes\Sftp\Requests\SftpWriteRequestTest.cs + + + Classes\Sftp\Responses\ExtendedReplies\StatVfsReplyInfoTest.cs + + + Classes\Sftp\Responses\SftpAttrsResponseTest.cs + + + Classes\Sftp\Responses\SftpDataResponseTest.cs + + + Classes\Sftp\Responses\SftpExtendedReplyResponseTest.cs + + + Classes\Sftp\Responses\SftpHandleResponseTest.cs + + + Classes\Sftp\Responses\SftpNameResponseTest.cs + + + Classes\Sftp\Responses\SftpStatusResponseTest.cs + + + Classes\Sftp\Responses\SftpVersionResponseTest.cs + + + Classes\Sftp\SftpDownloadAsyncResultTest.cs + + + Classes\Sftp\SftpFileAttributesTest.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs + + + Classes\Sftp\SftpFileStreamTest_Close_Closed.cs + + + Classes\Sftp\SftpFileStreamTest_Close_Disposed.cs + + + Classes\Sftp\SftpFileStreamTest_Close_SessionNotOpen.cs + + + Classes\Sftp\SftpFileStreamTest_Close_SessionOpen.cs + + + Classes\Sftp\SftpFileStreamTest_Dispose_Closed.cs + + + Classes\Sftp\SftpFileStreamTest_Dispose_Disposed.cs + + + Classes\Sftp\SftpFileStreamTest_Dispose_SessionNotOpen.cs + + + Classes\Sftp\SftpFileStreamTest_Dispose_SessionOpen.cs + + + Classes\Sftp\SftpFileStreamTest_Finalize_SessionOpen.cs + + + Classes\Sftp\SftpFileStreamTest_SetLength_Closed.cs + + + Classes\Sftp\SftpFileStreamTest_SetLength_Disposed.cs + + + Classes\Sftp\SftpFileStreamTest_SetLength_SessionNotOpen.cs + + + Classes\Sftp\SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs + + + Classes\Sftp\SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs + + + Classes\Sftp\SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs + + + Classes\Sftp\SftpFileSystemInformationTest.cs + + + Classes\Sftp\SftpFileTest.cs + + + Classes\Sftp\SftpListDirectoryAsyncResultTest.cs + + + Classes\Sftp\SftpSessionTest_Connected_RequestRead.cs + + + Classes\Sftp\SftpSessionTest_Connected_RequestStatVfs.cs + + + Classes\Sftp\SftpSynchronizeDirectoriesAsyncResultTest.cs + + + Classes\Sftp\SftpUploadAsyncResultTest.cs + + + Classes\Sftp\SftpVersionResponseBuilder.cs + + + Classes\ShellStreamTest.cs + + + Classes\ShellTestTest.cs + + + Classes\SshClientTest.cs + + + Classes\SshClientTest_Disconnect_ForwardedPortStarted.cs + + + Classes\SshClientTest_Dispose_ForwardedPortStarted.cs + + + Classes\SshCommandTest.cs + + + Classes\SshCommandTest_BeginExecute_EndExecuteInvokedOnAsyncResultFromPreviousInvocation.cs + + + Classes\SshCommandTest_BeginExecute_EndExecuteNotInvokedOnAsyncResultFromPreviousInvocation.cs + + + Classes\SshCommandTest_Dispose.cs + + + Classes\SshCommandTest_EndExecute.cs + + + Classes\SshCommandTest_EndExecute_AsyncResultFromOtherInstance.cs + + + Classes\SshCommandTest_EndExecute_AsyncResultIsNull.cs + + + Classes\SshCommandTest_EndExecute_ChannelOpen.cs + + + Classes\SubsystemSessionStub.cs + + + Classes\SubsystemSession_Connect_Connected.cs + + + Classes\SubsystemSession_Connect_Disconnected.cs + + + Classes\SubsystemSession_Connect_Disposed.cs + + + Classes\SubsystemSession_Connect_NeverConnected.cs + + + Classes\SubsystemSession_Disconnect_Connected.cs + + + Classes\SubsystemSession_Disconnect_Disposed.cs + + + Classes\SubsystemSession_Disconnect_NeverConnected.cs + + + Classes\SubsystemSession_Dispose_Connected.cs + + + Classes\SubsystemSession_Dispose_Disconnected.cs + + + Classes\SubsystemSession_Dispose_Disposed.cs + + + Classes\SubsystemSession_Dispose_NeverConnected.cs + + + Classes\SubsystemSession_OnChannelDataReceived_Connected.cs + + + Classes\SubsystemSession_OnChannelDataReceived_Disposed.cs + + + Classes\SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs + + + Classes\SubsystemSession_OnChannelException_Connected.cs + + + Classes\SubsystemSession_OnChannelException_Disposed.cs + + + Classes\SubsystemSession_OnSessionDisconnected_Connected.cs + + + Classes\SubsystemSession_OnSessionDisconnected_Disposed.cs + + + Classes\SubsystemSession_OnSessionErrorOccurred_Connected.cs + + + Classes\SubsystemSession_OnSessionErrorOccurred_Disposed.cs + + + Classes\SubsystemSession_SendData_Connected.cs + + + Classes\SubsystemSession_SendData_Disconnected.cs + + + Classes\SubsystemSession_SendData_Disposed.cs + + + Classes\SubsystemSession_SendData_NeverConnected.cs + + + Common\AsyncSocketListener.cs + + + Common\HttpProxyStub.cs + + + Common\HttpRequest.cs + + + Common\TestBase.cs + + + + + + + Properties\CommonAssemblyInfo.cs + + + True + True + Resources.resx + + + + + {DD1C552F-7F48-4269-ABB3-2E4C89B7E43A} + Renci.SshNet.NET35 + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + Data\Key.RSA.Encrypted.Aes.128.CBC.12345.txt + + + Data\Key.RSA.Encrypted.Aes.192.CBC.12345.txt + + + Data\Key.RSA.Encrypted.Aes.256.CBC.12345.txt + + + Data\Key.RSA.Encrypted.Des.CBC.12345.txt + + + Data\Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt + + + Data\Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt + + + Data\Key.RSA.txt + + + + + Renci.SshNet.snk + + + + + + Data\Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt + + + Data\Key.SSH2.DSA.txt + + + Data\Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt + + + Data\Key.SSH2.RSA.txt + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests.NET35/packages.config b/src/Renci.SshNet.Tests.NET35/packages.config index 07e93e94..e9365957 100644 --- a/src/Renci.SshNet.Tests.NET35/packages.config +++ b/src/Renci.SshNet.Tests.NET35/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs b/src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs index 83188a40..ff603874 100644 --- a/src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs +++ b/src/Renci.SshNet.Tests/Classes/BaseClientTest_Connected_KeepAlivesNotSentConcurrently.cs @@ -1,69 +1,69 @@ -using System; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class BaseClientTest_Connected_KeepAlivesNotSentConcurrently - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private BaseClient _client; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "pwd")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.Setup(p => p.Connect()); - _sessionMock.Setup(p => p.TrySendMessage(It.IsAny())) - .Returns(true) - .Callback(() => Thread.Sleep(300)); - - _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object) - { - KeepAliveInterval = TimeSpan.FromMilliseconds(50d) - }; - _client.Connect(); - } - - protected void Act() - { - // should keep-alive message be sent concurrently, then multiple keep-alive - // message would be sent during this sleep period - Thread.Sleep(200); - } - - [TestMethod] - public void SendMessageOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); - } - - private class MyClient : BaseClient - { - public MyClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory) : base(connectionInfo, ownsConnectionInfo, serviceFactory) - { - } - } - } -} +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class BaseClientTest_Connected_KeepAlivesNotSentConcurrently + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private BaseClient _client; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "pwd")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.Setup(p => p.Connect()); + _sessionMock.Setup(p => p.TrySendMessage(It.IsAny())) + .Returns(true) + .Callback(() => Thread.Sleep(300)); + + _client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object) + { + KeepAliveInterval = TimeSpan.FromMilliseconds(50d) + }; + _client.Connect(); + } + + protected void Act() + { + // should keep-alive message be sent concurrently, then multiple keep-alive + // message would be sent during this sleep period + Thread.Sleep(200); + } + + [TestMethod] + public void SendMessageOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); + } + + private class MyClient : BaseClient + { + public MyClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory) : base(connectionInfo, ownsConnectionInfo, serviceFactory) + { + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs index dd9cfe11..2de7725d 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelDirectTcpipTest.cs @@ -1,225 +1,225 @@ -using System; -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; -using Renci.SshNet.Messages.Connection; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelDirectTcpipTestTest : TestBase - { - private Mock _sessionMock; - private Mock _forwardedPortMock; - private Mock _connectionInfoMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private string _remoteHost; - private uint _port; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private uint _remoteChannelNumber; - - protected override void OnInit() - { - base.OnInit(); - - var random = new Random(); - - _localWindowSize = (uint) random.Next(2000, 3000); - _localPacketSize = (uint) random.Next(1000, 2000); - _remoteHost = random.Next().ToString(CultureInfo.InvariantCulture); - _port = (uint) random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _remoteWindowSize = (uint) random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(100, 200); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - - _sessionMock = new Mock(MockBehavior.Strict); - _forwardedPortMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - } - - [TestMethod] - public void SocketShouldBeClosedAndBindShouldEndWhenForwardedPortSignalsClosingEvent() - { - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.SendMessage(It.IsAny())) - .Callback(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage(((ChannelOpenMessage)m).LocalChannelNumber, _remoteWindowSize, _remotePacketSize, _remoteChannelNumber)))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(p => p.WaitOne(Session.Infinite)); - - var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - using (var localPortListener = new AsyncSocketListener(localPortEndPoint)) - { - localPortListener.Start(); - - localPortListener.Connected += socket => - { - var channel = new ChannelDirectTcpip(_sessionMock.Object, _localChannelNumber, _localWindowSize, - _localPacketSize); - channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); - - var closeForwardedPortThread = - new Thread(() => - { - // sleep for a short period to allow channel to actually start receiving from socket - Thread.Sleep(100); - // raise Closing event on forwarded port - _forwardedPortMock.Raise(p => p.Closing += null, EventArgs.Empty); - }); - closeForwardedPortThread.Start(); - - channel.Bind(); - - closeForwardedPortThread.Join(); - }; - - var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - client.Connect(localPortEndPoint); - - // attempt to receive from socket to verify it was shut down by channel - var buffer = new byte[16]; - var bytesReceived = client.Receive(buffer, 0, buffer.Length, SocketFlags.None); - Assert.AreEqual(0, bytesReceived); - Assert.IsTrue(client.Connected); - // signal to server that we also shut down the socket at our end - client.Shutdown(SocketShutdown.Send); - } - } - - [TestMethod] - public void SocketShouldBeClosedAndBindShouldEndWhenOnErrorOccurredIsInvoked() - { - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.SendMessage(It.IsAny())) - .Callback(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage(((ChannelOpenMessage)m).LocalChannelNumber, _remoteWindowSize, _remotePacketSize, _remoteChannelNumber)))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(p => p.WaitOne(Session.Infinite)); - - var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - using (var localPortListener = new AsyncSocketListener(localPortEndPoint)) - { - localPortListener.Start(); - - localPortListener.Connected += socket => - { - var channel = new ChannelDirectTcpip(_sessionMock.Object, _localChannelNumber, _localWindowSize, - _localPacketSize); - channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); - - var signalSessionErrorOccurredThread = - new Thread(() => - { - // sleep for a short period to allow channel to actually start receiving from socket - Thread.Sleep(100); - // raise ErrorOccured event on session - _sessionMock.Raise(s => s.ErrorOccured += null, - new ExceptionEventArgs(new SystemException())); - }); - signalSessionErrorOccurredThread.Start(); - - channel.Bind(); - - signalSessionErrorOccurredThread.Join(); - }; - - var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - client.Connect(localPortEndPoint); - - // attempt to receive from socket to verify it was shut down by channel - var buffer = new byte[16]; - var bytesReceived = client.Receive(buffer, 0, buffer.Length, SocketFlags.None); - Assert.AreEqual(0, bytesReceived); - Assert.IsTrue(client.Connected); - // signal to server that we also shut down the socket at our end - client.Shutdown(SocketShutdown.Send); - } - } - - [TestMethod] - public void SocketShouldBeClosedAndEofShouldBeSentToServerWhenClientShutsDownSocket() - { - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.SendMessage(It.IsAny())) - .Callback(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage(((ChannelOpenMessage) m).LocalChannelNumber, - _remoteWindowSize, _remotePacketSize, _remoteChannelNumber)))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(p => p.WaitOne(Session.Infinite)); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(60)); - _sessionMock.Setup(p => p.TrySendMessage(It.IsAny())) - .Returns(true) - .Callback( - m => new Thread(() => - { - Thread.Sleep(50); - _sessionMock.Raise(s => s.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - }).Start()); - _sessionMock.Setup(p => p.TrySendMessage(It.IsAny())) - .Returns(true) - .Callback( - m => new Thread(() => - { - Thread.Sleep(50); - _sessionMock.Raise(s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - }).Start()); - var channelBindFinishedWaitHandle = new ManualResetEvent(false); - Socket handler = null; - ChannelDirectTcpip channel = null; - - var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - using (var localPortListener = new AsyncSocketListener(localPortEndPoint)) - { - localPortListener.Start(); - - localPortListener.Connected += socket => - { - channel = new ChannelDirectTcpip(_sessionMock.Object, _localChannelNumber, _localWindowSize, - _localPacketSize); - channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); - channel.Bind(); - channel.Close(); - - handler = socket; - - 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(); - - Assert.IsNotNull(handler); - Assert.IsFalse(handler.Connected); - - _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); - _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); - - channel.Close(); - - _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); - _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); - } - } - } +using System; +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; +using Renci.SshNet.Messages.Connection; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelDirectTcpipTestTest : TestBase + { + private Mock _sessionMock; + private Mock _forwardedPortMock; + private Mock _connectionInfoMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private string _remoteHost; + private uint _port; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private uint _remoteChannelNumber; + + protected override void OnInit() + { + base.OnInit(); + + var random = new Random(); + + _localWindowSize = (uint) random.Next(2000, 3000); + _localPacketSize = (uint) random.Next(1000, 2000); + _remoteHost = random.Next().ToString(CultureInfo.InvariantCulture); + _port = (uint) random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _remoteWindowSize = (uint) random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(100, 200); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + + _sessionMock = new Mock(MockBehavior.Strict); + _forwardedPortMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + } + + [TestMethod] + public void SocketShouldBeClosedAndBindShouldEndWhenForwardedPortSignalsClosingEvent() + { + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.SendMessage(It.IsAny())) + .Callback(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage(((ChannelOpenMessage)m).LocalChannelNumber, _remoteWindowSize, _remotePacketSize, _remoteChannelNumber)))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(p => p.WaitOne(Session.Infinite)); + + var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + using (var localPortListener = new AsyncSocketListener(localPortEndPoint)) + { + localPortListener.Start(); + + localPortListener.Connected += socket => + { + var channel = new ChannelDirectTcpip(_sessionMock.Object, _localChannelNumber, _localWindowSize, + _localPacketSize); + channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); + + var closeForwardedPortThread = + new Thread(() => + { + // sleep for a short period to allow channel to actually start receiving from socket + Thread.Sleep(100); + // raise Closing event on forwarded port + _forwardedPortMock.Raise(p => p.Closing += null, EventArgs.Empty); + }); + closeForwardedPortThread.Start(); + + channel.Bind(); + + closeForwardedPortThread.Join(); + }; + + var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + client.Connect(localPortEndPoint); + + // attempt to receive from socket to verify it was shut down by channel + var buffer = new byte[16]; + var bytesReceived = client.Receive(buffer, 0, buffer.Length, SocketFlags.None); + Assert.AreEqual(0, bytesReceived); + Assert.IsTrue(client.Connected); + // signal to server that we also shut down the socket at our end + client.Shutdown(SocketShutdown.Send); + } + } + + [TestMethod] + public void SocketShouldBeClosedAndBindShouldEndWhenOnErrorOccurredIsInvoked() + { + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.SendMessage(It.IsAny())) + .Callback(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage(((ChannelOpenMessage)m).LocalChannelNumber, _remoteWindowSize, _remotePacketSize, _remoteChannelNumber)))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(p => p.WaitOne(Session.Infinite)); + + var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + using (var localPortListener = new AsyncSocketListener(localPortEndPoint)) + { + localPortListener.Start(); + + localPortListener.Connected += socket => + { + var channel = new ChannelDirectTcpip(_sessionMock.Object, _localChannelNumber, _localWindowSize, + _localPacketSize); + channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); + + var signalSessionErrorOccurredThread = + new Thread(() => + { + // sleep for a short period to allow channel to actually start receiving from socket + Thread.Sleep(100); + // raise ErrorOccured event on session + _sessionMock.Raise(s => s.ErrorOccured += null, + new ExceptionEventArgs(new SystemException())); + }); + signalSessionErrorOccurredThread.Start(); + + channel.Bind(); + + signalSessionErrorOccurredThread.Join(); + }; + + var client = new Socket(localPortEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + client.Connect(localPortEndPoint); + + // attempt to receive from socket to verify it was shut down by channel + var buffer = new byte[16]; + var bytesReceived = client.Receive(buffer, 0, buffer.Length, SocketFlags.None); + Assert.AreEqual(0, bytesReceived); + Assert.IsTrue(client.Connected); + // signal to server that we also shut down the socket at our end + client.Shutdown(SocketShutdown.Send); + } + } + + [TestMethod] + public void SocketShouldBeClosedAndEofShouldBeSentToServerWhenClientShutsDownSocket() + { + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.SendMessage(It.IsAny())) + .Callback(m => _sessionMock.Raise(p => p.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage(((ChannelOpenMessage) m).LocalChannelNumber, + _remoteWindowSize, _remotePacketSize, _remoteChannelNumber)))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(p => p.WaitOne(Session.Infinite)); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(60)); + _sessionMock.Setup(p => p.TrySendMessage(It.IsAny())) + .Returns(true) + .Callback( + m => new Thread(() => + { + Thread.Sleep(50); + _sessionMock.Raise(s => s.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + }).Start()); + _sessionMock.Setup(p => p.TrySendMessage(It.IsAny())) + .Returns(true) + .Callback( + m => new Thread(() => + { + Thread.Sleep(50); + _sessionMock.Raise(s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + }).Start()); + var channelBindFinishedWaitHandle = new ManualResetEvent(false); + Socket handler = null; + ChannelDirectTcpip channel = null; + + var localPortEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + using (var localPortListener = new AsyncSocketListener(localPortEndPoint)) + { + localPortListener.Start(); + + localPortListener.Connected += socket => + { + channel = new ChannelDirectTcpip(_sessionMock.Object, _localChannelNumber, _localWindowSize, + _localPacketSize); + channel.Open(_remoteHost, _port, _forwardedPortMock.Object, socket); + channel.Bind(); + channel.Close(); + + handler = socket; + + 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(); + + Assert.IsNotNull(handler); + Assert.IsFalse(handler.Connected); + + _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); + _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); + + channel.Close(); + + _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); + _sessionMock.Verify(p => p.TrySendMessage(It.IsAny()), Times.Once); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs index c200467e..de0984fc 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen.cs @@ -1,196 +1,196 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen - { - private Mock _sessionMock; - private Mock _forwardedPortMock; - private Mock _connectionInfoMock; - private ChannelForwardedTcpip _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private uint _remoteChannelNumber; - private IPEndPoint _remoteEndpoint; - private AsyncSocketListener _remoteListener; - private EventWaitHandle _channelBindFinishedWaitHandle; - private Exception _channelException; - private IList _connectedRegister; - private IList _disconnectedRegister; - private Thread _channelThread; - private TimeSpan _connectionInfoTimeout; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void CleanUp() - { - if (_remoteListener != null) - { - _remoteListener.Stop(); - _remoteListener = null; - } - - if (_channelThread != null) - { - if (_channelThread.IsAlive) - _channelThread.Abort(); - _channelThread = null; - } - if (_channel != null) - { - _channel.Dispose(); - _channel = null; - } - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(2000, 3000); - _localPacketSize = (uint) random.Next(1000, 2000); - _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); - _remoteWindowSize = (uint) random.Next(0, int.MaxValue); - _remotePacketSize = (uint) random.Next(100, 200); - _channelBindFinishedWaitHandle = new ManualResetEvent(false); - _channelException = null; - _connectedRegister = new List(); - _disconnectedRegister = new List(); - _connectionInfoTimeout = TimeSpan.FromSeconds(5); - - _remoteEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - _forwardedPortMock = new Mock(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( - 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(m => m.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence) - .Setup( - p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - w.WaitOne(); - }); - - _remoteListener = new AsyncSocketListener(_remoteEndpoint); - _remoteListener.Connected += socket => _connectedRegister.Add(socket); - _remoteListener.Disconnected += socket => _disconnectedRegister.Add(socket); - _remoteListener.Start(); - - _channel = new ChannelForwardedTcpip( - _sessionMock.Object, - _localChannelNumber, - _localWindowSize, - _localPacketSize, - _remoteChannelNumber, - _remoteWindowSize, - _remotePacketSize); - - _channelThread = new Thread(() => - { - try - { - _channel.Bind(_remoteEndpoint, _forwardedPortMock.Object); - } - catch (Exception ex) - { - _channelException = ex; - } - finally - { - _channelBindFinishedWaitHandle.Set(); - } - }); - _channelThread.Start(); - - // give channel time to bind to remote endpoint - Thread.Sleep(100); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void ChannelShouldShutdownSocketToRemoteListener() - { - Assert.AreEqual(1, _connectedRegister.Count); - Assert.AreEqual(1, _disconnectedRegister.Count); - Assert.AreSame(_connectedRegister[0], _disconnectedRegister[0]); - } - - [TestMethod] - public void BindShouldHaveFinishedWithoutException() - { - Assert.IsTrue(_channelBindFinishedWaitHandle.WaitOne(0)); - Assert.IsNull(_channelException, _channelException != null ? _channelException.ToString() : null); - } - - [TestMethod] - public void ChannelEofMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ChannelCloseMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelForwardedTcpipTest_Close_SessionIsConnectedAndChannelIsOpen + { + private Mock _sessionMock; + private Mock _forwardedPortMock; + private Mock _connectionInfoMock; + private ChannelForwardedTcpip _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private uint _remoteChannelNumber; + private IPEndPoint _remoteEndpoint; + private AsyncSocketListener _remoteListener; + private EventWaitHandle _channelBindFinishedWaitHandle; + private Exception _channelException; + private IList _connectedRegister; + private IList _disconnectedRegister; + private Thread _channelThread; + private TimeSpan _connectionInfoTimeout; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void CleanUp() + { + if (_remoteListener != null) + { + _remoteListener.Stop(); + _remoteListener = null; + } + + if (_channelThread != null) + { + if (_channelThread.IsAlive) + _channelThread.Abort(); + _channelThread = null; + } + if (_channel != null) + { + _channel.Dispose(); + _channel = null; + } + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(2000, 3000); + _localPacketSize = (uint) random.Next(1000, 2000); + _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); + _remoteWindowSize = (uint) random.Next(0, int.MaxValue); + _remotePacketSize = (uint) random.Next(100, 200); + _channelBindFinishedWaitHandle = new ManualResetEvent(false); + _channelException = null; + _connectedRegister = new List(); + _disconnectedRegister = new List(); + _connectionInfoTimeout = TimeSpan.FromSeconds(5); + + _remoteEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + _forwardedPortMock = new Mock(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( + 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(m => m.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence) + .Setup( + p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + w.WaitOne(); + }); + + _remoteListener = new AsyncSocketListener(_remoteEndpoint); + _remoteListener.Connected += socket => _connectedRegister.Add(socket); + _remoteListener.Disconnected += socket => _disconnectedRegister.Add(socket); + _remoteListener.Start(); + + _channel = new ChannelForwardedTcpip( + _sessionMock.Object, + _localChannelNumber, + _localWindowSize, + _localPacketSize, + _remoteChannelNumber, + _remoteWindowSize, + _remotePacketSize); + + _channelThread = new Thread(() => + { + try + { + _channel.Bind(_remoteEndpoint, _forwardedPortMock.Object); + } + catch (Exception ex) + { + _channelException = ex; + } + finally + { + _channelBindFinishedWaitHandle.Set(); + } + }); + _channelThread.Start(); + + // give channel time to bind to remote endpoint + Thread.Sleep(100); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void ChannelShouldShutdownSocketToRemoteListener() + { + Assert.AreEqual(1, _connectedRegister.Count); + Assert.AreEqual(1, _disconnectedRegister.Count); + Assert.AreSame(_connectedRegister[0], _disconnectedRegister[0]); + } + + [TestMethod] + public void BindShouldHaveFinishedWithoutException() + { + Assert.IsTrue(_channelBindFinishedWaitHandle.WaitOne(0)); + Assert.IsNull(_channelException, _channelException != null ? _channelException.ToString() : null); + } + + [TestMethod] + public void ChannelEofMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ChannelCloseMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs index f6c12fe0..d115681a 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_Closed.cs @@ -1,144 +1,144 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_Closed - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ChannelSession _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private uint _remoteChannelNumber; - private SemaphoreLight _sessionSemaphore; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(2000, 3000); - _localPacketSize = (uint)random.Next(1000, 2000); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(100, 200); - _sessionSemaphore = new SemaphoreLight(1); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - 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(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence) - .Setup(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - w.WaitOne(); - }); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - _channel.Close(); - } - - protected virtual void Act() - { - _channel.Close(); - } - - internal ChannelSession Channel - { - get { return _channel; } - } - - [TestMethod] - public void ChannelEofMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ChannelCloseMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_Closed + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ChannelSession _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private uint _remoteChannelNumber; + private SemaphoreLight _sessionSemaphore; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(2000, 3000); + _localPacketSize = (uint)random.Next(1000, 2000); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(100, 200); + _sessionSemaphore = new SemaphoreLight(1); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + 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(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence) + .Setup(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + w.WaitOne(); + }); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + _channel.Close(); + } + + protected virtual void Act() + { + _channel.Close(); + } + + internal ChannelSession Channel + { + get { return _channel; } + } + + [TestMethod] + public void ChannelEofMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ChannelCloseMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs index 622d87f0..e99818dc 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure.cs @@ -1,131 +1,131 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(false); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageFailure + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(false); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs index 128f5f1b..5b05fbf0 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess.cs @@ -1,131 +1,131 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(0, int.MaxValue); - _localPacketSize = (uint) random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); - _remoteWindowSize = (uint) random.Next(0, int.MaxValue); - _remotePacketSize = (uint) random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived_SendChannelCloseMessageSuccess + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(0, int.MaxValue); + _localPacketSize = (uint) random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); + _remoteWindowSize = (uint) random.Next(0, int.MaxValue); + _remotePacketSize = (uint) random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs index e4e1c60f..31c13338 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure.cs @@ -1,128 +1,128 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(false); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageFailure + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(false); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs index 7772248c..5c950564 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess.cs @@ -1,128 +1,128 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(0, int.MaxValue); - _localPacketSize = (uint) random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); - _remoteWindowSize = (uint) random.Next(0, int.MaxValue); - _remotePacketSize = (uint) random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelCloseReceived_SendChannelCloseMessageSuccess + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(0, int.MaxValue); + _localPacketSize = (uint) random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); + _remoteWindowSize = (uint) random.Next(0, int.MaxValue); + _remotePacketSize = (uint) random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs index 6165fe9a..2aa4f832 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure.cs @@ -1,127 +1,127 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(false); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageFailure + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(false); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs index 7345554a..383a4ff5 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess.cs @@ -1,138 +1,138 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(0, int.MaxValue); - _localPacketSize = (uint) random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); - _remoteWindowSize = (uint) random.Next(0, int.MaxValue); - _remotePacketSize = (uint) random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - w.WaitOne(); - }); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_ChannelEofReceived_SendChannelCloseMessageSuccess + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(0, int.MaxValue); + _localPacketSize = (uint) random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); + _remoteWindowSize = (uint) random.Next(0, int.MaxValue); + _remotePacketSize = (uint) random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + w.WaitOne(); + }); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs index 6a24a6ed..bc294c29 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs @@ -1,142 +1,142 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ChannelSession _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private uint _remoteChannelNumber; - private SemaphoreLight _sessionSemaphore; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(2000, 3000); - _localPacketSize = (uint)random.Next(1000, 2000); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(100, 200); - _sessionSemaphore = new SemaphoreLight(1); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - 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(m => m.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence) - .Setup( - p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - w.WaitOne(); - }); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void ChannelEofMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ChannelCloseMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ChannelSession _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private uint _remoteChannelNumber; + private SemaphoreLight _sessionSemaphore; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(2000, 3000); + _localPacketSize = (uint)random.Next(1000, 2000); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(100, 200); + _sessionSemaphore = new SemaphoreLight(1); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + 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(m => m.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence) + .Setup( + p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + w.WaitOne(); + }); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void ChannelEofMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ChannelCloseMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs index 705fcd29..8f53f68b 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure.cs @@ -1,142 +1,142 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ChannelSession _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private uint _remoteChannelNumber; - private SemaphoreLight _sessionSemaphore; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(2000, 3000); - _localPacketSize = (uint)random.Next(1000, 2000); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(100, 200); - _sessionSemaphore = new SemaphoreLight(1); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - 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(m => m.LocalChannelNumber == _remoteChannelNumber))) - .Returns(false); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence) - .Setup( - p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - w.WaitOne(); - }); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void ChannelEofMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ChannelCloseMessageShouldBeSentOnce() - { - _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived_SendChannelEofMessageFailure + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ChannelSession _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private uint _remoteChannelNumber; + private SemaphoreLight _sessionSemaphore; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(2000, 3000); + _localPacketSize = (uint)random.Next(1000, 2000); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(100, 200); + _sessionSemaphore = new SemaphoreLight(1); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + 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(m => m.LocalChannelNumber == _remoteChannelNumber))) + .Returns(false); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence) + .Setup( + p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + w.WaitOne(); + }); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void ChannelEofMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ChannelCloseMessageShouldBeSentOnce() + { + _sessionMock.Verify(p => p.TrySendMessage(It.Is(m => m.LocalChannelNumber == _remoteChannelNumber)), Times.Once); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs index 91eadd47..16e21508 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived.cs @@ -1,127 +1,127 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseAndChannelEofReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs index 31ef71b3..3a1a94af 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived.cs @@ -1,124 +1,124 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_ChannelCloseReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs index 54098e9c..050a6ec6 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived.cs @@ -1,119 +1,119 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldNotHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Close_SessionIsNotConnectedAndChannelIsOpen_NoChannelCloseOrChannelEofReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldNotHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs index ff7f6b6c..af9361f3 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Disposed_Closed.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Disposed_Closed : ChannelSessionTest_Close_Closed - { - protected override void Act() - { - Channel.Dispose(); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Disposed_Closed : ChannelSessionTest_Close_Closed + { + protected override void Act() + { + Channel.Dispose(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs index db23916e..9e0df191 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen.cs @@ -1,126 +1,126 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private ChannelSession _channel; - private Mock _connectionInfoMock; - private MockSequence _sequence; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(0, int.MaxValue); - _localPacketSize = (uint) random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); - _remoteWindowSize = (uint) random.Next(0, int.MaxValue); - _remotePacketSize = (uint) random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(_sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(_sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence) - .Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.Open(); - } - - private void Act() - { - _sessionMock.Raise( - p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } -} +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private ChannelSession _channel; + private Mock _connectionInfoMock; + private MockSequence _sequence; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(0, int.MaxValue); + _localPacketSize = (uint) random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); + _remoteWindowSize = (uint) random.Next(0, int.MaxValue); + _remotePacketSize = (uint) random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(_sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(_sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(_sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence) + .Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.Open(); + } + + private void Act() + { + _sessionMock.Raise( + p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation.cs index 35b63a42..54733501 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation.cs @@ -1,114 +1,114 @@ -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; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ChannelSession _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - private Exception _waitOnConfirmationException; - private SystemException _actualException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(2000, 3000); - _localPacketSize = (uint)random.Next(1000, 2000); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _waitOnConfirmationException = new SystemException(); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(2); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Throws(_waitOnConfirmationException); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - } - - private void Act() - { - try - { - _channel.Open(); - } - catch (SystemException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void OpenShouldHaveRethrownExceptionThrownByWaitOnHandle() - { - - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } +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; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Open_ExceptionWaitingOnOpenConfirmation + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ChannelSession _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + private Exception _waitOnConfirmationException; + private SystemException _actualException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(2000, 3000); + _localPacketSize = (uint)random.Next(1000, 2000); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _waitOnConfirmationException = new SystemException(); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(2); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Throws(_waitOnConfirmationException); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + } + + private void Act() + { + try + { + _channel.Open(); + } + catch (SystemException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void OpenShouldHaveRethrownExceptionThrownByWaitOnHandle() + { + + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable.cs index 2225de3f..870d8caa 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable.cs @@ -1,139 +1,139 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ChannelSession _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - private uint _failureReasonCode; - private string _failureDescription; - private string _failureLanguage; - private SshException _actualException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(2000, 3000); - _localPacketSize = (uint) random.Next(1000, 2000); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _actualException = null; - - _failureReasonCode = (uint)random.Next(0, int.MaxValue); - _failureDescription = random.Next().ToString(CultureInfo.InvariantCulture); - _failureLanguage = random.Next().ToString(CultureInfo.InvariantCulture); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenFailureReceived += null, - new MessageEventArgs( - new ChannelOpenFailureMessage( - _localChannelNumber, - _failureDescription, - _failureReasonCode, - _failureLanguage - ))); - w.WaitOne(); - }); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - } - - private void Act() - { - try - { - _channel.Open(); - } - catch (SshException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void OpenShouldHaveThrownSshException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(typeof (SshException), _actualException.GetType()); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("Failed to open a channel after 1 attempts.", _actualException.Message); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Open_OnOpenFailureReceived_NoRetriesAvailable + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ChannelSession _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + private uint _failureReasonCode; + private string _failureDescription; + private string _failureLanguage; + private SshException _actualException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(2000, 3000); + _localPacketSize = (uint) random.Next(1000, 2000); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _actualException = null; + + _failureReasonCode = (uint)random.Next(0, int.MaxValue); + _failureDescription = random.Next().ToString(CultureInfo.InvariantCulture); + _failureLanguage = random.Next().ToString(CultureInfo.InvariantCulture); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenFailureReceived += null, + new MessageEventArgs( + new ChannelOpenFailureMessage( + _localChannelNumber, + _failureDescription, + _failureReasonCode, + _failureLanguage + ))); + w.WaitOne(); + }); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + } + + private void Act() + { + try + { + _channel.Open(); + } + catch (SshException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void OpenShouldHaveThrownSshException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(typeof (SshException), _actualException.GetType()); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("Failed to open a channel after 1 attempts.", _actualException.Message); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeEqualToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable.cs index db48b52b..4b1edc1d 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable.cs @@ -1,152 +1,152 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ChannelSession _channel; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private List _channelExceptionRegister; - private SemaphoreLight _sessionSemaphore; - private int _initialSessionSemaphoreCount; - private uint _failureReasonCode; - private string _failureDescription; - private string _failureLanguage; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(2000, 3000); - _localPacketSize = (uint)random.Next(1000, 2000); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _initialSessionSemaphoreCount = random.Next(10, 20); - _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _failureReasonCode = (uint)random.Next(0, int.MaxValue); - _failureDescription = random.Next().ToString(CultureInfo.InvariantCulture); - _failureLanguage = random.Next().ToString(CultureInfo.InvariantCulture); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(2); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenFailureReceived += null, - new MessageEventArgs( - new ChannelOpenFailureMessage( - _localChannelNumber, - _failureDescription, - _failureReasonCode, - _failureLanguage - ))); - w.WaitOne(); - }); - _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(2); - _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); - _sessionMock.InSequence(sequence) - .Setup( - p => - p.SendMessage( - It.Is( - m => - m.LocalChannelNumber == _localChannelNumber && - m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && - m.Info is SessionChannelOpenInfo))); - _sessionMock.InSequence(sequence) - .Setup(p => p.WaitOnHandle(It.IsNotNull())) - .Callback( - w => - { - _sessionMock.Raise( - s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage( - _localChannelNumber, - _remoteWindowSize, - _remotePacketSize, - _remoteChannelNumber))); - w.WaitOne(); - }); - - _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - } - - private void Act() - { - _channel.Open(); - } - - [TestMethod] - public void CurrentCountOfSessionSemaphoreShouldBeOneLessThanToInitialCount() - { - Assert.AreEqual(_initialSessionSemaphoreCount - 1, _sessionSemaphore.CurrentCount); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrue() - { - Assert.IsTrue(_channel.IsOpen); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelSessionTest_Open_OnOpenFailureReceived_RetriesAvalable + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ChannelSession _channel; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private List _channelExceptionRegister; + private SemaphoreLight _sessionSemaphore; + private int _initialSessionSemaphoreCount; + private uint _failureReasonCode; + private string _failureDescription; + private string _failureLanguage; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(2000, 3000); + _localPacketSize = (uint)random.Next(1000, 2000); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _initialSessionSemaphoreCount = random.Next(10, 20); + _sessionSemaphore = new SemaphoreLight(_initialSessionSemaphoreCount); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _failureReasonCode = (uint)random.Next(0, int.MaxValue); + _failureDescription = random.Next().ToString(CultureInfo.InvariantCulture); + _failureLanguage = random.Next().ToString(CultureInfo.InvariantCulture); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(2); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenFailureReceived += null, + new MessageEventArgs( + new ChannelOpenFailureMessage( + _localChannelNumber, + _failureDescription, + _failureReasonCode, + _failureLanguage + ))); + w.WaitOne(); + }); + _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(2); + _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore); + _sessionMock.InSequence(sequence) + .Setup( + p => + p.SendMessage( + It.Is( + m => + m.LocalChannelNumber == _localChannelNumber && + m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize && + m.Info is SessionChannelOpenInfo))); + _sessionMock.InSequence(sequence) + .Setup(p => p.WaitOnHandle(It.IsNotNull())) + .Callback( + w => + { + _sessionMock.Raise( + s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage( + _localChannelNumber, + _remoteWindowSize, + _remotePacketSize, + _remoteChannelNumber))); + w.WaitOne(); + }); + + _channel = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + } + + private void Act() + { + _channel.Open(); + } + + [TestMethod] + public void CurrentCountOfSessionSemaphoreShouldBeOneLessThanToInitialCount() + { + Assert.AreEqual(_initialSessionSemaphoreCount - 1, _sessionSemaphore.CurrentCount); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrue() + { + Assert.IsTrue(_channel.IsOpen); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelStub.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelStub.cs index 80166651..ac141b9b 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelStub.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelStub.cs @@ -1,140 +1,140 @@ -using System; -using System.Collections.Generic; -using Renci.SshNet.Channels; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - internal class ChannelStub : Channel - { - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - public ChannelStub(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - OnErrorOccurredInvocations = new List(); - } - - public override ChannelTypes ChannelType - { - get { return ChannelTypes.X11; } - } - - public IList OnErrorOccurredInvocations { get; private set; } - - public Exception OnCloseException { get; set; } - - public Exception OnDataException { get; set; } - - public Exception OnDisconnectedException { get; set; } - - public Exception OnEofException{ get; set; } - - public Exception OnErrorOccurredException { get; set; } - - public Exception OnExtendedDataException { get; set; } - - public Exception OnFailureException { get; set; } - - public Exception OnRequestException { get; set; } - - public Exception OnSuccessException { get; set; } - - public Exception OnWindowAdjustException { get; set; } - - public void SetIsOpen(bool value) - { - IsOpen = value; - } - - public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - { - base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); - } - - protected override void OnClose() - { - base.OnClose(); - - if (OnCloseException != null) - throw OnCloseException; - } - - protected override void OnData(byte[] data) - { - base.OnData(data); - - if (OnDataException != null) - throw OnDataException; - } - - protected override void OnDisconnected() - { - base.OnDisconnected(); - - if (OnDisconnectedException != null) - throw OnDisconnectedException; - } - - protected override void OnEof() - { - base.OnEof(); - - if (OnEofException != null) - throw OnEofException; - } - - protected override void OnExtendedData(byte[] data, uint dataTypeCode) - { - base.OnExtendedData(data, dataTypeCode); - - if (OnExtendedDataException != null) - throw OnExtendedDataException; - } - - protected override void OnErrorOccured(Exception exp) - { - OnErrorOccurredInvocations.Add(exp); - - if (OnErrorOccurredException != null) - throw OnErrorOccurredException; - } - - protected override void OnFailure() - { - base.OnFailure(); - - if (OnFailureException != null) - throw OnFailureException; - } - - protected override void OnRequest(RequestInfo info) - { - base.OnRequest(info); - - if (OnRequestException != null) - throw OnRequestException; - } - - protected override void OnSuccess() - { - base.OnSuccess(); - - if (OnSuccessException != null) - throw OnSuccessException; - } - - protected override void OnWindowAdjust(uint bytesToAdd) - { - base.OnWindowAdjust(bytesToAdd); - - if (OnWindowAdjustException != null) - throw OnWindowAdjustException; - } - } -} +using System; +using System.Collections.Generic; +using Renci.SshNet.Channels; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + internal class ChannelStub : Channel + { + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + public ChannelStub(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + OnErrorOccurredInvocations = new List(); + } + + public override ChannelTypes ChannelType + { + get { return ChannelTypes.X11; } + } + + public IList OnErrorOccurredInvocations { get; private set; } + + public Exception OnCloseException { get; set; } + + public Exception OnDataException { get; set; } + + public Exception OnDisconnectedException { get; set; } + + public Exception OnEofException{ get; set; } + + public Exception OnErrorOccurredException { get; set; } + + public Exception OnExtendedDataException { get; set; } + + public Exception OnFailureException { get; set; } + + public Exception OnRequestException { get; set; } + + public Exception OnSuccessException { get; set; } + + public Exception OnWindowAdjustException { get; set; } + + public void SetIsOpen(bool value) + { + IsOpen = value; + } + + public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + { + base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); + } + + protected override void OnClose() + { + base.OnClose(); + + if (OnCloseException != null) + throw OnCloseException; + } + + protected override void OnData(byte[] data) + { + base.OnData(data); + + if (OnDataException != null) + throw OnDataException; + } + + protected override void OnDisconnected() + { + base.OnDisconnected(); + + if (OnDisconnectedException != null) + throw OnDisconnectedException; + } + + protected override void OnEof() + { + base.OnEof(); + + if (OnEofException != null) + throw OnEofException; + } + + protected override void OnExtendedData(byte[] data, uint dataTypeCode) + { + base.OnExtendedData(data, dataTypeCode); + + if (OnExtendedDataException != null) + throw OnExtendedDataException; + } + + protected override void OnErrorOccured(Exception exp) + { + OnErrorOccurredInvocations.Add(exp); + + if (OnErrorOccurredException != null) + throw OnErrorOccurredException; + } + + protected override void OnFailure() + { + base.OnFailure(); + + if (OnFailureException != null) + throw OnFailureException; + } + + protected override void OnRequest(RequestInfo info) + { + base.OnRequest(info); + + if (OnRequestException != null) + throw OnRequestException; + } + + protected override void OnSuccess() + { + base.OnSuccess(); + + if (OnSuccessException != null) + throw OnSuccessException; + } + + protected override void OnWindowAdjust(uint bytesToAdd) + { + base.OnWindowAdjust(bytesToAdd); + + if (OnWindowAdjustException != null) + throw OnWindowAdjustException; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs index a90e4d89..0dcaa177 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private Channel _channel; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(true); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void SendMessageOnSessionShouldNeverBeInvoked() - { - _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_Close_SessionIsConnectedAndChannelIsNotOpen + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private Channel _channel; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(true); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void SendMessageOnSessionShouldNeverBeInvoked() + { + _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs index 54c286bc..29ae3ed2 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs @@ -1,137 +1,137 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private Stopwatch _closeTimer; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _closeTimer = new Stopwatch(); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(w => - { - new Thread(() => - { - Thread.Sleep(100); - // raise ChannelCloseReceived event to set waithandle for receiving - // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after - // sending the SSH_MSG_CHANNEL_CLOSE message to the server - _sessionMock.Raise(s => s.ChannelCloseReceived += null, - new MessageEventArgs( - new ChannelCloseMessage(_localChannelNumber))); - }).Start(); - _closeTimer.Start(); - try - { - w.WaitOne(); - } - finally - { - _closeTimer.Stop(); - } - }); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelEofMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldWaitForChannelCloseMessageToBeReceived() - { - Assert.IsTrue(_closeTimer.ElapsedMilliseconds >= 100, "Elapsed milliseconds=" + _closeTimer.ElapsedMilliseconds); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private Stopwatch _closeTimer; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _closeTimer = new Stopwatch(); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(w => + { + new Thread(() => + { + Thread.Sleep(100); + // raise ChannelCloseReceived event to set waithandle for receiving + // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after + // sending the SSH_MSG_CHANNEL_CLOSE message to the server + _sessionMock.Raise(s => s.ChannelCloseReceived += null, + new MessageEventArgs( + new ChannelCloseMessage(_localChannelNumber))); + }).Start(); + _closeTimer.Start(); + try + { + w.WaitOne(); + } + finally + { + _closeTimer.Stop(); + } + }); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelEofMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldWaitForChannelCloseMessageToBeReceived() + { + Assert.IsTrue(_closeTimer.ElapsedMilliseconds >= 100, "Elapsed milliseconds=" + _closeTimer.ElapsedMilliseconds); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs index 9a9e9b7e..9b9b2a94 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked.cs @@ -1,137 +1,137 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private Stopwatch _closeTimer; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _closeTimer = new Stopwatch(); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(w => - { - new Thread(() => - { - Thread.Sleep(100); - // raise ChannelCloseReceived event to set waithandle for receiving - // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after - // sending the SSH_MSG_CHANNEL_CLOSE message to the server - _sessionMock.Raise(s => s.ChannelCloseReceived += null, - new MessageEventArgs( - new ChannelCloseMessage(_localChannelNumber))); - }).Start(); - _closeTimer.Start(); - try - { - w.WaitOne(); - } - finally - { - _closeTimer.Stop(); - } - }); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - _channel.SendEof(); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void SendMessageOnSessionShouldBeInvokedOnceForChannelEofMessage() - { - _sessionMock.Verify( - p => p.SendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldWaitForChannelCloseMessageToBeReceived() - { - Assert.IsTrue(_closeTimer.ElapsedMilliseconds >= 100, "Elapsed milliseconds=" + _closeTimer.ElapsedMilliseconds); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofNotReceived_SendEofInvoked + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private Stopwatch _closeTimer; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _closeTimer = new Stopwatch(); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(w => + { + new Thread(() => + { + Thread.Sleep(100); + // raise ChannelCloseReceived event to set waithandle for receiving + // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after + // sending the SSH_MSG_CHANNEL_CLOSE message to the server + _sessionMock.Raise(s => s.ChannelCloseReceived += null, + new MessageEventArgs( + new ChannelCloseMessage(_localChannelNumber))); + }).Start(); + _closeTimer.Start(); + try + { + w.WaitOne(); + } + finally + { + _closeTimer.Stop(); + } + }); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + _channel.SendEof(); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void SendMessageOnSessionShouldBeInvokedOnceForChannelEofMessage() + { + _sessionMock.Verify( + p => p.SendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldWaitForChannelCloseMessageToBeReceived() + { + Assert.IsTrue(_closeTimer.ElapsedMilliseconds >= 100, "Elapsed milliseconds=" + _closeTimer.ElapsedMilliseconds); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs index 6004195d..3dcca350 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived.cs @@ -1,139 +1,139 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private Stopwatch _closeTimer; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _closeTimer = new Stopwatch(); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(w => - { - new Thread(() => - { - Thread.Sleep(100); - // raise ChannelCloseReceived event to set waithandle for receiving - // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after - // sending the SSH_MSG_CHANNEL_CLOSE message to the server - _sessionMock.Raise(s => s.ChannelCloseReceived += null, - new MessageEventArgs( - new ChannelCloseMessage(_localChannelNumber))); - }).Start(); - _closeTimer.Start(); - try - { - w.WaitOne(); - } - finally - { - _closeTimer.Stop(); - } - }); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - - _sessionMock.Raise( - s => s.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Never); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldWaitForChannelCloseMessageToBeReceived() - { - Assert.IsTrue(_closeTimer.ElapsedMilliseconds >= 100, "Elapsed milliseconds=" + _closeTimer.ElapsedMilliseconds); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_Close_SessionIsConnectedAndChannelIsOpen_EofReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private Stopwatch _closeTimer; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _closeTimer = new Stopwatch(); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + _sessionMock.InSequence(sequence).Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(w => + { + new Thread(() => + { + Thread.Sleep(100); + // raise ChannelCloseReceived event to set waithandle for receiving + // SSH_MSG_CHANNEL_CLOSE message from server which is waited on after + // sending the SSH_MSG_CHANNEL_CLOSE message to the server + _sessionMock.Raise(s => s.ChannelCloseReceived += null, + new MessageEventArgs( + new ChannelCloseMessage(_localChannelNumber))); + }).Start(); + _closeTimer.Start(); + try + { + w.WaitOne(); + } + finally + { + _closeTimer.Stop(); + } + }); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + + _sessionMock.Raise( + s => s.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Never); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Once); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldWaitForChannelCloseMessageToBeReceived() + { + Assert.IsTrue(_closeTimer.ElapsedMilliseconds >= 100, "Elapsed milliseconds=" + _closeTimer.ElapsedMilliseconds); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs index c069faff..880ce65f 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private Channel _channel; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(0, int.MaxValue); - _localPacketSize = (uint) random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void SendMessageOnSessionShouldNeverBeInvoked() - { - _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsNotOpen + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private Channel _channel; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(0, int.MaxValue); + _localPacketSize = (uint) random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void SendMessageOnSessionShouldNeverBeInvoked() + { + _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs index b6320855..159ebdc9 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.SetIsOpen(true); - } - - private void Act() - { - _channel.Close(); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void SendMessageOnSessionShouldNeverBeInvoked() - { - _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_Close_SessionIsNotConnectedAndChannelIsOpen + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.SetIsOpen(true); + } + + private void Act() + { + _channel.Close(); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void SendMessageOnSessionShouldNeverBeInvoked() + { + _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs index f0be628d..9830be3a 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onCloseException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onCloseException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnCloseException = _onCloseException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onCloseException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onCloseException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelCloseReceived_OnClose_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onCloseException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onCloseException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnCloseException = _onCloseException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onCloseException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onCloseException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs index 697319ac..ab3c73d7 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived.cs @@ -1,103 +1,103 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private IList _channelExceptionRegister; - private ChannelStub _channel; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - } - - private void Act() - { - _sessionMock.Raise(p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Never); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldNeverBeInvoked() - { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Never); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofNotReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private IList _channelExceptionRegister; + private ChannelStub _channel; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))).Returns(true); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + } + + private void Act() + { + _sessionMock.Raise(p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Never); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldNeverBeInvoked() + { + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Never); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs index 98dde788..be1dfe28 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived.cs @@ -1,108 +1,108 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private IList _channelClosedRegister; - private IList _channelExceptionRegister; - private ChannelStub _channel; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) - .Returns(true); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - - _sessionMock.Raise(p => p.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - } - - private void Act() - { - _sessionMock.Raise(p => p.ChannelCloseReceived += null, - new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void SendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() - { - _sessionMock.Verify( - p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), - Times.Never); - } - - [TestMethod] - public void WaitOnHandleOnSessionShouldNeverBeInvoked() - { - _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Never); - } - - [TestMethod] - public void ClosedEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelClosedRegister.Count); - Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelCloseReceived_SessionIsConnectedAndChannelIsOpen_EofReceived + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private IList _channelClosedRegister; + private IList _channelExceptionRegister; + private ChannelStub _channel; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber))) + .Returns(true); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + + _sessionMock.Raise(p => p.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + } + + private void Act() + { + _sessionMock.Raise(p => p.ChannelCloseReceived += null, + new MessageEventArgs(new ChannelCloseMessage(_localChannelNumber))); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void TrySendMessageOnSessionShouldBeInvokedOnceForChannelCloseMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void SendMessageOnSessionShouldNeverBeInvokedForChannelEofMessage() + { + _sessionMock.Verify( + p => p.TrySendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumber)), + Times.Never); + } + + [TestMethod] + public void WaitOnHandleOnSessionShouldNeverBeInvoked() + { + _sessionMock.Verify(p => p.WaitOnHandle(It.IsAny()), Times.Never); + } + + [TestMethod] + public void ClosedEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelClosedRegister.Count); + Assert.AreEqual(_localChannelNumber, _channelClosedRegister[0].ChannelNumber); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs index 7768e393..6e1b4479 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelDataReceived_OnData_Exception.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelDataReceived_OnData_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onDataException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onDataException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnDataException = _onDataException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelDataReceived += null, - new MessageEventArgs(new ChannelDataMessage(_localChannelNumber, new byte[0]))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onDataException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onDataException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelDataReceived_OnData_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onDataException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onDataException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnDataException = _onDataException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelDataReceived += null, + new MessageEventArgs(new ChannelDataMessage(_localChannelNumber, new byte[0]))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onDataException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onDataException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs index 100c088f..ea2ff46e 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs @@ -1,72 +1,72 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelEofReceived_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onEofException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(0, 1000); - _localPacketSize = (uint)random.Next(1001, int.MaxValue); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _onEofException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - _channel.OnEofException = _onEofException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelEofReceived += null, - new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onEofException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onEofException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelEofReceived_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onEofException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(0, 1000); + _localPacketSize = (uint)random.Next(1001, int.MaxValue); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _onEofException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + _channel.OnEofException = _onEofException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelEofReceived += null, + new MessageEventArgs(new ChannelEofMessage(_localChannelNumber))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onEofException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onEofException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs index dec9bca3..fccb0081 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onExtendedDataException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onExtendedDataException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnExtendedDataException = _onExtendedDataException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelExtendedDataReceived += null, - new MessageEventArgs(new ChannelExtendedDataMessage(_localChannelNumber, 5, new byte[0]))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onExtendedDataException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onExtendedDataException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelExtendedDataReceived_OnExtendedData_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onExtendedDataException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onExtendedDataException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnExtendedDataException = _onExtendedDataException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelExtendedDataReceived += null, + new MessageEventArgs(new ChannelExtendedDataMessage(_localChannelNumber, 5, new byte[0]))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onExtendedDataException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onExtendedDataException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs index c446d9c3..76a9c8ad 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onFailureException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(0, 1000); - _localPacketSize = (uint)random.Next(1001, int.MaxValue); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onFailureException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnFailureException = _onFailureException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelFailureReceived += null, - new MessageEventArgs(new ChannelFailureMessage(_localChannelNumber))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onFailureException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onFailureException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelFailureReceived_OnFailure_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onFailureException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(0, 1000); + _localPacketSize = (uint)random.Next(1001, int.MaxValue); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onFailureException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnFailureException = _onFailureException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelFailureReceived += null, + new MessageEventArgs(new ChannelFailureMessage(_localChannelNumber))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onFailureException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onFailureException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs index 38006775..bcb59532 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception.cs @@ -1,68 +1,68 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onRequestException; - private SignalRequestInfo _requestInfo; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onRequestException = new SystemException(); - _channelExceptionRegister = new List(); - _requestInfo = new SignalRequestInfo("ABC"); - - _sessionMock = new Mock(MockBehavior.Strict); - _sessionMock.Setup(p => p.ConnectionInfo) - .Returns(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "password"))); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnRequestException = _onRequestException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelRequestReceived += null, - new MessageEventArgs(new ChannelRequestMessage(_localChannelNumber, _requestInfo))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onRequestException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onRequestException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelRequestReceived_OnRequest_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onRequestException; + private SignalRequestInfo _requestInfo; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onRequestException = new SystemException(); + _channelExceptionRegister = new List(); + _requestInfo = new SignalRequestInfo("ABC"); + + _sessionMock = new Mock(MockBehavior.Strict); + _sessionMock.Setup(p => p.ConnectionInfo) + .Returns(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "password"))); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnRequestException = _onRequestException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelRequestReceived += null, + new MessageEventArgs(new ChannelRequestMessage(_localChannelNumber, _requestInfo))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onRequestException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onRequestException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs index 83337bac..4bc8e849 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onSuccessException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, 1000); - _localPacketSize = (uint)random.Next(1001, int.MaxValue); - _onSuccessException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnSuccessException = _onSuccessException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelSuccessReceived += null, - new MessageEventArgs(new ChannelSuccessMessage(_localChannelNumber))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onSuccessException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onSuccessException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelSuccessReceived_OnSuccess_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onSuccessException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, 1000); + _localPacketSize = (uint)random.Next(1001, int.MaxValue); + _onSuccessException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnSuccessException = _onSuccessException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelSuccessReceived += null, + new MessageEventArgs(new ChannelSuccessMessage(_localChannelNumber))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onSuccessException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onSuccessException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs index b692c583..e4e0b863 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception.cs @@ -1,73 +1,73 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onWindowAdjustException; - private uint _bytesToAdd; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(1000, int.MaxValue); - _remotePacketSize = _localWindowSize - 1; - _bytesToAdd = (uint)random.Next(0, int.MaxValue); - _onWindowAdjustException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnWindowAdjustException = _onWindowAdjustException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelWindowAdjustReceived += null, - new MessageEventArgs(new ChannelWindowAdjustMessage(_localChannelNumber, _bytesToAdd))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onWindowAdjustException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onWindowAdjustException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionChannelWindowAdjustReceived_OnWindowAdjust_Exception + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onWindowAdjustException; + private uint _bytesToAdd; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(1000, int.MaxValue); + _remotePacketSize = _localWindowSize - 1; + _bytesToAdd = (uint)random.Next(0, int.MaxValue); + _onWindowAdjustException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnWindowAdjustException = _onWindowAdjustException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelWindowAdjustReceived += null, + new MessageEventArgs(new ChannelWindowAdjustMessage(_localChannelNumber, _bytesToAdd))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onWindowAdjustException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onWindowAdjustException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs index a268d12c..e570a215 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs @@ -1,62 +1,62 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionDisconnected_OnDisconnected_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onDisconnectedException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onDisconnectedException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnDisconnectedException = _onDisconnectedException; - } - - private void Act() - { - _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onDisconnectedException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onDisconnectedException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionDisconnected_OnDisconnected_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onDisconnectedException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onDisconnectedException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnDisconnectedException = _onDisconnectedException; + } + + private void Act() + { + _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onDisconnectedException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onDisconnectedException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs index cd273f17..c5c890b9 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(true); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - } - - private void Act() - { - _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(true); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + } + + private void Act() + { + _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs index 8fb9df45..21e8d91d 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs @@ -1,64 +1,64 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onErrorOccurredException; - private Exception _errorOccurredException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _onErrorOccurredException = new SystemException(); - _channelExceptionRegister = new List(); - _errorOccurredException = new SystemException(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnErrorOccurredException = _onErrorOccurredException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ErrorOccured += null, new ExceptionEventArgs(_errorOccurredException)); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onErrorOccurredException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_errorOccurredException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onErrorOccurredException; + private Exception _errorOccurredException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _onErrorOccurredException = new SystemException(); + _channelExceptionRegister = new List(); + _errorOccurredException = new SystemException(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnErrorOccurredException = _onErrorOccurredException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ErrorOccured += null, new ExceptionEventArgs(_errorOccurredException)); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onErrorOccurredException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_errorOccurredException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsNotOpen.cs index 852e2158..da712f4b 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsNotOpen.cs @@ -1,91 +1,91 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_SendEof_ChannelIsNotOpen - { - private Mock _sessionMock; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _localChannelNumber; - private ChannelStub _channel; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - private InvalidOperationException _actualException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - _actualException = null; - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - } - - private void Act() - { - try - { - _channel.SendEof(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_channel.IsOpen); - } - - [TestMethod] - public void SendEofShouldHaveThrownInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("The channel is closed.", _actualException.Message); - } - - [TestMethod] - public void SendMessageOnSessionShouldNeverBeInvoked() - { - _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_SendEof_ChannelIsNotOpen + { + private Mock _sessionMock; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _localChannelNumber; + private ChannelStub _channel; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + private InvalidOperationException _actualException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + _actualException = null; + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + } + + private void Act() + { + try + { + _channel.SendEof(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_channel.IsOpen); + } + + [TestMethod] + public void SendEofShouldHaveThrownInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("The channel is closed.", _actualException.Message); + } + + [TestMethod] + public void SendMessageOnSessionShouldNeverBeInvoked() + { + _sessionMock.Verify(p => p.SendMessage(It.IsAny()), Times.Never); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsOpen.cs b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsOpen.cs index 95fa35e1..9a28db11 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ChannelTest_SendEof_ChannelIsOpen.cs @@ -1,85 +1,85 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ChannelTest_SendEof_ChannelIsOpen - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private uint _remoteWindowSize; - private uint _remotePacketSize; - private ChannelStub _channel; - private List _channelClosedRegister; - private IList _channelExceptionRegister; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(0, int.MaxValue); - _localPacketSize = (uint)random.Next(0, int.MaxValue); - _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); - _remoteWindowSize = (uint)random.Next(0, int.MaxValue); - _remotePacketSize = (uint)random.Next(0, int.MaxValue); - _channelClosedRegister = new List(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.SendMessage(It.Is(e => e.LocalChannelNumber == _remoteChannelNumber))); - - _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); - _channel.SetIsOpen(true); - } - - private void Act() - { - _channel.SendEof(); - } - - [TestMethod] - public void IsOpenShouldReturnTrue() - { - Assert.IsTrue(_channel.IsOpen); - } - - [TestMethod] - public void SendMessageOnSessionShouldBeInvokedOnceWithChannelEofMessage() - { - _sessionMock.Verify( - p => p.SendMessage(It.Is(e => e.LocalChannelNumber == _remoteChannelNumber)), - Times.Once); - } - - [TestMethod] - public void ClosedEventShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelClosedRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNeverHaveFired() - { - Assert.AreEqual(0, _channelExceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ChannelTest_SendEof_ChannelIsOpen + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private uint _remoteWindowSize; + private uint _remotePacketSize; + private ChannelStub _channel; + private List _channelClosedRegister; + private IList _channelExceptionRegister; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(0, int.MaxValue); + _localPacketSize = (uint)random.Next(0, int.MaxValue); + _remoteChannelNumber = (uint)random.Next(0, int.MaxValue); + _remoteWindowSize = (uint)random.Next(0, int.MaxValue); + _remotePacketSize = (uint)random.Next(0, int.MaxValue); + _channelClosedRegister = new List(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.SendMessage(It.Is(e => e.LocalChannelNumber == _remoteChannelNumber))); + + _channel = new ChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Closed += (sender, args) => _channelClosedRegister.Add(args); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize); + _channel.SetIsOpen(true); + } + + private void Act() + { + _channel.SendEof(); + } + + [TestMethod] + public void IsOpenShouldReturnTrue() + { + Assert.IsTrue(_channel.IsOpen); + } + + [TestMethod] + public void SendMessageOnSessionShouldBeInvokedOnceWithChannelEofMessage() + { + _sessionMock.Verify( + p => p.SendMessage(It.Is(e => e.LocalChannelNumber == _remoteChannelNumber)), + Times.Once); + } + + [TestMethod] + public void ClosedEventShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelClosedRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNeverHaveFired() + { + Assert.AreEqual(0, _channelExceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelStub.cs b/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelStub.cs index c5ca49d5..621c4700 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelStub.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelStub.cs @@ -1,160 +1,160 @@ -using System; -using System.Collections.Generic; -using Renci.SshNet.Channels; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - internal class ClientChannelStub : ClientChannel - { - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - public ClientChannelStub(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - OnErrorOccurredInvocations = new List(); - } - - public override ChannelTypes ChannelType - { - get { return ChannelTypes.X11; } - } - - public IList OnErrorOccurredInvocations { get; private set; } - - public Exception OnCloseException { get; set; } - - public Exception OnDataException { get; set; } - - public Exception OnDisconnectedException { get; set; } - - public Exception OnEofException{ get; set; } - - public Exception OnErrorOccurredException { get; set; } - - public Exception OnExtendedDataException { get; set; } - - public Exception OnFailureException { get; set; } - - public Exception OnRequestException { get; set; } - - public Exception OnSuccessException { get; set; } - - public Exception OnWindowAdjustException { get; set; } - - public Exception OnOpenConfirmationException { get; set; } - - public Exception OnOpenFailureException { get; set; } - - public void SetIsOpen(bool value) - { - IsOpen = value; - } - - public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - { - base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); - } - - protected override void OnClose() - { - base.OnClose(); - - if (OnCloseException != null) - throw OnCloseException; - } - - protected override void OnData(byte[] data) - { - base.OnData(data); - - if (OnDataException != null) - throw OnDataException; - } - - protected override void OnDisconnected() - { - base.OnDisconnected(); - - if (OnDisconnectedException != null) - throw OnDisconnectedException; - } - - protected override void OnEof() - { - base.OnEof(); - - if (OnEofException != null) - throw OnEofException; - } - - protected override void OnExtendedData(byte[] data, uint dataTypeCode) - { - base.OnExtendedData(data, dataTypeCode); - - if (OnExtendedDataException != null) - throw OnExtendedDataException; - } - - protected override void OnErrorOccured(Exception exp) - { - OnErrorOccurredInvocations.Add(exp); - - if (OnErrorOccurredException != null) - throw OnErrorOccurredException; - } - - protected override void OnFailure() - { - base.OnFailure(); - - if (OnFailureException != null) - throw OnFailureException; - } - - protected override void OnRequest(RequestInfo info) - { - base.OnRequest(info); - - if (OnRequestException != null) - throw OnRequestException; - } - - protected override void OnSuccess() - { - base.OnSuccess(); - - if (OnSuccessException != null) - throw OnSuccessException; - } - - protected override void OnWindowAdjust(uint bytesToAdd) - { - base.OnWindowAdjust(bytesToAdd); - - if (OnWindowAdjustException != null) - throw OnWindowAdjustException; - } - - protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); - - if (OnOpenConfirmationException != null) - throw OnOpenConfirmationException; - } - - protected override void OnOpenFailure(uint reasonCode, string description, string language) - { - base.OnOpenFailure(reasonCode, description, language); - - if (OnOpenFailureException != null) - throw OnOpenFailureException; - } - } -} +using System; +using System.Collections.Generic; +using Renci.SshNet.Channels; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + internal class ClientChannelStub : ClientChannel + { + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + public ClientChannelStub(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + OnErrorOccurredInvocations = new List(); + } + + public override ChannelTypes ChannelType + { + get { return ChannelTypes.X11; } + } + + public IList OnErrorOccurredInvocations { get; private set; } + + public Exception OnCloseException { get; set; } + + public Exception OnDataException { get; set; } + + public Exception OnDisconnectedException { get; set; } + + public Exception OnEofException{ get; set; } + + public Exception OnErrorOccurredException { get; set; } + + public Exception OnExtendedDataException { get; set; } + + public Exception OnFailureException { get; set; } + + public Exception OnRequestException { get; set; } + + public Exception OnSuccessException { get; set; } + + public Exception OnWindowAdjustException { get; set; } + + public Exception OnOpenConfirmationException { get; set; } + + public Exception OnOpenFailureException { get; set; } + + public void SetIsOpen(bool value) + { + IsOpen = value; + } + + public void InitializeRemoteChannelInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + { + base.InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); + } + + protected override void OnClose() + { + base.OnClose(); + + if (OnCloseException != null) + throw OnCloseException; + } + + protected override void OnData(byte[] data) + { + base.OnData(data); + + if (OnDataException != null) + throw OnDataException; + } + + protected override void OnDisconnected() + { + base.OnDisconnected(); + + if (OnDisconnectedException != null) + throw OnDisconnectedException; + } + + protected override void OnEof() + { + base.OnEof(); + + if (OnEofException != null) + throw OnEofException; + } + + protected override void OnExtendedData(byte[] data, uint dataTypeCode) + { + base.OnExtendedData(data, dataTypeCode); + + if (OnExtendedDataException != null) + throw OnExtendedDataException; + } + + protected override void OnErrorOccured(Exception exp) + { + OnErrorOccurredInvocations.Add(exp); + + if (OnErrorOccurredException != null) + throw OnErrorOccurredException; + } + + protected override void OnFailure() + { + base.OnFailure(); + + if (OnFailureException != null) + throw OnFailureException; + } + + protected override void OnRequest(RequestInfo info) + { + base.OnRequest(info); + + if (OnRequestException != null) + throw OnRequestException; + } + + protected override void OnSuccess() + { + base.OnSuccess(); + + if (OnSuccessException != null) + throw OnSuccessException; + } + + protected override void OnWindowAdjust(uint bytesToAdd) + { + base.OnWindowAdjust(bytesToAdd); + + if (OnWindowAdjustException != null) + throw OnWindowAdjustException; + } + + protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); + + if (OnOpenConfirmationException != null) + throw OnOpenConfirmationException; + } + + protected override void OnOpenFailure(uint reasonCode, string description, string language) + { + base.OnOpenFailure(reasonCode, description, language); + + if (OnOpenFailureException != null) + throw OnOpenFailureException; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception.cs index 87dd22db..4f0b3cfa 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception.cs @@ -1,68 +1,68 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private uint _remoteChannelNumber; - private ClientChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onOpenConfirmationException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint) random.Next(0, int.MaxValue); - _localWindowSize = (uint) random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); - _onOpenConfirmationException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ClientChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnOpenConfirmationException = _onOpenConfirmationException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelOpenConfirmationReceived += null, - new MessageEventArgs( - new ChannelOpenConfirmationMessage(_localChannelNumber, _localWindowSize, _localPacketSize, - _remoteChannelNumber))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onOpenConfirmationException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onOpenConfirmationException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ClientChannelTest_OnSessionChannelOpenConfirmationReceived_OnOpenConfirmation_Exception + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private uint _remoteChannelNumber; + private ClientChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onOpenConfirmationException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint) random.Next(0, int.MaxValue); + _localWindowSize = (uint) random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _remoteChannelNumber = (uint) random.Next(0, int.MaxValue); + _onOpenConfirmationException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ClientChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnOpenConfirmationException = _onOpenConfirmationException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelOpenConfirmationReceived += null, + new MessageEventArgs( + new ChannelOpenConfirmationMessage(_localChannelNumber, _localWindowSize, _localPacketSize, + _remoteChannelNumber))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onOpenConfirmationException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onOpenConfirmationException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception.cs b/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception.cs index 2d44dcca..a7ccde35 100644 --- a/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/Channels/ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception.cs @@ -1,65 +1,65 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes.Channels -{ - [TestClass] - public class ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception - { - private Mock _sessionMock; - private uint _localChannelNumber; - private uint _localWindowSize; - private uint _localPacketSize; - private ClientChannelStub _channel; - private IList _channelExceptionRegister; - private Exception _onOpenFailureException; - - [TestInitialize] - public void Initialize() - { - Arrange(); - Act(); - } - - private void Arrange() - { - var random = new Random(); - _localChannelNumber = (uint)random.Next(0, int.MaxValue); - _localWindowSize = (uint)random.Next(1000, int.MaxValue); - _localPacketSize = _localWindowSize - 1; - _onOpenFailureException = new SystemException(); - _channelExceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _channel = new ClientChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); - _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); - _channel.OnOpenFailureException = _onOpenFailureException; - } - - private void Act() - { - _sessionMock.Raise(s => s.ChannelOpenFailureReceived += null, - new MessageEventArgs( - new ChannelOpenFailureMessage(_localChannelNumber, "", ChannelOpenFailureMessage.ConnectFailed))); - } - - [TestMethod] - public void ExceptionEventShouldHaveFiredOnce() - { - Assert.AreEqual(1, _channelExceptionRegister.Count); - Assert.AreSame(_onOpenFailureException, _channelExceptionRegister[0].Exception); - } - - [TestMethod] - public void OnErrorOccuredShouldBeInvokedOnce() - { - Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); - Assert.AreSame(_onOpenFailureException, _channel.OnErrorOccurredInvocations[0]); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes.Channels +{ + [TestClass] + public class ClientChannelTest_OnSessionChannelOpenFailureReceived_OnOpenFailure_Exception + { + private Mock _sessionMock; + private uint _localChannelNumber; + private uint _localWindowSize; + private uint _localPacketSize; + private ClientChannelStub _channel; + private IList _channelExceptionRegister; + private Exception _onOpenFailureException; + + [TestInitialize] + public void Initialize() + { + Arrange(); + Act(); + } + + private void Arrange() + { + var random = new Random(); + _localChannelNumber = (uint)random.Next(0, int.MaxValue); + _localWindowSize = (uint)random.Next(1000, int.MaxValue); + _localPacketSize = _localWindowSize - 1; + _onOpenFailureException = new SystemException(); + _channelExceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _channel = new ClientChannelStub(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize); + _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args); + _channel.OnOpenFailureException = _onOpenFailureException; + } + + private void Act() + { + _sessionMock.Raise(s => s.ChannelOpenFailureReceived += null, + new MessageEventArgs( + new ChannelOpenFailureMessage(_localChannelNumber, "", ChannelOpenFailureMessage.ConnectFailed))); + } + + [TestMethod] + public void ExceptionEventShouldHaveFiredOnce() + { + Assert.AreEqual(1, _channelExceptionRegister.Count); + Assert.AreSame(_onOpenFailureException, _channelExceptionRegister[0].Exception); + } + + [TestMethod] + public void OnErrorOccuredShouldBeInvokedOnce() + { + Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count); + Assert.AreSame(_onOpenFailureException, _channel.OnErrorOccurredInvocations[0]); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/CipherInfoTest.cs b/src/Renci.SshNet.Tests/Classes/CipherInfoTest.cs index e2527a76..91b3221c 100644 --- a/src/Renci.SshNet.Tests/Classes/CipherInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/CipherInfoTest.cs @@ -1,27 +1,27 @@ -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 -{ - /// - /// Holds information about key size and cipher to use - /// - [TestClass] - public class CipherInfoTest : TestBase - { - /// - ///A test for CipherInfo Constructor - /// - [TestMethod()] - public void CipherInfoConstructorTest() - { - int keySize = 0; // TODO: Initialize to an appropriate value - Func cipher = null; // TODO: Initialize to an appropriate value - CipherInfo target = new CipherInfo(keySize, cipher); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +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 +{ + /// + /// Holds information about key size and cipher to use + /// + [TestClass] + public class CipherInfoTest : TestBase + { + /// + ///A test for CipherInfo Constructor + /// + [TestMethod()] + public void CipherInfoConstructorTest() + { + int keySize = 0; // TODO: Initialize to an appropriate value + Func cipher = null; // TODO: Initialize to an appropriate value + CipherInfo target = new CipherInfo(keySize, cipher); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest.cs index 9b007791..37e9a0ed 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest.cs @@ -1,54 +1,54 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest - { - private ClientAuthentication _clientAuthentication; - - [TestInitialize] - public void Init() - { - _clientAuthentication = new ClientAuthentication(); - } - - [TestMethod] - public void AuthenticateShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull() - { - IConnectionInfoInternal connectionInfo = null; - var session = new Mock(MockBehavior.Strict).Object; - - try - { - _clientAuthentication.Authenticate(connectionInfo, session); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("connectionInfo", ex.ParamName); - } - } - - [TestMethod] - public void AuthenticateShouldThrowArgumentNullExceptionWhenSessionIsNull() - { - var connectionInfo = new Mock(MockBehavior.Strict).Object; - ISession session = null; - - try - { - _clientAuthentication.Authenticate(connectionInfo, session); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("session", ex.ParamName); - } - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest + { + private ClientAuthentication _clientAuthentication; + + [TestInitialize] + public void Init() + { + _clientAuthentication = new ClientAuthentication(); + } + + [TestMethod] + public void AuthenticateShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull() + { + IConnectionInfoInternal connectionInfo = null; + var session = new Mock(MockBehavior.Strict).Object; + + try + { + _clientAuthentication.Authenticate(connectionInfo, session); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("connectionInfo", ex.ParamName); + } + } + + [TestMethod] + public void AuthenticateShouldThrowArgumentNullExceptionWhenSessionIsNull() + { + var connectionInfo = new Mock(MockBehavior.Strict).Object; + ISession session = null; + + try + { + _clientAuthentication.Authenticate(connectionInfo, session); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("session", ex.ParamName); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTestBase.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTestBase.cs index a0846bf1..3ff76d18 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTestBase.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTestBase.cs @@ -1,81 +1,81 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public abstract class ClientAuthenticationTestBase : TestBase - { - internal Mock ConnectionInfoMock { get; private set; } - internal Mock SessionMock { get; private set; } - internal Mock NoneAuthenticationMethodMock { get; private set; } - internal Mock PasswordAuthenticationMethodMock { get; private set; } - internal Mock PublicKeyAuthenticationMethodMock { get; private set; } - internal Mock KeyboardInteractiveAuthenticationMethodMock { get; private set; } - internal ClientAuthentication ClientAuthentication { get; private set; } - - protected void CreateMocks() - { - ConnectionInfoMock = new Mock(MockBehavior.Strict); - SessionMock = new Mock(MockBehavior.Strict); - NoneAuthenticationMethodMock = new Mock(MockBehavior.Strict); - PasswordAuthenticationMethodMock = new Mock(MockBehavior.Strict); - PublicKeyAuthenticationMethodMock = new Mock(MockBehavior.Strict); - KeyboardInteractiveAuthenticationMethodMock = new Mock(MockBehavior.Strict); - } - - protected abstract void SetupMocks(); - - protected abstract void Act(); - - protected override void OnInit() - { - base.OnInit(); - - // Arrange - CreateMocks(); - SetupMocks(); - ClientAuthentication = new ClientAuthentication(); - - // Act - Act(); - } - - [TestMethod] - public void RegisterMessageWithUserAuthFailureShouldBeInvokedOnce() - { - SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once); - } - - [TestMethod] - public void RegisterMessageWithUserAuthSuccessShouldBeInvokedOnce() - { - SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once); - } - - [TestMethod] - public void RegisterMessageWithUserAuthBannerShouldBeInvokedOnce() - { - SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once); - } - - [TestMethod] - public void UnRegisterMessageWithUserAuthFailureShouldBeInvokedOnce() - { - SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once); - } - - [TestMethod] - public void UnRegisterMessageWithUserAuthSuccessShouldBeInvokedOnce() - { - SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once); - } - - [TestMethod] - public void UnRegisterMessageWithUserAuthBannerShouldBeInvokedOnce() - { - SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public abstract class ClientAuthenticationTestBase : TestBase + { + internal Mock ConnectionInfoMock { get; private set; } + internal Mock SessionMock { get; private set; } + internal Mock NoneAuthenticationMethodMock { get; private set; } + internal Mock PasswordAuthenticationMethodMock { get; private set; } + internal Mock PublicKeyAuthenticationMethodMock { get; private set; } + internal Mock KeyboardInteractiveAuthenticationMethodMock { get; private set; } + internal ClientAuthentication ClientAuthentication { get; private set; } + + protected void CreateMocks() + { + ConnectionInfoMock = new Mock(MockBehavior.Strict); + SessionMock = new Mock(MockBehavior.Strict); + NoneAuthenticationMethodMock = new Mock(MockBehavior.Strict); + PasswordAuthenticationMethodMock = new Mock(MockBehavior.Strict); + PublicKeyAuthenticationMethodMock = new Mock(MockBehavior.Strict); + KeyboardInteractiveAuthenticationMethodMock = new Mock(MockBehavior.Strict); + } + + protected abstract void SetupMocks(); + + protected abstract void Act(); + + protected override void OnInit() + { + base.OnInit(); + + // Arrange + CreateMocks(); + SetupMocks(); + ClientAuthentication = new ClientAuthentication(); + + // Act + Act(); + } + + [TestMethod] + public void RegisterMessageWithUserAuthFailureShouldBeInvokedOnce() + { + SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once); + } + + [TestMethod] + public void RegisterMessageWithUserAuthSuccessShouldBeInvokedOnce() + { + SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once); + } + + [TestMethod] + public void RegisterMessageWithUserAuthBannerShouldBeInvokedOnce() + { + SessionMock.Verify(p => p.RegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once); + } + + [TestMethod] + public void UnRegisterMessageWithUserAuthFailureShouldBeInvokedOnce() + { + SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_FAILURE"), Times.Once); + } + + [TestMethod] + public void UnRegisterMessageWithUserAuthSuccessShouldBeInvokedOnce() + { + SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_SUCCESS"), Times.Once); + } + + [TestMethod] + public void UnRegisterMessageWithUserAuthBannerShouldBeInvokedOnce() + { + SessionMock.Verify(p => p.UnRegisterMessage("SSH_MSG_USERAUTH_BANNER"), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs index 408c2067..a3b939d9 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed.cs @@ -1,70 +1,70 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed : ClientAuthenticationTestBase - { - private SshAuthenticationException _actualException; - - protected override void SetupMocks() - { - 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 - { - PublicKeyAuthenticationMethodMock.Object, - PasswordAuthenticationMethodMock.Object - }); - NoneAuthenticationMethodMock.InSequence(seq) - .Setup(p => p.AllowedAuthentications) - .Returns(new[] { "password" }); - - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) - .Returns(AuthenticationResult.Failure); - // obtain name for inclusion in SshAuthenticationException - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - - 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 Act() - { - try - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - Assert.Fail(); - } - catch (SshAuthenticationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void AuthenticateShouldThrowSshAuthenticationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("Permission denied (password).", _actualException.Message); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodFailed : ClientAuthenticationTestBase + { + private SshAuthenticationException _actualException; + + protected override void SetupMocks() + { + 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 + { + PublicKeyAuthenticationMethodMock.Object, + PasswordAuthenticationMethodMock.Object + }); + NoneAuthenticationMethodMock.InSequence(seq) + .Setup(p => p.AllowedAuthentications) + .Returns(new[] { "password" }); + + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) + .Returns(AuthenticationResult.Failure); + // obtain name for inclusion in SshAuthenticationException + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + + 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 Act() + { + try + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + Assert.Fail(); + } + catch (SshAuthenticationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void AuthenticateShouldThrowSshAuthenticationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("Permission denied (password).", _actualException.Message); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotConfigured.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotConfigured.cs index 734d5d97..b87a3409 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotConfigured.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotConfigured.cs @@ -1,63 +1,63 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotSupported : ClientAuthenticationTestBase - { - private SshAuthenticationException _actualException; - - protected override void SetupMocks() - { - 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 - { - PublicKeyAuthenticationMethodMock.Object - }); - NoneAuthenticationMethodMock.InSequence(seq) - .Setup(p => p.AllowedAuthentications) - .Returns(new[] { "password" }); - - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - - 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 Act() - { - try - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - Assert.Fail(); - } - catch (SshAuthenticationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void AuthenticateShouldThrowSshAuthenticationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("No suitable authentication method found to complete authentication (password).", _actualException.Message); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Failure_SingleList_AuthenticationMethodNotSupported : ClientAuthenticationTestBase + { + private SshAuthenticationException _actualException; + + protected override void SetupMocks() + { + 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 + { + PublicKeyAuthenticationMethodMock.Object + }); + NoneAuthenticationMethodMock.InSequence(seq) + .Setup(p => p.AllowedAuthentications) + .Returns(new[] { "password" }); + + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + + 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 Act() + { + try + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + Assert.Fail(); + } + catch (SshAuthenticationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void AuthenticateShouldThrowSshAuthenticationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("No suitable authentication method found to complete authentication (password).", _actualException.Message); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs index 73358b15..9ef8e98b 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess.cs @@ -1,55 +1,55 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess : ClientAuthenticationTestBase - { - protected override void SetupMocks() - { - 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 - { - PasswordAuthenticationMethodMock.Object, - PublicKeyAuthenticationMethodMock.Object, - KeyboardInteractiveAuthenticationMethodMock.Object, - }); - NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "publickey", "password" }); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); - - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) - .Returns(AuthenticationResult.PartialSuccess); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) - .Returns(new[] { "keyboard-interactive", "publickey" }); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); - - PublicKeyAuthenticationMethodMock.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 Act() - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Success_MultiList_DifferentAllowedAuthenticationsAfterPartialSuccess : ClientAuthenticationTestBase + { + protected override void SetupMocks() + { + 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 + { + PasswordAuthenticationMethodMock.Object, + PublicKeyAuthenticationMethodMock.Object, + KeyboardInteractiveAuthenticationMethodMock.Object, + }); + NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "publickey", "password" }); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); + + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) + .Returns(AuthenticationResult.PartialSuccess); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) + .Returns(new[] { "keyboard-interactive", "publickey" }); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); + + PublicKeyAuthenticationMethodMock.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 Act() + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs index c27d7be6..7112ca95 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod.cs @@ -1,57 +1,57 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod : ClientAuthenticationTestBase - { - protected override void SetupMocks() - { - 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 - { - 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).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 Act() - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Success_MultiList_PostponePartialAccessAuthenticationMethod : ClientAuthenticationTestBase + { + protected override void SetupMocks() + { + 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 + { + 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).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 Act() + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs index b3685925..90476047 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess.cs @@ -1,61 +1,61 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess : ClientAuthenticationTestBase - { - protected override void SetupMocks() - { - 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 - { - PasswordAuthenticationMethodMock.Object, - PublicKeyAuthenticationMethodMock.Object, - KeyboardInteractiveAuthenticationMethodMock.Object, - }); - NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password", "publickey" }); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); - - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) - .Returns(AuthenticationResult.PartialSuccess); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) - .Returns(new[] {"password", "publickey"}); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); - - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)).Returns(AuthenticationResult.PartialSuccess); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) - .Returns(new[] { "password", "publickey", "keyboard-interactive" }); - - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); - KeyboardInteractiveAuthenticationMethodMock.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 Act() - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Success_MultiList_SameAllowedAuthenticationsAfterPartialSuccess : ClientAuthenticationTestBase + { + protected override void SetupMocks() + { + 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 + { + PasswordAuthenticationMethodMock.Object, + PublicKeyAuthenticationMethodMock.Object, + KeyboardInteractiveAuthenticationMethodMock.Object, + }); + NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password", "publickey" }); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); + + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) + .Returns(AuthenticationResult.PartialSuccess); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) + .Returns(new[] {"password", "publickey"}); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); + + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)).Returns(AuthenticationResult.PartialSuccess); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) + .Returns(new[] { "password", "publickey", "keyboard-interactive" }); + + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + KeyboardInteractiveAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("keyboard-interactive"); + KeyboardInteractiveAuthenticationMethodMock.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 Act() + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod.cs index 94e361fa..1d409500 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod.cs @@ -1,55 +1,55 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod : ClientAuthenticationTestBase - { - protected override void SetupMocks() - { - 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 - { - PasswordAuthenticationMethodMock.Object, - PublicKeyAuthenticationMethodMock.Object, - }); - NoneAuthenticationMethodMock.InSequence(seq) - .Setup(p => p.AllowedAuthentications) - .Returns(new[] { "publickey", "password" }); - - 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.Failure); - // obtain name for inclusion in SshAuthenticationException - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - - PublicKeyAuthenticationMethodMock.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 Act() - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Success_MultiList_SkipFailedAuthenticationMethod : ClientAuthenticationTestBase + { + protected override void SetupMocks() + { + 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 + { + PasswordAuthenticationMethodMock.Object, + PublicKeyAuthenticationMethodMock.Object, + }); + NoneAuthenticationMethodMock.InSequence(seq) + .Setup(p => p.AllowedAuthentications) + .Returns(new[] { "publickey", "password" }); + + 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.Failure); + // obtain name for inclusion in SshAuthenticationException + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + + PublicKeyAuthenticationMethodMock.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 Act() + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs index f16cf42f..5327ea33 100644 --- a/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs +++ b/src/Renci.SshNet.Tests/Classes/ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess.cs @@ -1,53 +1,53 @@ -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess : ClientAuthenticationTestBase - { - protected override void SetupMocks() - { - 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 - { - PublicKeyAuthenticationMethodMock.Object, - PasswordAuthenticationMethodMock.Object - }); - NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password" }); - - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) - .Returns(AuthenticationResult.PartialSuccess); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) - .Returns(new[] { "password" }); - PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); - PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); - - 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 Act() - { - ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); - } - } -} +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ClientAuthenticationTest_Success_SingleList_SameAllowedAuthenticationAfterPartialSuccess : ClientAuthenticationTestBase + { + protected override void SetupMocks() + { + 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 + { + PublicKeyAuthenticationMethodMock.Object, + PasswordAuthenticationMethodMock.Object + }); + NoneAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications).Returns(new[] { "password" }); + + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Authenticate(SessionMock.Object)) + .Returns(AuthenticationResult.PartialSuccess); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.AllowedAuthentications) + .Returns(new[] { "password" }); + PublicKeyAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("publickey"); + PasswordAuthenticationMethodMock.InSequence(seq).Setup(p => p.Name).Returns("password"); + + 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 Act() + { + ClientAuthentication.Authenticate(ConnectionInfoMock.Object, SessionMock.Object); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/CommandAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/CommandAsyncResultTest.cs index 96217fc3..c04b83d7 100644 --- a/src/Renci.SshNet.Tests/Classes/CommandAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/CommandAsyncResultTest.cs @@ -1,32 +1,32 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass()] - public class CommandAsyncResultTest : TestBase - { - [TestMethod()] - public void BytesSentTest() - { - var target = new CommandAsyncResult(); - int expected = new Random().Next(); - - target.BytesSent = expected; - - Assert.AreEqual(expected, target.BytesSent); - } - - [TestMethod()] - public void BytesReceivedTest() - { - var target = new CommandAsyncResult(); - var expected = new Random().Next(); - - target.BytesReceived = expected; - - Assert.AreEqual(expected, target.BytesReceived); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass()] + public class CommandAsyncResultTest : TestBase + { + [TestMethod()] + public void BytesSentTest() + { + var target = new CommandAsyncResult(); + int expected = new Random().Next(); + + target.BytesSent = expected; + + Assert.AreEqual(expected, target.BytesSent); + } + + [TestMethod()] + public void BytesReceivedTest() + { + var target = new CommandAsyncResult(); + var expected = new Random().Next(); + + target.BytesReceived = expected; + + Assert.AreEqual(expected, target.BytesReceived); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs index a6ed59cc..349ced1f 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ASCIIEncodingTest.cs @@ -1,237 +1,237 @@ -using System; -using System.Diagnostics; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - [TestClass] - public class ASCIIEncodingTest : TestBase - { - private Random _random; - private Encoding _ascii; - - [TestInitialize] - public void SetUp() - { - _random = new Random(); - _ascii = SshData.Ascii; - } - - [TestMethod] - public void GetByteCount_Chars() - { - var chars = new[] { 'B', 'e', 'l', 'g', 'i', 'u', 'm' }; - - var actual = _ascii.GetByteCount(chars); - - Assert.AreEqual(chars.Length, actual); - } - - [TestMethod] - public void GetBytes_CharArray() - { - var chars = new[] {'B', 'e', 'l', 'g', 'i', 'u', 'm'}; - - var actual = _ascii.GetBytes(chars); - - Assert.IsNotNull(actual); - Assert.AreEqual(7, actual.Length); - Assert.AreEqual(0x42, actual[0]); - Assert.AreEqual(0x65, actual[1]); - Assert.AreEqual(0x6c, actual[2]); - Assert.AreEqual(0x67, actual[3]); - Assert.AreEqual(0x69, actual[4]); - Assert.AreEqual(0x75, actual[5]); - Assert.AreEqual(0x6d ,actual[6]); - } - - [TestMethod] - public void GetCharCount_Bytes() - { - var bytes = new byte[] { 0x42, 0x65, 0x6c, 0x67, 0x69, 0x75, 0x6d }; - - var actual = _ascii.GetCharCount(bytes); - - Assert.AreEqual(bytes.Length, actual); - } - - [TestMethod] - public void GetChars_Bytes() - { - var bytes = new byte[] {0x42, 0x65, 0x6c, 0x67, 0x69, 0x75, 0x6d}; - - var actual = _ascii.GetChars(bytes); - - Assert.AreEqual("Belgium", new string(actual)); - } - - [TestMethod] - public void GetChars_Bytes_DefaultFallback() - { - var bytes = new byte[] { 0x42, 0x65, 0x6c, 0x80, 0x69, 0x75, 0x6d }; - - var actual = _ascii.GetChars(bytes); - - Assert.AreEqual("Bel?ium", new string(actual)); - } - - [TestMethod] - public void GetMaxByteCount_ShouldReturnCharCountPlusOneWhenCharCountIsNonNegative() - { - var charCount = _random.Next(0, 20000); - - var actual = _ascii.GetMaxByteCount(charCount); - - Assert.AreEqual(++charCount, actual); - } - - [TestMethod] - public void GetMaxByteCount_ShouldThrowArgumentOutOfRangeExceptionWhenCharCountIsNegative() - { - var charCount = _random.Next(-5000, -1); - - try - { - var actual = _ascii.GetMaxByteCount(charCount); - Assert.Fail(actual.ToString(CultureInfo.InvariantCulture)); - } - catch (ArgumentOutOfRangeException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("charCount", ex.ParamName); - } - } - - [TestMethod] - public void GetMaxCharCount_ShouldReturnByteCountWhenByteCountIsNonNegative() - { - var byteCount = _random.Next(0, 20000); - - var actual = _ascii.GetMaxCharCount(byteCount); - - Assert.AreEqual(byteCount, actual); - } - - [TestMethod] - public void GetMaxCharCount_ShouldThrowArgumentOutOfRangeExceptionWhenByteCountIsNegative() - { - var byteCount = _random.Next(-5000, -1); - - try - { - var actual = _ascii.GetMaxCharCount(byteCount); - Assert.Fail(actual.ToString(CultureInfo.InvariantCulture)); - } - catch (ArgumentOutOfRangeException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("byteCount", ex.ParamName); - } - } - - [TestMethod] - public void GetPreamble() - { - var actual = _ascii.GetPreamble(); - - Assert.AreEqual(0, actual.Length); - } - - [TestMethod] - public void IsSingleByte() - { - Assert.IsTrue(_ascii.IsSingleByte); - } - - [TestMethod] - public void GetBytes_Performance() - { - const string input = "eererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqs"; - const int loopCount = 10000000; - var result = new byte[input.Length]; - - var corefxAscii = new System.Text.ASCIIEncoding(); - var sshAscii = _ascii; - - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - corefxAscii.GetBytes(input, 0, input.Length, result, 0); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - sshAscii.GetBytes(input, 0, input.Length, result, 0); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - [TestMethod] - public void GetChars_Performance() - { - var input = new byte[2000]; - new Random().NextBytes(input); - const int loopCount = 100000; - - var corefxAscii = new System.Text.ASCIIEncoding(); - var sshAscii = _ascii; - - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - var actual = corefxAscii.GetChars(input); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - - stopWatch.Reset(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - var actual = sshAscii.GetChars(input); - } - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - } +using System; +using System.Diagnostics; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + [TestClass] + public class ASCIIEncodingTest : TestBase + { + private Random _random; + private Encoding _ascii; + + [TestInitialize] + public void SetUp() + { + _random = new Random(); + _ascii = SshData.Ascii; + } + + [TestMethod] + public void GetByteCount_Chars() + { + var chars = new[] { 'B', 'e', 'l', 'g', 'i', 'u', 'm' }; + + var actual = _ascii.GetByteCount(chars); + + Assert.AreEqual(chars.Length, actual); + } + + [TestMethod] + public void GetBytes_CharArray() + { + var chars = new[] {'B', 'e', 'l', 'g', 'i', 'u', 'm'}; + + var actual = _ascii.GetBytes(chars); + + Assert.IsNotNull(actual); + Assert.AreEqual(7, actual.Length); + Assert.AreEqual(0x42, actual[0]); + Assert.AreEqual(0x65, actual[1]); + Assert.AreEqual(0x6c, actual[2]); + Assert.AreEqual(0x67, actual[3]); + Assert.AreEqual(0x69, actual[4]); + Assert.AreEqual(0x75, actual[5]); + Assert.AreEqual(0x6d ,actual[6]); + } + + [TestMethod] + public void GetCharCount_Bytes() + { + var bytes = new byte[] { 0x42, 0x65, 0x6c, 0x67, 0x69, 0x75, 0x6d }; + + var actual = _ascii.GetCharCount(bytes); + + Assert.AreEqual(bytes.Length, actual); + } + + [TestMethod] + public void GetChars_Bytes() + { + var bytes = new byte[] {0x42, 0x65, 0x6c, 0x67, 0x69, 0x75, 0x6d}; + + var actual = _ascii.GetChars(bytes); + + Assert.AreEqual("Belgium", new string(actual)); + } + + [TestMethod] + public void GetChars_Bytes_DefaultFallback() + { + var bytes = new byte[] { 0x42, 0x65, 0x6c, 0x80, 0x69, 0x75, 0x6d }; + + var actual = _ascii.GetChars(bytes); + + Assert.AreEqual("Bel?ium", new string(actual)); + } + + [TestMethod] + public void GetMaxByteCount_ShouldReturnCharCountPlusOneWhenCharCountIsNonNegative() + { + var charCount = _random.Next(0, 20000); + + var actual = _ascii.GetMaxByteCount(charCount); + + Assert.AreEqual(++charCount, actual); + } + + [TestMethod] + public void GetMaxByteCount_ShouldThrowArgumentOutOfRangeExceptionWhenCharCountIsNegative() + { + var charCount = _random.Next(-5000, -1); + + try + { + var actual = _ascii.GetMaxByteCount(charCount); + Assert.Fail(actual.ToString(CultureInfo.InvariantCulture)); + } + catch (ArgumentOutOfRangeException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("charCount", ex.ParamName); + } + } + + [TestMethod] + public void GetMaxCharCount_ShouldReturnByteCountWhenByteCountIsNonNegative() + { + var byteCount = _random.Next(0, 20000); + + var actual = _ascii.GetMaxCharCount(byteCount); + + Assert.AreEqual(byteCount, actual); + } + + [TestMethod] + public void GetMaxCharCount_ShouldThrowArgumentOutOfRangeExceptionWhenByteCountIsNegative() + { + var byteCount = _random.Next(-5000, -1); + + try + { + var actual = _ascii.GetMaxCharCount(byteCount); + Assert.Fail(actual.ToString(CultureInfo.InvariantCulture)); + } + catch (ArgumentOutOfRangeException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("byteCount", ex.ParamName); + } + } + + [TestMethod] + public void GetPreamble() + { + var actual = _ascii.GetPreamble(); + + Assert.AreEqual(0, actual.Length); + } + + [TestMethod] + public void IsSingleByte() + { + Assert.IsTrue(_ascii.IsSingleByte); + } + + [TestMethod] + public void GetBytes_Performance() + { + const string input = "eererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqseererzfdfdsfsfsfsqdqs"; + const int loopCount = 10000000; + var result = new byte[input.Length]; + + var corefxAscii = new System.Text.ASCIIEncoding(); + var sshAscii = _ascii; + + var stopWatch = new Stopwatch(); + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Start(); + + for (var i = 0; i < loopCount; i++) + { + corefxAscii.GetBytes(input, 0, input.Length, result, 0); + } + + stopWatch.Stop(); + + Console.WriteLine(stopWatch.ElapsedMilliseconds); + + stopWatch.Reset(); + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Start(); + + for (var i = 0; i < loopCount; i++) + { + sshAscii.GetBytes(input, 0, input.Length, result, 0); + } + + stopWatch.Stop(); + + Console.WriteLine(stopWatch.ElapsedMilliseconds); + } + + [TestMethod] + public void GetChars_Performance() + { + var input = new byte[2000]; + new Random().NextBytes(input); + const int loopCount = 100000; + + var corefxAscii = new System.Text.ASCIIEncoding(); + var sshAscii = _ascii; + + var stopWatch = new Stopwatch(); + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Start(); + + for (var i = 0; i < loopCount; i++) + { + var actual = corefxAscii.GetChars(input); + } + + stopWatch.Stop(); + + Console.WriteLine(stopWatch.ElapsedMilliseconds); + + stopWatch.Reset(); + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Start(); + + for (var i = 0; i < loopCount; i++) + { + var actual = sshAscii.GetChars(input); + } + + stopWatch.Stop(); + + Console.WriteLine(stopWatch.ElapsedMilliseconds); + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/AsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Common/AsyncResultTest.cs index 599f5e8b..b0a18aff 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/AsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/AsyncResultTest.cs @@ -1,140 +1,140 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Threading; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for AsyncResultTest and is intended - ///to contain all AsyncResultTest Unit Tests - /// - [TestClass] - [Ignore] // placeholder for actual test - public class AsyncResultTest : TestBase - { - /// - ///A test for EndInvoke - /// - public void EndInvokeTest1Helper() - { - AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value - TResult expected = default(TResult); // TODO: Initialize to an appropriate value - TResult actual; - actual = target.EndInvoke(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - internal virtual AsyncResult CreateAsyncResult() - { - // TODO: Instantiate an appropriate concrete class. - AsyncResult target = null; - return target; - } - - [TestMethod()] - public void EndInvokeTest1() - { - EndInvokeTest1Helper(); - } - - /// - ///A test for SetAsCompleted - /// - public void SetAsCompletedTest1Helper() - { - AsyncResult target = CreateAsyncResult(); // 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 - target.SetAsCompleted(result, completedSynchronously); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - [TestMethod()] - public void SetAsCompletedTest1() - { - SetAsCompletedTest1Helper(); - } - - internal virtual AsyncResult CreateAsyncResult() - { - // TODO: Instantiate an appropriate concrete class. - AsyncResult target = null; - return target; - } - - /// - ///A test for EndInvoke - /// - [TestMethod()] - public void EndInvokeTest() - { - AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value - target.EndInvoke(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetAsCompleted - /// - [TestMethod()] - public void SetAsCompletedTest() - { - AsyncResult 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 - target.SetAsCompleted(exception, completedSynchronously); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AsyncState - /// - [TestMethod()] - public void AsyncStateTest() - { - AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value - object actual; - actual = target.AsyncState; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AsyncWaitHandle - /// - [TestMethod()] - public void AsyncWaitHandleTest() - { - AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value - WaitHandle actual; - actual = target.AsyncWaitHandle; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CompletedSynchronously - /// - [TestMethod()] - public void CompletedSynchronouslyTest() - { - AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value - bool actual; - actual = target.CompletedSynchronously; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for IsCompleted - /// - [TestMethod()] - public void IsCompletedTest() - { - AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value - bool actual; - actual = target.IsCompleted; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Threading; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for AsyncResultTest and is intended + ///to contain all AsyncResultTest Unit Tests + /// + [TestClass] + [Ignore] // placeholder for actual test + public class AsyncResultTest : TestBase + { + /// + ///A test for EndInvoke + /// + public void EndInvokeTest1Helper() + { + AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value + TResult expected = default(TResult); // TODO: Initialize to an appropriate value + TResult actual; + actual = target.EndInvoke(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + internal virtual AsyncResult CreateAsyncResult() + { + // TODO: Instantiate an appropriate concrete class. + AsyncResult target = null; + return target; + } + + [TestMethod()] + public void EndInvokeTest1() + { + EndInvokeTest1Helper(); + } + + /// + ///A test for SetAsCompleted + /// + public void SetAsCompletedTest1Helper() + { + AsyncResult target = CreateAsyncResult(); // 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 + target.SetAsCompleted(result, completedSynchronously); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + [TestMethod()] + public void SetAsCompletedTest1() + { + SetAsCompletedTest1Helper(); + } + + internal virtual AsyncResult CreateAsyncResult() + { + // TODO: Instantiate an appropriate concrete class. + AsyncResult target = null; + return target; + } + + /// + ///A test for EndInvoke + /// + [TestMethod()] + public void EndInvokeTest() + { + AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value + target.EndInvoke(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetAsCompleted + /// + [TestMethod()] + public void SetAsCompletedTest() + { + AsyncResult 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 + target.SetAsCompleted(exception, completedSynchronously); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AsyncState + /// + [TestMethod()] + public void AsyncStateTest() + { + AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value + object actual; + actual = target.AsyncState; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AsyncWaitHandle + /// + [TestMethod()] + public void AsyncWaitHandleTest() + { + AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value + WaitHandle actual; + actual = target.AsyncWaitHandle; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CompletedSynchronously + /// + [TestMethod()] + public void CompletedSynchronouslyTest() + { + AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value + bool actual; + actual = target.CompletedSynchronously; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for IsCompleted + /// + [TestMethod()] + public void IsCompletedTest() + { + AsyncResult target = CreateAsyncResult(); // TODO: Initialize to an appropriate value + bool actual; + actual = target.IsCompleted; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationBannerEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationBannerEventArgsTest.cs index d1ce5374..a671b0ae 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationBannerEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationBannerEventArgsTest.cs @@ -1,30 +1,30 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - - - /// - ///This is a test class for AuthenticationBannerEventArgsTest and is intended - ///to contain all AuthenticationBannerEventArgsTest Unit Tests - /// - [TestClass()] - public class AuthenticationBannerEventArgsTest : TestBase - { - /// - ///A test for AuthenticationBannerEventArgs Constructor - /// - [TestMethod()] - public void AuthenticationBannerEventArgsConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - string message = string.Empty; // TODO: Initialize to an appropriate value - string language = string.Empty; // TODO: Initialize to an appropriate value - AuthenticationBannerEventArgs target = new AuthenticationBannerEventArgs(username, message, language); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + + + /// + ///This is a test class for AuthenticationBannerEventArgsTest and is intended + ///to contain all AuthenticationBannerEventArgsTest Unit Tests + /// + [TestClass()] + public class AuthenticationBannerEventArgsTest : TestBase + { + /// + ///A test for AuthenticationBannerEventArgs Constructor + /// + [TestMethod()] + public void AuthenticationBannerEventArgsConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + string message = string.Empty; // TODO: Initialize to an appropriate value + string language = string.Empty; // TODO: Initialize to an appropriate value + AuthenticationBannerEventArgs target = new AuthenticationBannerEventArgs(username, message, language); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPasswordChangeEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPasswordChangeEventArgsTest.cs index 87dc5351..fe4c1a9b 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPasswordChangeEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPasswordChangeEventArgsTest.cs @@ -1,44 +1,44 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - - - /// - ///This is a test class for AuthenticationPasswordChangeEventArgsTest and is intended - ///to contain all AuthenticationPasswordChangeEventArgsTest Unit Tests - /// - [TestClass()] - public class AuthenticationPasswordChangeEventArgsTest : TestBase - { - /// - ///A test for AuthenticationPasswordChangeEventArgs Constructor - /// - [TestMethod()] - public void AuthenticationPasswordChangeEventArgsConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - AuthenticationPasswordChangeEventArgs target = new AuthenticationPasswordChangeEventArgs(username); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NewPassword - /// - [TestMethod()] - public void NewPasswordTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - AuthenticationPasswordChangeEventArgs target = new AuthenticationPasswordChangeEventArgs(username); // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - target.NewPassword = expected; - actual = target.NewPassword; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + + + /// + ///This is a test class for AuthenticationPasswordChangeEventArgsTest and is intended + ///to contain all AuthenticationPasswordChangeEventArgsTest Unit Tests + /// + [TestClass()] + public class AuthenticationPasswordChangeEventArgsTest : TestBase + { + /// + ///A test for AuthenticationPasswordChangeEventArgs Constructor + /// + [TestMethod()] + public void AuthenticationPasswordChangeEventArgsConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + AuthenticationPasswordChangeEventArgs target = new AuthenticationPasswordChangeEventArgs(username); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NewPassword + /// + [TestMethod()] + public void NewPasswordTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + AuthenticationPasswordChangeEventArgs target = new AuthenticationPasswordChangeEventArgs(username); // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + target.NewPassword = expected; + actual = target.NewPassword; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptEventArgsTest.cs index 718d3333..80519bdc 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptEventArgsTest.cs @@ -1,32 +1,32 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - - - /// - ///This is a test class for AuthenticationPromptEventArgsTest and is intended - ///to contain all AuthenticationPromptEventArgsTest Unit Tests - /// - [TestClass()] - public class AuthenticationPromptEventArgsTest : TestBase - { - /// - ///A test for AuthenticationPromptEventArgs Constructor - /// - [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 - IEnumerable prompts = null; // TODO: Initialize to an appropriate value - AuthenticationPromptEventArgs target = new AuthenticationPromptEventArgs(username, instruction, language, prompts); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + + + /// + ///This is a test class for AuthenticationPromptEventArgsTest and is intended + ///to contain all AuthenticationPromptEventArgsTest Unit Tests + /// + [TestClass()] + public class AuthenticationPromptEventArgsTest : TestBase + { + /// + ///A test for AuthenticationPromptEventArgs Constructor + /// + [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 + IEnumerable prompts = null; // TODO: Initialize to an appropriate value + AuthenticationPromptEventArgs target = new AuthenticationPromptEventArgs(username, instruction, language, prompts); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptTest.cs b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptTest.cs index 221fb40e..9c56df4d 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/AuthenticationPromptTest.cs @@ -1,46 +1,46 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for AuthenticationPromptTest and is intended - ///to contain all AuthenticationPromptTest Unit Tests - /// - [TestClass()] - public class AuthenticationPromptTest : TestBase - { - /// - ///A test for AuthenticationPrompt Constructor - /// - [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); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Response - /// - [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; - target.Response = expected; - actual = target.Response; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for AuthenticationPromptTest and is intended + ///to contain all AuthenticationPromptTest Unit Tests + /// + [TestClass()] + public class AuthenticationPromptTest : TestBase + { + /// + ///A test for AuthenticationPrompt Constructor + /// + [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); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Response + /// + [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; + target.Response = expected; + actual = target.Response; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs index 8c0100cd..8acab7b6 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/BigIntegerTest.cs @@ -1,1654 +1,1654 @@ -// Based in huge part on: -// -// https://github.com/mono/mono/blob/master/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs -// -// Authors: -// Rodrigo Kumpera -// -// Copyright (C) 2010 Novell, Inc (http://www.novell.com) -// - -//#define FEATURE_NUMERICS_BIGINTEGER - -using System; -using System.Diagnostics; -using System.Globalization; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -#if FEATURE_NUMERICS_BIGINTEGER -using BigInteger = System.Numerics.BigInteger; -#else -using BigInteger = Renci.SshNet.Common.BigInteger; -#endif - - -namespace Renci.SshNet.Tests.Classes.Common -{ - [TestClass] - public class BigIntegerTest - { - private static readonly byte[] huge_a = - { - 0x1D, 0x33, 0xFB, 0xFE, 0xB1, 0x2, 0x85, 0x44, 0xCA, 0xDC, 0xFB, 0x70, 0xD, 0x39, - 0xB1, 0x47, 0xB6, 0xE6, 0xA2, 0xD1, 0x19, 0x1E, 0x9F, 0xE4, 0x3C, 0x1E, 0x16, 0x56, 0x13, 0x9C, 0x4D, 0xD3, - 0x5C, 0x74, 0xC9, 0xBD, 0xFA, 0x56, 0x40, 0x58, 0xAC, 0x20, 0x6B, 0x55, 0xA2, 0xD5, 0x41, 0x38, 0xA4, 0x6D, - 0xF6, 0x8C, - }; - - private static readonly byte[] huge_b = - { - 0x96, 0x5, 0xDA, 0xFE, 0x93, 0x17, 0xC1, 0x93, 0xEC, 0x2F, 0x30, 0x2D, 0x8F, - 0x28, 0x13, 0x99, 0x70, 0xF4, 0x4C, 0x60, 0xA6, 0x49, 0x24, 0xF9, 0xB3, 0x4A, 0x41, 0x67, 0xDC, 0xDD, 0xB1, - 0xA5, 0xA6, 0xC0, 0x3D, 0x57, 0x9A, 0xCB, 0x29, 0xE2, 0x94, 0xAC, 0x6C, 0x7D, 0xEF, 0x3E, 0xC6, 0x7A, 0xC1, - 0xA8, 0xC8, 0xB0, 0x20, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, - }; - - private static readonly byte[] huge_add = - { - 0xB3, 0x38, 0xD5, 0xFD, 0x45, 0x1A, 0x46, 0xD8, 0xB6, 0xC, 0x2C, 0x9E, 0x9C, - 0x61, 0xC4, 0xE0, 0x26, 0xDB, 0xEF, 0x31, 0xC0, 0x67, 0xC3, 0xDD, 0xF0, 0x68, 0x57, 0xBD, 0xEF, 0x79, 0xFF, - 0x78, 0x3, 0x35, 0x7, 0x15, 0x95, 0x22, 0x6A, 0x3A, 0x41, 0xCD, 0xD7, 0xD2, 0x91, 0x14, 0x8, 0xB3, 0x65, - 0x16, 0xBF, 0x3D, 0x20, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, - }; - - private static readonly byte[] a_m_b = - { - 0x87, 0x2D, 0x21, 0x0, 0x1E, 0xEB, 0xC3, 0xB0, 0xDD, 0xAC, 0xCB, 0x43, 0x7E, 0x10, - 0x9E, 0xAE, 0x45, 0xF2, 0x55, 0x71, 0x73, 0xD4, 0x7A, 0xEB, 0x88, 0xD3, 0xD4, 0xEE, 0x36, 0xBE, 0x9B, 0x2D, - 0xB6, 0xB3, 0x8B, 0x66, 0x60, 0x8B, 0x16, 0x76, 0x17, 0x74, 0xFE, 0xD7, 0xB2, 0x96, 0x7B, 0xBD, 0xE2, 0xC4, - 0x2D, 0xDC, 0xDE, 0x6A, 0x19, 0xB3, 0x1E, 0x1F, 0xB4, 0xB6, 0x2A, 0xA5, 0x48, - }; - - private static readonly byte[] b_m_a = - { - 0x79, 0xD2, 0xDE, 0xFF, 0xE1, 0x14, 0x3C, 0x4F, 0x22, 0x53, 0x34, 0xBC, 0x81, - 0xEF, 0x61, 0x51, 0xBA, 0xD, 0xAA, 0x8E, 0x8C, 0x2B, 0x85, 0x14, 0x77, 0x2C, 0x2B, 0x11, 0xC9, 0x41, 0x64, - 0xD2, 0x49, 0x4C, 0x74, 0x99, 0x9F, 0x74, 0xE9, 0x89, 0xE8, 0x8B, 0x1, 0x28, 0x4D, 0x69, 0x84, 0x42, 0x1D, - 0x3B, 0xD2, 0x23, 0x21, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, - }; - - private static readonly byte[] huge_mul = - { - 0xFE, 0x83, 0xE1, 0x9B, 0x8D, 0x61, 0x40, 0xD1, 0x60, 0x19, 0xBD, 0x38, 0xF0, - 0xFF, 0x90, 0xAE, 0xDD, 0xAE, 0x73, 0x2C, 0x20, 0x23, 0xCF, 0x6, 0x7A, 0xB4, 0x1C, 0xE7, 0xD9, 0x64, 0x96, - 0x2C, 0x87, 0x7E, 0x1D, 0xB3, 0x8F, 0xD4, 0x33, 0xBA, 0xF4, 0x22, 0xB4, 0xDB, 0xC0, 0x5B, 0xA5, 0x64, 0xA0, - 0xBC, 0xCA, 0x3E, 0x94, 0x95, 0xDA, 0x49, 0xE2, 0xA8, 0x33, 0xA2, 0x6A, 0x33, 0xB1, 0xF2, 0xEA, 0x99, 0x32, - 0xD0, 0xB2, 0xAE, 0x55, 0x75, 0xBD, 0x19, 0xFC, 0x9A, 0xEC, 0x54, 0x87, 0x2A, 0x6, 0xCC, 0x78, 0xDA, 0x88, - 0xBB, 0xAB, 0xA5, 0x47, 0xEF, 0xC7, 0x2B, 0xC7, 0x5B, 0x32, 0x31, 0xCD, 0xD9, 0x53, 0x96, 0x1A, 0x9D, 0x9A, - 0x57, 0x40, 0x51, 0xB6, 0x5D, 0xC, 0x17, 0xD1, 0x86, 0xE9, 0xA4, 0x20, - }; - - private static readonly byte[] huge_div = {0x0,}; - - private static readonly byte[] huge_rem = - { - 0x1D, 0x33, 0xFB, 0xFE, 0xB1, 0x2, 0x85, 0x44, 0xCA, 0xDC, 0xFB, 0x70, 0xD, - 0x39, 0xB1, 0x47, 0xB6, 0xE6, 0xA2, 0xD1, 0x19, 0x1E, 0x9F, 0xE4, 0x3C, 0x1E, 0x16, 0x56, 0x13, 0x9C, 0x4D, - 0xD3, 0x5C, 0x74, 0xC9, 0xBD, 0xFA, 0x56, 0x40, 0x58, 0xAC, 0x20, 0x6B, 0x55, 0xA2, 0xD5, 0x41, 0x38, 0xA4, - 0x6D, 0xF6, 0x8C, - }; - private static readonly byte[][] add_a = {new byte[] {1}, new byte[] {0xFF}, huge_a}; - private static readonly byte[][] add_b = {new byte[] {1}, new byte[] {1}, huge_b}; - private static readonly byte[][] add_c = {new byte[] {2}, new byte[] {0}, huge_add}; - - private readonly NumberFormatInfo _nfi = NumberFormatInfo.InvariantInfo; - private NumberFormatInfo _nfiUser; - - [TestInitialize] - public void SetUpFixture() - { - _nfiUser = new NumberFormatInfo(); - _nfiUser.CurrencyDecimalDigits = 3; - _nfiUser.CurrencyDecimalSeparator = ":"; - _nfiUser.CurrencyGroupSeparator = "/"; - _nfiUser.CurrencyGroupSizes = new[] { 2, 1, 0 }; - _nfiUser.CurrencyNegativePattern = 10; // n $- - _nfiUser.CurrencyPositivePattern = 3; // n $ - _nfiUser.CurrencySymbol = "XYZ"; - _nfiUser.PercentDecimalDigits = 1; - _nfiUser.PercentDecimalSeparator = ";"; - _nfiUser.PercentGroupSeparator = "~"; - _nfiUser.PercentGroupSizes = new[] { 1 }; - _nfiUser.PercentNegativePattern = 2; - _nfiUser.PercentPositivePattern = 2; - _nfiUser.PercentSymbol = "%%%"; - _nfiUser.NumberDecimalSeparator = "."; - } - - [TestMethod] - public void Mul() - { - long[] values = { -1000000000L, -1000, -1, 0, 1, 1000, 100000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - var c = a * b; - Assert.AreEqual(values[i] * values[j], (long)c, "#_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestHugeMul() - { - var a = new BigInteger(huge_a); - var b = new BigInteger(huge_b); - - Assert.IsTrue(huge_mul.IsEqualTo((a * b).ToByteArray())); - } - - [TestMethod] - public void DivRem() - { - long[] values = { -10000000330L, -5000, -1, 0, 1, 1000, 333, 10234544400L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - if (values[j] == 0) - continue; - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - BigInteger d; - var c = BigInteger.DivRem(a, b, out d); - - Assert.AreEqual(values[i] / values[j], (long)c, "#a_" + i + "_" + j); - Assert.AreEqual(values[i] % values[j], (long)d, "#b_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestHugeDivRem() - { - var a = new BigInteger(huge_a); - var b = new BigInteger(huge_b); - BigInteger d; - var c = BigInteger.DivRem(a, b, out d); - - AssertEqual(huge_div, c.ToByteArray()); - AssertEqual(huge_rem, d.ToByteArray()); - } - - [TestMethod] - public void Pow() - { - try - { - BigInteger.Pow(1, -1); - Assert.Fail("#1"); - } - catch (ArgumentOutOfRangeException) { } - - Assert.AreEqual(1, (int)BigInteger.Pow(99999, 0), "#2"); - Assert.AreEqual(99999, (int)BigInteger.Pow(99999, 1), "#5"); - Assert.AreEqual(59049, (int)BigInteger.Pow(3, 10), "#4"); - Assert.AreEqual(177147, (int)BigInteger.Pow(3, 11), "#5"); - Assert.AreEqual(-177147, (int)BigInteger.Pow(-3, 11), "#6"); - } - - [TestMethod] - public void ModPow() - { - try - { - BigInteger.ModPow(1, -1, 5); - Assert.Fail("#1"); - } - catch (ArgumentOutOfRangeException) { } - - try - { - BigInteger.ModPow(1, 5, 0); - Assert.Fail("#2"); - } - catch (DivideByZeroException) { } - - Assert.AreEqual(4L, (long)BigInteger.ModPow(3, 2, 5), "#2"); - Assert.AreEqual(20L, (long)BigInteger.ModPow(555, 10, 71), "#3"); - Assert.AreEqual(20L, (long)BigInteger.ModPow(-555, 10, 71), "#3"); - Assert.AreEqual(-24L, (long)BigInteger.ModPow(-555, 11, 71), "#3"); - } - - [TestMethod] - public void GreatestCommonDivisor() - { - Assert.AreEqual(999999, (int)BigInteger.GreatestCommonDivisor(999999, 0), "#1"); - Assert.AreEqual(999999, (int)BigInteger.GreatestCommonDivisor(0, 999999), "#2"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(999999, 1), "#3"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(1, 999999), "#4"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(1, 0), "#5"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(0, 1), "#6"); - - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(999999, -1), "#7"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(-1, 999999), "#8"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(-1, 0), "#9"); - Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(0, -1), "#10"); - - Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(12345678, 8765432), "#11"); - Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(-12345678, 8765432), "#12"); - Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(12345678, -8765432), "#13"); - Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(-12345678, -8765432), "#14"); - - Assert.AreEqual(40, (int)BigInteger.GreatestCommonDivisor(5581 * 40, 6671 * 40), "#15"); - - Assert.AreEqual(5, (int)BigInteger.GreatestCommonDivisor(-5, 0), "#16"); - Assert.AreEqual(5, (int)BigInteger.GreatestCommonDivisor(0, -5), "#17"); - } - - [TestMethod] - public void Log() - { - const double delta = 0.000000000000001d; - - Assert.AreEqual(double.NegativeInfinity, BigInteger.Log(0)); - Assert.AreEqual(0d, BigInteger.Log(1)); - Assert.AreEqual(double.NaN, BigInteger.Log(-1)); - Assert.AreEqual(2.3025850929940459d, BigInteger.Log(10), delta); - Assert.AreEqual(6.9077552789821368d, BigInteger.Log(1000), delta); - Assert.AreEqual(double.NaN, BigInteger.Log(-234)); - } - - [TestMethod] - public void LogN() - { - const double delta = 0.000000000000001d; - - Assert.AreEqual(double.NaN, BigInteger.Log(10, 1), "#1"); - Assert.AreEqual(double.NaN, BigInteger.Log(10, 0), "#2"); - Assert.AreEqual(double.NaN, BigInteger.Log(10, -1), "#3"); - - Assert.AreEqual(double.NaN, BigInteger.Log(10, double.NaN), "#4"); - Assert.AreEqual(double.NaN, BigInteger.Log(10, double.NegativeInfinity), "#5"); - Assert.AreEqual(double.NaN, BigInteger.Log(10, double.PositiveInfinity), "#6"); - - Assert.AreEqual(0d, BigInteger.Log(1, 0), "#7"); - Assert.AreEqual(double.NaN, BigInteger.Log(1, double.NegativeInfinity), "#8"); - Assert.AreEqual(0, BigInteger.Log(1, double.PositiveInfinity), "#9"); - Assert.AreEqual(double.NaN, BigInteger.Log(1, double.NaN), "#10"); - - Assert.AreEqual(-2.5129415947320606d, BigInteger.Log(10, 0.4), delta, "#11"); - } - - [TestMethod] - public void DivRemByZero() - { - try - { - BigInteger d; - BigInteger.DivRem(100, 0, out d); - Assert.Fail("#1"); - } - catch (DivideByZeroException) - { - } - } - - [TestMethod] - public void TestAdd() - { - for (var i = 0; i < add_a.Length; ++i) - { - var a = new BigInteger(add_a[i]); - var b = new BigInteger(add_b[i]); - var c = new BigInteger(add_c[i]); - - Assert.AreEqual(c, a + b, "#" + i + "a"); - Assert.AreEqual(c, b + a, "#" + i + "b"); - Assert.AreEqual(c, BigInteger.Add(a, b), "#" + i + "c"); - AssertEqual(add_c[i], (a + b).ToByteArray()); - } - } - - [TestMethod] - public void TestAdd2() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - var c = a + b; - Assert.AreEqual(values[i] + values[j], (long)c, "#_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestHugeSub() - { - var a = new BigInteger(huge_a); - var b = new BigInteger(huge_b); - - AssertEqual(a_m_b, (a - b).ToByteArray()); - AssertEqual(b_m_a, (b - a).ToByteArray()); - } - - [TestMethod] - public void TestSub() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - var c = a - b; - var d = BigInteger.Subtract(a, b); - - Assert.AreEqual(values[i] - values[j], (long)c, "#_" + i + "_" + j); - Assert.AreEqual(values[i] - values[j], (long)d, "#_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestMin() - { - long[] values = { -100000000000L, -1000L, -1L, 0L, 1L, 1000L, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - var c = BigInteger.Min(a, b); - - Assert.AreEqual(Math.Min(values[i], values[j]), (long) c, "#_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestMax() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - var c = BigInteger.Max(a, b); - - Assert.AreEqual(Math.Max(values[i], values[j]), (long) c, "#_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestAbs() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - var a = new BigInteger(values[i]); - var c = BigInteger.Abs(a); - - Assert.AreEqual(Math.Abs(values[i]), (long) c, "#_" + i); - } - } - - [TestMethod] - public void TestNegate() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - var a = new BigInteger(values[i]); - var c = -a; - var d = BigInteger.Negate(a); - - Assert.AreEqual(-values[i], (long) c, "#_" + i); - Assert.AreEqual(-values[i], (long) d, "#_" + i); - } - } - - [TestMethod] - public void TestInc() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - var a = new BigInteger(values[i]); - var b = ++a; - - Assert.AreEqual(++values[i], (long)b, "#_" + i); - } - } - - [TestMethod] - public void TestDec() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - var a = new BigInteger(values[i]); - var b = --a; - - Assert.AreEqual(--values[i], (long) b, "#_" + i); - } - } - - [TestMethod] - public void TestBitwiseOps() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L, 0xFFFF00000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - - Assert.AreEqual(values[i] | values[j], (long) (a | b), "#b_" + i + "_" + j); - Assert.AreEqual(values[i] & values[j], (long) (a & b), "#a_" + i + "_" + j); - Assert.AreEqual(values[i] ^ values[j], (long) (a ^ b), "#c_" + i + "_" + j); - Assert.AreEqual(~values[i], (long) ~a, "#d_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestLeftShift() - { - AssertEqual(new byte[] { 0x00, 0x28 }, (new BigInteger(0x0A) << 10).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0xD8 }, (new BigInteger(-10) << 10).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0xFF }, (new BigInteger(-1) << 16).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A }, (new BigInteger(0x0A) << 80).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF6 }, (new BigInteger(-10) << 80).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, (new BigInteger(-1) << 80).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xD9 }, (new BigInteger(-1234) << 75).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x91, 0x00 }, (new BigInteger(0x1234) << 75).ToByteArray()); - AssertEqual(new byte[] { 0xFF, 0x00 }, (new BigInteger(0xFF00) << -8).ToByteArray()); - } - - [TestMethod] - public void TestRightShift() - { - AssertEqual(new byte[] { 0x16, 0xB0, 0x4C, 0x02 }, (new BigInteger(1234567899L) >> 5).ToByteArray()); - AssertEqual(new byte[] { 0x2C, 0x93, 0x00 }, (new BigInteger(1234567899L) >> 15).ToByteArray()); - AssertEqual(new byte[] { 0xFF, 0xFF, 0x7F }, (new BigInteger(long.MaxValue - 100) >> 40).ToByteArray()); - AssertEqual(new byte[] { 0xE9, 0x4F, 0xB3, 0xFD }, (new BigInteger(-1234567899L) >> 5).ToByteArray()); - AssertEqual(new byte[] { 0xD3, 0x6C, 0xFF }, (new BigInteger(-1234567899L) >> 15).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x80 }, (new BigInteger(long.MinValue + 100) >> 40).ToByteArray()); - AssertEqual(new byte[] { 0xFF }, (new BigInteger(-1234567899L) >> 90).ToByteArray()); - AssertEqual(new byte[] { 0x00 }, (new BigInteger(999999) >> 90).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0xFF, 0x00 }, (new BigInteger(0xFF00) >> -8).ToByteArray()); - } - - [TestMethod] - public void CompareOps() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = new BigInteger(values[j]); - - Assert.AreEqual(values[i].CompareTo(values[j]), a.CompareTo(b), "#a_" + i + "_" + j); - Assert.AreEqual(values[i].CompareTo(values[j]), BigInteger.Compare(a, b), "#b_" + i + "_" + j); - - Assert.AreEqual(values[i] < values[j], a < b, "#c_" + i + "_" + j); - Assert.AreEqual(values[i] <= values[j], a <= b, "#d_" + i + "_" + j); - Assert.AreEqual(values[i] == values[j], a == b, "#e_" + i + "_" + j); - Assert.AreEqual(values[i] != values[j], a != b, "#f_" + i + "_" + j); - Assert.AreEqual(values[i] >= values[j], a >= b, "#g_" + i + "_" + j); - Assert.AreEqual(values[i] > values[j], a > b, "#h_" + i + "_" + j); - } - } - } - - [TestMethod] - public void CompareOps2() - { - var a = new BigInteger(100000000000L); - var b = new BigInteger(28282828282UL); - - Assert.IsTrue(a >= b, "#1"); - Assert.IsTrue(a >= b, "#2"); - Assert.IsFalse(a < b, "#3"); - Assert.IsFalse(a <= b, "#4"); - Assert.AreEqual(1, a.CompareTo(b), "#5"); - } - - [TestMethod] - public void CompareULong() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L, 0xAA00000000L }; - ulong[] uvalues = { 0, 1, 1000, 100000000000L, 999999, 28282828282, 0xAA00000000, ulong.MaxValue }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < uvalues.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = uvalues[j]; - var c = new BigInteger(b); - - Assert.AreEqual(a.CompareTo(c), a.CompareTo(b), "#a_" + i + "_" + j); - - Assert.AreEqual(a > c, a > b, "#b_" + i + "_" + j); - Assert.AreEqual(a < c, a < b, "#c_" + i + "_" + j); - Assert.AreEqual(a <= c, a <= b, "#d_" + i + "_" + j); - Assert.AreEqual(a == c, a == b, "#e_" + i + "_" + j); - Assert.AreEqual(a != c, a != b, "#f_" + i + "_" + j); - Assert.AreEqual(a >= c, a >= b, "#g_" + i + "_" + j); - - Assert.AreEqual(c > a, b > a, "#ib_" + i + "_" + j); - Assert.AreEqual(c < a, b < a, "#ic_" + i + "_" + j); - Assert.AreEqual(c <= a, b <= a, "#id_" + i + "_" + j); - Assert.AreEqual(c == a, b == a, "#ie_" + i + "_" + j); - Assert.AreEqual(c != a, b != a, "#if_" + i + "_" + j); - Assert.AreEqual(c >= a, b >= a, "#ig_" + i + "_" + j); - } - } - } - - [TestMethod] - public void CompareLong() - { - long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 9999999, 100000000000L, 0xAA00000000, long.MaxValue, long.MinValue }; - - for (var i = 0; i < values.Length; ++i) - { - for (var j = 0; j < values.Length; ++j) - { - var a = new BigInteger(values[i]); - var b = values[j]; - var c = new BigInteger(b); - - Assert.AreEqual(a.CompareTo(c), a.CompareTo(b), "#a_" + i + "_" + j); - - Assert.AreEqual(a > c, a > b, "#b_" + i + "_" + j); - Assert.AreEqual(a < c, a < b, "#c_" + i + "_" + j); - Assert.AreEqual(a <= c, a <= b, "#d_" + i + "_" + j); - Assert.AreEqual(a == c, a == b, "#e_" + i + "_" + j); - Assert.AreEqual(a != c, a != b, "#f_" + i + "_" + j); - Assert.AreEqual(a >= c, a >= b, "#g_" + i + "_" + j); - - Assert.AreEqual(c > a, b > a, "#ib_" + i + "_" + j); - Assert.AreEqual(c < a, b < a, "#ic_" + i + "_" + j); - Assert.AreEqual(c <= a, b <= a, "#id_" + i + "_" + j); - Assert.AreEqual(c == a, b == a, "#ie_" + i + "_" + j); - Assert.AreEqual(c != a, b != a, "#if_" + i + "_" + j); - Assert.AreEqual(c >= a, b >= a, "#ig_" + i + "_" + j); - } - } - } - - [TestMethod] - public void TestEquals() - { - var a = new BigInteger(10); - var b = new BigInteger(10); - var c = new BigInteger(-10); - - Assert.AreEqual(a, b, "#1"); - Assert.AreNotEqual(a, c, "#2"); - Assert.AreEqual(a, 10, "#3"); - } - - [TestMethod] - public void Ctor_ByteArray_ShouldThrowArgumentNullExceptionWhenValueIsNull() - { - const byte[] value = null; - - try - { - var actual = new BigInteger(value); - Assert.Fail("#1:" + actual); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("value", ex.ParamName); - } - } - - [TestMethod] - public void ByteArrayCtor() - { - Assert.AreEqual(0, (int) new BigInteger(new byte[0])); - Assert.AreEqual(0, (int) new BigInteger(new byte[1])); - Assert.AreEqual(0, (int) new BigInteger(new byte[2])); - } - - [TestMethod] - public void IntCtorRoundTrip() - { - int[] values = - { - int.MinValue, -0x2F33BB, -0x1F33, -0x33, 0, 0x33, - 0x80, 0x8190, 0xFF0011, 0x1234, 0x11BB99, 0x44BB22CC, - int.MaxValue - }; - - foreach (var val in values) - { - var a = new BigInteger(val); - var b = new BigInteger(a.ToByteArray()); - - Assert.AreEqual(val, (int)a, "#a_" + val); - Assert.AreEqual(val, (int)b, "#b_" + val); - } - } - - [TestMethod] - public void LongCtorRoundTrip() - { - long[] values = - { - 0L, long.MinValue, long.MaxValue, -1, 1L + int.MaxValue, -1L + int.MinValue, 0x1234, 0xFFFFFFFFL, - 0x1FFFFFFFFL, -0xFFFFFFFFL, -0x1FFFFFFFFL, 0x100000000L, -0x100000000L, 0x100000001L, -0x100000001L, - 4294967295L, -4294967295L, 4294967296L, -4294967296L - }; - - foreach (var val in values) - { - try - { - var a = new BigInteger(val); - var b = new BigInteger(a.ToByteArray()); - - Assert.AreEqual(val, (long) a, "#a_" + val); - Assert.AreEqual(val, (long) b, "#b_" + val); - Assert.AreEqual(a, b, "#a == #b (" + val + ")"); - } - catch (Exception e) - { - Assert.Fail("Failed to roundtrip {0}: {1}", val, e); - } - } - } - - [TestMethod] - public void ByteArrayCtorRoundTrip() - { - var arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 0xFF, 0x0 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xF0 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4, 5 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4, 5, 6 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 2, 3, 4, 5 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 0 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 0xFF, 00 }; - AssertEqual(arr, new BigInteger(arr).ToByteArray()); - - arr = new byte[] { 1, 0, 0, 0, 0, 0, }; - AssertEqual(new byte[] { 1 }, new BigInteger(arr).ToByteArray()); - } - - [TestMethod] - public void TestIntCtorProperties() - { - BigInteger a = new BigInteger(10); - Assert.IsTrue(a.IsEven, "#1"); - Assert.IsFalse(a.IsOne, "#2"); - Assert.IsFalse(a.IsPowerOfTwo, "#3"); - Assert.IsFalse(a.IsZero, "#4"); - Assert.AreEqual(1, a.Sign, "#5"); - - Assert.IsFalse(new BigInteger(11).IsEven, "#6"); - Assert.IsTrue(new BigInteger(1).IsOne, "#7"); - Assert.IsTrue(new BigInteger(32).IsPowerOfTwo, "#8"); - Assert.IsTrue(new BigInteger(0).IsZero, "#9"); - Assert.IsTrue(new BigInteger().IsZero, "#9b"); - Assert.AreEqual(0, new BigInteger(0).Sign, "#10"); - Assert.AreEqual(-1, new BigInteger(-99999).Sign, "#11"); - - Assert.IsFalse(new BigInteger(0).IsPowerOfTwo, "#12"); - Assert.IsFalse(new BigInteger().IsPowerOfTwo, "#12b"); - Assert.IsFalse(new BigInteger(-16).IsPowerOfTwo, "#13"); - Assert.IsTrue(new BigInteger(1).IsPowerOfTwo, "#14"); - } - - [TestMethod] - public void TestIntCtorToString() - { - Assert.AreEqual("5555", new BigInteger(5555).ToString(), "#1"); - Assert.AreEqual("-99999", new BigInteger(-99999).ToString(), "#2"); - } - - [TestMethod] - public void TestToStringFmt() - { - Assert.AreEqual("123456789123456", new BigInteger(123456789123456).ToString("D2"), "#1"); - Assert.AreEqual("0000000005", new BigInteger(5).ToString("d10"), "#2"); - Assert.AreEqual("0A8", new BigInteger(168).ToString("X"), "#3"); - Assert.AreEqual("0", new BigInteger(0).ToString("X"), "#4"); - Assert.AreEqual("0", new BigInteger().ToString("X"), "#4b"); - Assert.AreEqual("1", new BigInteger(1).ToString("X"), "#5"); - Assert.AreEqual("0A", new BigInteger(10).ToString("X"), "#6"); - Assert.AreEqual("F6", new BigInteger(-10).ToString("X"), "#7"); - - Assert.AreEqual("10000000000000000000000000000000000000000000000000000000", BigInteger.Pow(10, 55).ToString("G"), "#8"); - - Assert.AreEqual("10000000000000000000000000000000000000000000000000000000", BigInteger.Pow(10, 55).ToString("R"), "#9"); - - - Assert.AreEqual("000000000A", new BigInteger(10).ToString("X10"), "#10"); - Assert.AreEqual("0000000010", new BigInteger(10).ToString("G10"), "#11"); - } - - [TestMethod] - public void TestToStringFmtProvider() - { - NumberFormatInfo info = new NumberFormatInfo - { - NegativeSign = ">", - PositiveSign = "%" - }; - - Assert.AreEqual("10", new BigInteger(10).ToString(info), "#1"); - Assert.AreEqual(">10", new BigInteger(-10).ToString(info), "#2"); - Assert.AreEqual("0A", new BigInteger(10).ToString("X", info), "#3"); - Assert.AreEqual("F6", new BigInteger(-10).ToString("X", info), "#4"); - Assert.AreEqual("10", new BigInteger(10).ToString("G", info), "#5"); - Assert.AreEqual(">10", new BigInteger(-10).ToString("G", info), "#6"); - Assert.AreEqual("10", new BigInteger(10).ToString("D", info), "#7"); - Assert.AreEqual(">10", new BigInteger(-10).ToString("D", info), "#8"); - Assert.AreEqual("10", new BigInteger(10).ToString("R", info), "#9"); - Assert.AreEqual(">10", new BigInteger(-10).ToString("R", info), "#10"); - - info = new NumberFormatInfo(); - info.NegativeSign = "#$%"; - Assert.AreEqual("#$%10", new BigInteger(-10).ToString(info), "#2"); - Assert.AreEqual("#$%10", new BigInteger(-10).ToString(null, info), "#2"); - - info = new NumberFormatInfo(); - Assert.AreEqual("-10", new BigInteger(-10).ToString(info), "#2"); - - } - - [TestMethod] - public void TestToIntOperator() - { - try - { - int v = (int)new BigInteger(huge_a); - Assert.Fail("#1"); - } - catch (OverflowException) { } - - try - { - int v = (int)new BigInteger(1L + int.MaxValue); - Assert.Fail("#2"); - } - catch (OverflowException) { } - - try - { - int v = (int)new BigInteger(-1L + int.MinValue); - Assert.Fail("#3"); - } - catch (OverflowException) { } - - Assert.AreEqual(int.MaxValue, (int)new BigInteger(int.MaxValue), "#4"); - Assert.AreEqual(int.MinValue, (int)new BigInteger(int.MinValue), "#5"); - } - - - [TestMethod] - public void TestToLongOperator() - { - try - { - long v = (long)new BigInteger(huge_a); - Assert.Fail("#1"); - } - catch (OverflowException) { } - - //long.MaxValue + 1 - try - { - long v = (long)new BigInteger(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00 }); - Assert.Fail("#2"); - } - catch (OverflowException) { } - - //TODO long.MinValue - 1 - try - { - long v = (long)new BigInteger(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF }); - Assert.Fail("#3"); - } - catch (OverflowException) { } - - Assert.AreEqual(long.MaxValue, (long)new BigInteger(long.MaxValue), "#4"); - Assert.AreEqual(long.MinValue, (long)new BigInteger(long.MinValue), "#5"); - } - - [TestMethod] - public void TestIntCtorToByteArray() - { - AssertEqual(new byte[] { 0xFF }, new BigInteger(-1).ToByteArray()); - AssertEqual(new byte[] { 0xD4, 0xFE }, new BigInteger(-300).ToByteArray()); - AssertEqual(new byte[] { 0x80, 0x00 }, new BigInteger(128).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x60 }, new BigInteger(0x6000).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x80, 0x00 }, new BigInteger(0x8000).ToByteArray()); - AssertEqual(new byte[] { 0xDD, 0xBC, 0x00, 0x7A }, new BigInteger(0x7A00BCDD).ToByteArray()); - AssertEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0x7F }, new BigInteger(int.MaxValue).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x80 }, new BigInteger(int.MinValue).ToByteArray()); - AssertEqual(new byte[] { 0x01, 0x00, 0x00, 0x80 }, new BigInteger(int.MinValue + 1).ToByteArray()); - AssertEqual(new byte[] { 0x7F }, new BigInteger(0x7F).ToByteArray()); - AssertEqual(new byte[] { 0x45, 0xCC, 0xD0 }, new BigInteger(-0x2F33BB).ToByteArray()); - AssertEqual(new byte[] { 0 }, new BigInteger(0).ToByteArray()); - AssertEqual(new byte[] { 0 }, new BigInteger().ToByteArray()); - } - - [TestMethod] - public void TestLongCtorToByteArray() - { - AssertEqual(new byte[] { 0x01 }, new BigInteger(0x01L).ToByteArray()); - AssertEqual(new byte[] { 0x02, 0x01 }, new BigInteger(0x0102L).ToByteArray()); - AssertEqual(new byte[] { 0x03, 0x02, 0x01 }, new BigInteger(0x010203L).ToByteArray()); - AssertEqual(new byte[] { 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x01020304L).ToByteArray()); - AssertEqual(new byte[] { 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x0102030405L).ToByteArray()); - AssertEqual(new byte[] { 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x010203040506L).ToByteArray()); - AssertEqual(new byte[] { 0x07, 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x01020304050607L).ToByteArray()); - AssertEqual(new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x0102030405060708L).ToByteArray()); - - AssertEqual(new byte[] { 0xFF }, new BigInteger(-0x01L).ToByteArray()); - AssertEqual(new byte[] { 0xFE, 0xFE }, new BigInteger(-0x0102L).ToByteArray()); - AssertEqual(new byte[] { 0xFD, 0xFD, 0xFE }, new BigInteger(-0x010203L).ToByteArray()); - AssertEqual(new byte[] { 0xFC, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x01020304L).ToByteArray()); - AssertEqual(new byte[] { 0xFB, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x0102030405L).ToByteArray()); - AssertEqual(new byte[] { 0xFA, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x010203040506L).ToByteArray()); - AssertEqual(new byte[] { 0xF9, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x01020304050607L).ToByteArray()); - AssertEqual(new byte[] { 0xF8, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x0102030405060708L).ToByteArray()); - - AssertEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, new BigInteger(long.MaxValue).ToByteArray()); - AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, new BigInteger(long.MinValue).ToByteArray()); - - AssertEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0x7F, 0xFF }, new BigInteger(-2147483649L).ToByteArray()); - } - - [TestMethod] - public void CompareTo() - { - var a = new BigInteger(99); - Assert.AreEqual(-1, a.CompareTo(100), "#1"); - Assert.AreEqual(1, a.CompareTo(null), "#2"); - } - - [TestMethod] - public void ShortOperators() - { - Assert.AreEqual(22, (int)new BigInteger((short)22), "#1"); - Assert.AreEqual(-22, (int)new BigInteger((short)-22), "#2"); - - try - { - short x = (short)new BigInteger(10000000); - Assert.Fail("#3"); - } - catch (OverflowException) { } - - try - { - short x = (short)new BigInteger(-10000000); - Assert.Fail("#4"); - } - catch (OverflowException) { } - } - - [TestMethod] - public void Ctor_Double_NaN() - { - try - { - new BigInteger(double.NaN); - Assert.Fail(); - } - catch (OverflowException) - { - } - } - - [TestMethod] - public void Ctor_Double_NegativeInfinity() - { - try - { - new BigInteger(double.NegativeInfinity); - Assert.Fail(); - } - catch (OverflowException) - { - } - } - - [TestMethod] - public void Ctor_Double_PositiveInfinity() - { - try - { - new BigInteger(double.PositiveInfinity); - Assert.Fail(); - } - catch (OverflowException) - { - } - } - - [TestMethod] - public void Ctor_Double() - { - Assert.AreEqual(10000, (int)new BigInteger(10000.2)); - Assert.AreEqual(10000, (int)new BigInteger(10000.9)); - Assert.AreEqual(10000, (int)new BigInteger(10000.2)); - Assert.AreEqual(0, (int)new BigInteger(0.9)); - Assert.AreEqual(12345678999L, (long)new BigInteger(12345678999.33)); - } - - [TestMethod] - public void DoubleConversion() - { - Assert.AreEqual(999d, (double)new BigInteger(999), "#1"); - Assert.AreEqual(double.PositiveInfinity, (double)BigInteger.Pow(2, 1024), "#2"); - Assert.AreEqual(double.NegativeInfinity, (double)BigInteger.Pow(-2, 1025), "#3"); - - Assert.AreEqual(0d, (double)BigInteger.Zero, "#4"); - Assert.AreEqual(1d, (double)BigInteger.One, "#5"); - Assert.AreEqual(-1d, (double)BigInteger.MinusOne, "#6"); - - var result1 = BitConverter.Int64BitsToDouble(-4337852273739220173); - Assert.AreEqual(result1, (double)new BigInteger(new byte[] { 53, 152, 137, 177, 240, 81, 75, 198 }), "#7"); - var result2 = BitConverter.Int64BitsToDouble(4893382453283402035); - Assert.AreEqual(result2, (double)new BigInteger(new byte[] { 53, 152, 137, 177, 240, 81, 75, 198, 0 }), "#8"); - - var result3 = BitConverter.Int64BitsToDouble(5010775143622804480); - var result4 = BitConverter.Int64BitsToDouble(5010775143622804481); - var result5 = BitConverter.Int64BitsToDouble(5010775143622804482); - Assert.AreEqual(result3, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 16, 128, 208, 159, 60, 46, 59, 3 }), "#9"); - Assert.AreEqual(result3, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 17, 128, 208, 159, 60, 46, 59, 3 }), "#10"); - Assert.AreEqual(result3, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 24, 128, 208, 159, 60, 46, 59, 3 }), "#11"); - Assert.AreEqual(result4, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 32, 128, 208, 159, 60, 46, 59, 3 }), "#12"); - Assert.AreEqual(result4, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 48, 128, 208, 159, 60, 46, 59, 3 }), "#13"); - Assert.AreEqual(result5, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 64, 128, 208, 159, 60, 46, 59, 3 }), "#14"); - - Assert.AreEqual(BitConverter.Int64BitsToDouble(-2748107935317889142), (double)new BigInteger(huge_a), "#15"); - Assert.AreEqual(BitConverter.Int64BitsToDouble(-2354774254443231289), (double)new BigInteger(huge_b), "#16"); - Assert.AreEqual(BitConverter.Int64BitsToDouble(8737073938546854790), (double)new BigInteger(huge_mul), "#17"); - - Assert.AreEqual(BitConverter.Int64BitsToDouble(6912920136897069886), (double)(2278888483353476799 * BigInteger.Pow(2, 451)), "#18"); - Assert.AreEqual(double.PositiveInfinity, (double)(843942696292817306 * BigInteger.Pow(2, 965)), "#19"); - } - - [TestMethod] - public void DecimalCtor() - { - Assert.AreEqual(999, (int)new BigInteger(999.99m), "#1"); - Assert.AreEqual(-10000, (int)new BigInteger(-10000m), "#2"); - Assert.AreEqual(0, (int)new BigInteger(0m), "#3"); - } - - [TestMethod] - public void DecimalConversion() - { - Assert.AreEqual(999m, (decimal)new BigInteger(999), "#1"); - - try - { - var x = (decimal) BigInteger.Pow(2, 1024); - Assert.Fail("#2: " + x); - } - catch (OverflowException) - { - } - - try - { - var x = (decimal) BigInteger.Pow(-2, 1025); - Assert.Fail("#3: " + x); - } - catch (OverflowException) - { - } - - Assert.AreEqual(0m, (decimal)new BigInteger(0), "#4"); - Assert.AreEqual(1m, (decimal)new BigInteger(1), "#5"); - Assert.AreEqual(-1m, (decimal)new BigInteger(-1), "#6"); - Assert.AreEqual(9999999999999999999999999999m, (decimal)new BigInteger(9999999999999999999999999999m), "#7"); - Assert.AreEqual(0m, (decimal)new BigInteger(), "#8"); - } - - [TestMethod] - public void Parse() - { - try - { - BigInteger.Parse(null); - Assert.Fail("#1"); - } - catch (ArgumentNullException) { } - - try - { - BigInteger.Parse(""); - Assert.Fail("#2"); - } - catch (FormatException) { } - - - try - { - BigInteger.Parse(" "); - Assert.Fail("#3"); - } - catch (FormatException) { } - - try - { - BigInteger.Parse("hh"); - Assert.Fail("#4"); - } - catch (FormatException) { } - - try - { - BigInteger.Parse("-"); - Assert.Fail("#5"); - } - catch (FormatException) { } - - try - { - BigInteger.Parse("-+"); - Assert.Fail("#6"); - } - catch (FormatException) { } - - Assert.AreEqual(10, (int)BigInteger.Parse("+10"), "#7"); - Assert.AreEqual(10, (int)BigInteger.Parse("10 "), "#8"); - Assert.AreEqual(-10, (int)BigInteger.Parse("-10 "), "#9"); - Assert.AreEqual(10, (int)BigInteger.Parse(" 10 "), "#10"); - Assert.AreEqual(-10, (int)BigInteger.Parse(" -10 "), "#11"); - - Assert.AreEqual(-1, (int)BigInteger.Parse("F", NumberStyles.AllowHexSpecifier), "#12"); - Assert.AreEqual(-8, (int)BigInteger.Parse("8", NumberStyles.AllowHexSpecifier), "#13"); - Assert.AreEqual(8, (int)BigInteger.Parse("08", NumberStyles.AllowHexSpecifier), "#14"); - Assert.AreEqual(15, (int)BigInteger.Parse("0F", NumberStyles.AllowHexSpecifier), "#15"); - Assert.AreEqual(-1, (int)BigInteger.Parse("FF", NumberStyles.AllowHexSpecifier), "#16"); - Assert.AreEqual(255, (int)BigInteger.Parse("0FF", NumberStyles.AllowHexSpecifier), "#17"); - - Assert.AreEqual(-17, (int)BigInteger.Parse(" (17) ", NumberStyles.AllowParentheses | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite), "#18"); - Assert.AreEqual(-23, (int)BigInteger.Parse(" -23 ", NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite), "#19"); - - Assert.AreEqual(300000, (int)BigInteger.Parse("3E5", NumberStyles.AllowExponent), "#20"); - var dsep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; - Assert.AreEqual(250, (int)BigInteger.Parse("2" + dsep + "5E2", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint), "#21");//2.5E2 = 250 - Assert.AreEqual(25, (int)BigInteger.Parse("2500E-2", NumberStyles.AllowExponent), "#22"); - - Assert.AreEqual("136236974127783066520110477975349088954559032721408", BigInteger.Parse("136236974127783066520110477975349088954559032721408", NumberStyles.None).ToString(), "#23"); - Assert.AreEqual("136236974127783066520110477975349088954559032721408", BigInteger.Parse("136236974127783066520110477975349088954559032721408").ToString(), "#24"); - - try - { - BigInteger.Parse("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent - Assert.Fail("#25"); - } - catch (FormatException) - { - } - - try - { - Int32.Parse("2" + dsep + "09E1", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); - Assert.Fail("#26"); - } - catch (OverflowException) - { - } - } - - [TestMethod] - public void TryParse_Value_ShouldReturnFalseWhenValueIsNull() - { - BigInteger x; - - var actual = BigInteger.TryParse(null, out x); - - Assert.IsFalse(actual); - Assert.AreEqual(BigInteger.Zero, x); - } - - [TestMethod] - public void TryParse_Value() - { - BigInteger x; - - Assert.IsFalse(BigInteger.TryParse("", out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse(" ", out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse(" -", out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse(" +", out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse(" FF", out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsTrue(BigInteger.TryParse(" 99", out x)); - Assert.AreEqual(99, (int) x); - - Assert.IsTrue(BigInteger.TryParse("+133", out x)); - Assert.AreEqual(133, (int) x); - - Assert.IsTrue(BigInteger.TryParse("-010", out x)); - Assert.AreEqual(-10, (int) x); - } - - [TestMethod] - public void TryParse_ValueAndStyleAndProvider() - { - BigInteger x; - - Assert.IsFalse(BigInteger.TryParse("null", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse("-10", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse("(10)", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse(" 10", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse("10 ", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsTrue(BigInteger.TryParse("-10", NumberStyles.AllowLeadingSign, null, out x)); - Assert.AreEqual(-10, (int) x); - - Assert.IsTrue(BigInteger.TryParse("(10)", NumberStyles.AllowParentheses, null, out x)); - Assert.AreEqual(-10, (int) x); - - Assert.IsTrue(BigInteger.TryParse(" 10", NumberStyles.AllowLeadingWhite, null, out x)); - Assert.AreEqual(10, (int) x); - - Assert.IsTrue(BigInteger.TryParse("10 ", NumberStyles.AllowTrailingWhite, null, out x)); - Assert.AreEqual(10, (int) x); - - Assert.IsFalse(BigInteger.TryParse("$10", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse("$10", NumberStyles.None, _nfi, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse("%10", NumberStyles.None, _nfi, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsFalse(BigInteger.TryParse("10 ", NumberStyles.None, null, out x)); - Assert.AreEqual(BigInteger.Zero, x); - - Assert.IsTrue(BigInteger.TryParse("10", NumberStyles.None, null, out x)); - Assert.AreEqual(10, (int) x); - - Assert.IsTrue(BigInteger.TryParse(_nfi.CurrencySymbol + "10", NumberStyles.AllowCurrencySymbol, _nfi, out x)); - Assert.AreEqual(10, (int) x); - - Assert.IsFalse(BigInteger.TryParse("%10", NumberStyles.AllowCurrencySymbol, _nfi, out x)); - Assert.AreEqual(BigInteger.Zero, x); - } - - [TestMethod] - public void TryParse_ValueAndStyleAndProvider_ShouldReturnFalseWhenValueIsNull() - { - BigInteger x; - - var actual = BigInteger.TryParse(null, NumberStyles.Any, CultureInfo.InvariantCulture, out x); - - Assert.IsFalse(actual); - Assert.AreEqual(BigInteger.Zero, x); - } - - [TestMethod] - public void TestUserCurrency() - { - const int val1 = -1234567; - const int val2 = 1234567; - - var s = val1.ToString("c", _nfiUser); - Assert.AreEqual("1234/5/67:000 XYZ-", s, "Currency value type 1 is not what we want to try to parse"); - - var v = BigInteger.Parse("1234/5/67:000 XYZ-", NumberStyles.Currency, _nfiUser); - Assert.AreEqual(val1, (int) v); - - s = val2.ToString("c", _nfiUser); - Assert.AreEqual("1234/5/67:000 XYZ", s, "Currency value type 2 is not what we want to try to parse"); - - v = BigInteger.Parse(s, NumberStyles.Currency, _nfiUser); - Assert.AreEqual(val2, (int)v); - } - - [TestMethod] - public void TryParseWeirdCulture() - { - var old = Thread.CurrentThread.CurrentCulture; - var cur = (CultureInfo)old.Clone(); - - var ninfo = new NumberFormatInfo - { - NegativeSign = ">", - PositiveSign = "%" - }; - cur.NumberFormat = ninfo; - - Thread.CurrentThread.CurrentCulture = cur; - - try - { - BigInteger x; - Assert.IsTrue(BigInteger.TryParse("%11", out x)); - Assert.AreEqual(11, (int) x); - - Assert.IsTrue(BigInteger.TryParse(">11", out x)); - Assert.AreEqual(-11, (int) x); - } - finally - { - Thread.CurrentThread.CurrentCulture = old; - } - } - - [TestMethod] - public void CompareToLongToWithBigNumber() - { - var a = BigInteger.Parse("123456789123456789"); - Assert.AreEqual(1, a.CompareTo(2000)); - Assert.AreEqual(1, a.CompareTo(-2000)); - - var b = BigInteger.Parse("-123456789123456789"); - Assert.AreEqual(-1, b.CompareTo(2000)); - Assert.AreEqual(-1, b.CompareTo(-2000)); - } - - [TestMethod] - public void LeftShiftByInt() - { - var v = BigInteger.Parse("230794411440927908251127453634"); - - Assert.AreEqual("230794411440927908251127453634", (v << 0).ToString(), "#0"); - Assert.AreEqual("461588822881855816502254907268", (v << 1).ToString(), "#1"); - Assert.AreEqual("923177645763711633004509814536", (v << 2).ToString(), "#2"); - Assert.AreEqual("1846355291527423266009019629072", (v << 3).ToString(), "#3"); - Assert.AreEqual("3692710583054846532018039258144", (v << 4).ToString(), "#4"); - Assert.AreEqual("7385421166109693064036078516288", (v << 5).ToString(), "#5"); - Assert.AreEqual("14770842332219386128072157032576", (v << 6).ToString(), "#6"); - Assert.AreEqual("29541684664438772256144314065152", (v << 7).ToString(), "#7"); - Assert.AreEqual("59083369328877544512288628130304", (v << 8).ToString(), "#8"); - Assert.AreEqual("118166738657755089024577256260608", (v << 9).ToString(), "#9"); - Assert.AreEqual("236333477315510178049154512521216", (v << 10).ToString(), "#10"); - Assert.AreEqual("472666954631020356098309025042432", (v << 11).ToString(), "#11"); - Assert.AreEqual("945333909262040712196618050084864", (v << 12).ToString(), "#12"); - Assert.AreEqual("1890667818524081424393236100169728", (v << 13).ToString(), "#13"); - Assert.AreEqual("3781335637048162848786472200339456", (v << 14).ToString(), "#14"); - Assert.AreEqual("7562671274096325697572944400678912", (v << 15).ToString(), "#15"); - Assert.AreEqual("15125342548192651395145888801357824", (v << 16).ToString(), "#16"); - Assert.AreEqual("30250685096385302790291777602715648", (v << 17).ToString(), "#17"); - Assert.AreEqual("60501370192770605580583555205431296", (v << 18).ToString(), "#18"); - Assert.AreEqual("121002740385541211161167110410862592", (v << 19).ToString(), "#19"); - Assert.AreEqual("242005480771082422322334220821725184", (v << 20).ToString(), "#20"); - Assert.AreEqual("484010961542164844644668441643450368", (v << 21).ToString(), "#21"); - Assert.AreEqual("968021923084329689289336883286900736", (v << 22).ToString(), "#22"); - Assert.AreEqual("1936043846168659378578673766573801472", (v << 23).ToString(), "#23"); - Assert.AreEqual("3872087692337318757157347533147602944", (v << 24).ToString(), "#24"); - Assert.AreEqual("7744175384674637514314695066295205888", (v << 25).ToString(), "#25"); - Assert.AreEqual("15488350769349275028629390132590411776", (v << 26).ToString(), "#26"); - Assert.AreEqual("30976701538698550057258780265180823552", (v << 27).ToString(), "#27"); - Assert.AreEqual("61953403077397100114517560530361647104", (v << 28).ToString(), "#28"); - Assert.AreEqual("123906806154794200229035121060723294208", (v << 29).ToString(), "#29"); - Assert.AreEqual("247813612309588400458070242121446588416", (v << 30).ToString(), "#30"); - Assert.AreEqual("495627224619176800916140484242893176832", (v << 31).ToString(), "#31"); - Assert.AreEqual("991254449238353601832280968485786353664", (v << 32).ToString(), "#32"); - Assert.AreEqual("1982508898476707203664561936971572707328", (v << 33).ToString(), "#33"); - Assert.AreEqual("3965017796953414407329123873943145414656", (v << 34).ToString(), "#34"); - Assert.AreEqual("7930035593906828814658247747886290829312", (v << 35).ToString(), "#35"); - Assert.AreEqual("15860071187813657629316495495772581658624", (v << 36).ToString(), "#36"); - Assert.AreEqual("31720142375627315258632990991545163317248", (v << 37).ToString(), "#37"); - Assert.AreEqual("63440284751254630517265981983090326634496", (v << 38).ToString(), "#38"); - Assert.AreEqual("126880569502509261034531963966180653268992", (v << 39).ToString(), "#39"); - Assert.AreEqual("253761139005018522069063927932361306537984", (v << 40).ToString(), "#40"); - Assert.AreEqual("507522278010037044138127855864722613075968", (v << 41).ToString(), "#41"); - Assert.AreEqual("1015044556020074088276255711729445226151936", (v << 42).ToString(), "#42"); - Assert.AreEqual("2030089112040148176552511423458890452303872", (v << 43).ToString(), "#43"); - Assert.AreEqual("4060178224080296353105022846917780904607744", (v << 44).ToString(), "#44"); - Assert.AreEqual("8120356448160592706210045693835561809215488", (v << 45).ToString(), "#45"); - Assert.AreEqual("16240712896321185412420091387671123618430976", (v << 46).ToString(), "#46"); - Assert.AreEqual("32481425792642370824840182775342247236861952", (v << 47).ToString(), "#47"); - Assert.AreEqual("64962851585284741649680365550684494473723904", (v << 48).ToString(), "#48"); - Assert.AreEqual("129925703170569483299360731101368988947447808", (v << 49).ToString(), "#49"); - Assert.AreEqual("259851406341138966598721462202737977894895616", (v << 50).ToString(), "#50"); - Assert.AreEqual("519702812682277933197442924405475955789791232", (v << 51).ToString(), "#51"); - Assert.AreEqual("1039405625364555866394885848810951911579582464", (v << 52).ToString(), "#52"); - Assert.AreEqual("2078811250729111732789771697621903823159164928", (v << 53).ToString(), "#53"); - Assert.AreEqual("4157622501458223465579543395243807646318329856", (v << 54).ToString(), "#54"); - Assert.AreEqual("8315245002916446931159086790487615292636659712", (v << 55).ToString(), "#55"); - Assert.AreEqual("16630490005832893862318173580975230585273319424", (v << 56).ToString(), "#56"); - Assert.AreEqual("33260980011665787724636347161950461170546638848", (v << 57).ToString(), "#57"); - Assert.AreEqual("66521960023331575449272694323900922341093277696", (v << 58).ToString(), "#58"); - Assert.AreEqual("133043920046663150898545388647801844682186555392", (v << 59).ToString(), "#59"); - Assert.AreEqual("266087840093326301797090777295603689364373110784", (v << 60).ToString(), "#60"); - Assert.AreEqual("532175680186652603594181554591207378728746221568", (v << 61).ToString(), "#61"); - Assert.AreEqual("1064351360373305207188363109182414757457492443136", (v << 62).ToString(), "#62"); - Assert.AreEqual("2128702720746610414376726218364829514914984886272", (v << 63).ToString(), "#63"); - Assert.AreEqual("4257405441493220828753452436729659029829969772544", (v << 64).ToString(), "#64"); - Assert.AreEqual("8514810882986441657506904873459318059659939545088", (v << 65).ToString(), "#65"); - Assert.AreEqual("17029621765972883315013809746918636119319879090176", (v << 66).ToString(), "#66"); - Assert.AreEqual("34059243531945766630027619493837272238639758180352", (v << 67).ToString(), "#67"); - Assert.AreEqual("68118487063891533260055238987674544477279516360704", (v << 68).ToString(), "#68"); - Assert.AreEqual("136236974127783066520110477975349088954559032721408", (v << 69).ToString(), "#69"); - } - - - [TestMethod] - public void RightShiftByInt() - { - var v = BigInteger.Parse("230794411440927908251127453634"); - v = v * BigInteger.Pow(2, 70); - - Assert.AreEqual("272473948255566133040220955950698177909118065442816", (v >> 0).ToString(), "#0"); - Assert.AreEqual("136236974127783066520110477975349088954559032721408", (v >> 1).ToString(), "#1"); - Assert.AreEqual("68118487063891533260055238987674544477279516360704", (v >> 2).ToString(), "#2"); - Assert.AreEqual("34059243531945766630027619493837272238639758180352", (v >> 3).ToString(), "#3"); - Assert.AreEqual("17029621765972883315013809746918636119319879090176", (v >> 4).ToString(), "#4"); - Assert.AreEqual("8514810882986441657506904873459318059659939545088", (v >> 5).ToString(), "#5"); - Assert.AreEqual("4257405441493220828753452436729659029829969772544", (v >> 6).ToString(), "#6"); - Assert.AreEqual("2128702720746610414376726218364829514914984886272", (v >> 7).ToString(), "#7"); - Assert.AreEqual("1064351360373305207188363109182414757457492443136", (v >> 8).ToString(), "#8"); - Assert.AreEqual("532175680186652603594181554591207378728746221568", (v >> 9).ToString(), "#9"); - Assert.AreEqual("266087840093326301797090777295603689364373110784", (v >> 10).ToString(), "#10"); - Assert.AreEqual("133043920046663150898545388647801844682186555392", (v >> 11).ToString(), "#11"); - Assert.AreEqual("66521960023331575449272694323900922341093277696", (v >> 12).ToString(), "#12"); - Assert.AreEqual("33260980011665787724636347161950461170546638848", (v >> 13).ToString(), "#13"); - Assert.AreEqual("16630490005832893862318173580975230585273319424", (v >> 14).ToString(), "#14"); - Assert.AreEqual("8315245002916446931159086790487615292636659712", (v >> 15).ToString(), "#15"); - Assert.AreEqual("4157622501458223465579543395243807646318329856", (v >> 16).ToString(), "#16"); - Assert.AreEqual("2078811250729111732789771697621903823159164928", (v >> 17).ToString(), "#17"); - Assert.AreEqual("1039405625364555866394885848810951911579582464", (v >> 18).ToString(), "#18"); - Assert.AreEqual("519702812682277933197442924405475955789791232", (v >> 19).ToString(), "#19"); - Assert.AreEqual("259851406341138966598721462202737977894895616", (v >> 20).ToString(), "#20"); - Assert.AreEqual("129925703170569483299360731101368988947447808", (v >> 21).ToString(), "#21"); - Assert.AreEqual("64962851585284741649680365550684494473723904", (v >> 22).ToString(), "#22"); - Assert.AreEqual("32481425792642370824840182775342247236861952", (v >> 23).ToString(), "#23"); - Assert.AreEqual("16240712896321185412420091387671123618430976", (v >> 24).ToString(), "#24"); - Assert.AreEqual("8120356448160592706210045693835561809215488", (v >> 25).ToString(), "#25"); - Assert.AreEqual("4060178224080296353105022846917780904607744", (v >> 26).ToString(), "#26"); - Assert.AreEqual("2030089112040148176552511423458890452303872", (v >> 27).ToString(), "#27"); - Assert.AreEqual("1015044556020074088276255711729445226151936", (v >> 28).ToString(), "#28"); - Assert.AreEqual("507522278010037044138127855864722613075968", (v >> 29).ToString(), "#29"); - Assert.AreEqual("253761139005018522069063927932361306537984", (v >> 30).ToString(), "#30"); - Assert.AreEqual("126880569502509261034531963966180653268992", (v >> 31).ToString(), "#31"); - Assert.AreEqual("63440284751254630517265981983090326634496", (v >> 32).ToString(), "#32"); - Assert.AreEqual("31720142375627315258632990991545163317248", (v >> 33).ToString(), "#33"); - Assert.AreEqual("15860071187813657629316495495772581658624", (v >> 34).ToString(), "#34"); - Assert.AreEqual("7930035593906828814658247747886290829312", (v >> 35).ToString(), "#35"); - Assert.AreEqual("3965017796953414407329123873943145414656", (v >> 36).ToString(), "#36"); - Assert.AreEqual("1982508898476707203664561936971572707328", (v >> 37).ToString(), "#37"); - Assert.AreEqual("991254449238353601832280968485786353664", (v >> 38).ToString(), "#38"); - Assert.AreEqual("495627224619176800916140484242893176832", (v >> 39).ToString(), "#39"); - Assert.AreEqual("247813612309588400458070242121446588416", (v >> 40).ToString(), "#40"); - Assert.AreEqual("123906806154794200229035121060723294208", (v >> 41).ToString(), "#41"); - Assert.AreEqual("61953403077397100114517560530361647104", (v >> 42).ToString(), "#42"); - Assert.AreEqual("30976701538698550057258780265180823552", (v >> 43).ToString(), "#43"); - Assert.AreEqual("15488350769349275028629390132590411776", (v >> 44).ToString(), "#44"); - Assert.AreEqual("7744175384674637514314695066295205888", (v >> 45).ToString(), "#45"); - Assert.AreEqual("3872087692337318757157347533147602944", (v >> 46).ToString(), "#46"); - Assert.AreEqual("1936043846168659378578673766573801472", (v >> 47).ToString(), "#47"); - Assert.AreEqual("968021923084329689289336883286900736", (v >> 48).ToString(), "#48"); - Assert.AreEqual("484010961542164844644668441643450368", (v >> 49).ToString(), "#49"); - Assert.AreEqual("242005480771082422322334220821725184", (v >> 50).ToString(), "#50"); - Assert.AreEqual("121002740385541211161167110410862592", (v >> 51).ToString(), "#51"); - Assert.AreEqual("60501370192770605580583555205431296", (v >> 52).ToString(), "#52"); - Assert.AreEqual("30250685096385302790291777602715648", (v >> 53).ToString(), "#53"); - Assert.AreEqual("15125342548192651395145888801357824", (v >> 54).ToString(), "#54"); - Assert.AreEqual("7562671274096325697572944400678912", (v >> 55).ToString(), "#55"); - Assert.AreEqual("3781335637048162848786472200339456", (v >> 56).ToString(), "#56"); - Assert.AreEqual("1890667818524081424393236100169728", (v >> 57).ToString(), "#57"); - Assert.AreEqual("945333909262040712196618050084864", (v >> 58).ToString(), "#58"); - Assert.AreEqual("472666954631020356098309025042432", (v >> 59).ToString(), "#59"); - Assert.AreEqual("236333477315510178049154512521216", (v >> 60).ToString(), "#60"); - Assert.AreEqual("118166738657755089024577256260608", (v >> 61).ToString(), "#61"); - Assert.AreEqual("59083369328877544512288628130304", (v >> 62).ToString(), "#62"); - Assert.AreEqual("29541684664438772256144314065152", (v >> 63).ToString(), "#63"); - Assert.AreEqual("14770842332219386128072157032576", (v >> 64).ToString(), "#64"); - Assert.AreEqual("7385421166109693064036078516288", (v >> 65).ToString(), "#65"); - Assert.AreEqual("3692710583054846532018039258144", (v >> 66).ToString(), "#66"); - Assert.AreEqual("1846355291527423266009019629072", (v >> 67).ToString(), "#67"); - Assert.AreEqual("923177645763711633004509814536", (v >> 68).ToString(), "#68"); - Assert.AreEqual("461588822881855816502254907268", (v >> 69).ToString(), "#69"); - } - - [TestMethod] - public void Bug10887() - { - BigInteger b = 0; - for (var i = 1; i <= 16; i++) - b = b * 256 + i; - var p = BigInteger.Pow(2, 32); - - Assert.AreEqual("1339673755198158349044581307228491536", b.ToString()); - Assert.AreEqual("1339673755198158349044581307228491536", ((b << 32) / p).ToString()); - Assert.AreEqual("1339673755198158349044581307228491536", (b * p >> 32).ToString()); - } - - [TestMethod] - public void DefaultCtorWorks() - { - var a = new BigInteger(); - Assert.AreEqual(BigInteger.One, ++a, "#1"); - - a = new BigInteger(); - Assert.AreEqual(BigInteger.MinusOne, --a, "#2"); - - a = new BigInteger(); - Assert.AreEqual(BigInteger.MinusOne, ~a, "#3"); - - a = new BigInteger(); - Assert.AreEqual("0", a.ToString(), "#4"); - - a = new BigInteger(); - Assert.AreEqual(true, a == a, "#5"); - - a = new BigInteger(); - Assert.AreEqual(false, a < a, "#6"); - - a = new BigInteger(); - Assert.AreEqual(true, a < 10L, "#7"); - - a = new BigInteger(); - Assert.AreEqual(true, a.IsEven, "#8"); - - a = new BigInteger(); - Assert.AreEqual(0, (int)a, "#9"); - - a = new BigInteger(); - Assert.AreEqual((uint) 0, (uint)a, "#10"); - - a = new BigInteger(); - Assert.AreEqual((ulong) 0, (ulong)a, "#11"); - - a = new BigInteger(); - Assert.AreEqual(true, a.Equals(a), "#12"); - - a = new BigInteger(); - Assert.AreEqual(a, BigInteger.Min(a, a), "#13"); - - a = new BigInteger(); - Assert.AreEqual(a, BigInteger.GreatestCommonDivisor(a, a), "#14"); - - a = new BigInteger(); - Assert.AreEqual(BigInteger.Zero.GetHashCode(), a.GetHashCode(), "#15"); - - a = new BigInteger(); - Assert.AreEqual(BigInteger.Zero, a, "#16"); - } - - [TestMethod] - public void Bug16526() - { - var x = BigInteger.Pow(2, 63); - x *= -1; - x -= 1; - Assert.AreEqual("-9223372036854775809", x.ToString(), "#1"); - try - { - x = (long)x; - Assert.Fail("#2 Must OVF: " + x); - } - catch (OverflowException) - { - } - } - - [TestMethod] - public void ToArray_Performance() - { - const int loopCount = 100000000; - var bigInteger = new BigInteger(huge_a); - - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - bigInteger.ToByteArray(); - } - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - [TestMethod] - public void Ctor_ByteArray_Performance() - { - const int loopCount = 100000000; - - var stopWatch = new Stopwatch(); - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Start(); - - for (var i = 0; i < loopCount; i++) - { - new BigInteger(huge_a); - } - - GC.Collect(); - GC.WaitForFullGCComplete(); - - stopWatch.Stop(); - - Console.WriteLine(stopWatch.ElapsedMilliseconds); - } - - [TestMethod] - public void MinusOne() - { - var minusOne = BigInteger.MinusOne; - - Assert.IsFalse(minusOne.IsEven); - Assert.IsFalse(minusOne.IsOne); - Assert.IsFalse(minusOne.IsPowerOfTwo); - Assert.IsFalse(minusOne.IsZero); - Assert.AreEqual(-1, minusOne.Sign); - } - - [TestMethod] - public void One() - { - var one = BigInteger.One; - - Assert.IsFalse(one.IsEven); - Assert.IsTrue(one.IsOne); - Assert.IsTrue(one.IsPowerOfTwo); - Assert.IsFalse(one.IsZero); - Assert.AreEqual(1, one.Sign); - } - - [TestMethod] - public void Zero() - { - var zero = BigInteger.Zero; - - Assert.IsTrue(zero.IsEven); - Assert.IsFalse(zero.IsOne); - Assert.IsFalse(zero.IsPowerOfTwo); - Assert.IsTrue(zero.IsZero); - Assert.AreEqual(0, zero.Sign); - } - - private static void AssertEqual(byte[] a, byte[] b) - { - Assert.IsTrue(a.IsEqualTo(b)); - } - } -} +// Based in huge part on: +// +// https://github.com/mono/mono/blob/master/mcs/class/System.Numerics/Test/System.Numerics/BigIntegerTest.cs +// +// Authors: +// Rodrigo Kumpera +// +// Copyright (C) 2010 Novell, Inc (http://www.novell.com) +// + +//#define FEATURE_NUMERICS_BIGINTEGER + +using System; +using System.Diagnostics; +using System.Globalization; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +#if FEATURE_NUMERICS_BIGINTEGER +using BigInteger = System.Numerics.BigInteger; +#else +using BigInteger = Renci.SshNet.Common.BigInteger; +#endif + + +namespace Renci.SshNet.Tests.Classes.Common +{ + [TestClass] + public class BigIntegerTest + { + private static readonly byte[] huge_a = + { + 0x1D, 0x33, 0xFB, 0xFE, 0xB1, 0x2, 0x85, 0x44, 0xCA, 0xDC, 0xFB, 0x70, 0xD, 0x39, + 0xB1, 0x47, 0xB6, 0xE6, 0xA2, 0xD1, 0x19, 0x1E, 0x9F, 0xE4, 0x3C, 0x1E, 0x16, 0x56, 0x13, 0x9C, 0x4D, 0xD3, + 0x5C, 0x74, 0xC9, 0xBD, 0xFA, 0x56, 0x40, 0x58, 0xAC, 0x20, 0x6B, 0x55, 0xA2, 0xD5, 0x41, 0x38, 0xA4, 0x6D, + 0xF6, 0x8C, + }; + + private static readonly byte[] huge_b = + { + 0x96, 0x5, 0xDA, 0xFE, 0x93, 0x17, 0xC1, 0x93, 0xEC, 0x2F, 0x30, 0x2D, 0x8F, + 0x28, 0x13, 0x99, 0x70, 0xF4, 0x4C, 0x60, 0xA6, 0x49, 0x24, 0xF9, 0xB3, 0x4A, 0x41, 0x67, 0xDC, 0xDD, 0xB1, + 0xA5, 0xA6, 0xC0, 0x3D, 0x57, 0x9A, 0xCB, 0x29, 0xE2, 0x94, 0xAC, 0x6C, 0x7D, 0xEF, 0x3E, 0xC6, 0x7A, 0xC1, + 0xA8, 0xC8, 0xB0, 0x20, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, + }; + + private static readonly byte[] huge_add = + { + 0xB3, 0x38, 0xD5, 0xFD, 0x45, 0x1A, 0x46, 0xD8, 0xB6, 0xC, 0x2C, 0x9E, 0x9C, + 0x61, 0xC4, 0xE0, 0x26, 0xDB, 0xEF, 0x31, 0xC0, 0x67, 0xC3, 0xDD, 0xF0, 0x68, 0x57, 0xBD, 0xEF, 0x79, 0xFF, + 0x78, 0x3, 0x35, 0x7, 0x15, 0x95, 0x22, 0x6A, 0x3A, 0x41, 0xCD, 0xD7, 0xD2, 0x91, 0x14, 0x8, 0xB3, 0x65, + 0x16, 0xBF, 0x3D, 0x20, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, + }; + + private static readonly byte[] a_m_b = + { + 0x87, 0x2D, 0x21, 0x0, 0x1E, 0xEB, 0xC3, 0xB0, 0xDD, 0xAC, 0xCB, 0x43, 0x7E, 0x10, + 0x9E, 0xAE, 0x45, 0xF2, 0x55, 0x71, 0x73, 0xD4, 0x7A, 0xEB, 0x88, 0xD3, 0xD4, 0xEE, 0x36, 0xBE, 0x9B, 0x2D, + 0xB6, 0xB3, 0x8B, 0x66, 0x60, 0x8B, 0x16, 0x76, 0x17, 0x74, 0xFE, 0xD7, 0xB2, 0x96, 0x7B, 0xBD, 0xE2, 0xC4, + 0x2D, 0xDC, 0xDE, 0x6A, 0x19, 0xB3, 0x1E, 0x1F, 0xB4, 0xB6, 0x2A, 0xA5, 0x48, + }; + + private static readonly byte[] b_m_a = + { + 0x79, 0xD2, 0xDE, 0xFF, 0xE1, 0x14, 0x3C, 0x4F, 0x22, 0x53, 0x34, 0xBC, 0x81, + 0xEF, 0x61, 0x51, 0xBA, 0xD, 0xAA, 0x8E, 0x8C, 0x2B, 0x85, 0x14, 0x77, 0x2C, 0x2B, 0x11, 0xC9, 0x41, 0x64, + 0xD2, 0x49, 0x4C, 0x74, 0x99, 0x9F, 0x74, 0xE9, 0x89, 0xE8, 0x8B, 0x1, 0x28, 0x4D, 0x69, 0x84, 0x42, 0x1D, + 0x3B, 0xD2, 0x23, 0x21, 0x95, 0xE6, 0x4C, 0xE1, 0xE0, 0x4B, 0x49, 0xD5, 0x5A, 0xB7, + }; + + private static readonly byte[] huge_mul = + { + 0xFE, 0x83, 0xE1, 0x9B, 0x8D, 0x61, 0x40, 0xD1, 0x60, 0x19, 0xBD, 0x38, 0xF0, + 0xFF, 0x90, 0xAE, 0xDD, 0xAE, 0x73, 0x2C, 0x20, 0x23, 0xCF, 0x6, 0x7A, 0xB4, 0x1C, 0xE7, 0xD9, 0x64, 0x96, + 0x2C, 0x87, 0x7E, 0x1D, 0xB3, 0x8F, 0xD4, 0x33, 0xBA, 0xF4, 0x22, 0xB4, 0xDB, 0xC0, 0x5B, 0xA5, 0x64, 0xA0, + 0xBC, 0xCA, 0x3E, 0x94, 0x95, 0xDA, 0x49, 0xE2, 0xA8, 0x33, 0xA2, 0x6A, 0x33, 0xB1, 0xF2, 0xEA, 0x99, 0x32, + 0xD0, 0xB2, 0xAE, 0x55, 0x75, 0xBD, 0x19, 0xFC, 0x9A, 0xEC, 0x54, 0x87, 0x2A, 0x6, 0xCC, 0x78, 0xDA, 0x88, + 0xBB, 0xAB, 0xA5, 0x47, 0xEF, 0xC7, 0x2B, 0xC7, 0x5B, 0x32, 0x31, 0xCD, 0xD9, 0x53, 0x96, 0x1A, 0x9D, 0x9A, + 0x57, 0x40, 0x51, 0xB6, 0x5D, 0xC, 0x17, 0xD1, 0x86, 0xE9, 0xA4, 0x20, + }; + + private static readonly byte[] huge_div = {0x0,}; + + private static readonly byte[] huge_rem = + { + 0x1D, 0x33, 0xFB, 0xFE, 0xB1, 0x2, 0x85, 0x44, 0xCA, 0xDC, 0xFB, 0x70, 0xD, + 0x39, 0xB1, 0x47, 0xB6, 0xE6, 0xA2, 0xD1, 0x19, 0x1E, 0x9F, 0xE4, 0x3C, 0x1E, 0x16, 0x56, 0x13, 0x9C, 0x4D, + 0xD3, 0x5C, 0x74, 0xC9, 0xBD, 0xFA, 0x56, 0x40, 0x58, 0xAC, 0x20, 0x6B, 0x55, 0xA2, 0xD5, 0x41, 0x38, 0xA4, + 0x6D, 0xF6, 0x8C, + }; + private static readonly byte[][] add_a = {new byte[] {1}, new byte[] {0xFF}, huge_a}; + private static readonly byte[][] add_b = {new byte[] {1}, new byte[] {1}, huge_b}; + private static readonly byte[][] add_c = {new byte[] {2}, new byte[] {0}, huge_add}; + + private readonly NumberFormatInfo _nfi = NumberFormatInfo.InvariantInfo; + private NumberFormatInfo _nfiUser; + + [TestInitialize] + public void SetUpFixture() + { + _nfiUser = new NumberFormatInfo(); + _nfiUser.CurrencyDecimalDigits = 3; + _nfiUser.CurrencyDecimalSeparator = ":"; + _nfiUser.CurrencyGroupSeparator = "/"; + _nfiUser.CurrencyGroupSizes = new[] { 2, 1, 0 }; + _nfiUser.CurrencyNegativePattern = 10; // n $- + _nfiUser.CurrencyPositivePattern = 3; // n $ + _nfiUser.CurrencySymbol = "XYZ"; + _nfiUser.PercentDecimalDigits = 1; + _nfiUser.PercentDecimalSeparator = ";"; + _nfiUser.PercentGroupSeparator = "~"; + _nfiUser.PercentGroupSizes = new[] { 1 }; + _nfiUser.PercentNegativePattern = 2; + _nfiUser.PercentPositivePattern = 2; + _nfiUser.PercentSymbol = "%%%"; + _nfiUser.NumberDecimalSeparator = "."; + } + + [TestMethod] + public void Mul() + { + long[] values = { -1000000000L, -1000, -1, 0, 1, 1000, 100000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + var c = a * b; + Assert.AreEqual(values[i] * values[j], (long)c, "#_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestHugeMul() + { + var a = new BigInteger(huge_a); + var b = new BigInteger(huge_b); + + Assert.IsTrue(huge_mul.IsEqualTo((a * b).ToByteArray())); + } + + [TestMethod] + public void DivRem() + { + long[] values = { -10000000330L, -5000, -1, 0, 1, 1000, 333, 10234544400L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + if (values[j] == 0) + continue; + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + BigInteger d; + var c = BigInteger.DivRem(a, b, out d); + + Assert.AreEqual(values[i] / values[j], (long)c, "#a_" + i + "_" + j); + Assert.AreEqual(values[i] % values[j], (long)d, "#b_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestHugeDivRem() + { + var a = new BigInteger(huge_a); + var b = new BigInteger(huge_b); + BigInteger d; + var c = BigInteger.DivRem(a, b, out d); + + AssertEqual(huge_div, c.ToByteArray()); + AssertEqual(huge_rem, d.ToByteArray()); + } + + [TestMethod] + public void Pow() + { + try + { + BigInteger.Pow(1, -1); + Assert.Fail("#1"); + } + catch (ArgumentOutOfRangeException) { } + + Assert.AreEqual(1, (int)BigInteger.Pow(99999, 0), "#2"); + Assert.AreEqual(99999, (int)BigInteger.Pow(99999, 1), "#5"); + Assert.AreEqual(59049, (int)BigInteger.Pow(3, 10), "#4"); + Assert.AreEqual(177147, (int)BigInteger.Pow(3, 11), "#5"); + Assert.AreEqual(-177147, (int)BigInteger.Pow(-3, 11), "#6"); + } + + [TestMethod] + public void ModPow() + { + try + { + BigInteger.ModPow(1, -1, 5); + Assert.Fail("#1"); + } + catch (ArgumentOutOfRangeException) { } + + try + { + BigInteger.ModPow(1, 5, 0); + Assert.Fail("#2"); + } + catch (DivideByZeroException) { } + + Assert.AreEqual(4L, (long)BigInteger.ModPow(3, 2, 5), "#2"); + Assert.AreEqual(20L, (long)BigInteger.ModPow(555, 10, 71), "#3"); + Assert.AreEqual(20L, (long)BigInteger.ModPow(-555, 10, 71), "#3"); + Assert.AreEqual(-24L, (long)BigInteger.ModPow(-555, 11, 71), "#3"); + } + + [TestMethod] + public void GreatestCommonDivisor() + { + Assert.AreEqual(999999, (int)BigInteger.GreatestCommonDivisor(999999, 0), "#1"); + Assert.AreEqual(999999, (int)BigInteger.GreatestCommonDivisor(0, 999999), "#2"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(999999, 1), "#3"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(1, 999999), "#4"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(1, 0), "#5"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(0, 1), "#6"); + + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(999999, -1), "#7"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(-1, 999999), "#8"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(-1, 0), "#9"); + Assert.AreEqual(1, (int)BigInteger.GreatestCommonDivisor(0, -1), "#10"); + + Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(12345678, 8765432), "#11"); + Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(-12345678, 8765432), "#12"); + Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(12345678, -8765432), "#13"); + Assert.AreEqual(2, (int)BigInteger.GreatestCommonDivisor(-12345678, -8765432), "#14"); + + Assert.AreEqual(40, (int)BigInteger.GreatestCommonDivisor(5581 * 40, 6671 * 40), "#15"); + + Assert.AreEqual(5, (int)BigInteger.GreatestCommonDivisor(-5, 0), "#16"); + Assert.AreEqual(5, (int)BigInteger.GreatestCommonDivisor(0, -5), "#17"); + } + + [TestMethod] + public void Log() + { + const double delta = 0.000000000000001d; + + Assert.AreEqual(double.NegativeInfinity, BigInteger.Log(0)); + Assert.AreEqual(0d, BigInteger.Log(1)); + Assert.AreEqual(double.NaN, BigInteger.Log(-1)); + Assert.AreEqual(2.3025850929940459d, BigInteger.Log(10), delta); + Assert.AreEqual(6.9077552789821368d, BigInteger.Log(1000), delta); + Assert.AreEqual(double.NaN, BigInteger.Log(-234)); + } + + [TestMethod] + public void LogN() + { + const double delta = 0.000000000000001d; + + Assert.AreEqual(double.NaN, BigInteger.Log(10, 1), "#1"); + Assert.AreEqual(double.NaN, BigInteger.Log(10, 0), "#2"); + Assert.AreEqual(double.NaN, BigInteger.Log(10, -1), "#3"); + + Assert.AreEqual(double.NaN, BigInteger.Log(10, double.NaN), "#4"); + Assert.AreEqual(double.NaN, BigInteger.Log(10, double.NegativeInfinity), "#5"); + Assert.AreEqual(double.NaN, BigInteger.Log(10, double.PositiveInfinity), "#6"); + + Assert.AreEqual(0d, BigInteger.Log(1, 0), "#7"); + Assert.AreEqual(double.NaN, BigInteger.Log(1, double.NegativeInfinity), "#8"); + Assert.AreEqual(0, BigInteger.Log(1, double.PositiveInfinity), "#9"); + Assert.AreEqual(double.NaN, BigInteger.Log(1, double.NaN), "#10"); + + Assert.AreEqual(-2.5129415947320606d, BigInteger.Log(10, 0.4), delta, "#11"); + } + + [TestMethod] + public void DivRemByZero() + { + try + { + BigInteger d; + BigInteger.DivRem(100, 0, out d); + Assert.Fail("#1"); + } + catch (DivideByZeroException) + { + } + } + + [TestMethod] + public void TestAdd() + { + for (var i = 0; i < add_a.Length; ++i) + { + var a = new BigInteger(add_a[i]); + var b = new BigInteger(add_b[i]); + var c = new BigInteger(add_c[i]); + + Assert.AreEqual(c, a + b, "#" + i + "a"); + Assert.AreEqual(c, b + a, "#" + i + "b"); + Assert.AreEqual(c, BigInteger.Add(a, b), "#" + i + "c"); + AssertEqual(add_c[i], (a + b).ToByteArray()); + } + } + + [TestMethod] + public void TestAdd2() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + var c = a + b; + Assert.AreEqual(values[i] + values[j], (long)c, "#_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestHugeSub() + { + var a = new BigInteger(huge_a); + var b = new BigInteger(huge_b); + + AssertEqual(a_m_b, (a - b).ToByteArray()); + AssertEqual(b_m_a, (b - a).ToByteArray()); + } + + [TestMethod] + public void TestSub() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + var c = a - b; + var d = BigInteger.Subtract(a, b); + + Assert.AreEqual(values[i] - values[j], (long)c, "#_" + i + "_" + j); + Assert.AreEqual(values[i] - values[j], (long)d, "#_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestMin() + { + long[] values = { -100000000000L, -1000L, -1L, 0L, 1L, 1000L, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + var c = BigInteger.Min(a, b); + + Assert.AreEqual(Math.Min(values[i], values[j]), (long) c, "#_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestMax() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + var c = BigInteger.Max(a, b); + + Assert.AreEqual(Math.Max(values[i], values[j]), (long) c, "#_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestAbs() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + var a = new BigInteger(values[i]); + var c = BigInteger.Abs(a); + + Assert.AreEqual(Math.Abs(values[i]), (long) c, "#_" + i); + } + } + + [TestMethod] + public void TestNegate() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + var a = new BigInteger(values[i]); + var c = -a; + var d = BigInteger.Negate(a); + + Assert.AreEqual(-values[i], (long) c, "#_" + i); + Assert.AreEqual(-values[i], (long) d, "#_" + i); + } + } + + [TestMethod] + public void TestInc() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + var a = new BigInteger(values[i]); + var b = ++a; + + Assert.AreEqual(++values[i], (long)b, "#_" + i); + } + } + + [TestMethod] + public void TestDec() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + var a = new BigInteger(values[i]); + var b = --a; + + Assert.AreEqual(--values[i], (long) b, "#_" + i); + } + } + + [TestMethod] + public void TestBitwiseOps() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L, 0xFFFF00000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + + Assert.AreEqual(values[i] | values[j], (long) (a | b), "#b_" + i + "_" + j); + Assert.AreEqual(values[i] & values[j], (long) (a & b), "#a_" + i + "_" + j); + Assert.AreEqual(values[i] ^ values[j], (long) (a ^ b), "#c_" + i + "_" + j); + Assert.AreEqual(~values[i], (long) ~a, "#d_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestLeftShift() + { + AssertEqual(new byte[] { 0x00, 0x28 }, (new BigInteger(0x0A) << 10).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0xD8 }, (new BigInteger(-10) << 10).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0xFF }, (new BigInteger(-1) << 16).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A }, (new BigInteger(0x0A) << 80).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF6 }, (new BigInteger(-10) << 80).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, (new BigInteger(-1) << 80).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xD9 }, (new BigInteger(-1234) << 75).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x91, 0x00 }, (new BigInteger(0x1234) << 75).ToByteArray()); + AssertEqual(new byte[] { 0xFF, 0x00 }, (new BigInteger(0xFF00) << -8).ToByteArray()); + } + + [TestMethod] + public void TestRightShift() + { + AssertEqual(new byte[] { 0x16, 0xB0, 0x4C, 0x02 }, (new BigInteger(1234567899L) >> 5).ToByteArray()); + AssertEqual(new byte[] { 0x2C, 0x93, 0x00 }, (new BigInteger(1234567899L) >> 15).ToByteArray()); + AssertEqual(new byte[] { 0xFF, 0xFF, 0x7F }, (new BigInteger(long.MaxValue - 100) >> 40).ToByteArray()); + AssertEqual(new byte[] { 0xE9, 0x4F, 0xB3, 0xFD }, (new BigInteger(-1234567899L) >> 5).ToByteArray()); + AssertEqual(new byte[] { 0xD3, 0x6C, 0xFF }, (new BigInteger(-1234567899L) >> 15).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x80 }, (new BigInteger(long.MinValue + 100) >> 40).ToByteArray()); + AssertEqual(new byte[] { 0xFF }, (new BigInteger(-1234567899L) >> 90).ToByteArray()); + AssertEqual(new byte[] { 0x00 }, (new BigInteger(999999) >> 90).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0xFF, 0x00 }, (new BigInteger(0xFF00) >> -8).ToByteArray()); + } + + [TestMethod] + public void CompareOps() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = new BigInteger(values[j]); + + Assert.AreEqual(values[i].CompareTo(values[j]), a.CompareTo(b), "#a_" + i + "_" + j); + Assert.AreEqual(values[i].CompareTo(values[j]), BigInteger.Compare(a, b), "#b_" + i + "_" + j); + + Assert.AreEqual(values[i] < values[j], a < b, "#c_" + i + "_" + j); + Assert.AreEqual(values[i] <= values[j], a <= b, "#d_" + i + "_" + j); + Assert.AreEqual(values[i] == values[j], a == b, "#e_" + i + "_" + j); + Assert.AreEqual(values[i] != values[j], a != b, "#f_" + i + "_" + j); + Assert.AreEqual(values[i] >= values[j], a >= b, "#g_" + i + "_" + j); + Assert.AreEqual(values[i] > values[j], a > b, "#h_" + i + "_" + j); + } + } + } + + [TestMethod] + public void CompareOps2() + { + var a = new BigInteger(100000000000L); + var b = new BigInteger(28282828282UL); + + Assert.IsTrue(a >= b, "#1"); + Assert.IsTrue(a >= b, "#2"); + Assert.IsFalse(a < b, "#3"); + Assert.IsFalse(a <= b, "#4"); + Assert.AreEqual(1, a.CompareTo(b), "#5"); + } + + [TestMethod] + public void CompareULong() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 100000000000L, 0xAA00000000L }; + ulong[] uvalues = { 0, 1, 1000, 100000000000L, 999999, 28282828282, 0xAA00000000, ulong.MaxValue }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < uvalues.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = uvalues[j]; + var c = new BigInteger(b); + + Assert.AreEqual(a.CompareTo(c), a.CompareTo(b), "#a_" + i + "_" + j); + + Assert.AreEqual(a > c, a > b, "#b_" + i + "_" + j); + Assert.AreEqual(a < c, a < b, "#c_" + i + "_" + j); + Assert.AreEqual(a <= c, a <= b, "#d_" + i + "_" + j); + Assert.AreEqual(a == c, a == b, "#e_" + i + "_" + j); + Assert.AreEqual(a != c, a != b, "#f_" + i + "_" + j); + Assert.AreEqual(a >= c, a >= b, "#g_" + i + "_" + j); + + Assert.AreEqual(c > a, b > a, "#ib_" + i + "_" + j); + Assert.AreEqual(c < a, b < a, "#ic_" + i + "_" + j); + Assert.AreEqual(c <= a, b <= a, "#id_" + i + "_" + j); + Assert.AreEqual(c == a, b == a, "#ie_" + i + "_" + j); + Assert.AreEqual(c != a, b != a, "#if_" + i + "_" + j); + Assert.AreEqual(c >= a, b >= a, "#ig_" + i + "_" + j); + } + } + } + + [TestMethod] + public void CompareLong() + { + long[] values = { -100000000000L, -1000, -1, 0, 1, 1000, 9999999, 100000000000L, 0xAA00000000, long.MaxValue, long.MinValue }; + + for (var i = 0; i < values.Length; ++i) + { + for (var j = 0; j < values.Length; ++j) + { + var a = new BigInteger(values[i]); + var b = values[j]; + var c = new BigInteger(b); + + Assert.AreEqual(a.CompareTo(c), a.CompareTo(b), "#a_" + i + "_" + j); + + Assert.AreEqual(a > c, a > b, "#b_" + i + "_" + j); + Assert.AreEqual(a < c, a < b, "#c_" + i + "_" + j); + Assert.AreEqual(a <= c, a <= b, "#d_" + i + "_" + j); + Assert.AreEqual(a == c, a == b, "#e_" + i + "_" + j); + Assert.AreEqual(a != c, a != b, "#f_" + i + "_" + j); + Assert.AreEqual(a >= c, a >= b, "#g_" + i + "_" + j); + + Assert.AreEqual(c > a, b > a, "#ib_" + i + "_" + j); + Assert.AreEqual(c < a, b < a, "#ic_" + i + "_" + j); + Assert.AreEqual(c <= a, b <= a, "#id_" + i + "_" + j); + Assert.AreEqual(c == a, b == a, "#ie_" + i + "_" + j); + Assert.AreEqual(c != a, b != a, "#if_" + i + "_" + j); + Assert.AreEqual(c >= a, b >= a, "#ig_" + i + "_" + j); + } + } + } + + [TestMethod] + public void TestEquals() + { + var a = new BigInteger(10); + var b = new BigInteger(10); + var c = new BigInteger(-10); + + Assert.AreEqual(a, b, "#1"); + Assert.AreNotEqual(a, c, "#2"); + Assert.AreEqual(a, 10, "#3"); + } + + [TestMethod] + public void Ctor_ByteArray_ShouldThrowArgumentNullExceptionWhenValueIsNull() + { + const byte[] value = null; + + try + { + var actual = new BigInteger(value); + Assert.Fail("#1:" + actual); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("value", ex.ParamName); + } + } + + [TestMethod] + public void ByteArrayCtor() + { + Assert.AreEqual(0, (int) new BigInteger(new byte[0])); + Assert.AreEqual(0, (int) new BigInteger(new byte[1])); + Assert.AreEqual(0, (int) new BigInteger(new byte[2])); + } + + [TestMethod] + public void IntCtorRoundTrip() + { + int[] values = + { + int.MinValue, -0x2F33BB, -0x1F33, -0x33, 0, 0x33, + 0x80, 0x8190, 0xFF0011, 0x1234, 0x11BB99, 0x44BB22CC, + int.MaxValue + }; + + foreach (var val in values) + { + var a = new BigInteger(val); + var b = new BigInteger(a.ToByteArray()); + + Assert.AreEqual(val, (int)a, "#a_" + val); + Assert.AreEqual(val, (int)b, "#b_" + val); + } + } + + [TestMethod] + public void LongCtorRoundTrip() + { + long[] values = + { + 0L, long.MinValue, long.MaxValue, -1, 1L + int.MaxValue, -1L + int.MinValue, 0x1234, 0xFFFFFFFFL, + 0x1FFFFFFFFL, -0xFFFFFFFFL, -0x1FFFFFFFFL, 0x100000000L, -0x100000000L, 0x100000001L, -0x100000001L, + 4294967295L, -4294967295L, 4294967296L, -4294967296L + }; + + foreach (var val in values) + { + try + { + var a = new BigInteger(val); + var b = new BigInteger(a.ToByteArray()); + + Assert.AreEqual(val, (long) a, "#a_" + val); + Assert.AreEqual(val, (long) b, "#b_" + val); + Assert.AreEqual(a, b, "#a == #b (" + val + ")"); + } + catch (Exception e) + { + Assert.Fail("Failed to roundtrip {0}: {1}", val, e); + } + } + } + + [TestMethod] + public void ByteArrayCtorRoundTrip() + { + var arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 0xFF, 0x0 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xF0 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4, 5 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4, 5, 6 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 2, 3, 4, 5 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 0 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 0xFF, 00 }; + AssertEqual(arr, new BigInteger(arr).ToByteArray()); + + arr = new byte[] { 1, 0, 0, 0, 0, 0, }; + AssertEqual(new byte[] { 1 }, new BigInteger(arr).ToByteArray()); + } + + [TestMethod] + public void TestIntCtorProperties() + { + BigInteger a = new BigInteger(10); + Assert.IsTrue(a.IsEven, "#1"); + Assert.IsFalse(a.IsOne, "#2"); + Assert.IsFalse(a.IsPowerOfTwo, "#3"); + Assert.IsFalse(a.IsZero, "#4"); + Assert.AreEqual(1, a.Sign, "#5"); + + Assert.IsFalse(new BigInteger(11).IsEven, "#6"); + Assert.IsTrue(new BigInteger(1).IsOne, "#7"); + Assert.IsTrue(new BigInteger(32).IsPowerOfTwo, "#8"); + Assert.IsTrue(new BigInteger(0).IsZero, "#9"); + Assert.IsTrue(new BigInteger().IsZero, "#9b"); + Assert.AreEqual(0, new BigInteger(0).Sign, "#10"); + Assert.AreEqual(-1, new BigInteger(-99999).Sign, "#11"); + + Assert.IsFalse(new BigInteger(0).IsPowerOfTwo, "#12"); + Assert.IsFalse(new BigInteger().IsPowerOfTwo, "#12b"); + Assert.IsFalse(new BigInteger(-16).IsPowerOfTwo, "#13"); + Assert.IsTrue(new BigInteger(1).IsPowerOfTwo, "#14"); + } + + [TestMethod] + public void TestIntCtorToString() + { + Assert.AreEqual("5555", new BigInteger(5555).ToString(), "#1"); + Assert.AreEqual("-99999", new BigInteger(-99999).ToString(), "#2"); + } + + [TestMethod] + public void TestToStringFmt() + { + Assert.AreEqual("123456789123456", new BigInteger(123456789123456).ToString("D2"), "#1"); + Assert.AreEqual("0000000005", new BigInteger(5).ToString("d10"), "#2"); + Assert.AreEqual("0A8", new BigInteger(168).ToString("X"), "#3"); + Assert.AreEqual("0", new BigInteger(0).ToString("X"), "#4"); + Assert.AreEqual("0", new BigInteger().ToString("X"), "#4b"); + Assert.AreEqual("1", new BigInteger(1).ToString("X"), "#5"); + Assert.AreEqual("0A", new BigInteger(10).ToString("X"), "#6"); + Assert.AreEqual("F6", new BigInteger(-10).ToString("X"), "#7"); + + Assert.AreEqual("10000000000000000000000000000000000000000000000000000000", BigInteger.Pow(10, 55).ToString("G"), "#8"); + + Assert.AreEqual("10000000000000000000000000000000000000000000000000000000", BigInteger.Pow(10, 55).ToString("R"), "#9"); + + + Assert.AreEqual("000000000A", new BigInteger(10).ToString("X10"), "#10"); + Assert.AreEqual("0000000010", new BigInteger(10).ToString("G10"), "#11"); + } + + [TestMethod] + public void TestToStringFmtProvider() + { + NumberFormatInfo info = new NumberFormatInfo + { + NegativeSign = ">", + PositiveSign = "%" + }; + + Assert.AreEqual("10", new BigInteger(10).ToString(info), "#1"); + Assert.AreEqual(">10", new BigInteger(-10).ToString(info), "#2"); + Assert.AreEqual("0A", new BigInteger(10).ToString("X", info), "#3"); + Assert.AreEqual("F6", new BigInteger(-10).ToString("X", info), "#4"); + Assert.AreEqual("10", new BigInteger(10).ToString("G", info), "#5"); + Assert.AreEqual(">10", new BigInteger(-10).ToString("G", info), "#6"); + Assert.AreEqual("10", new BigInteger(10).ToString("D", info), "#7"); + Assert.AreEqual(">10", new BigInteger(-10).ToString("D", info), "#8"); + Assert.AreEqual("10", new BigInteger(10).ToString("R", info), "#9"); + Assert.AreEqual(">10", new BigInteger(-10).ToString("R", info), "#10"); + + info = new NumberFormatInfo(); + info.NegativeSign = "#$%"; + Assert.AreEqual("#$%10", new BigInteger(-10).ToString(info), "#2"); + Assert.AreEqual("#$%10", new BigInteger(-10).ToString(null, info), "#2"); + + info = new NumberFormatInfo(); + Assert.AreEqual("-10", new BigInteger(-10).ToString(info), "#2"); + + } + + [TestMethod] + public void TestToIntOperator() + { + try + { + int v = (int)new BigInteger(huge_a); + Assert.Fail("#1"); + } + catch (OverflowException) { } + + try + { + int v = (int)new BigInteger(1L + int.MaxValue); + Assert.Fail("#2"); + } + catch (OverflowException) { } + + try + { + int v = (int)new BigInteger(-1L + int.MinValue); + Assert.Fail("#3"); + } + catch (OverflowException) { } + + Assert.AreEqual(int.MaxValue, (int)new BigInteger(int.MaxValue), "#4"); + Assert.AreEqual(int.MinValue, (int)new BigInteger(int.MinValue), "#5"); + } + + + [TestMethod] + public void TestToLongOperator() + { + try + { + long v = (long)new BigInteger(huge_a); + Assert.Fail("#1"); + } + catch (OverflowException) { } + + //long.MaxValue + 1 + try + { + long v = (long)new BigInteger(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00 }); + Assert.Fail("#2"); + } + catch (OverflowException) { } + + //TODO long.MinValue - 1 + try + { + long v = (long)new BigInteger(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF }); + Assert.Fail("#3"); + } + catch (OverflowException) { } + + Assert.AreEqual(long.MaxValue, (long)new BigInteger(long.MaxValue), "#4"); + Assert.AreEqual(long.MinValue, (long)new BigInteger(long.MinValue), "#5"); + } + + [TestMethod] + public void TestIntCtorToByteArray() + { + AssertEqual(new byte[] { 0xFF }, new BigInteger(-1).ToByteArray()); + AssertEqual(new byte[] { 0xD4, 0xFE }, new BigInteger(-300).ToByteArray()); + AssertEqual(new byte[] { 0x80, 0x00 }, new BigInteger(128).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x60 }, new BigInteger(0x6000).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x80, 0x00 }, new BigInteger(0x8000).ToByteArray()); + AssertEqual(new byte[] { 0xDD, 0xBC, 0x00, 0x7A }, new BigInteger(0x7A00BCDD).ToByteArray()); + AssertEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0x7F }, new BigInteger(int.MaxValue).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x80 }, new BigInteger(int.MinValue).ToByteArray()); + AssertEqual(new byte[] { 0x01, 0x00, 0x00, 0x80 }, new BigInteger(int.MinValue + 1).ToByteArray()); + AssertEqual(new byte[] { 0x7F }, new BigInteger(0x7F).ToByteArray()); + AssertEqual(new byte[] { 0x45, 0xCC, 0xD0 }, new BigInteger(-0x2F33BB).ToByteArray()); + AssertEqual(new byte[] { 0 }, new BigInteger(0).ToByteArray()); + AssertEqual(new byte[] { 0 }, new BigInteger().ToByteArray()); + } + + [TestMethod] + public void TestLongCtorToByteArray() + { + AssertEqual(new byte[] { 0x01 }, new BigInteger(0x01L).ToByteArray()); + AssertEqual(new byte[] { 0x02, 0x01 }, new BigInteger(0x0102L).ToByteArray()); + AssertEqual(new byte[] { 0x03, 0x02, 0x01 }, new BigInteger(0x010203L).ToByteArray()); + AssertEqual(new byte[] { 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x01020304L).ToByteArray()); + AssertEqual(new byte[] { 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x0102030405L).ToByteArray()); + AssertEqual(new byte[] { 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x010203040506L).ToByteArray()); + AssertEqual(new byte[] { 0x07, 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x01020304050607L).ToByteArray()); + AssertEqual(new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x2, 0x01 }, new BigInteger(0x0102030405060708L).ToByteArray()); + + AssertEqual(new byte[] { 0xFF }, new BigInteger(-0x01L).ToByteArray()); + AssertEqual(new byte[] { 0xFE, 0xFE }, new BigInteger(-0x0102L).ToByteArray()); + AssertEqual(new byte[] { 0xFD, 0xFD, 0xFE }, new BigInteger(-0x010203L).ToByteArray()); + AssertEqual(new byte[] { 0xFC, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x01020304L).ToByteArray()); + AssertEqual(new byte[] { 0xFB, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x0102030405L).ToByteArray()); + AssertEqual(new byte[] { 0xFA, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x010203040506L).ToByteArray()); + AssertEqual(new byte[] { 0xF9, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x01020304050607L).ToByteArray()); + AssertEqual(new byte[] { 0xF8, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE }, new BigInteger(-0x0102030405060708L).ToByteArray()); + + AssertEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, new BigInteger(long.MaxValue).ToByteArray()); + AssertEqual(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, new BigInteger(long.MinValue).ToByteArray()); + + AssertEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0x7F, 0xFF }, new BigInteger(-2147483649L).ToByteArray()); + } + + [TestMethod] + public void CompareTo() + { + var a = new BigInteger(99); + Assert.AreEqual(-1, a.CompareTo(100), "#1"); + Assert.AreEqual(1, a.CompareTo(null), "#2"); + } + + [TestMethod] + public void ShortOperators() + { + Assert.AreEqual(22, (int)new BigInteger((short)22), "#1"); + Assert.AreEqual(-22, (int)new BigInteger((short)-22), "#2"); + + try + { + short x = (short)new BigInteger(10000000); + Assert.Fail("#3"); + } + catch (OverflowException) { } + + try + { + short x = (short)new BigInteger(-10000000); + Assert.Fail("#4"); + } + catch (OverflowException) { } + } + + [TestMethod] + public void Ctor_Double_NaN() + { + try + { + new BigInteger(double.NaN); + Assert.Fail(); + } + catch (OverflowException) + { + } + } + + [TestMethod] + public void Ctor_Double_NegativeInfinity() + { + try + { + new BigInteger(double.NegativeInfinity); + Assert.Fail(); + } + catch (OverflowException) + { + } + } + + [TestMethod] + public void Ctor_Double_PositiveInfinity() + { + try + { + new BigInteger(double.PositiveInfinity); + Assert.Fail(); + } + catch (OverflowException) + { + } + } + + [TestMethod] + public void Ctor_Double() + { + Assert.AreEqual(10000, (int)new BigInteger(10000.2)); + Assert.AreEqual(10000, (int)new BigInteger(10000.9)); + Assert.AreEqual(10000, (int)new BigInteger(10000.2)); + Assert.AreEqual(0, (int)new BigInteger(0.9)); + Assert.AreEqual(12345678999L, (long)new BigInteger(12345678999.33)); + } + + [TestMethod] + public void DoubleConversion() + { + Assert.AreEqual(999d, (double)new BigInteger(999), "#1"); + Assert.AreEqual(double.PositiveInfinity, (double)BigInteger.Pow(2, 1024), "#2"); + Assert.AreEqual(double.NegativeInfinity, (double)BigInteger.Pow(-2, 1025), "#3"); + + Assert.AreEqual(0d, (double)BigInteger.Zero, "#4"); + Assert.AreEqual(1d, (double)BigInteger.One, "#5"); + Assert.AreEqual(-1d, (double)BigInteger.MinusOne, "#6"); + + var result1 = BitConverter.Int64BitsToDouble(-4337852273739220173); + Assert.AreEqual(result1, (double)new BigInteger(new byte[] { 53, 152, 137, 177, 240, 81, 75, 198 }), "#7"); + var result2 = BitConverter.Int64BitsToDouble(4893382453283402035); + Assert.AreEqual(result2, (double)new BigInteger(new byte[] { 53, 152, 137, 177, 240, 81, 75, 198, 0 }), "#8"); + + var result3 = BitConverter.Int64BitsToDouble(5010775143622804480); + var result4 = BitConverter.Int64BitsToDouble(5010775143622804481); + var result5 = BitConverter.Int64BitsToDouble(5010775143622804482); + Assert.AreEqual(result3, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 16, 128, 208, 159, 60, 46, 59, 3 }), "#9"); + Assert.AreEqual(result3, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 17, 128, 208, 159, 60, 46, 59, 3 }), "#10"); + Assert.AreEqual(result3, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 24, 128, 208, 159, 60, 46, 59, 3 }), "#11"); + Assert.AreEqual(result4, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 32, 128, 208, 159, 60, 46, 59, 3 }), "#12"); + Assert.AreEqual(result4, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 48, 128, 208, 159, 60, 46, 59, 3 }), "#13"); + Assert.AreEqual(result5, (double)new BigInteger(new byte[] { 0, 0, 0, 0, 64, 128, 208, 159, 60, 46, 59, 3 }), "#14"); + + Assert.AreEqual(BitConverter.Int64BitsToDouble(-2748107935317889142), (double)new BigInteger(huge_a), "#15"); + Assert.AreEqual(BitConverter.Int64BitsToDouble(-2354774254443231289), (double)new BigInteger(huge_b), "#16"); + Assert.AreEqual(BitConverter.Int64BitsToDouble(8737073938546854790), (double)new BigInteger(huge_mul), "#17"); + + Assert.AreEqual(BitConverter.Int64BitsToDouble(6912920136897069886), (double)(2278888483353476799 * BigInteger.Pow(2, 451)), "#18"); + Assert.AreEqual(double.PositiveInfinity, (double)(843942696292817306 * BigInteger.Pow(2, 965)), "#19"); + } + + [TestMethod] + public void DecimalCtor() + { + Assert.AreEqual(999, (int)new BigInteger(999.99m), "#1"); + Assert.AreEqual(-10000, (int)new BigInteger(-10000m), "#2"); + Assert.AreEqual(0, (int)new BigInteger(0m), "#3"); + } + + [TestMethod] + public void DecimalConversion() + { + Assert.AreEqual(999m, (decimal)new BigInteger(999), "#1"); + + try + { + var x = (decimal) BigInteger.Pow(2, 1024); + Assert.Fail("#2: " + x); + } + catch (OverflowException) + { + } + + try + { + var x = (decimal) BigInteger.Pow(-2, 1025); + Assert.Fail("#3: " + x); + } + catch (OverflowException) + { + } + + Assert.AreEqual(0m, (decimal)new BigInteger(0), "#4"); + Assert.AreEqual(1m, (decimal)new BigInteger(1), "#5"); + Assert.AreEqual(-1m, (decimal)new BigInteger(-1), "#6"); + Assert.AreEqual(9999999999999999999999999999m, (decimal)new BigInteger(9999999999999999999999999999m), "#7"); + Assert.AreEqual(0m, (decimal)new BigInteger(), "#8"); + } + + [TestMethod] + public void Parse() + { + try + { + BigInteger.Parse(null); + Assert.Fail("#1"); + } + catch (ArgumentNullException) { } + + try + { + BigInteger.Parse(""); + Assert.Fail("#2"); + } + catch (FormatException) { } + + + try + { + BigInteger.Parse(" "); + Assert.Fail("#3"); + } + catch (FormatException) { } + + try + { + BigInteger.Parse("hh"); + Assert.Fail("#4"); + } + catch (FormatException) { } + + try + { + BigInteger.Parse("-"); + Assert.Fail("#5"); + } + catch (FormatException) { } + + try + { + BigInteger.Parse("-+"); + Assert.Fail("#6"); + } + catch (FormatException) { } + + Assert.AreEqual(10, (int)BigInteger.Parse("+10"), "#7"); + Assert.AreEqual(10, (int)BigInteger.Parse("10 "), "#8"); + Assert.AreEqual(-10, (int)BigInteger.Parse("-10 "), "#9"); + Assert.AreEqual(10, (int)BigInteger.Parse(" 10 "), "#10"); + Assert.AreEqual(-10, (int)BigInteger.Parse(" -10 "), "#11"); + + Assert.AreEqual(-1, (int)BigInteger.Parse("F", NumberStyles.AllowHexSpecifier), "#12"); + Assert.AreEqual(-8, (int)BigInteger.Parse("8", NumberStyles.AllowHexSpecifier), "#13"); + Assert.AreEqual(8, (int)BigInteger.Parse("08", NumberStyles.AllowHexSpecifier), "#14"); + Assert.AreEqual(15, (int)BigInteger.Parse("0F", NumberStyles.AllowHexSpecifier), "#15"); + Assert.AreEqual(-1, (int)BigInteger.Parse("FF", NumberStyles.AllowHexSpecifier), "#16"); + Assert.AreEqual(255, (int)BigInteger.Parse("0FF", NumberStyles.AllowHexSpecifier), "#17"); + + Assert.AreEqual(-17, (int)BigInteger.Parse(" (17) ", NumberStyles.AllowParentheses | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite), "#18"); + Assert.AreEqual(-23, (int)BigInteger.Parse(" -23 ", NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite), "#19"); + + Assert.AreEqual(300000, (int)BigInteger.Parse("3E5", NumberStyles.AllowExponent), "#20"); + var dsep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator; + Assert.AreEqual(250, (int)BigInteger.Parse("2" + dsep + "5E2", NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint), "#21");//2.5E2 = 250 + Assert.AreEqual(25, (int)BigInteger.Parse("2500E-2", NumberStyles.AllowExponent), "#22"); + + Assert.AreEqual("136236974127783066520110477975349088954559032721408", BigInteger.Parse("136236974127783066520110477975349088954559032721408", NumberStyles.None).ToString(), "#23"); + Assert.AreEqual("136236974127783066520110477975349088954559032721408", BigInteger.Parse("136236974127783066520110477975349088954559032721408").ToString(), "#24"); + + try + { + BigInteger.Parse("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent + Assert.Fail("#25"); + } + catch (FormatException) + { + } + + try + { + Int32.Parse("2" + dsep + "09E1", NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent); + Assert.Fail("#26"); + } + catch (OverflowException) + { + } + } + + [TestMethod] + public void TryParse_Value_ShouldReturnFalseWhenValueIsNull() + { + BigInteger x; + + var actual = BigInteger.TryParse(null, out x); + + Assert.IsFalse(actual); + Assert.AreEqual(BigInteger.Zero, x); + } + + [TestMethod] + public void TryParse_Value() + { + BigInteger x; + + Assert.IsFalse(BigInteger.TryParse("", out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse(" ", out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse(" -", out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse(" +", out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse(" FF", out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsTrue(BigInteger.TryParse(" 99", out x)); + Assert.AreEqual(99, (int) x); + + Assert.IsTrue(BigInteger.TryParse("+133", out x)); + Assert.AreEqual(133, (int) x); + + Assert.IsTrue(BigInteger.TryParse("-010", out x)); + Assert.AreEqual(-10, (int) x); + } + + [TestMethod] + public void TryParse_ValueAndStyleAndProvider() + { + BigInteger x; + + Assert.IsFalse(BigInteger.TryParse("null", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse("-10", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse("(10)", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse(" 10", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse("10 ", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsTrue(BigInteger.TryParse("-10", NumberStyles.AllowLeadingSign, null, out x)); + Assert.AreEqual(-10, (int) x); + + Assert.IsTrue(BigInteger.TryParse("(10)", NumberStyles.AllowParentheses, null, out x)); + Assert.AreEqual(-10, (int) x); + + Assert.IsTrue(BigInteger.TryParse(" 10", NumberStyles.AllowLeadingWhite, null, out x)); + Assert.AreEqual(10, (int) x); + + Assert.IsTrue(BigInteger.TryParse("10 ", NumberStyles.AllowTrailingWhite, null, out x)); + Assert.AreEqual(10, (int) x); + + Assert.IsFalse(BigInteger.TryParse("$10", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse("$10", NumberStyles.None, _nfi, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse("%10", NumberStyles.None, _nfi, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsFalse(BigInteger.TryParse("10 ", NumberStyles.None, null, out x)); + Assert.AreEqual(BigInteger.Zero, x); + + Assert.IsTrue(BigInteger.TryParse("10", NumberStyles.None, null, out x)); + Assert.AreEqual(10, (int) x); + + Assert.IsTrue(BigInteger.TryParse(_nfi.CurrencySymbol + "10", NumberStyles.AllowCurrencySymbol, _nfi, out x)); + Assert.AreEqual(10, (int) x); + + Assert.IsFalse(BigInteger.TryParse("%10", NumberStyles.AllowCurrencySymbol, _nfi, out x)); + Assert.AreEqual(BigInteger.Zero, x); + } + + [TestMethod] + public void TryParse_ValueAndStyleAndProvider_ShouldReturnFalseWhenValueIsNull() + { + BigInteger x; + + var actual = BigInteger.TryParse(null, NumberStyles.Any, CultureInfo.InvariantCulture, out x); + + Assert.IsFalse(actual); + Assert.AreEqual(BigInteger.Zero, x); + } + + [TestMethod] + public void TestUserCurrency() + { + const int val1 = -1234567; + const int val2 = 1234567; + + var s = val1.ToString("c", _nfiUser); + Assert.AreEqual("1234/5/67:000 XYZ-", s, "Currency value type 1 is not what we want to try to parse"); + + var v = BigInteger.Parse("1234/5/67:000 XYZ-", NumberStyles.Currency, _nfiUser); + Assert.AreEqual(val1, (int) v); + + s = val2.ToString("c", _nfiUser); + Assert.AreEqual("1234/5/67:000 XYZ", s, "Currency value type 2 is not what we want to try to parse"); + + v = BigInteger.Parse(s, NumberStyles.Currency, _nfiUser); + Assert.AreEqual(val2, (int)v); + } + + [TestMethod] + public void TryParseWeirdCulture() + { + var old = Thread.CurrentThread.CurrentCulture; + var cur = (CultureInfo)old.Clone(); + + var ninfo = new NumberFormatInfo + { + NegativeSign = ">", + PositiveSign = "%" + }; + cur.NumberFormat = ninfo; + + Thread.CurrentThread.CurrentCulture = cur; + + try + { + BigInteger x; + Assert.IsTrue(BigInteger.TryParse("%11", out x)); + Assert.AreEqual(11, (int) x); + + Assert.IsTrue(BigInteger.TryParse(">11", out x)); + Assert.AreEqual(-11, (int) x); + } + finally + { + Thread.CurrentThread.CurrentCulture = old; + } + } + + [TestMethod] + public void CompareToLongToWithBigNumber() + { + var a = BigInteger.Parse("123456789123456789"); + Assert.AreEqual(1, a.CompareTo(2000)); + Assert.AreEqual(1, a.CompareTo(-2000)); + + var b = BigInteger.Parse("-123456789123456789"); + Assert.AreEqual(-1, b.CompareTo(2000)); + Assert.AreEqual(-1, b.CompareTo(-2000)); + } + + [TestMethod] + public void LeftShiftByInt() + { + var v = BigInteger.Parse("230794411440927908251127453634"); + + Assert.AreEqual("230794411440927908251127453634", (v << 0).ToString(), "#0"); + Assert.AreEqual("461588822881855816502254907268", (v << 1).ToString(), "#1"); + Assert.AreEqual("923177645763711633004509814536", (v << 2).ToString(), "#2"); + Assert.AreEqual("1846355291527423266009019629072", (v << 3).ToString(), "#3"); + Assert.AreEqual("3692710583054846532018039258144", (v << 4).ToString(), "#4"); + Assert.AreEqual("7385421166109693064036078516288", (v << 5).ToString(), "#5"); + Assert.AreEqual("14770842332219386128072157032576", (v << 6).ToString(), "#6"); + Assert.AreEqual("29541684664438772256144314065152", (v << 7).ToString(), "#7"); + Assert.AreEqual("59083369328877544512288628130304", (v << 8).ToString(), "#8"); + Assert.AreEqual("118166738657755089024577256260608", (v << 9).ToString(), "#9"); + Assert.AreEqual("236333477315510178049154512521216", (v << 10).ToString(), "#10"); + Assert.AreEqual("472666954631020356098309025042432", (v << 11).ToString(), "#11"); + Assert.AreEqual("945333909262040712196618050084864", (v << 12).ToString(), "#12"); + Assert.AreEqual("1890667818524081424393236100169728", (v << 13).ToString(), "#13"); + Assert.AreEqual("3781335637048162848786472200339456", (v << 14).ToString(), "#14"); + Assert.AreEqual("7562671274096325697572944400678912", (v << 15).ToString(), "#15"); + Assert.AreEqual("15125342548192651395145888801357824", (v << 16).ToString(), "#16"); + Assert.AreEqual("30250685096385302790291777602715648", (v << 17).ToString(), "#17"); + Assert.AreEqual("60501370192770605580583555205431296", (v << 18).ToString(), "#18"); + Assert.AreEqual("121002740385541211161167110410862592", (v << 19).ToString(), "#19"); + Assert.AreEqual("242005480771082422322334220821725184", (v << 20).ToString(), "#20"); + Assert.AreEqual("484010961542164844644668441643450368", (v << 21).ToString(), "#21"); + Assert.AreEqual("968021923084329689289336883286900736", (v << 22).ToString(), "#22"); + Assert.AreEqual("1936043846168659378578673766573801472", (v << 23).ToString(), "#23"); + Assert.AreEqual("3872087692337318757157347533147602944", (v << 24).ToString(), "#24"); + Assert.AreEqual("7744175384674637514314695066295205888", (v << 25).ToString(), "#25"); + Assert.AreEqual("15488350769349275028629390132590411776", (v << 26).ToString(), "#26"); + Assert.AreEqual("30976701538698550057258780265180823552", (v << 27).ToString(), "#27"); + Assert.AreEqual("61953403077397100114517560530361647104", (v << 28).ToString(), "#28"); + Assert.AreEqual("123906806154794200229035121060723294208", (v << 29).ToString(), "#29"); + Assert.AreEqual("247813612309588400458070242121446588416", (v << 30).ToString(), "#30"); + Assert.AreEqual("495627224619176800916140484242893176832", (v << 31).ToString(), "#31"); + Assert.AreEqual("991254449238353601832280968485786353664", (v << 32).ToString(), "#32"); + Assert.AreEqual("1982508898476707203664561936971572707328", (v << 33).ToString(), "#33"); + Assert.AreEqual("3965017796953414407329123873943145414656", (v << 34).ToString(), "#34"); + Assert.AreEqual("7930035593906828814658247747886290829312", (v << 35).ToString(), "#35"); + Assert.AreEqual("15860071187813657629316495495772581658624", (v << 36).ToString(), "#36"); + Assert.AreEqual("31720142375627315258632990991545163317248", (v << 37).ToString(), "#37"); + Assert.AreEqual("63440284751254630517265981983090326634496", (v << 38).ToString(), "#38"); + Assert.AreEqual("126880569502509261034531963966180653268992", (v << 39).ToString(), "#39"); + Assert.AreEqual("253761139005018522069063927932361306537984", (v << 40).ToString(), "#40"); + Assert.AreEqual("507522278010037044138127855864722613075968", (v << 41).ToString(), "#41"); + Assert.AreEqual("1015044556020074088276255711729445226151936", (v << 42).ToString(), "#42"); + Assert.AreEqual("2030089112040148176552511423458890452303872", (v << 43).ToString(), "#43"); + Assert.AreEqual("4060178224080296353105022846917780904607744", (v << 44).ToString(), "#44"); + Assert.AreEqual("8120356448160592706210045693835561809215488", (v << 45).ToString(), "#45"); + Assert.AreEqual("16240712896321185412420091387671123618430976", (v << 46).ToString(), "#46"); + Assert.AreEqual("32481425792642370824840182775342247236861952", (v << 47).ToString(), "#47"); + Assert.AreEqual("64962851585284741649680365550684494473723904", (v << 48).ToString(), "#48"); + Assert.AreEqual("129925703170569483299360731101368988947447808", (v << 49).ToString(), "#49"); + Assert.AreEqual("259851406341138966598721462202737977894895616", (v << 50).ToString(), "#50"); + Assert.AreEqual("519702812682277933197442924405475955789791232", (v << 51).ToString(), "#51"); + Assert.AreEqual("1039405625364555866394885848810951911579582464", (v << 52).ToString(), "#52"); + Assert.AreEqual("2078811250729111732789771697621903823159164928", (v << 53).ToString(), "#53"); + Assert.AreEqual("4157622501458223465579543395243807646318329856", (v << 54).ToString(), "#54"); + Assert.AreEqual("8315245002916446931159086790487615292636659712", (v << 55).ToString(), "#55"); + Assert.AreEqual("16630490005832893862318173580975230585273319424", (v << 56).ToString(), "#56"); + Assert.AreEqual("33260980011665787724636347161950461170546638848", (v << 57).ToString(), "#57"); + Assert.AreEqual("66521960023331575449272694323900922341093277696", (v << 58).ToString(), "#58"); + Assert.AreEqual("133043920046663150898545388647801844682186555392", (v << 59).ToString(), "#59"); + Assert.AreEqual("266087840093326301797090777295603689364373110784", (v << 60).ToString(), "#60"); + Assert.AreEqual("532175680186652603594181554591207378728746221568", (v << 61).ToString(), "#61"); + Assert.AreEqual("1064351360373305207188363109182414757457492443136", (v << 62).ToString(), "#62"); + Assert.AreEqual("2128702720746610414376726218364829514914984886272", (v << 63).ToString(), "#63"); + Assert.AreEqual("4257405441493220828753452436729659029829969772544", (v << 64).ToString(), "#64"); + Assert.AreEqual("8514810882986441657506904873459318059659939545088", (v << 65).ToString(), "#65"); + Assert.AreEqual("17029621765972883315013809746918636119319879090176", (v << 66).ToString(), "#66"); + Assert.AreEqual("34059243531945766630027619493837272238639758180352", (v << 67).ToString(), "#67"); + Assert.AreEqual("68118487063891533260055238987674544477279516360704", (v << 68).ToString(), "#68"); + Assert.AreEqual("136236974127783066520110477975349088954559032721408", (v << 69).ToString(), "#69"); + } + + + [TestMethod] + public void RightShiftByInt() + { + var v = BigInteger.Parse("230794411440927908251127453634"); + v = v * BigInteger.Pow(2, 70); + + Assert.AreEqual("272473948255566133040220955950698177909118065442816", (v >> 0).ToString(), "#0"); + Assert.AreEqual("136236974127783066520110477975349088954559032721408", (v >> 1).ToString(), "#1"); + Assert.AreEqual("68118487063891533260055238987674544477279516360704", (v >> 2).ToString(), "#2"); + Assert.AreEqual("34059243531945766630027619493837272238639758180352", (v >> 3).ToString(), "#3"); + Assert.AreEqual("17029621765972883315013809746918636119319879090176", (v >> 4).ToString(), "#4"); + Assert.AreEqual("8514810882986441657506904873459318059659939545088", (v >> 5).ToString(), "#5"); + Assert.AreEqual("4257405441493220828753452436729659029829969772544", (v >> 6).ToString(), "#6"); + Assert.AreEqual("2128702720746610414376726218364829514914984886272", (v >> 7).ToString(), "#7"); + Assert.AreEqual("1064351360373305207188363109182414757457492443136", (v >> 8).ToString(), "#8"); + Assert.AreEqual("532175680186652603594181554591207378728746221568", (v >> 9).ToString(), "#9"); + Assert.AreEqual("266087840093326301797090777295603689364373110784", (v >> 10).ToString(), "#10"); + Assert.AreEqual("133043920046663150898545388647801844682186555392", (v >> 11).ToString(), "#11"); + Assert.AreEqual("66521960023331575449272694323900922341093277696", (v >> 12).ToString(), "#12"); + Assert.AreEqual("33260980011665787724636347161950461170546638848", (v >> 13).ToString(), "#13"); + Assert.AreEqual("16630490005832893862318173580975230585273319424", (v >> 14).ToString(), "#14"); + Assert.AreEqual("8315245002916446931159086790487615292636659712", (v >> 15).ToString(), "#15"); + Assert.AreEqual("4157622501458223465579543395243807646318329856", (v >> 16).ToString(), "#16"); + Assert.AreEqual("2078811250729111732789771697621903823159164928", (v >> 17).ToString(), "#17"); + Assert.AreEqual("1039405625364555866394885848810951911579582464", (v >> 18).ToString(), "#18"); + Assert.AreEqual("519702812682277933197442924405475955789791232", (v >> 19).ToString(), "#19"); + Assert.AreEqual("259851406341138966598721462202737977894895616", (v >> 20).ToString(), "#20"); + Assert.AreEqual("129925703170569483299360731101368988947447808", (v >> 21).ToString(), "#21"); + Assert.AreEqual("64962851585284741649680365550684494473723904", (v >> 22).ToString(), "#22"); + Assert.AreEqual("32481425792642370824840182775342247236861952", (v >> 23).ToString(), "#23"); + Assert.AreEqual("16240712896321185412420091387671123618430976", (v >> 24).ToString(), "#24"); + Assert.AreEqual("8120356448160592706210045693835561809215488", (v >> 25).ToString(), "#25"); + Assert.AreEqual("4060178224080296353105022846917780904607744", (v >> 26).ToString(), "#26"); + Assert.AreEqual("2030089112040148176552511423458890452303872", (v >> 27).ToString(), "#27"); + Assert.AreEqual("1015044556020074088276255711729445226151936", (v >> 28).ToString(), "#28"); + Assert.AreEqual("507522278010037044138127855864722613075968", (v >> 29).ToString(), "#29"); + Assert.AreEqual("253761139005018522069063927932361306537984", (v >> 30).ToString(), "#30"); + Assert.AreEqual("126880569502509261034531963966180653268992", (v >> 31).ToString(), "#31"); + Assert.AreEqual("63440284751254630517265981983090326634496", (v >> 32).ToString(), "#32"); + Assert.AreEqual("31720142375627315258632990991545163317248", (v >> 33).ToString(), "#33"); + Assert.AreEqual("15860071187813657629316495495772581658624", (v >> 34).ToString(), "#34"); + Assert.AreEqual("7930035593906828814658247747886290829312", (v >> 35).ToString(), "#35"); + Assert.AreEqual("3965017796953414407329123873943145414656", (v >> 36).ToString(), "#36"); + Assert.AreEqual("1982508898476707203664561936971572707328", (v >> 37).ToString(), "#37"); + Assert.AreEqual("991254449238353601832280968485786353664", (v >> 38).ToString(), "#38"); + Assert.AreEqual("495627224619176800916140484242893176832", (v >> 39).ToString(), "#39"); + Assert.AreEqual("247813612309588400458070242121446588416", (v >> 40).ToString(), "#40"); + Assert.AreEqual("123906806154794200229035121060723294208", (v >> 41).ToString(), "#41"); + Assert.AreEqual("61953403077397100114517560530361647104", (v >> 42).ToString(), "#42"); + Assert.AreEqual("30976701538698550057258780265180823552", (v >> 43).ToString(), "#43"); + Assert.AreEqual("15488350769349275028629390132590411776", (v >> 44).ToString(), "#44"); + Assert.AreEqual("7744175384674637514314695066295205888", (v >> 45).ToString(), "#45"); + Assert.AreEqual("3872087692337318757157347533147602944", (v >> 46).ToString(), "#46"); + Assert.AreEqual("1936043846168659378578673766573801472", (v >> 47).ToString(), "#47"); + Assert.AreEqual("968021923084329689289336883286900736", (v >> 48).ToString(), "#48"); + Assert.AreEqual("484010961542164844644668441643450368", (v >> 49).ToString(), "#49"); + Assert.AreEqual("242005480771082422322334220821725184", (v >> 50).ToString(), "#50"); + Assert.AreEqual("121002740385541211161167110410862592", (v >> 51).ToString(), "#51"); + Assert.AreEqual("60501370192770605580583555205431296", (v >> 52).ToString(), "#52"); + Assert.AreEqual("30250685096385302790291777602715648", (v >> 53).ToString(), "#53"); + Assert.AreEqual("15125342548192651395145888801357824", (v >> 54).ToString(), "#54"); + Assert.AreEqual("7562671274096325697572944400678912", (v >> 55).ToString(), "#55"); + Assert.AreEqual("3781335637048162848786472200339456", (v >> 56).ToString(), "#56"); + Assert.AreEqual("1890667818524081424393236100169728", (v >> 57).ToString(), "#57"); + Assert.AreEqual("945333909262040712196618050084864", (v >> 58).ToString(), "#58"); + Assert.AreEqual("472666954631020356098309025042432", (v >> 59).ToString(), "#59"); + Assert.AreEqual("236333477315510178049154512521216", (v >> 60).ToString(), "#60"); + Assert.AreEqual("118166738657755089024577256260608", (v >> 61).ToString(), "#61"); + Assert.AreEqual("59083369328877544512288628130304", (v >> 62).ToString(), "#62"); + Assert.AreEqual("29541684664438772256144314065152", (v >> 63).ToString(), "#63"); + Assert.AreEqual("14770842332219386128072157032576", (v >> 64).ToString(), "#64"); + Assert.AreEqual("7385421166109693064036078516288", (v >> 65).ToString(), "#65"); + Assert.AreEqual("3692710583054846532018039258144", (v >> 66).ToString(), "#66"); + Assert.AreEqual("1846355291527423266009019629072", (v >> 67).ToString(), "#67"); + Assert.AreEqual("923177645763711633004509814536", (v >> 68).ToString(), "#68"); + Assert.AreEqual("461588822881855816502254907268", (v >> 69).ToString(), "#69"); + } + + [TestMethod] + public void Bug10887() + { + BigInteger b = 0; + for (var i = 1; i <= 16; i++) + b = b * 256 + i; + var p = BigInteger.Pow(2, 32); + + Assert.AreEqual("1339673755198158349044581307228491536", b.ToString()); + Assert.AreEqual("1339673755198158349044581307228491536", ((b << 32) / p).ToString()); + Assert.AreEqual("1339673755198158349044581307228491536", (b * p >> 32).ToString()); + } + + [TestMethod] + public void DefaultCtorWorks() + { + var a = new BigInteger(); + Assert.AreEqual(BigInteger.One, ++a, "#1"); + + a = new BigInteger(); + Assert.AreEqual(BigInteger.MinusOne, --a, "#2"); + + a = new BigInteger(); + Assert.AreEqual(BigInteger.MinusOne, ~a, "#3"); + + a = new BigInteger(); + Assert.AreEqual("0", a.ToString(), "#4"); + + a = new BigInteger(); + Assert.AreEqual(true, a == a, "#5"); + + a = new BigInteger(); + Assert.AreEqual(false, a < a, "#6"); + + a = new BigInteger(); + Assert.AreEqual(true, a < 10L, "#7"); + + a = new BigInteger(); + Assert.AreEqual(true, a.IsEven, "#8"); + + a = new BigInteger(); + Assert.AreEqual(0, (int)a, "#9"); + + a = new BigInteger(); + Assert.AreEqual((uint) 0, (uint)a, "#10"); + + a = new BigInteger(); + Assert.AreEqual((ulong) 0, (ulong)a, "#11"); + + a = new BigInteger(); + Assert.AreEqual(true, a.Equals(a), "#12"); + + a = new BigInteger(); + Assert.AreEqual(a, BigInteger.Min(a, a), "#13"); + + a = new BigInteger(); + Assert.AreEqual(a, BigInteger.GreatestCommonDivisor(a, a), "#14"); + + a = new BigInteger(); + Assert.AreEqual(BigInteger.Zero.GetHashCode(), a.GetHashCode(), "#15"); + + a = new BigInteger(); + Assert.AreEqual(BigInteger.Zero, a, "#16"); + } + + [TestMethod] + public void Bug16526() + { + var x = BigInteger.Pow(2, 63); + x *= -1; + x -= 1; + Assert.AreEqual("-9223372036854775809", x.ToString(), "#1"); + try + { + x = (long)x; + Assert.Fail("#2 Must OVF: " + x); + } + catch (OverflowException) + { + } + } + + [TestMethod] + public void ToArray_Performance() + { + const int loopCount = 100000000; + var bigInteger = new BigInteger(huge_a); + + var stopWatch = new Stopwatch(); + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Start(); + + for (var i = 0; i < loopCount; i++) + { + bigInteger.ToByteArray(); + } + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Stop(); + + Console.WriteLine(stopWatch.ElapsedMilliseconds); + } + + [TestMethod] + public void Ctor_ByteArray_Performance() + { + const int loopCount = 100000000; + + var stopWatch = new Stopwatch(); + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Start(); + + for (var i = 0; i < loopCount; i++) + { + new BigInteger(huge_a); + } + + GC.Collect(); + GC.WaitForFullGCComplete(); + + stopWatch.Stop(); + + Console.WriteLine(stopWatch.ElapsedMilliseconds); + } + + [TestMethod] + public void MinusOne() + { + var minusOne = BigInteger.MinusOne; + + Assert.IsFalse(minusOne.IsEven); + Assert.IsFalse(minusOne.IsOne); + Assert.IsFalse(minusOne.IsPowerOfTwo); + Assert.IsFalse(minusOne.IsZero); + Assert.AreEqual(-1, minusOne.Sign); + } + + [TestMethod] + public void One() + { + var one = BigInteger.One; + + Assert.IsFalse(one.IsEven); + Assert.IsTrue(one.IsOne); + Assert.IsTrue(one.IsPowerOfTwo); + Assert.IsFalse(one.IsZero); + Assert.AreEqual(1, one.Sign); + } + + [TestMethod] + public void Zero() + { + var zero = BigInteger.Zero; + + Assert.IsTrue(zero.IsEven); + Assert.IsFalse(zero.IsOne); + Assert.IsFalse(zero.IsPowerOfTwo); + Assert.IsTrue(zero.IsZero); + Assert.AreEqual(0, zero.Sign); + } + + private static void AssertEqual(byte[] a, byte[] b) + { + Assert.IsTrue(a.IsEqualTo(b)); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs index 952213c8..3c68163f 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ChannelDataEventArgsTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event and events. - /// - [TestClass] - public class ChannelDataEventArgsTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + /// Provides data for event and events. + /// + [TestClass] + public class ChannelDataEventArgsTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs index 4cee62a6..4e411de9 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ChannelEventArgsTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Base class forTest : TestBaseall channel related events. - /// - [TestClass] - public class ChannelEventArgsTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + /// Base class forTest : TestBaseall channel related events. + /// + [TestClass] + public class ChannelEventArgsTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs index b44ef8e3..8a8efdf2 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ChannelOpenFailedEventArgsTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event. - /// - [TestClass] - public class ChannelOpenFailedEventArgsTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + /// Provides data for event. + /// + [TestClass] + public class ChannelOpenFailedEventArgsTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs index ddc76564..093a59c9 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ChannelRequestEventArgsTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event. - /// - [TestClass] - public class ChannelRequestEventArgsTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + /// Provides data for event. + /// + [TestClass] + public class ChannelRequestEventArgsTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/DerDataTest.cs b/src/Renci.SshNet.Tests/Classes/Common/DerDataTest.cs index 60a5c220..83824a8e 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/DerDataTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/DerDataTest.cs @@ -1,174 +1,174 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for DerDataTest and is intended - ///to contain all DerDataTest Unit Tests - /// - [TestClass()] - [Ignore] // placeholder for actual test - public class DerDataTest : TestBase - { - /// - ///A test for DerData Constructor - /// - [TestMethod()] - public void DerDataConstructorTest() - { - DerData target = new DerData(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DerData Constructor - /// - [TestMethod()] - public void DerDataConstructorTest1() - { - byte[] data = null; // TODO: Initialize to an appropriate value - DerData target = new DerData(data); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Encode - /// - [TestMethod()] - public void EncodeTest() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Encode(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadBigInteger - /// - [TestMethod()] - public void ReadBigIntegerTest() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - BigInteger expected = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.ReadBigInteger(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadInteger - /// - [TestMethod()] - public void ReadIntegerTest() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.ReadInteger(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Write - /// - [TestMethod()] - public void WriteTest() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - bool data = false; // TODO: Initialize to an appropriate value - target.Write(data); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Write - /// - [TestMethod()] - public void WriteTest1() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - uint data = 0; // TODO: Initialize to an appropriate value - target.Write(data); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Write - /// - [TestMethod()] - public void WriteTest2() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - BigInteger data = new BigInteger(); // TODO: Initialize to an appropriate value - target.Write(data); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Write - /// - [TestMethod()] - public void WriteTest3() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - target.Write(data); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Write - /// - [TestMethod()] - public void WriteTest4() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - ObjectIdentifier identifier = new ObjectIdentifier(); // TODO: Initialize to an appropriate value - target.Write(identifier); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Write - /// - [TestMethod()] - public void WriteTest5() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - DerData data = null; // TODO: Initialize to an appropriate value - target.Write(data); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteNull - /// - [TestMethod()] - public void WriteNullTest() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - target.WriteNull(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for IsEndOfData - /// - [TestMethod()] - public void IsEndOfDataTest() - { - DerData target = new DerData(); // TODO: Initialize to an appropriate value - bool actual; - actual = target.IsEndOfData; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for DerDataTest and is intended + ///to contain all DerDataTest Unit Tests + /// + [TestClass()] + [Ignore] // placeholder for actual test + public class DerDataTest : TestBase + { + /// + ///A test for DerData Constructor + /// + [TestMethod()] + public void DerDataConstructorTest() + { + DerData target = new DerData(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DerData Constructor + /// + [TestMethod()] + public void DerDataConstructorTest1() + { + byte[] data = null; // TODO: Initialize to an appropriate value + DerData target = new DerData(data); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Encode + /// + [TestMethod()] + public void EncodeTest() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Encode(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadBigInteger + /// + [TestMethod()] + public void ReadBigIntegerTest() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + BigInteger expected = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.ReadBigInteger(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadInteger + /// + [TestMethod()] + public void ReadIntegerTest() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.ReadInteger(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Write + /// + [TestMethod()] + public void WriteTest() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + bool data = false; // TODO: Initialize to an appropriate value + target.Write(data); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Write + /// + [TestMethod()] + public void WriteTest1() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + uint data = 0; // TODO: Initialize to an appropriate value + target.Write(data); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Write + /// + [TestMethod()] + public void WriteTest2() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + BigInteger data = new BigInteger(); // TODO: Initialize to an appropriate value + target.Write(data); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Write + /// + [TestMethod()] + public void WriteTest3() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + target.Write(data); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Write + /// + [TestMethod()] + public void WriteTest4() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + ObjectIdentifier identifier = new ObjectIdentifier(); // TODO: Initialize to an appropriate value + target.Write(identifier); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Write + /// + [TestMethod()] + public void WriteTest5() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + DerData data = null; // TODO: Initialize to an appropriate value + target.Write(data); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteNull + /// + [TestMethod()] + public void WriteNullTest() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + target.WriteNull(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for IsEndOfData + /// + [TestMethod()] + public void IsEndOfDataTest() + { + DerData target = new DerData(); // TODO: Initialize to an appropriate value + bool actual; + actual = target.IsEndOfData; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ExceptionEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ExceptionEventArgsTest.cs index b3ca281c..f68b8228 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ExceptionEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ExceptionEventArgsTest.cs @@ -1,26 +1,26 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ExceptionEventArgsTest and is intended - ///to contain all ExceptionEventArgsTest Unit Tests - /// - [TestClass()] - public class ExceptionEventArgsTest : TestBase - { - /// - ///A test for ExceptionEventArgs Constructor - /// - [TestMethod()] - public void ExceptionEventArgsConstructorTest() - { - Exception exception = null; // TODO: Initialize to an appropriate value - ExceptionEventArgs target = new ExceptionEventArgs(exception); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ExceptionEventArgsTest and is intended + ///to contain all ExceptionEventArgsTest Unit Tests + /// + [TestClass()] + public class ExceptionEventArgsTest : TestBase + { + /// + ///A test for ExceptionEventArgs Constructor + /// + [TestMethod()] + public void ExceptionEventArgsConstructorTest() + { + Exception exception = null; // TODO: Initialize to an appropriate value + ExceptionEventArgs target = new ExceptionEventArgs(exception); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/HostKeyEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/HostKeyEventArgsTest.cs index 82c6d527..691860e1 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/HostKeyEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/HostKeyEventArgsTest.cs @@ -1,44 +1,44 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for HostKeyEventArgsTest and is intended - ///to contain all HostKeyEventArgsTest Unit Tests - /// - [TestClass()] - [Ignore] // placeholder for actual test - public class HostKeyEventArgsTest : TestBase - { - /// - ///A test for HostKeyEventArgs Constructor - /// - [TestMethod()] - public void HostKeyEventArgsConstructorTest() - { - KeyHostAlgorithm host = null; // TODO: Initialize to an appropriate value - HostKeyEventArgs target = new HostKeyEventArgs(host); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for CanTrust - /// - [TestMethod()] - public void CanTrustTest() - { - KeyHostAlgorithm host = null; // TODO: Initialize to an appropriate value - HostKeyEventArgs target = new HostKeyEventArgs(host); // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.CanTrust = expected; - actual = target.CanTrust; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for HostKeyEventArgsTest and is intended + ///to contain all HostKeyEventArgsTest Unit Tests + /// + [TestClass()] + [Ignore] // placeholder for actual test + public class HostKeyEventArgsTest : TestBase + { + /// + ///A test for HostKeyEventArgs Constructor + /// + [TestMethod()] + public void HostKeyEventArgsConstructorTest() + { + KeyHostAlgorithm host = null; // TODO: Initialize to an appropriate value + HostKeyEventArgs target = new HostKeyEventArgs(host); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for CanTrust + /// + [TestMethod()] + public void CanTrustTest() + { + KeyHostAlgorithm host = null; // TODO: Initialize to an appropriate value + HostKeyEventArgs target = new HostKeyEventArgs(host); // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.CanTrust = expected; + actual = target.CanTrust; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/NetConfServerExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/NetConfServerExceptionTest.cs index 0abb1c24..03c999e6 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/NetConfServerExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/NetConfServerExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for NetConfServerExceptionTest and is intended - ///to contain all NetConfServerExceptionTest Unit Tests - /// - [TestClass()] - public class NetConfServerExceptionTest : TestBase - { - /// - ///A test for NetConfServerException Constructor - /// - [TestMethod()] - public void NetConfServerExceptionConstructorTest() - { - NetConfServerException target = new NetConfServerException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NetConfServerException Constructor - /// - [TestMethod()] - public void NetConfServerExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - NetConfServerException target = new NetConfServerException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NetConfServerException Constructor - /// - [TestMethod()] - public void NetConfServerExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - NetConfServerException target = new NetConfServerException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for NetConfServerExceptionTest and is intended + ///to contain all NetConfServerExceptionTest Unit Tests + /// + [TestClass()] + public class NetConfServerExceptionTest : TestBase + { + /// + ///A test for NetConfServerException Constructor + /// + [TestMethod()] + public void NetConfServerExceptionConstructorTest() + { + NetConfServerException target = new NetConfServerException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NetConfServerException Constructor + /// + [TestMethod()] + public void NetConfServerExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + NetConfServerException target = new NetConfServerException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NetConfServerException Constructor + /// + [TestMethod()] + public void NetConfServerExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + NetConfServerException target = new NetConfServerException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ObjectIdentifierTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ObjectIdentifierTest.cs index 4c410256..4663d3e6 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ObjectIdentifierTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ObjectIdentifierTest.cs @@ -1,27 +1,27 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ObjectIdentifierTest and is intended - ///to contain all ObjectIdentifierTest Unit Tests - /// - [TestClass()] - [Ignore] // placeholder for actual test - public class ObjectIdentifierTest : TestBase - { - /// - ///A test for ObjectIdentifier Constructor - /// - [TestMethod()] - public void ObjectIdentifierConstructorTest() - { - ulong[] identifiers = null; // TODO: Initialize to an appropriate value - ObjectIdentifier target = new ObjectIdentifier(identifiers); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ObjectIdentifierTest and is intended + ///to contain all ObjectIdentifierTest Unit Tests + /// + [TestClass()] + [Ignore] // placeholder for actual test + public class ObjectIdentifierTest : TestBase + { + /// + ///A test for ObjectIdentifier Constructor + /// + [TestMethod()] + public void ObjectIdentifierConstructorTest() + { + ulong[] identifiers = null; // TODO: Initialize to an appropriate value + ObjectIdentifier target = new ObjectIdentifier(identifiers); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/PipeStreamTest.cs b/src/Renci.SshNet.Tests/Classes/Common/PipeStreamTest.cs index 6bd38767..3fb5b15f 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/PipeStreamTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/PipeStreamTest.cs @@ -1,256 +1,256 @@ -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using System; -using System.IO; - -namespace Renci.SshNet.Tests.Classes.Common -{ - [TestClass] - public class PipeStreamTest : TestBase - { - [TestMethod] - [TestCategory("PipeStream")] - public void Test_PipeStream_Write_Read_Buffer() - { - var testBuffer = new byte[1024]; - new Random().NextBytes(testBuffer); - - var outputBuffer = new byte[1024]; - - using (var stream = new PipeStream()) - { - stream.Write(testBuffer, 0, testBuffer.Length); - - Assert.AreEqual(stream.Length, testBuffer.Length); - - stream.Read(outputBuffer, 0, outputBuffer.Length); - - Assert.AreEqual(stream.Length, 0); - - Assert.IsTrue(testBuffer.IsEqualTo(outputBuffer)); - } - } - - [TestMethod] - [TestCategory("PipeStream")] - public void Test_PipeStream_Write_Read_Byte() - { - var testBuffer = new byte[1024]; - new Random().NextBytes(testBuffer); - - var outputBuffer = new byte[1024]; - - using (var stream = new PipeStream()) - { - stream.Write(testBuffer, 0, testBuffer.Length); - - Assert.AreEqual(stream.Length, testBuffer.Length); - - stream.ReadByte(); - - Assert.AreEqual(stream.Length, testBuffer.Length - 1); - - stream.ReadByte(); - - Assert.AreEqual(stream.Length, testBuffer.Length - 2); - } - } - /// - ///A test for PipeStream Constructor - /// - [TestMethod] - public void PipeStreamConstructorTest() - { - PipeStream target = new PipeStream(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Flush - /// - [TestMethod] - public void FlushTest() - { - PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value - target.Flush(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - [TestMethod] - public void Read() - { - const int sleepTime = 100; - - var target = new PipeStream(); - target.WriteByte(0x0a); - target.WriteByte(0x0d); - target.WriteByte(0x09); - - var readBuffer = new byte[2]; - var bytesRead = target.Read(readBuffer, 0, readBuffer.Length); - Assert.AreEqual(2, bytesRead); - Assert.AreEqual(0x0a, readBuffer[0]); - Assert.AreEqual(0x0d, readBuffer[1]); - - var writeToStreamThread = new Thread( - () => - { - Thread.Sleep(sleepTime); - var writeBuffer = new byte[] {0x05, 0x03}; - target.Write(writeBuffer, 0, writeBuffer.Length); - }); - writeToStreamThread.Start(); - - readBuffer = new byte[2]; - bytesRead = target.Read(readBuffer, 0, readBuffer.Length); - Assert.AreEqual(2, bytesRead); - Assert.AreEqual(0x09, readBuffer[0]); - Assert.AreEqual(0x05, readBuffer[1]); - } - - [TestMethod] - public void SeekShouldThrowNotSupportedException() - { - const long offset = 0; - const SeekOrigin origin = new SeekOrigin(); - var target = new PipeStream(); - - try - { - target.Seek(offset, origin); - Assert.Fail(); - } - catch (NotSupportedException) - { - } - - } - - [TestMethod] - public void SetLengthShouldThrowNotSupportedException() - { - var target = new PipeStream(); - - try - { - target.SetLength(1); - Assert.Fail(); - } - catch (NotSupportedException) - { - } - } - - [TestMethod] - public void WriteTest() - { - var target = new PipeStream(); - - var writeBuffer = new byte[] {0x0a, 0x05, 0x0d}; - target.Write(writeBuffer, 0, 2); - - writeBuffer = new byte[] { 0x02, 0x04, 0x03, 0x06, 0x09 }; - target.Write(writeBuffer, 1, 2); - - var readBuffer = new byte[6]; - var bytesRead = target.Read(readBuffer, 0, 4); - - Assert.AreEqual(4, bytesRead); - Assert.AreEqual(0x0a, readBuffer[0]); - Assert.AreEqual(0x05, readBuffer[1]); - Assert.AreEqual(0x04, readBuffer[2]); - Assert.AreEqual(0x03, readBuffer[3]); - Assert.AreEqual(0x00, readBuffer[4]); - Assert.AreEqual(0x00, readBuffer[5]); - } - - /// - ///A test for BlockLastReadBuffer - /// - [TestMethod] - public void BlockLastReadBufferTest() - { - PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.BlockLastReadBuffer = expected; - actual = target.BlockLastReadBuffer; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void CanReadTest() - { - var target = new PipeStream(); - Assert.IsTrue(target.CanRead); - } - - [TestMethod] - public void CanSeekTest() - { - var target = new PipeStream(); // TODO: Initialize to an appropriate value - Assert.IsFalse(target.CanSeek); - } - - [TestMethod] - public void CanWriteTest() - { - var target = new PipeStream(); - Assert.IsTrue(target.CanWrite); - } - - [TestMethod] - public void LengthTest() - { - PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value - long actual; - actual = target.Length; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for MaxBufferLength - /// - [TestMethod] - public void MaxBufferLengthTest() - { - PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value - long expected = 0; // TODO: Initialize to an appropriate value - long actual; - target.MaxBufferLength = expected; - actual = target.MaxBufferLength; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void Position_GetterAlwaysReturnsZero() - { - var target = new PipeStream(); - - Assert.AreEqual(0, target.Position); - target.WriteByte(0x0a); - Assert.AreEqual(0, target.Position); - target.ReadByte(); - Assert.AreEqual(0, target.Position); - } - - [TestMethod] - public void Position_SetterAlwaysThrowsNotSupportedException() - { - var target = new PipeStream(); - - try - { - target.Position = 0; - Assert.Fail(); - } - catch (NotSupportedException) - { - } - } - } +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using System; +using System.IO; + +namespace Renci.SshNet.Tests.Classes.Common +{ + [TestClass] + public class PipeStreamTest : TestBase + { + [TestMethod] + [TestCategory("PipeStream")] + public void Test_PipeStream_Write_Read_Buffer() + { + var testBuffer = new byte[1024]; + new Random().NextBytes(testBuffer); + + var outputBuffer = new byte[1024]; + + using (var stream = new PipeStream()) + { + stream.Write(testBuffer, 0, testBuffer.Length); + + Assert.AreEqual(stream.Length, testBuffer.Length); + + stream.Read(outputBuffer, 0, outputBuffer.Length); + + Assert.AreEqual(stream.Length, 0); + + Assert.IsTrue(testBuffer.IsEqualTo(outputBuffer)); + } + } + + [TestMethod] + [TestCategory("PipeStream")] + public void Test_PipeStream_Write_Read_Byte() + { + var testBuffer = new byte[1024]; + new Random().NextBytes(testBuffer); + + var outputBuffer = new byte[1024]; + + using (var stream = new PipeStream()) + { + stream.Write(testBuffer, 0, testBuffer.Length); + + Assert.AreEqual(stream.Length, testBuffer.Length); + + stream.ReadByte(); + + Assert.AreEqual(stream.Length, testBuffer.Length - 1); + + stream.ReadByte(); + + Assert.AreEqual(stream.Length, testBuffer.Length - 2); + } + } + /// + ///A test for PipeStream Constructor + /// + [TestMethod] + public void PipeStreamConstructorTest() + { + PipeStream target = new PipeStream(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Flush + /// + [TestMethod] + public void FlushTest() + { + PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value + target.Flush(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + [TestMethod] + public void Read() + { + const int sleepTime = 100; + + var target = new PipeStream(); + target.WriteByte(0x0a); + target.WriteByte(0x0d); + target.WriteByte(0x09); + + var readBuffer = new byte[2]; + var bytesRead = target.Read(readBuffer, 0, readBuffer.Length); + Assert.AreEqual(2, bytesRead); + Assert.AreEqual(0x0a, readBuffer[0]); + Assert.AreEqual(0x0d, readBuffer[1]); + + var writeToStreamThread = new Thread( + () => + { + Thread.Sleep(sleepTime); + var writeBuffer = new byte[] {0x05, 0x03}; + target.Write(writeBuffer, 0, writeBuffer.Length); + }); + writeToStreamThread.Start(); + + readBuffer = new byte[2]; + bytesRead = target.Read(readBuffer, 0, readBuffer.Length); + Assert.AreEqual(2, bytesRead); + Assert.AreEqual(0x09, readBuffer[0]); + Assert.AreEqual(0x05, readBuffer[1]); + } + + [TestMethod] + public void SeekShouldThrowNotSupportedException() + { + const long offset = 0; + const SeekOrigin origin = new SeekOrigin(); + var target = new PipeStream(); + + try + { + target.Seek(offset, origin); + Assert.Fail(); + } + catch (NotSupportedException) + { + } + + } + + [TestMethod] + public void SetLengthShouldThrowNotSupportedException() + { + var target = new PipeStream(); + + try + { + target.SetLength(1); + Assert.Fail(); + } + catch (NotSupportedException) + { + } + } + + [TestMethod] + public void WriteTest() + { + var target = new PipeStream(); + + var writeBuffer = new byte[] {0x0a, 0x05, 0x0d}; + target.Write(writeBuffer, 0, 2); + + writeBuffer = new byte[] { 0x02, 0x04, 0x03, 0x06, 0x09 }; + target.Write(writeBuffer, 1, 2); + + var readBuffer = new byte[6]; + var bytesRead = target.Read(readBuffer, 0, 4); + + Assert.AreEqual(4, bytesRead); + Assert.AreEqual(0x0a, readBuffer[0]); + Assert.AreEqual(0x05, readBuffer[1]); + Assert.AreEqual(0x04, readBuffer[2]); + Assert.AreEqual(0x03, readBuffer[3]); + Assert.AreEqual(0x00, readBuffer[4]); + Assert.AreEqual(0x00, readBuffer[5]); + } + + /// + ///A test for BlockLastReadBuffer + /// + [TestMethod] + public void BlockLastReadBufferTest() + { + PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.BlockLastReadBuffer = expected; + actual = target.BlockLastReadBuffer; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void CanReadTest() + { + var target = new PipeStream(); + Assert.IsTrue(target.CanRead); + } + + [TestMethod] + public void CanSeekTest() + { + var target = new PipeStream(); // TODO: Initialize to an appropriate value + Assert.IsFalse(target.CanSeek); + } + + [TestMethod] + public void CanWriteTest() + { + var target = new PipeStream(); + Assert.IsTrue(target.CanWrite); + } + + [TestMethod] + public void LengthTest() + { + PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value + long actual; + actual = target.Length; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for MaxBufferLength + /// + [TestMethod] + public void MaxBufferLengthTest() + { + PipeStream target = new PipeStream(); // TODO: Initialize to an appropriate value + long expected = 0; // TODO: Initialize to an appropriate value + long actual; + target.MaxBufferLength = expected; + actual = target.MaxBufferLength; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void Position_GetterAlwaysReturnsZero() + { + var target = new PipeStream(); + + Assert.AreEqual(0, target.Position); + target.WriteByte(0x0a); + Assert.AreEqual(0, target.Position); + target.ReadByte(); + Assert.AreEqual(0, target.Position); + } + + [TestMethod] + public void Position_SetterAlwaysThrowsNotSupportedException() + { + var target = new PipeStream(); + + try + { + target.Position = 0; + Assert.Fail(); + } + catch (NotSupportedException) + { + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/PortForwardEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/PortForwardEventArgsTest.cs index 16788747..25236768 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/PortForwardEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/PortForwardEventArgsTest.cs @@ -1,67 +1,67 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using System; -using System.Net; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - /// Provides data for event. - /// - [TestClass] - public class PortForwardEventArgsTest : TestBase - { - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenHostIsNull() - { - try - { - new PortForwardEventArgs(null, 80); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("host", ex.ParamName); - } - } - - [TestMethod] - public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty() - { - var host = string.Empty; - - var eventArgs = new PortForwardEventArgs(host, 80); - - Assert.AreSame(host, eventArgs.OriginatorHost); - } - - [TestMethod] - public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName() - { - const string host = "in_valid_host."; - - var eventArgs = new PortForwardEventArgs(host, 80); - - Assert.AreSame(host, eventArgs.OriginatorHost); - } - - [TestMethod] - public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsGreaterThanMaximumValue() - { - const int port = IPEndPoint.MaxPort + 1; - - try - { - new PortForwardEventArgs(Resources.HOST, port); - Assert.Fail(); - } - catch (ArgumentOutOfRangeException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("port", ex.ParamName); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using System; +using System.Net; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + /// Provides data for event. + /// + [TestClass] + public class PortForwardEventArgsTest : TestBase + { + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenHostIsNull() + { + try + { + new PortForwardEventArgs(null, 80); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("host", ex.ParamName); + } + } + + [TestMethod] + public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty() + { + var host = string.Empty; + + var eventArgs = new PortForwardEventArgs(host, 80); + + Assert.AreSame(host, eventArgs.OriginatorHost); + } + + [TestMethod] + public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName() + { + const string host = "in_valid_host."; + + var eventArgs = new PortForwardEventArgs(host, 80); + + Assert.AreSame(host, eventArgs.OriginatorHost); + } + + [TestMethod] + public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsGreaterThanMaximumValue() + { + const int port = IPEndPoint.MaxPort + 1; + + try + { + new PortForwardEventArgs(Resources.HOST, port); + Assert.Fail(); + } + catch (ArgumentOutOfRangeException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("port", ex.ParamName); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.NET40.cs b/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.NET40.cs index 7209ee70..711878dc 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.NET40.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.NET40.cs @@ -1,8 +1,8 @@ -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - public partial class ProxyExceptionTest : TestBase - { - } +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + public partial class ProxyExceptionTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.cs index 9e48dfeb..facc7aff 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ProxyExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ProxyExceptionTest and is intended - ///to contain all ProxyExceptionTest Unit Tests - /// - [TestClass()] - public class ProxyExceptionTest : TestBase - { - /// - ///A test for ProxyException Constructor - /// - [TestMethod()] - public void ProxyExceptionConstructorTest() - { - ProxyException target = new ProxyException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ProxyException Constructor - /// - [TestMethod()] - public void ProxyExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - ProxyException target = new ProxyException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ProxyException Constructor - /// - [TestMethod()] - public void ProxyExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - ProxyException target = new ProxyException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ProxyExceptionTest and is intended + ///to contain all ProxyExceptionTest Unit Tests + /// + [TestClass()] + public class ProxyExceptionTest : TestBase + { + /// + ///A test for ProxyException Constructor + /// + [TestMethod()] + public void ProxyExceptionConstructorTest() + { + ProxyException target = new ProxyException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ProxyException Constructor + /// + [TestMethod()] + public void ProxyExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + ProxyException target = new ProxyException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ProxyException Constructor + /// + [TestMethod()] + public void ProxyExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + ProxyException target = new ProxyException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ScpDownloadEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ScpDownloadEventArgsTest.cs index 08211860..c48b442a 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ScpDownloadEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ScpDownloadEventArgsTest.cs @@ -1,28 +1,28 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ScpDownloadEventArgsTest and is intended - ///to contain all ScpDownloadEventArgsTest Unit Tests - /// - [TestClass()] - public class ScpDownloadEventArgsTest : TestBase - { - /// - ///A test for ScpDownloadEventArgs Constructor - /// - [TestMethod()] - public void ScpDownloadEventArgsConstructorTest() - { - string filename = string.Empty; // TODO: Initialize to an appropriate value - long size = 0; // TODO: Initialize to an appropriate value - long downloaded = 0; // TODO: Initialize to an appropriate value - ScpDownloadEventArgs target = new ScpDownloadEventArgs(filename, size, downloaded); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ScpDownloadEventArgsTest and is intended + ///to contain all ScpDownloadEventArgsTest Unit Tests + /// + [TestClass()] + public class ScpDownloadEventArgsTest : TestBase + { + /// + ///A test for ScpDownloadEventArgs Constructor + /// + [TestMethod()] + public void ScpDownloadEventArgsConstructorTest() + { + string filename = string.Empty; // TODO: Initialize to an appropriate value + long size = 0; // TODO: Initialize to an appropriate value + long downloaded = 0; // TODO: Initialize to an appropriate value + ScpDownloadEventArgs target = new ScpDownloadEventArgs(filename, size, downloaded); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ScpExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ScpExceptionTest.cs index c167faff..83b27796 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ScpExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ScpExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ScpExceptionTest and is intended - ///to contain all ScpExceptionTest Unit Tests - /// - [TestClass()] - public class ScpExceptionTest : TestBase - { - /// - ///A test for ScpException Constructor - /// - [TestMethod()] - public void ScpExceptionConstructorTest() - { - ScpException target = new ScpException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ScpException Constructor - /// - [TestMethod()] - public void ScpExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - ScpException target = new ScpException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ScpException Constructor - /// - [TestMethod()] - public void ScpExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - ScpException target = new ScpException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ScpExceptionTest and is intended + ///to contain all ScpExceptionTest Unit Tests + /// + [TestClass()] + public class ScpExceptionTest : TestBase + { + /// + ///A test for ScpException Constructor + /// + [TestMethod()] + public void ScpExceptionConstructorTest() + { + ScpException target = new ScpException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ScpException Constructor + /// + [TestMethod()] + public void ScpExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + ScpException target = new ScpException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ScpException Constructor + /// + [TestMethod()] + public void ScpExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + ScpException target = new ScpException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ScpUploadEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ScpUploadEventArgsTest.cs index 2500344a..6e4907d5 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ScpUploadEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ScpUploadEventArgsTest.cs @@ -1,28 +1,28 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ScpUploadEventArgsTest and is intended - ///to contain all ScpUploadEventArgsTest Unit Tests - /// - [TestClass()] - public class ScpUploadEventArgsTest : TestBase - { - /// - ///A test for ScpUploadEventArgs Constructor - /// - [TestMethod()] - public void ScpUploadEventArgsConstructorTest() - { - string filename = string.Empty; // TODO: Initialize to an appropriate value - long size = 0; // TODO: Initialize to an appropriate value - long uploaded = 0; // TODO: Initialize to an appropriate value - ScpUploadEventArgs target = new ScpUploadEventArgs(filename, size, uploaded); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ScpUploadEventArgsTest and is intended + ///to contain all ScpUploadEventArgsTest Unit Tests + /// + [TestClass()] + public class ScpUploadEventArgsTest : TestBase + { + /// + ///A test for ScpUploadEventArgs Constructor + /// + [TestMethod()] + public void ScpUploadEventArgsConstructorTest() + { + string filename = string.Empty; // TODO: Initialize to an appropriate value + long size = 0; // TODO: Initialize to an appropriate value + long uploaded = 0; // TODO: Initialize to an appropriate value + ScpUploadEventArgs target = new ScpUploadEventArgs(filename, size, uploaded); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs index 3a3d3957..414cf46a 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SemaphoreLightTest.cs @@ -1,94 +1,94 @@ -using System.Threading; -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - [TestClass()] - public class SemaphoreLightTest : TestBase - { - [TestMethod()] - public void SemaphoreLightConstructorTest() - { - var initialCount = new Random().Next(1, 10); - var target = new SemaphoreLight(initialCount); - Assert.AreEqual(initialCount, target.CurrentCount); - } - - [TestMethod()] - public void Release() - { - var initialCount = new Random().Next(1, 10); - var target = new SemaphoreLight(initialCount); - - Assert.AreEqual(initialCount, target.Release()); - Assert.AreEqual(initialCount + 1, target.CurrentCount); - - Assert.AreEqual(initialCount + 1, target.Release()); - Assert.AreEqual(initialCount + 2, target.CurrentCount); - } - - /// - ///A test for Release - /// - [TestMethod()] - public void Release_ReleaseCount() - { - var initialCount = new Random().Next(1, 10); - var target = new SemaphoreLight(initialCount); - - var releaseCount1 = new Random().Next(1, 10); - Assert.AreEqual(initialCount, target.Release(releaseCount1)); - Assert.AreEqual(initialCount + releaseCount1, target.CurrentCount); - - var releaseCount2 = new Random().Next(1, 10); - Assert.AreEqual(initialCount + releaseCount1, target.Release(releaseCount2)); - Assert.AreEqual(initialCount + releaseCount1 + releaseCount2, target.CurrentCount); - } - - /// - ///A test for Wait - /// - [TestMethod()] - public void WaitTest() - { - const int sleepTime = 200; - const int initialCount = 2; - var target = new SemaphoreLight(initialCount); - - var start = DateTime.Now; - - target.Wait(); - target.Wait(); - - Assert.IsTrue((DateTime.Now - start).TotalMilliseconds < 50); - - var releaseThread = new Thread( - () => - { - Thread.Sleep(sleepTime); - target.Release(); - }); - releaseThread.Start(); - - target.Wait(); - - var end = DateTime.Now; - var elapsed = end - start; - - Assert.IsTrue(elapsed.TotalMilliseconds > 200); - Assert.IsTrue(elapsed.TotalMilliseconds < 250); - } - - [TestMethod()] - public void CurrentCountTest() - { - var initialCount = new Random().Next(1, 20); - var target = new SemaphoreLight(initialCount); - - Assert.AreEqual(initialCount, target.CurrentCount); - } - } -} +using System.Threading; +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + [TestClass()] + public class SemaphoreLightTest : TestBase + { + [TestMethod()] + public void SemaphoreLightConstructorTest() + { + var initialCount = new Random().Next(1, 10); + var target = new SemaphoreLight(initialCount); + Assert.AreEqual(initialCount, target.CurrentCount); + } + + [TestMethod()] + public void Release() + { + var initialCount = new Random().Next(1, 10); + var target = new SemaphoreLight(initialCount); + + Assert.AreEqual(initialCount, target.Release()); + Assert.AreEqual(initialCount + 1, target.CurrentCount); + + Assert.AreEqual(initialCount + 1, target.Release()); + Assert.AreEqual(initialCount + 2, target.CurrentCount); + } + + /// + ///A test for Release + /// + [TestMethod()] + public void Release_ReleaseCount() + { + var initialCount = new Random().Next(1, 10); + var target = new SemaphoreLight(initialCount); + + var releaseCount1 = new Random().Next(1, 10); + Assert.AreEqual(initialCount, target.Release(releaseCount1)); + Assert.AreEqual(initialCount + releaseCount1, target.CurrentCount); + + var releaseCount2 = new Random().Next(1, 10); + Assert.AreEqual(initialCount + releaseCount1, target.Release(releaseCount2)); + Assert.AreEqual(initialCount + releaseCount1 + releaseCount2, target.CurrentCount); + } + + /// + ///A test for Wait + /// + [TestMethod()] + public void WaitTest() + { + const int sleepTime = 200; + const int initialCount = 2; + var target = new SemaphoreLight(initialCount); + + var start = DateTime.Now; + + target.Wait(); + target.Wait(); + + Assert.IsTrue((DateTime.Now - start).TotalMilliseconds < 50); + + var releaseThread = new Thread( + () => + { + Thread.Sleep(sleepTime); + target.Release(); + }); + releaseThread.Start(); + + target.Wait(); + + var end = DateTime.Now; + var elapsed = end - start; + + Assert.IsTrue(elapsed.TotalMilliseconds > 200); + Assert.IsTrue(elapsed.TotalMilliseconds < 250); + } + + [TestMethod()] + public void CurrentCountTest() + { + var initialCount = new Random().Next(1, 20); + var target = new SemaphoreLight(initialCount); + + Assert.AreEqual(initialCount, target.CurrentCount); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SftpPathNotFoundExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SftpPathNotFoundExceptionTest.cs index 8f885288..48b6ed36 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SftpPathNotFoundExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SftpPathNotFoundExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SftpPathNotFoundExceptionTest and is intended - ///to contain all SftpPathNotFoundExceptionTest Unit Tests - /// - [TestClass()] - public class SftpPathNotFoundExceptionTest : TestBase - { - /// - ///A test for SftpPathNotFoundException Constructor - /// - [TestMethod()] - public void SftpPathNotFoundExceptionConstructorTest() - { - SftpPathNotFoundException target = new SftpPathNotFoundException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpPathNotFoundException Constructor - /// - [TestMethod()] - public void SftpPathNotFoundExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SftpPathNotFoundException target = new SftpPathNotFoundException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpPathNotFoundException Constructor - /// - [TestMethod()] - public void SftpPathNotFoundExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - SftpPathNotFoundException target = new SftpPathNotFoundException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SftpPathNotFoundExceptionTest and is intended + ///to contain all SftpPathNotFoundExceptionTest Unit Tests + /// + [TestClass()] + public class SftpPathNotFoundExceptionTest : TestBase + { + /// + ///A test for SftpPathNotFoundException Constructor + /// + [TestMethod()] + public void SftpPathNotFoundExceptionConstructorTest() + { + SftpPathNotFoundException target = new SftpPathNotFoundException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpPathNotFoundException Constructor + /// + [TestMethod()] + public void SftpPathNotFoundExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SftpPathNotFoundException target = new SftpPathNotFoundException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpPathNotFoundException Constructor + /// + [TestMethod()] + public void SftpPathNotFoundExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + SftpPathNotFoundException target = new SftpPathNotFoundException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SftpPermissionDeniedExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SftpPermissionDeniedExceptionTest.cs index 7a0a803f..0e63606d 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SftpPermissionDeniedExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SftpPermissionDeniedExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SftpPermissionDeniedExceptionTest and is intended - ///to contain all SftpPermissionDeniedExceptionTest Unit Tests - /// - [TestClass()] - public class SftpPermissionDeniedExceptionTest : TestBase - { - /// - ///A test for SftpPermissionDeniedException Constructor - /// - [TestMethod()] - public void SftpPermissionDeniedExceptionConstructorTest() - { - SftpPermissionDeniedException target = new SftpPermissionDeniedException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpPermissionDeniedException Constructor - /// - [TestMethod()] - public void SftpPermissionDeniedExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SftpPermissionDeniedException target = new SftpPermissionDeniedException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpPermissionDeniedException Constructor - /// - [TestMethod()] - public void SftpPermissionDeniedExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - SftpPermissionDeniedException target = new SftpPermissionDeniedException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SftpPermissionDeniedExceptionTest and is intended + ///to contain all SftpPermissionDeniedExceptionTest Unit Tests + /// + [TestClass()] + public class SftpPermissionDeniedExceptionTest : TestBase + { + /// + ///A test for SftpPermissionDeniedException Constructor + /// + [TestMethod()] + public void SftpPermissionDeniedExceptionConstructorTest() + { + SftpPermissionDeniedException target = new SftpPermissionDeniedException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpPermissionDeniedException Constructor + /// + [TestMethod()] + public void SftpPermissionDeniedExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SftpPermissionDeniedException target = new SftpPermissionDeniedException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpPermissionDeniedException Constructor + /// + [TestMethod()] + public void SftpPermissionDeniedExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + SftpPermissionDeniedException target = new SftpPermissionDeniedException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/ShellDataEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/Common/ShellDataEventArgsTest.cs index 28a81ae2..ce27941c 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/ShellDataEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/ShellDataEventArgsTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for ShellDataEventArgsTest and is intended - ///to contain all ShellDataEventArgsTest Unit Tests - /// - [TestClass()] - public class ShellDataEventArgsTest - { - /// - ///A test for ShellDataEventArgs Constructor - /// - [TestMethod()] - public void ShellDataEventArgsConstructorTest() - { - byte[] data = null; // TODO: Initialize to an appropriate value - ShellDataEventArgs target = new ShellDataEventArgs(data); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ShellDataEventArgs Constructor - /// - [TestMethod()] - public void ShellDataEventArgsConstructorTest1() - { - string line = string.Empty; // TODO: Initialize to an appropriate value - ShellDataEventArgs target = new ShellDataEventArgs(line); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for ShellDataEventArgsTest and is intended + ///to contain all ShellDataEventArgsTest Unit Tests + /// + [TestClass()] + public class ShellDataEventArgsTest + { + /// + ///A test for ShellDataEventArgs Constructor + /// + [TestMethod()] + public void ShellDataEventArgsConstructorTest() + { + byte[] data = null; // TODO: Initialize to an appropriate value + ShellDataEventArgs target = new ShellDataEventArgs(data); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ShellDataEventArgs Constructor + /// + [TestMethod()] + public void ShellDataEventArgsConstructorTest1() + { + string line = string.Empty; // TODO: Initialize to an appropriate value + ShellDataEventArgs target = new ShellDataEventArgs(line); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SshAuthenticationExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SshAuthenticationExceptionTest.cs index 3608c1ae..c0266dcf 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SshAuthenticationExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SshAuthenticationExceptionTest.cs @@ -1,47 +1,47 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SshAuthenticationExceptionTest and is intended - ///to contain all SshAuthenticationExceptionTest Unit Tests - /// - [TestClass()] - public class SshAuthenticationExceptionTest - { - /// - ///A test for SshAuthenticationException Constructor - /// - [TestMethod()] - public void SshAuthenticationExceptionConstructorTest() - { - SshAuthenticationException target = new SshAuthenticationException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshAuthenticationException Constructor - /// - [TestMethod()] - public void SshAuthenticationExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SshAuthenticationException target = new SshAuthenticationException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshAuthenticationException Constructor - /// - [TestMethod()] - public void SshAuthenticationExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - SshAuthenticationException target = new SshAuthenticationException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SshAuthenticationExceptionTest and is intended + ///to contain all SshAuthenticationExceptionTest Unit Tests + /// + [TestClass()] + public class SshAuthenticationExceptionTest + { + /// + ///A test for SshAuthenticationException Constructor + /// + [TestMethod()] + public void SshAuthenticationExceptionConstructorTest() + { + SshAuthenticationException target = new SshAuthenticationException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshAuthenticationException Constructor + /// + [TestMethod()] + public void SshAuthenticationExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SshAuthenticationException target = new SshAuthenticationException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshAuthenticationException Constructor + /// + [TestMethod()] + public void SshAuthenticationExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + SshAuthenticationException target = new SshAuthenticationException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SshConnectionExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SshConnectionExceptionTest.cs index 049fbe72..9eede2cc 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SshConnectionExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SshConnectionExceptionTest.cs @@ -1,77 +1,77 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Messages.Transport; -using System.Runtime.Serialization; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SshConnectionExceptionTest and is intended - ///to contain all SshConnectionExceptionTest Unit Tests - /// - [TestClass()] - public class SshConnectionExceptionTest : TestBase - { - /// - ///A test for SshConnectionException Constructor - /// - [TestMethod()] - public void SshConnectionExceptionConstructorTest() - { - SshConnectionException target = new SshConnectionException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshConnectionException Constructor - /// - [TestMethod()] - public void SshConnectionExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SshConnectionException target = new SshConnectionException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshConnectionException Constructor - /// - [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); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshConnectionException Constructor - /// - [TestMethod()] - public void SshConnectionExceptionConstructorTest3() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - DisconnectReason 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); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for GetObjectData - /// - [TestMethod()] - [Ignore] // placeholder for actual test - public void GetObjectDataTest() - { - SshConnectionException 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 - target.GetObjectData(info, context); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Messages.Transport; +using System.Runtime.Serialization; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SshConnectionExceptionTest and is intended + ///to contain all SshConnectionExceptionTest Unit Tests + /// + [TestClass()] + public class SshConnectionExceptionTest : TestBase + { + /// + ///A test for SshConnectionException Constructor + /// + [TestMethod()] + public void SshConnectionExceptionConstructorTest() + { + SshConnectionException target = new SshConnectionException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshConnectionException Constructor + /// + [TestMethod()] + public void SshConnectionExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SshConnectionException target = new SshConnectionException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshConnectionException Constructor + /// + [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); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshConnectionException Constructor + /// + [TestMethod()] + public void SshConnectionExceptionConstructorTest3() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + DisconnectReason 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); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for GetObjectData + /// + [TestMethod()] + [Ignore] // placeholder for actual test + public void GetObjectDataTest() + { + SshConnectionException 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 + target.GetObjectData(info, context); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs index 3a1eb285..c460d624 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs @@ -1,58 +1,58 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - [TestClass] - public class SshDataTest - { - [TestMethod] - public void Write_Boolean_False() - { - var sshData = new BoolSshData(false); - - var bytes = sshData.GetBytes(); - - Assert.AreEqual((byte) 0, bytes[0]); - } - - [TestMethod] - public void Write_Boolean_True() - { - var sshData = new BoolSshData(true); - - var bytes = sshData.GetBytes(); - - Assert.AreEqual((byte) 1, bytes[0]); - } - - private class BoolSshData : SshData - { - private readonly bool _value; - - public BoolSshData(bool value) - { - _value = value; - } - - public new bool IsEndOfData - { - get { return base.IsEndOfData; } - } - - public new byte ReadByte() - { - return base.ReadByte(); - } - - protected override void LoadData() - { - } - - protected override void SaveData() - { - Write(_value); - } - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + [TestClass] + public class SshDataTest + { + [TestMethod] + public void Write_Boolean_False() + { + var sshData = new BoolSshData(false); + + var bytes = sshData.GetBytes(); + + Assert.AreEqual((byte) 0, bytes[0]); + } + + [TestMethod] + public void Write_Boolean_True() + { + var sshData = new BoolSshData(true); + + var bytes = sshData.GetBytes(); + + Assert.AreEqual((byte) 1, bytes[0]); + } + + private class BoolSshData : SshData + { + private readonly bool _value; + + public BoolSshData(bool value) + { + _value = value; + } + + public new bool IsEndOfData + { + get { return base.IsEndOfData; } + } + + public new byte ReadByte() + { + return base.ReadByte(); + } + + protected override void LoadData() + { + } + + protected override void SaveData() + { + Write(_value); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SshExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SshExceptionTest.cs index e1713323..26ff8daf 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SshExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SshExceptionTest.cs @@ -1,63 +1,63 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Runtime.Serialization; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SshExceptionTest and is intended - ///to contain all SshExceptionTest Unit Tests - /// - [TestClass()] - public class SshExceptionTest : TestBase - { - /// - ///A test for SshException Constructor - /// - [TestMethod()] - public void SshExceptionConstructorTest() - { - SshException target = new SshException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshException Constructor - /// - [TestMethod()] - public void SshExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SshException target = new SshException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshException Constructor - /// - [TestMethod()] - public void SshExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception inner = null; // TODO: Initialize to an appropriate value - SshException target = new SshException(message, inner); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for GetObjectData - /// - [TestMethod()] - [Ignore] // placeholder for actual test - public void GetObjectDataTest() - { - SshException target = new SshException(); // 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 - target.GetObjectData(info, context); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Runtime.Serialization; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SshExceptionTest and is intended + ///to contain all SshExceptionTest Unit Tests + /// + [TestClass()] + public class SshExceptionTest : TestBase + { + /// + ///A test for SshException Constructor + /// + [TestMethod()] + public void SshExceptionConstructorTest() + { + SshException target = new SshException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshException Constructor + /// + [TestMethod()] + public void SshExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SshException target = new SshException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshException Constructor + /// + [TestMethod()] + public void SshExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception inner = null; // TODO: Initialize to an appropriate value + SshException target = new SshException(message, inner); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for GetObjectData + /// + [TestMethod()] + [Ignore] // placeholder for actual test + public void GetObjectDataTest() + { + SshException target = new SshException(); // 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 + target.GetObjectData(info, context); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SshOperationTimeoutExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SshOperationTimeoutExceptionTest.cs index bf22e1fa..6aef4751 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SshOperationTimeoutExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SshOperationTimeoutExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SshOperationTimeoutExceptionTest and is intended - ///to contain all SshOperationTimeoutExceptionTest Unit Tests - /// - [TestClass()] - public class SshOperationTimeoutExceptionTest : TestBase - { - /// - ///A test for SshOperationTimeoutException Constructor - /// - [TestMethod()] - public void SshOperationTimeoutExceptionConstructorTest() - { - SshOperationTimeoutException target = new SshOperationTimeoutException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshOperationTimeoutException Constructor - /// - [TestMethod()] - public void SshOperationTimeoutExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SshOperationTimeoutException target = new SshOperationTimeoutException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshOperationTimeoutException Constructor - /// - [TestMethod()] - public void SshOperationTimeoutExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - SshOperationTimeoutException target = new SshOperationTimeoutException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SshOperationTimeoutExceptionTest and is intended + ///to contain all SshOperationTimeoutExceptionTest Unit Tests + /// + [TestClass()] + public class SshOperationTimeoutExceptionTest : TestBase + { + /// + ///A test for SshOperationTimeoutException Constructor + /// + [TestMethod()] + public void SshOperationTimeoutExceptionConstructorTest() + { + SshOperationTimeoutException target = new SshOperationTimeoutException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshOperationTimeoutException Constructor + /// + [TestMethod()] + public void SshOperationTimeoutExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SshOperationTimeoutException target = new SshOperationTimeoutException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshOperationTimeoutException Constructor + /// + [TestMethod()] + public void SshOperationTimeoutExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + SshOperationTimeoutException target = new SshOperationTimeoutException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Common/SshPassPhraseNullOrEmptyExceptionTest.cs b/src/Renci.SshNet.Tests/Classes/Common/SshPassPhraseNullOrEmptyExceptionTest.cs index ff34db84..b1d788dd 100644 --- a/src/Renci.SshNet.Tests/Classes/Common/SshPassPhraseNullOrEmptyExceptionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Common/SshPassPhraseNullOrEmptyExceptionTest.cs @@ -1,48 +1,48 @@ -using Renci.SshNet.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Common -{ - /// - ///This is a test class for SshPassPhraseNullOrEmptyExceptionTest and is intended - ///to contain all SshPassPhraseNullOrEmptyExceptionTest Unit Tests - /// - [TestClass()] - public class SshPassPhraseNullOrEmptyExceptionTest : TestBase - { - /// - ///A test for SshPassPhraseNullOrEmptyException Constructor - /// - [TestMethod()] - public void SshPassPhraseNullOrEmptyExceptionConstructorTest() - { - SshPassPhraseNullOrEmptyException target = new SshPassPhraseNullOrEmptyException(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshPassPhraseNullOrEmptyException Constructor - /// - [TestMethod()] - public void SshPassPhraseNullOrEmptyExceptionConstructorTest1() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - SshPassPhraseNullOrEmptyException target = new SshPassPhraseNullOrEmptyException(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshPassPhraseNullOrEmptyException Constructor - /// - [TestMethod()] - public void SshPassPhraseNullOrEmptyExceptionConstructorTest2() - { - string message = string.Empty; // TODO: Initialize to an appropriate value - Exception innerException = null; // TODO: Initialize to an appropriate value - SshPassPhraseNullOrEmptyException target = new SshPassPhraseNullOrEmptyException(message, innerException); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Common +{ + /// + ///This is a test class for SshPassPhraseNullOrEmptyExceptionTest and is intended + ///to contain all SshPassPhraseNullOrEmptyExceptionTest Unit Tests + /// + [TestClass()] + public class SshPassPhraseNullOrEmptyExceptionTest : TestBase + { + /// + ///A test for SshPassPhraseNullOrEmptyException Constructor + /// + [TestMethod()] + public void SshPassPhraseNullOrEmptyExceptionConstructorTest() + { + SshPassPhraseNullOrEmptyException target = new SshPassPhraseNullOrEmptyException(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshPassPhraseNullOrEmptyException Constructor + /// + [TestMethod()] + public void SshPassPhraseNullOrEmptyExceptionConstructorTest1() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + SshPassPhraseNullOrEmptyException target = new SshPassPhraseNullOrEmptyException(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshPassPhraseNullOrEmptyException Constructor + /// + [TestMethod()] + public void SshPassPhraseNullOrEmptyExceptionConstructorTest2() + { + string message = string.Empty; // TODO: Initialize to an appropriate value + Exception innerException = null; // TODO: Initialize to an appropriate value + SshPassPhraseNullOrEmptyException target = new SshPassPhraseNullOrEmptyException(message, innerException); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Compression/CompressorTest.cs b/src/Renci.SshNet.Tests/Classes/Compression/CompressorTest.cs index 54990cf1..cf47c71d 100644 --- a/src/Renci.SshNet.Tests/Classes/Compression/CompressorTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Compression/CompressorTest.cs @@ -1,77 +1,77 @@ -using Renci.SshNet.Compression; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Compression -{ - /// - ///This is a test class for CompressorTest and is intended - ///to contain all CompressorTest Unit Tests - /// - [TestClass] - [Ignore] // placeholders only - public class CompressorTest : TestBase - { - internal virtual Compressor CreateCompressor() - { - // TODO: Instantiate an appropriate concrete class. - Compressor target = null; - return target; - } - - /// - ///A test for Compress - /// - [TestMethod()] - public void CompressTest() - { - Compressor target = CreateCompressor(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Compress(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Decompress - /// - [TestMethod()] - public void DecompressTest() - { - Compressor target = CreateCompressor(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Decompress(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - Compressor target = CreateCompressor(); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Init - /// - [TestMethod()] - public void InitTest() - { - Compressor target = CreateCompressor(); // 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."); - } - } -} +using Renci.SshNet.Compression; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Compression +{ + /// + ///This is a test class for CompressorTest and is intended + ///to contain all CompressorTest Unit Tests + /// + [TestClass] + [Ignore] // placeholders only + public class CompressorTest : TestBase + { + internal virtual Compressor CreateCompressor() + { + // TODO: Instantiate an appropriate concrete class. + Compressor target = null; + return target; + } + + /// + ///A test for Compress + /// + [TestMethod()] + public void CompressTest() + { + Compressor target = CreateCompressor(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Compress(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Decompress + /// + [TestMethod()] + public void DecompressTest() + { + Compressor target = CreateCompressor(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Decompress(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + Compressor target = CreateCompressor(); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Init + /// + [TestMethod()] + public void InitTest() + { + Compressor target = CreateCompressor(); // 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."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Compression/ZlibOpenSshTest.cs b/src/Renci.SshNet.Tests/Classes/Compression/ZlibOpenSshTest.cs index f163b1df..c11e13dc 100644 --- a/src/Renci.SshNet.Tests/Classes/Compression/ZlibOpenSshTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Compression/ZlibOpenSshTest.cs @@ -1,51 +1,51 @@ -using Renci.SshNet.Compression; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Compression -{ - /// - ///This is a test class for ZlibOpenSshTest and is intended - ///to contain all ZlibOpenSshTest Unit Tests - /// - [TestClass] - [Ignore] // placeholders only - public class ZlibOpenSshTest : TestBase - { - /// - ///A test for ZlibOpenSsh Constructor - /// - [TestMethod()] - public void ZlibOpenSshConstructorTest() - { - ZlibOpenSsh target = new ZlibOpenSsh(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Init - /// - [TestMethod()] - public void InitTest() - { - ZlibOpenSsh 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."); - } - - /// - ///A test for Name - /// - [TestMethod()] - public void NameTest() - { - ZlibOpenSsh target = new ZlibOpenSsh(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Compression; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Compression +{ + /// + ///This is a test class for ZlibOpenSshTest and is intended + ///to contain all ZlibOpenSshTest Unit Tests + /// + [TestClass] + [Ignore] // placeholders only + public class ZlibOpenSshTest : TestBase + { + /// + ///A test for ZlibOpenSsh Constructor + /// + [TestMethod()] + public void ZlibOpenSshConstructorTest() + { + ZlibOpenSsh target = new ZlibOpenSsh(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Init + /// + [TestMethod()] + public void InitTest() + { + ZlibOpenSsh 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."); + } + + /// + ///A test for Name + /// + [TestMethod()] + public void NameTest() + { + ZlibOpenSsh target = new ZlibOpenSsh(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Compression/ZlibStreamTest.cs b/src/Renci.SshNet.Tests/Classes/Compression/ZlibStreamTest.cs index 8c77e64a..489bc660 100644 --- a/src/Renci.SshNet.Tests/Classes/Compression/ZlibStreamTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Compression/ZlibStreamTest.cs @@ -1,44 +1,44 @@ -using Renci.SshNet.Compression; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.IO; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Compression -{ - /// - ///This is a test class for ZlibStreamTest and is intended - ///to contain all ZlibStreamTest Unit Tests - /// - [TestClass()] - public class ZlibStreamTest : TestBase - { - /// - ///A test for ZlibStream Constructor - /// - [TestMethod()] - 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); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Write - /// - [TestMethod()] - 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 - 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 - target.Write(buffer, offset, count); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } -} +using Renci.SshNet.Compression; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.IO; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Compression +{ + /// + ///This is a test class for ZlibStreamTest and is intended + ///to contain all ZlibStreamTest Unit Tests + /// + [TestClass()] + public class ZlibStreamTest : TestBase + { + /// + ///A test for ZlibStream Constructor + /// + [TestMethod()] + 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); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Write + /// + [TestMethod()] + 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 + 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 + target.Write(buffer, offset, count); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Compression/ZlibTest.cs b/src/Renci.SshNet.Tests/Classes/Compression/ZlibTest.cs index bd0af588..d460b3eb 100644 --- a/src/Renci.SshNet.Tests/Classes/Compression/ZlibTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Compression/ZlibTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Compression -{ - /// - /// Represents "zlib" compression implementation - /// - [TestClass] - public class ZlibTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Compression +{ + /// + /// Represents "zlib" compression implementation + /// + [TestClass] + public class ZlibTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs index ca68af0f..5fc1cd83 100644 --- a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest.cs @@ -1,347 +1,347 @@ -using System.Globalization; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Represents remote connection information class. - /// - [TestClass] - public class ConnectionInfoTest : TestBase - { - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldNotThrowExceptionhenProxyTypesIsNoneAndProxyHostIsNull() - { - const string proxyHost = null; - - var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, - ProxyTypes.None, proxyHost, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.IsNull(connectionInfo.ProxyHost); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentNullExceptionhenProxyTypesIsNotNoneAndProxyHostIsNull() - { - 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)); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("proxyHost", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldNotThrowExceptionWhenProxyTypesIsNotNoneAndProxyHostIsEmpty() - { - 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, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.AreSame(proxyHost, connectionInfo.ProxyHost); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenProxyTypesIsNotNoneAndProxyPortIsGreaterThanMaximumValue() - { - var maxPort = IPEndPoint.MaxPort; - - try - { - 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) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("proxyPort", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenProxyTypesIsNotNoneAndProxyPortIsLessThanMinimumValue() - { - var minPort = IPEndPoint.MinPort; - - try - { - 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) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("proxyPort", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void Test_ConnectionInfo_ProxyPort_Valid() - { - var proxyPort = new Random().Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); - - var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, - ProxyTypes.None, Resources.HOST, proxyPort, Resources.USERNAME, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.AreEqual(proxyPort, connectionInfo.ProxyPort); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldNotThrowExceptionWhenProxyTypesIsNotNoneAndProxyUsernameIsNull() - { - const string proxyUsername = null; - - var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.Http, - Resources.PROXY_HOST, int.Parse(Resources.PORT), proxyUsername, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.IsNull(connectionInfo.ProxyUsername); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentNullExceptionhenHostIsNull() - { - try - { - 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) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("host", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty() - { - var host = string.Empty; - - var connectionInfo = new ConnectionInfo(host, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, - Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.AreSame(host, connectionInfo.Host); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName() - { - const string host = "in_valid_host."; - - var connectionInfo = new ConnectionInfo(host, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, - Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.AreSame(host, connectionInfo.Host); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void Test_ConnectionInfo_Host_Valid() - { - var host = new Random().Next().ToString(CultureInfo.InvariantCulture); - - var connectionInfo = new ConnectionInfo(host, int.Parse(Resources.PORT), Resources.USERNAME, - ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.AreSame(host, connectionInfo.Host); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsGreaterThanMaximumValue() - { - const int port = IPEndPoint.MaxPort + 1; - - try - { - 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) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("port", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsLessThanMinimumValue() - { - const int port = IPEndPoint.MinPort - 1; - - try - { - 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) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("port", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void Test_ConnectionInfo_Port_Valid() - { - var port = new Random().Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); - - var connectionInfo = new ConnectionInfo(Resources.HOST, port, Resources.USERNAME, ProxyTypes.None, - Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - - Assert.AreEqual(port, connectionInfo.Port); - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentExceptionhenUsernameIsNull() - { - const string username = null; - - 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)); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("username", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentExceptionhenUsernameIsEmpty() - { - var username = string.Empty; - - 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)); - Assert.Fail(); - } - catch (ArgumentException ex) - { - Assert.AreEqual(typeof(ArgumentException), ex.GetType()); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("username", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentExceptionhenUsernameContainsOnlyWhitespace() - { - const string username = " \t\r"; - - 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)); - Assert.Fail(); - } - catch (ArgumentException ex) - { - Assert.AreEqual(typeof (ArgumentException), ex.GetType()); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("username", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentNullExceptionWhenAuthenticationMethodsIsNull() - { - try - { - 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) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("authenticationMethods", ex.ParamName); - } - } - - [TestMethod] - [TestCategory("ConnectionInfo")] - public void ConstructorShouldThrowArgumentNullExceptionWhenAuthenticationMethodsIsZeroLength() - { - 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]); - Assert.Fail(); - } - catch (ArgumentException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("authenticationMethods", ex.ParamName); - } - } - - [TestMethod] - [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 session = new Mock(MockBehavior.Strict).Object; - IServiceFactory serviceFactory = null; - - try - { - connectionInfo.Authenticate(session, serviceFactory); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("serviceFactory", ex.ParamName); - } - } - } +using System.Globalization; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Represents remote connection information class. + /// + [TestClass] + public class ConnectionInfoTest : TestBase + { + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldNotThrowExceptionhenProxyTypesIsNoneAndProxyHostIsNull() + { + const string proxyHost = null; + + var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.None, proxyHost, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.IsNull(connectionInfo.ProxyHost); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentNullExceptionhenProxyTypesIsNotNoneAndProxyHostIsNull() + { + 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)); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("proxyHost", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldNotThrowExceptionWhenProxyTypesIsNotNoneAndProxyHostIsEmpty() + { + 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, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreSame(proxyHost, connectionInfo.ProxyHost); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenProxyTypesIsNotNoneAndProxyPortIsGreaterThanMaximumValue() + { + var maxPort = IPEndPoint.MaxPort; + + try + { + 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) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("proxyPort", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenProxyTypesIsNotNoneAndProxyPortIsLessThanMinimumValue() + { + var minPort = IPEndPoint.MinPort; + + try + { + 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) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("proxyPort", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void Test_ConnectionInfo_ProxyPort_Valid() + { + var proxyPort = new Random().Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); + + var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.None, Resources.HOST, proxyPort, Resources.USERNAME, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreEqual(proxyPort, connectionInfo.ProxyPort); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldNotThrowExceptionWhenProxyTypesIsNotNoneAndProxyUsernameIsNull() + { + const string proxyUsername = null; + + var connectionInfo = new ConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.Http, + Resources.PROXY_HOST, int.Parse(Resources.PORT), proxyUsername, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.IsNull(connectionInfo.ProxyUsername); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentNullExceptionhenHostIsNull() + { + try + { + 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) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("host", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty() + { + var host = string.Empty; + + var connectionInfo = new ConnectionInfo(host, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, + Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreSame(host, connectionInfo.Host); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName() + { + const string host = "in_valid_host."; + + var connectionInfo = new ConnectionInfo(host, int.Parse(Resources.PORT), Resources.USERNAME, ProxyTypes.None, + Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreSame(host, connectionInfo.Host); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void Test_ConnectionInfo_Host_Valid() + { + var host = new Random().Next().ToString(CultureInfo.InvariantCulture); + + var connectionInfo = new ConnectionInfo(host, int.Parse(Resources.PORT), Resources.USERNAME, + ProxyTypes.None, Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreSame(host, connectionInfo.Host); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsGreaterThanMaximumValue() + { + const int port = IPEndPoint.MaxPort + 1; + + try + { + 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) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("port", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsLessThanMinimumValue() + { + const int port = IPEndPoint.MinPort - 1; + + try + { + 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) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("port", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void Test_ConnectionInfo_Port_Valid() + { + var port = new Random().Next(IPEndPoint.MinPort, IPEndPoint.MaxPort); + + var connectionInfo = new ConnectionInfo(Resources.HOST, port, Resources.USERNAME, ProxyTypes.None, + Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + + Assert.AreEqual(port, connectionInfo.Port); + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentExceptionhenUsernameIsNull() + { + const string username = null; + + 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)); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("username", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentExceptionhenUsernameIsEmpty() + { + var username = string.Empty; + + 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)); + Assert.Fail(); + } + catch (ArgumentException ex) + { + Assert.AreEqual(typeof(ArgumentException), ex.GetType()); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("username", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentExceptionhenUsernameContainsOnlyWhitespace() + { + const string username = " \t\r"; + + 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)); + Assert.Fail(); + } + catch (ArgumentException ex) + { + Assert.AreEqual(typeof (ArgumentException), ex.GetType()); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("username", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentNullExceptionWhenAuthenticationMethodsIsNull() + { + try + { + 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) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("authenticationMethods", ex.ParamName); + } + } + + [TestMethod] + [TestCategory("ConnectionInfo")] + public void ConstructorShouldThrowArgumentNullExceptionWhenAuthenticationMethodsIsZeroLength() + { + 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]); + Assert.Fail(); + } + catch (ArgumentException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("authenticationMethods", ex.ParamName); + } + } + + [TestMethod] + [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 session = new Mock(MockBehavior.Strict).Object; + IServiceFactory serviceFactory = null; + + try + { + connectionInfo.Authenticate(session, serviceFactory); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("serviceFactory", ex.ParamName); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Failure.cs b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Failure.cs index d43be3ee..597b400f 100644 --- a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Failure.cs +++ b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Failure.cs @@ -1,78 +1,78 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ConnectionInfoTest_Authenticate_Failure - { - private Mock _serviceFactoryMock; - private Mock _clientAuthenticationMock; - private Mock _sessionMock; - private ConnectionInfo _connectionInfo; - private SshAuthenticationException _authenticationException; - private SshAuthenticationException _actualException; - - [TestInitialize] - public void Init() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _clientAuthenticationMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _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)); - _authenticationException = new SshAuthenticationException(); - - _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Returns(_clientAuthenticationMock.Object); - _clientAuthenticationMock.Setup(p => p.Authenticate(_connectionInfo, _sessionMock.Object)) - .Throws(_authenticationException); - } - - protected void Act() - { - try - { - _connectionInfo.Authenticate(_sessionMock.Object, _serviceFactoryMock.Object); - } - catch (SshAuthenticationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void AuthenticateShouldHaveThrownSshAuthenticationException() - { - Assert.IsNotNull(_actualException); - Assert.AreSame(_authenticationException, _actualException); - } - - [TestMethod] - public void IsAuthenticatedShouldReturnFalse() - { - Assert.IsFalse(_connectionInfo.IsAuthenticated); - } - - [TestMethod] - public void CreateClientAuthenticationOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateClientAuthentication(), Times.Once); - } - - [TestMethod] - public void AuthenticateOnClientAuthenticationShouldBeInvokedOnce() - { - _clientAuthenticationMock.Verify(p => p.Authenticate(_connectionInfo, _sessionMock.Object), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ConnectionInfoTest_Authenticate_Failure + { + private Mock _serviceFactoryMock; + private Mock _clientAuthenticationMock; + private Mock _sessionMock; + private ConnectionInfo _connectionInfo; + private SshAuthenticationException _authenticationException; + private SshAuthenticationException _actualException; + + [TestInitialize] + public void Init() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _clientAuthenticationMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _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)); + _authenticationException = new SshAuthenticationException(); + + _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Returns(_clientAuthenticationMock.Object); + _clientAuthenticationMock.Setup(p => p.Authenticate(_connectionInfo, _sessionMock.Object)) + .Throws(_authenticationException); + } + + protected void Act() + { + try + { + _connectionInfo.Authenticate(_sessionMock.Object, _serviceFactoryMock.Object); + } + catch (SshAuthenticationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void AuthenticateShouldHaveThrownSshAuthenticationException() + { + Assert.IsNotNull(_actualException); + Assert.AreSame(_authenticationException, _actualException); + } + + [TestMethod] + public void IsAuthenticatedShouldReturnFalse() + { + Assert.IsFalse(_connectionInfo.IsAuthenticated); + } + + [TestMethod] + public void CreateClientAuthenticationOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateClientAuthentication(), Times.Once); + } + + [TestMethod] + public void AuthenticateOnClientAuthenticationShouldBeInvokedOnce() + { + _clientAuthenticationMock.Verify(p => p.Authenticate(_connectionInfo, _sessionMock.Object), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Success.cs b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Success.cs index 1a23c865..7b6ce1c2 100644 --- a/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Success.cs +++ b/src/Renci.SshNet.Tests/Classes/ConnectionInfoTest_Authenticate_Success.cs @@ -1,59 +1,59 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ConnectionInfoTest_Authenticate_Success - { - private Mock _serviceFactoryMock; - private Mock _clientAuthenticationMock; - private Mock _sessionMock; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Init() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _clientAuthenticationMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _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)); - - _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Returns(_clientAuthenticationMock.Object); - _clientAuthenticationMock.Setup(p => p.Authenticate(_connectionInfo, _sessionMock.Object)); - } - - protected void Act() - { - _connectionInfo.Authenticate(_sessionMock.Object, _serviceFactoryMock.Object); - } - - [TestMethod] - public void IsAuthenticatedShouldReturnTrue() - { - Assert.IsTrue(_connectionInfo.IsAuthenticated); - } - - [TestMethod] - public void CreateClientAuthenticationOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateClientAuthentication(), Times.Once); - } - - [TestMethod] - public void AuthenticateOnClientAuthenticationShouldBeInvokedOnce() - { - _clientAuthenticationMock.Verify(p => p.Authenticate(_connectionInfo, _sessionMock.Object), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ConnectionInfoTest_Authenticate_Success + { + private Mock _serviceFactoryMock; + private Mock _clientAuthenticationMock; + private Mock _sessionMock; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Init() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _clientAuthenticationMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _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)); + + _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Returns(_clientAuthenticationMock.Object); + _clientAuthenticationMock.Setup(p => p.Authenticate(_connectionInfo, _sessionMock.Object)); + } + + protected void Act() + { + _connectionInfo.Authenticate(_sessionMock.Object, _serviceFactoryMock.Object); + } + + [TestMethod] + public void IsAuthenticatedShouldReturnTrue() + { + Assert.IsTrue(_connectionInfo.IsAuthenticated); + } + + [TestMethod] + public void CreateClientAuthenticationOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateClientAuthentication(), Times.Once); + } + + [TestMethod] + public void AuthenticateOnClientAuthenticationShouldBeInvokedOnce() + { + _clientAuthenticationMock.Verify(p => p.Authenticate(_connectionInfo, _sessionMock.Object), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ExpectActionTest.cs b/src/Renci.SshNet.Tests/Classes/ExpectActionTest.cs index 514b8927..777875f0 100644 --- a/src/Renci.SshNet.Tests/Classes/ExpectActionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ExpectActionTest.cs @@ -1,37 +1,37 @@ -using System.Globalization; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using System; -using System.Text.RegularExpressions; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ExpectActionTest : TestBase - { - [TestMethod()] - public void Constructor_StringAndAction() - { - var expect = new Random().Next().ToString(CultureInfo.InvariantCulture); - Action action = Console.WriteLine; - - var target = new ExpectAction(expect, action); - - Assert.IsNotNull(target.Expect); - Assert.AreEqual(expect, target.Expect.ToString()); - Assert.AreSame(action, target.Action); - } - - [TestMethod()] - public void Constructor_RegexAndAction() - { - var expect = new Regex("^.*"); - Action action = Console.WriteLine; - - var target = new ExpectAction(expect, action); - - Assert.AreSame(expect, target.Expect); - Assert.AreSame(action, target.Action); - } - } +using System.Globalization; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using System; +using System.Text.RegularExpressions; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ExpectActionTest : TestBase + { + [TestMethod()] + public void Constructor_StringAndAction() + { + var expect = new Random().Next().ToString(CultureInfo.InvariantCulture); + Action action = Console.WriteLine; + + var target = new ExpectAction(expect, action); + + Assert.IsNotNull(target.Expect); + Assert.AreEqual(expect, target.Expect.ToString()); + Assert.AreSame(action, target.Action); + } + + [TestMethod()] + public void Constructor_RegexAndAction() + { + var expect = new Regex("^.*"); + Action action = Console.WriteLine; + + var target = new ExpectAction(expect, action); + + Assert.AreSame(expect, target.Expect); + Assert.AreSame(action, target.Action); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest.cs index 3e8a4798..a836cebd 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest.cs @@ -1,34 +1,34 @@ -using System; -using System.Globalization; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest : TestBase - { - [TestMethod()] - public void Constructor_HostAndPort() - { - var host = new Random().Next().ToString(CultureInfo.InvariantCulture); - var port = (uint) new Random().Next(0, int.MaxValue); - - var target = new ForwardedPortDynamic(host, port); - - Assert.AreSame(host, target.BoundHost); - Assert.AreEqual(port, target.BoundPort); - } - - [TestMethod()] - public void Constructor_Port() - { - var port = (uint)new Random().Next(0, int.MaxValue); - - var target = new ForwardedPortDynamic(port); - - Assert.AreSame(string.Empty, target.BoundHost); - Assert.AreEqual(port, target.BoundPort); - } - } +using System; +using System.Globalization; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest : TestBase + { + [TestMethod()] + public void Constructor_HostAndPort() + { + var host = new Random().Next().ToString(CultureInfo.InvariantCulture); + var port = (uint) new Random().Next(0, int.MaxValue); + + var target = new ForwardedPortDynamic(host, port); + + Assert.AreSame(host, target.BoundHost); + Assert.AreEqual(port, target.BoundPort); + } + + [TestMethod()] + public void Constructor_Port() + { + var port = (uint)new Random().Next(0, int.MaxValue); + + var target = new ForwardedPortDynamic(port); + + Assert.AreSame(string.Empty, target.BoundHost); + Assert.AreEqual(port, target.BoundPort); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs index 2d928610..36fc91dd 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortDisposed.cs @@ -1,60 +1,60 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Dispose_PortDisposed - { - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - - _forwardedPort = new ForwardedPortDynamic("host", 22); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Dispose_PortDisposed + { + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + + _forwardedPort = new ForwardedPortDynamic("host", 22); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs index 3d0e73b1..afa281d8 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortNeverStarted.cs @@ -1,97 +1,97 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortDynamicTest_Dispose_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortDynamicTest_Dispose_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs index 6ce243b3..4a307949 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound.cs @@ -1,221 +1,221 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - private Socket _client; - private IPEndPoint _remoteEndpoint; - private string _userName; - private TimeSpan _expectedElapsedTime; - private TimeSpan _elapsedTimeOfStop; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _userName = random.Next().ToString(CultureInfo.InvariantCulture); - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - Socket handlerSocket = null; - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.IsOpen).Returns(true); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - Thread.Sleep(_expectedElapsedTime); - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - - _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) - { - ReceiveTimeout = 500, - SendTimeout = 500, - SendBufferSize = 0 - }; - EstablishSocks4Connection(_client); - } - - protected void Act() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - _forwardedPort.Dispose(); - - stopwatch.Stop(); - _elapsedTimeOfStop = stopwatch.Elapsed; - } - - [TestMethod] - public void StopShouldBlockUntilBoundChannelHasClosed() - { - Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime); - Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ExistingConnectionShouldBeClosed() - { - try - { - _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void OpenOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify( - p => - p.Open(_remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port, _forwardedPort, - It.IsAny()), Times.Once); - } - - [TestMethod] - public void BindOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Bind(), Times.Once); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - - private void EstablishSocks4Connection(Socket client) - { - var userNameBytes = Encoding.ASCII.GetBytes(_userName); - var addressBytes = _remoteEndpoint.Address.GetAddressBytes(); - var portBytes = BitConverter.GetBytes((ushort)_remoteEndpoint.Port).Reverse().ToArray(); - - _client.Connect(_endpoint); - - // send SOCKS version - client.Send(new byte[] { 0x04 }, 0, 1, SocketFlags.None); - // send command byte - client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); - // send port - client.Send(portBytes, 0, portBytes.Length, SocketFlags.None); - // send address - client.Send(addressBytes, 0, addressBytes.Length, SocketFlags.None); - // send user name - client.Send(userNameBytes, 0, userNameBytes.Length, SocketFlags.None); - // terminate user name with null - client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); - - var buffer = new byte[16]; - client.Receive(buffer, 0, buffer.Length, SocketFlags.None); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Dispose_PortStarted_ChannelBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + private Socket _client; + private IPEndPoint _remoteEndpoint; + private string _userName; + private TimeSpan _expectedElapsedTime; + private TimeSpan _elapsedTimeOfStop; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_client != null) + { + _client.Dispose(); + _client = null; + } + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _userName = random.Next().ToString(CultureInfo.InvariantCulture); + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + Socket handlerSocket = null; + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.IsOpen).Returns(true); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + Thread.Sleep(_expectedElapsedTime); + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + + _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) + { + ReceiveTimeout = 500, + SendTimeout = 500, + SendBufferSize = 0 + }; + EstablishSocks4Connection(_client); + } + + protected void Act() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + _forwardedPort.Dispose(); + + stopwatch.Stop(); + _elapsedTimeOfStop = stopwatch.Elapsed; + } + + [TestMethod] + public void StopShouldBlockUntilBoundChannelHasClosed() + { + Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime); + Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ExistingConnectionShouldBeClosed() + { + try + { + _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void OpenOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify( + p => + p.Open(_remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port, _forwardedPort, + It.IsAny()), Times.Once); + } + + [TestMethod] + public void BindOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Bind(), Times.Once); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + + private void EstablishSocks4Connection(Socket client) + { + var userNameBytes = Encoding.ASCII.GetBytes(_userName); + var addressBytes = _remoteEndpoint.Address.GetAddressBytes(); + var portBytes = BitConverter.GetBytes((ushort)_remoteEndpoint.Port).Reverse().ToArray(); + + _client.Connect(_endpoint); + + // send SOCKS version + client.Send(new byte[] { 0x04 }, 0, 1, SocketFlags.None); + // send command byte + client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); + // send port + client.Send(portBytes, 0, portBytes.Length, SocketFlags.None); + // send address + client.Send(addressBytes, 0, addressBytes.Length, SocketFlags.None); + // send user name + client.Send(userNameBytes, 0, userNameBytes.Length, SocketFlags.None); + // terminate user name with null + client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); + + var buffer = new byte[16]; + client.Receive(buffer, 0, buffer.Length, SocketFlags.None); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs index 4f2a1190..137ad5aa 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs @@ -1,149 +1,149 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - private Socket _client; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - - _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) - { - ReceiveTimeout = 500, - SendTimeout = 500, - SendBufferSize = 0 - }; - _client.Connect(_endpoint); - - // allow for client socket to establish connection - Thread.Sleep(50); - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ExistingConnectionShouldBeClosed() - { - try - { - _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Runtime.InteropServices; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + private Socket _client; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_client != null) + { + _client.Dispose(); + _client = null; + } + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + + _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) + { + ReceiveTimeout = 500, + SendTimeout = 500, + SendBufferSize = 0 + }; + _client.Connect(_endpoint); + + // allow for client socket to establish connection + Thread.Sleep(50); + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ExistingConnectionShouldBeClosed() + { + try + { + _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs index 5a5a9b7c..9eeca0de 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStopped.cs @@ -1,100 +1,100 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Dispose_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Dispose_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs index 0b745c26..ba758f79 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortDisposed.cs @@ -1,76 +1,76 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Start_PortDisposed - { - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - - _forwardedPort = new ForwardedPortDynamic("host", 22); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Start_PortDisposed + { + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + + _forwardedPort = new ForwardedPortDynamic("host", 22); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs index d2e9d857..cb97c1ec 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortNeverStarted.cs @@ -1,93 +1,93 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortDynamicTest_Start_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Start(); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(_endpoint); - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortDynamicTest_Start_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Start(); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(_endpoint); + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs index 389eeef8..4978ea79 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStarted.cs @@ -1,110 +1,110 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortDynamicTest_Start_PortStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - private InvalidOperationException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowInvalidOperatationException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Forwarded port is already started.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(_endpoint); - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortDynamicTest_Start_PortStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + private InvalidOperationException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowInvalidOperatationException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Forwarded port is already started.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(_endpoint); + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs index e66a351a..3c5eb998 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_PortStopped.cs @@ -1,97 +1,97 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortDynamicTest_Start_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Start(); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(_endpoint); - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortDynamicTest_Start_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Start(); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(_endpoint); + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs index 7b171154..f35a6582 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNotConnected.cs @@ -1,112 +1,112 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Start_SessionNotConnected - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private SshConnectionException _actualException; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(false); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowSshConnectionException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Client not connected.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Start_SessionNotConnected + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private SshConnectionException _actualException; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(false); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowSshConnectionException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Client not connected.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs index 701799db..a3b717e5 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Start_SessionNull.cs @@ -1,101 +1,101 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Start_SessionNull - { - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private InvalidOperationException _actualException; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Forwarded port is not added to a client.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Start_SessionNull + { + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private InvalidOperationException _actualException; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Forwarded port is not added to a client.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs index 213bb4ab..93e1e499 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortDisposed.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Stop_PortDisposed - { - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private ObjectDisposedException _actualException; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - try - { - _forwardedPort.Stop(); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StopShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Stop_PortDisposed + { + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private ObjectDisposedException _actualException; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + try + { + _forwardedPort.Stop(); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StopShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs index 20a9a3f1..92999ab7 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortNeverStarted.cs @@ -1,85 +1,85 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Stop_PortNeverStarted - { - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Stop_PortNeverStarted + { + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint)_endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs index 155f54b6..8b56473d 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound.cs @@ -1,207 +1,207 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; -using System.Net; -using System.Net.Sockets; -using System.Text; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - private Socket _client; - private IPEndPoint _remoteEndpoint; - private string _userName; - private TimeSpan _expectedElapsedTime; - private TimeSpan _elapsedTimeOfStop; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _userName = random.Next().ToString(CultureInfo.InvariantCulture); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); - - Socket handlerSocket = null; - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.IsOpen).Returns(true); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - Thread.Sleep(_expectedElapsedTime); - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - - _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) - { - ReceiveTimeout = 500, - SendTimeout = 500, - SendBufferSize = 0 - }; - EstablishSocks4Connection(_client); - } - - protected void Act() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - _forwardedPort.Stop(); - - stopwatch.Stop(); - _elapsedTimeOfStop = stopwatch.Elapsed; - } - - [TestMethod] - public void StopShouldBlockUntilBoundChannelHasClosed() - { - Assert.IsTrue(_elapsedTimeOfStop >=_expectedElapsedTime); - Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ExistingConnectionShouldBeClosed() - { - try - { - _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - - private void EstablishSocks4Connection(Socket client) - { - var userNameBytes = Encoding.ASCII.GetBytes(_userName); - var addressBytes = _remoteEndpoint.Address.GetAddressBytes(); - var portBytes = BitConverter.GetBytes((ushort)_remoteEndpoint.Port).Reverse().ToArray(); - - _client.Connect(_endpoint); - - // send SOCKS version - client.Send(new byte[] { 0x04 }, 0, 1, SocketFlags.None); - // send command byte - client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); - // send port - client.Send(portBytes, 0, portBytes.Length, SocketFlags.None); - // send address - client.Send(addressBytes, 0, addressBytes.Length, SocketFlags.None); - // send user name - client.Send(userNameBytes, 0, userNameBytes.Length, SocketFlags.None); - // terminate user name with null - client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); - - var buffer = new byte[16]; - client.Receive(buffer, 0, buffer.Length, SocketFlags.None); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Stop_PortStarted_ChannelBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + private Socket _client; + private IPEndPoint _remoteEndpoint; + private string _userName; + private TimeSpan _expectedElapsedTime; + private TimeSpan _elapsedTimeOfStop; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_client != null) + { + _client.Dispose(); + _client = null; + } + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _userName = random.Next().ToString(CultureInfo.InvariantCulture); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); + + Socket handlerSocket = null; + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.IsOpen).Returns(true); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + Thread.Sleep(_expectedElapsedTime); + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + + _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) + { + ReceiveTimeout = 500, + SendTimeout = 500, + SendBufferSize = 0 + }; + EstablishSocks4Connection(_client); + } + + protected void Act() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + _forwardedPort.Stop(); + + stopwatch.Stop(); + _elapsedTimeOfStop = stopwatch.Elapsed; + } + + [TestMethod] + public void StopShouldBlockUntilBoundChannelHasClosed() + { + Assert.IsTrue(_elapsedTimeOfStop >=_expectedElapsedTime); + Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ExistingConnectionShouldBeClosed() + { + try + { + _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + + private void EstablishSocks4Connection(Socket client) + { + var userNameBytes = Encoding.ASCII.GetBytes(_userName); + var addressBytes = _remoteEndpoint.Address.GetAddressBytes(); + var portBytes = BitConverter.GetBytes((ushort)_remoteEndpoint.Port).Reverse().ToArray(); + + _client.Connect(_endpoint); + + // send SOCKS version + client.Send(new byte[] { 0x04 }, 0, 1, SocketFlags.None); + // send command byte + client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); + // send port + client.Send(portBytes, 0, portBytes.Length, SocketFlags.None); + // send address + client.Send(addressBytes, 0, addressBytes.Length, SocketFlags.None); + // send user name + client.Send(userNameBytes, 0, userNameBytes.Length, SocketFlags.None); + // terminate user name with null + client.Send(new byte[] { 0x00 }, 0, 1, SocketFlags.None); + + var buffer = new byte[16]; + client.Receive(buffer, 0, buffer.Length, SocketFlags.None); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs index a0325e5c..d27c0751 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs @@ -1,149 +1,149 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using System.Runtime.InteropServices; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - private Socket _client; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - - _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) - { - ReceiveTimeout = 500, - SendTimeout = 500, - SendBufferSize = 0 - }; - _client.Connect(_endpoint); - - // allow for client socket to establish connection - Thread.Sleep(50); - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ExistingConnectionShouldBeClosed() - { - try - { - _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Runtime.InteropServices; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + private Socket _client; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_client != null) + { + _client.Dispose(); + _client = null; + } + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + + _client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) + { + ReceiveTimeout = 500, + SendTimeout = 500, + SendBufferSize = 0 + }; + _client.Connect(_endpoint); + + // allow for client socket to establish connection + Thread.Sleep(50); + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ExistingConnectionShouldBeClosed() + { + try + { + _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs index dcade293..3fc61917 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStopped.cs @@ -1,100 +1,100 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortDynamicTest_Stop_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortDynamic _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _endpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_endpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortDynamicTest_Stop_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortDynamic _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _endpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + _endpoint = new IPEndPoint(IPAddress.Loopback, 8122); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortDynamic(_endpoint.Address.ToString(), (uint) _endpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_endpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.NET40.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.NET40.cs index c8970365..115fe662 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.NET40.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.NET40.cs @@ -1,103 +1,103 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes -{ - public partial class ForwardedPortLocalTest - { - [TestMethod] - [TestCategory("integration")] - [ExpectedException(typeof(SshConnectionException))] - public void Test_PortForwarding_Local_Without_Connecting() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80); - client.AddForwardedPort(port1); - port1.Exception += delegate(object sender, ExceptionEventArgs e) - { - Assert.Fail(e.Exception.ToString()); - }; - port1.Start(); - - System.Threading.Tasks.Parallel.For(0, 100, - - //new ParallelOptions - //{ - // MaxDegreeOfParallelism = 20, - //}, - (counter) => - { - var start = DateTime.Now; - var req = HttpWebRequest.Create("http://localhost:8084"); - using (var response = req.GetResponse()) - { - var data = ReadStream(response.GetResponseStream()); - var end = DateTime.Now; - - Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, (end - start), counter)); - } - } - ); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_PortForwarding_Local() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80); - client.AddForwardedPort(port1); - port1.Exception += delegate(object sender, ExceptionEventArgs e) - { - Assert.Fail(e.Exception.ToString()); - }; - port1.Start(); - - System.Threading.Tasks.Parallel.For(0, 100, - - //new ParallelOptions - //{ - // MaxDegreeOfParallelism = 20, - //}, - (counter) => - { - var start = DateTime.Now; - var req = HttpWebRequest.Create("http://localhost:8084"); - using (var response = req.GetResponse()) - { - var data = ReadStream(response.GetResponseStream()); - var end = DateTime.Now; - - Debug.WriteLine(string.Format("Request# {2}: Length: {0} Time: {1}", data.Length, (end - start), counter)); - } - } - ); - } - } - - private static byte[] ReadStream(Stream stream) - { - byte[] buffer = new byte[1024]; - using (var ms = new MemoryStream()) - { - while (true) - { - int read = stream.Read(buffer, 0, buffer.Length); - if (read > 0) - ms.Write(buffer, 0, read); - else - return ms.ToArray(); - } - } - } - } +using System; +using System.Diagnostics; +using System.IO; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes +{ + public partial class ForwardedPortLocalTest + { + [TestMethod] + [TestCategory("integration")] + [ExpectedException(typeof(SshConnectionException))] + public void Test_PortForwarding_Local_Without_Connecting() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80); + client.AddForwardedPort(port1); + port1.Exception += delegate(object sender, ExceptionEventArgs e) + { + Assert.Fail(e.Exception.ToString()); + }; + port1.Start(); + + System.Threading.Tasks.Parallel.For(0, 100, + + //new ParallelOptions + //{ + // MaxDegreeOfParallelism = 20, + //}, + (counter) => + { + var start = DateTime.Now; + var req = HttpWebRequest.Create("http://localhost:8084"); + using (var response = req.GetResponse()) + { + var data = ReadStream(response.GetResponseStream()); + var end = DateTime.Now; + + Debug.WriteLine(string.Format("Request# {2}: Lenght: {0} Time: {1}", data.Length, (end - start), counter)); + } + } + ); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_PortForwarding_Local() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80); + client.AddForwardedPort(port1); + port1.Exception += delegate(object sender, ExceptionEventArgs e) + { + Assert.Fail(e.Exception.ToString()); + }; + port1.Start(); + + System.Threading.Tasks.Parallel.For(0, 100, + + //new ParallelOptions + //{ + // MaxDegreeOfParallelism = 20, + //}, + (counter) => + { + var start = DateTime.Now; + var req = HttpWebRequest.Create("http://localhost:8084"); + using (var response = req.GetResponse()) + { + var data = ReadStream(response.GetResponseStream()); + var end = DateTime.Now; + + Debug.WriteLine(string.Format("Request# {2}: Length: {0} Time: {1}", data.Length, (end - start), counter)); + } + } + ); + } + } + + private static byte[] ReadStream(Stream stream) + { + byte[] buffer = new byte[1024]; + using (var ms = new MemoryStream()) + { + while (true) + { + int read = stream.Read(buffer, 0, buffer.Length); + if (read > 0) + ms.Write(buffer, 0, read); + else + return ms.ToArray(); + } + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.cs index b176f1ac..26b6dfd1 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest.cs @@ -1,191 +1,191 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Diagnostics; -using System.Net; -using System.Threading; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality for local port forwarding - /// - [TestClass] - public partial class ForwardedPortLocalTest : TestBase - { - [TestMethod] - [WorkItem(713)] - [Owner("Kenneth_aa")] - [TestCategory("PortForwarding")] - [TestCategory("integration")] - [Description("Test if calling Stop on ForwardedPortLocal instance causes wait.")] - public void Test_PortForwarding_Local_Stop_Hangs_On_Wait() - { - using (var client = new SshClient(Resources.HOST, Int32.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - - var port1 = new ForwardedPortLocal("localhost", 8084, "www.google.com", 80); - client.AddForwardedPort(port1); - port1.Exception += delegate(object sender, ExceptionEventArgs e) - { - Assert.Fail(e.Exception.ToString()); - }; - - port1.Start(); - - bool hasTestedTunnel = false; - System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state) - { - try - { - var url = "http://www.google.com/"; - Debug.WriteLine("Starting web request to \"" + url + "\""); - HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); - HttpWebResponse response = (HttpWebResponse)request.GetResponse(); - - Assert.IsNotNull(response); - - Debug.WriteLine("Http Response status code: " + response.StatusCode.ToString()); - - response.Close(); - - hasTestedTunnel = true; - } - catch (Exception ex) - { - Assert.Fail(ex.ToString()); - } - }); - - // Wait for the web request to complete. - while (!hasTestedTunnel) - { - System.Threading.Thread.Sleep(1000); - } - - try - { - // Try stop the port forwarding, wait 3 seconds and fail if it is still started. - System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state) - { - Debug.WriteLine("Trying to stop port forward."); - port1.Stop(); - Debug.WriteLine("Port forwarding stopped."); - }); - - System.Threading.Thread.Sleep(3000); - if (port1.IsStarted) - { - Assert.Fail("Port forwarding not stopped."); - } - } - catch (Exception ex) - { - Assert.Fail(ex.ToString()); - } - client.Disconnect(); - Debug.WriteLine("Success."); - } - } - - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenBoundHostIsNull() - { - try - { - new ForwardedPortLocal(null, 8080, Resources.HOST, 80); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("boundHost", ex.ParamName); - } - } - - [TestMethod] - public void ConstructorShouldNotThrowExceptionWhenBoundHostIsEmpty() - { - var boundHost = string.Empty; - - var forwardedPort = new ForwardedPortLocal(boundHost, 8080, Resources.HOST, 80); - - Assert.AreSame(boundHost, forwardedPort.BoundHost); - } - - [TestMethod] - public void ConstructorShouldNotThrowExceptionWhenBoundHostIsInvalidDnsName() - { - const string boundHost = "in_valid_host."; - - var forwardedPort = new ForwardedPortLocal(boundHost, 8080, Resources.HOST, 80); - - Assert.AreSame(boundHost, forwardedPort.BoundHost); - } - - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenHostIsNull() - { - try - { - new ForwardedPortLocal(Resources.HOST, 8080, null, 80); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("host", ex.ParamName); - } - } - - [TestMethod] - public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty() - { - var host = string.Empty; - - var forwardedPort = new ForwardedPortLocal(Resources.HOST, 8080, string.Empty, 80); - - Assert.AreSame(host, forwardedPort.Host); - } - - [TestMethod] - public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName() - { - const string host = "in_valid_host."; - - var forwardedPort = new ForwardedPortLocal(Resources.HOST, 8080, host, 80); - - Assert.AreSame(host, forwardedPort.Host); - } - - /// - ///A test for ForwardedPortRemote Constructor - /// - [TestMethod] - [TestCategory("integration")] - public void Test_ForwardedPortRemote() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshClient AddForwardedPort Start Stop ForwardedPortLocal - client.Connect(); - var port = new ForwardedPortLocal(8082, "www.cnn.com", 80); - client.AddForwardedPort(port); - port.Exception += delegate(object sender, ExceptionEventArgs e) - { - Console.WriteLine(e.Exception.ToString()); - }; - port.Start(); - - Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded - - port.Stop(); - #endregion - } - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Diagnostics; +using System.Net; +using System.Threading; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality for local port forwarding + /// + [TestClass] + public partial class ForwardedPortLocalTest : TestBase + { + [TestMethod] + [WorkItem(713)] + [Owner("Kenneth_aa")] + [TestCategory("PortForwarding")] + [TestCategory("integration")] + [Description("Test if calling Stop on ForwardedPortLocal instance causes wait.")] + public void Test_PortForwarding_Local_Stop_Hangs_On_Wait() + { + using (var client = new SshClient(Resources.HOST, Int32.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + + var port1 = new ForwardedPortLocal("localhost", 8084, "www.google.com", 80); + client.AddForwardedPort(port1); + port1.Exception += delegate(object sender, ExceptionEventArgs e) + { + Assert.Fail(e.Exception.ToString()); + }; + + port1.Start(); + + bool hasTestedTunnel = false; + System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state) + { + try + { + var url = "http://www.google.com/"; + Debug.WriteLine("Starting web request to \"" + url + "\""); + HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + + Assert.IsNotNull(response); + + Debug.WriteLine("Http Response status code: " + response.StatusCode.ToString()); + + response.Close(); + + hasTestedTunnel = true; + } + catch (Exception ex) + { + Assert.Fail(ex.ToString()); + } + }); + + // Wait for the web request to complete. + while (!hasTestedTunnel) + { + System.Threading.Thread.Sleep(1000); + } + + try + { + // Try stop the port forwarding, wait 3 seconds and fail if it is still started. + System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state) + { + Debug.WriteLine("Trying to stop port forward."); + port1.Stop(); + Debug.WriteLine("Port forwarding stopped."); + }); + + System.Threading.Thread.Sleep(3000); + if (port1.IsStarted) + { + Assert.Fail("Port forwarding not stopped."); + } + } + catch (Exception ex) + { + Assert.Fail(ex.ToString()); + } + client.Disconnect(); + Debug.WriteLine("Success."); + } + } + + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenBoundHostIsNull() + { + try + { + new ForwardedPortLocal(null, 8080, Resources.HOST, 80); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("boundHost", ex.ParamName); + } + } + + [TestMethod] + public void ConstructorShouldNotThrowExceptionWhenBoundHostIsEmpty() + { + var boundHost = string.Empty; + + var forwardedPort = new ForwardedPortLocal(boundHost, 8080, Resources.HOST, 80); + + Assert.AreSame(boundHost, forwardedPort.BoundHost); + } + + [TestMethod] + public void ConstructorShouldNotThrowExceptionWhenBoundHostIsInvalidDnsName() + { + const string boundHost = "in_valid_host."; + + var forwardedPort = new ForwardedPortLocal(boundHost, 8080, Resources.HOST, 80); + + Assert.AreSame(boundHost, forwardedPort.BoundHost); + } + + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenHostIsNull() + { + try + { + new ForwardedPortLocal(Resources.HOST, 8080, null, 80); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("host", ex.ParamName); + } + } + + [TestMethod] + public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty() + { + var host = string.Empty; + + var forwardedPort = new ForwardedPortLocal(Resources.HOST, 8080, string.Empty, 80); + + Assert.AreSame(host, forwardedPort.Host); + } + + [TestMethod] + public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName() + { + const string host = "in_valid_host."; + + var forwardedPort = new ForwardedPortLocal(Resources.HOST, 8080, host, 80); + + Assert.AreSame(host, forwardedPort.Host); + } + + /// + ///A test for ForwardedPortRemote Constructor + /// + [TestMethod] + [TestCategory("integration")] + public void Test_ForwardedPortRemote() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshClient AddForwardedPort Start Stop ForwardedPortLocal + client.Connect(); + var port = new ForwardedPortLocal(8082, "www.cnn.com", 80); + client.AddForwardedPort(port); + port.Exception += delegate(object sender, ExceptionEventArgs e) + { + Console.WriteLine(e.Exception.ToString()); + }; + port.Start(); + + Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded + + port.Stop(); + #endregion + } + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs index 8abf03b6..2ca34f41 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed.cs @@ -1,80 +1,80 @@ -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Dispose_PortDisposed - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(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(TimeSpan.FromSeconds(30)); - - _forwardedPort = new ForwardedPortLocal(IPAddress.Loopback.ToString(), "host", 22); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Dispose(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void SessionShouldBeNull() - { - Assert.IsNull(_forwardedPort.Session); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Dispose_PortDisposed + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(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(TimeSpan.FromSeconds(30)); + + _forwardedPort = new ForwardedPortLocal(IPAddress.Loopback.ToString(), "host", 22); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Dispose(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void SessionShouldBeNull() + { + Assert.IsNull(_forwardedPort.Session); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs index 384c1c30..dd4e73f9 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted.cs @@ -1,60 +1,60 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted - { - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - - _forwardedPort = new ForwardedPortLocal("boundHost", "host", 22); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Dispose_PortDisposed_NeverStarted + { + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + + _forwardedPort = new ForwardedPortLocal("boundHost", "host", 22); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs index 81f90364..6ba24a87 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortNeverStarted.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Dispose_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Dispose_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs index f9075b94..2168e27e 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound.cs @@ -1,194 +1,194 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -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; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private Socket _client; - private TimeSpan _expectedElapsedTime; - private TimeSpan _elapsedTimeOfStop; - private Stopwatch _stopwatch; - - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - Socket handlerSocket = null; - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - Thread.Sleep(_expectedElapsedTime); - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - - _client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) - { - ReceiveTimeout = 500, - SendTimeout = 500, - SendBufferSize = 0 - }; - - _stopwatch = new Stopwatch(); - _stopwatch.Start(); - - _client.Connect(_localEndpoint); - - // give client socket time to establish connection - Thread.Sleep(50); - } - - protected void Act() - { - _forwardedPort.Dispose(); - - _stopwatch.Stop(); - _elapsedTimeOfStop = _stopwatch.Elapsed; - } - - [TestMethod] - public void StopShouldBlockUntilBoundChannelHasClosed() - { - Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime, string.Format("Expected {0} or greater but was {1}.", _expectedElapsedTime.TotalMilliseconds, _elapsedTimeOfStop.TotalMilliseconds)); - Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ExistingConnectionShouldBeClosed() - { - try - { - _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void OpenOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny()), Times.Once); - } - - [TestMethod] - public void BindOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Bind(), Times.Once); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +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; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Dispose_PortStarted_ChannelBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private Socket _client; + private TimeSpan _expectedElapsedTime; + private TimeSpan _elapsedTimeOfStop; + private Stopwatch _stopwatch; + + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_client != null) + { + _client.Dispose(); + _client = null; + } + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + Socket handlerSocket = null; + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + Thread.Sleep(_expectedElapsedTime); + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + + _client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) + { + ReceiveTimeout = 500, + SendTimeout = 500, + SendBufferSize = 0 + }; + + _stopwatch = new Stopwatch(); + _stopwatch.Start(); + + _client.Connect(_localEndpoint); + + // give client socket time to establish connection + Thread.Sleep(50); + } + + protected void Act() + { + _forwardedPort.Dispose(); + + _stopwatch.Stop(); + _elapsedTimeOfStop = _stopwatch.Elapsed; + } + + [TestMethod] + public void StopShouldBlockUntilBoundChannelHasClosed() + { + Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime, string.Format("Expected {0} or greater but was {1}.", _expectedElapsedTime.TotalMilliseconds, _elapsedTimeOfStop.TotalMilliseconds)); + Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ExistingConnectionShouldBeClosed() + { + try + { + _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void OpenOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny()), Times.Once); + } + + [TestMethod] + public void BindOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Bind(), Times.Once); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs index 33b1ba41..f7dadf62 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound.cs @@ -1,107 +1,107 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortLocalTest_Dispose_PortStarted_ChannelNotBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs index f7d8ce18..3e8e6321 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Dispose_PortStopped.cs @@ -1,105 +1,105 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Dispose_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Dispose_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs index 207ecf9c..78d5ba52 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortDisposed.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Start_PortDisposed - { - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Start_PortDisposed + { + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs index 76bd9a89..416fb331 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortNeverStarted.cs @@ -1,109 +1,109 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortLocalTest_Start_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Start(); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - Socket handlerSocket = null; - - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(_localEndpoint); - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortLocalTest_Start_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Start(); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + Socket handlerSocket = null; + + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(_localEndpoint); + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs index 8f5bbbec..4db07a97 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStarted.cs @@ -1,126 +1,126 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortLocalTest_Start_PortStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private InvalidOperationException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowInvalidOperatationException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Forwarded port is already started.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - Socket handlerSocket = null; - - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(_localEndpoint); - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortLocalTest_Start_PortStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private InvalidOperationException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowInvalidOperatationException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Forwarded port is already started.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + Socket handlerSocket = null; + + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(_localEndpoint); + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs index 328a839f..79b5ae61 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_PortStopped.cs @@ -1,113 +1,113 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortLocalTest_Start_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Start(); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - Socket handlerSocket = null; - - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - client.Connect(_localEndpoint); - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortLocalTest_Start_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Start(); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + Socket handlerSocket = null; + + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + client.Connect(_localEndpoint); + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNotConnected.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNotConnected.cs index e0e1fc35..fda16ba8 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNotConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNotConnected.cs @@ -1,117 +1,117 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Start_SessionNotConnected - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private SshConnectionException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowSshConnectionException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Client not connected.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Start_SessionNotConnected + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private SshConnectionException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowSshConnectionException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Client not connected.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNull.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNull.cs index 719caa34..01caca5b 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNull.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Start_SessionNull.cs @@ -1,116 +1,116 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Start_SessionNull - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private InvalidOperationException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(false); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Forwarded port is not added to a client.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Start_SessionNull + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private InvalidOperationException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(false); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Forwarded port is not added to a client.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs index 89ea31a1..5e11e4e6 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortDisposed.cs @@ -1,82 +1,82 @@ -using System; -using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Stop_PortDisposed - { - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - _closingRegister = new List(); - _exceptionRegister = new List(); - - _forwardedPort = new ForwardedPortLocal("boundHost", "host", 22); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - try - { - _forwardedPort.Stop(); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StopShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Stop_PortDisposed + { + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + _closingRegister = new List(); + _exceptionRegister = new List(); + + _forwardedPort = new ForwardedPortLocal("boundHost", "host", 22); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + try + { + _forwardedPort.Stop(); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StopShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortNeverStarted.cs index 73c56d10..a6c1ef5f 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortNeverStarted.cs @@ -1,99 +1,99 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Stop_PortNeverStarted - { - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private Mock _sessionMock; - private Mock _connectionInfoMock; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Stop_PortNeverStarted + { + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private Mock _sessionMock; + private Mock _connectionInfoMock; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs index 8d732c3a..db4c0f5f 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelBound.cs @@ -1,193 +1,193 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -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; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Stop_PortStarted_ChannelBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private Socket _client; - private TimeSpan _expectedElapsedTime; - private TimeSpan _elapsedTimeOfStop; - private Stopwatch _stopwatch; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_client != null) - { - _client.Dispose(); - _client = null; - } - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - Socket handlerSocket = null; - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); - _channelMock.Setup(p => p.Bind()).Callback(() => - { - Thread.Sleep(_expectedElapsedTime); - if (handlerSocket != null && handlerSocket.Connected) - handlerSocket.Shutdown(SocketShutdown.Both); - }); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - - _client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) - { - ReceiveTimeout = 500, - SendTimeout = 500, - SendBufferSize = 0 - }; - - _stopwatch = new Stopwatch(); - _stopwatch.Start(); - - _client.Connect(_localEndpoint); - - // give client socket time to establish connection - Thread.Sleep(50); - } - - protected void Act() - { - _forwardedPort.Stop(); - - _stopwatch.Stop(); - _elapsedTimeOfStop = _stopwatch.Elapsed; - } - - [TestMethod] - public void StopShouldBlockUntilBoundChannelHasClosed() - { - Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime, string.Format("Expected {0} or greater but was {1}.", _expectedElapsedTime.TotalMilliseconds, _elapsedTimeOfStop.TotalMilliseconds)); - Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ExistingConnectionShouldBeClosed() - { - try - { - _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void OpenOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny()), Times.Once); - } - - [TestMethod] - public void BindOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Bind(), Times.Once); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +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; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Stop_PortStarted_ChannelBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private Socket _client; + private TimeSpan _expectedElapsedTime; + private TimeSpan _elapsedTimeOfStop; + private Stopwatch _stopwatch; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_client != null) + { + _client.Dispose(); + _client = null; + } + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + Socket handlerSocket = null; + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + _channelMock.Setup(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny())).Callback((address, port, forwardedPort, socket) => handlerSocket = socket); + _channelMock.Setup(p => p.Bind()).Callback(() => + { + Thread.Sleep(_expectedElapsedTime); + if (handlerSocket != null && handlerSocket.Connected) + handlerSocket.Shutdown(SocketShutdown.Both); + }); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + + _client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp) + { + ReceiveTimeout = 500, + SendTimeout = 500, + SendBufferSize = 0 + }; + + _stopwatch = new Stopwatch(); + _stopwatch.Start(); + + _client.Connect(_localEndpoint); + + // give client socket time to establish connection + Thread.Sleep(50); + } + + protected void Act() + { + _forwardedPort.Stop(); + + _stopwatch.Stop(); + _elapsedTimeOfStop = _stopwatch.Elapsed; + } + + [TestMethod] + public void StopShouldBlockUntilBoundChannelHasClosed() + { + Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime, string.Format("Expected {0} or greater but was {1}.", _expectedElapsedTime.TotalMilliseconds, _elapsedTimeOfStop.TotalMilliseconds)); + Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ExistingConnectionShouldBeClosed() + { + try + { + _client.Send(new byte[] { 0x0a }, 0, 1, SocketFlags.None); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionReset, ex.SocketErrorCode); + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void OpenOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Open(_forwardedPort.Host, _forwardedPort.Port, _forwardedPort, It.IsAny()), Times.Once); + } + + [TestMethod] + public void BindOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Bind(), Times.Once); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs index 60597cb1..d43ee28f 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound.cs @@ -1,107 +1,107 @@ -using System; -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 -{ - [TestClass] - public class ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private ForwardedPortLocal _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +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 +{ + [TestClass] + public class ForwardedPortLocalTest_Stop_PortStarted_ChannelNotBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private ForwardedPortLocal _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.CreateChannelDirectTcpip()).Returns(_channelMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint) _localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint) _remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs index 91ac8028..ff55acb3 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortLocalTest_Stop_PortStopped.cs @@ -1,106 +1,106 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortLocalTest_Stop_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortLocal _forwardedPort; - private IPEndPoint _localEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), - random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, - _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRefuseNewConnections() - { - using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) - { - try - { - client.Connect(_localEndpoint); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); - } - } - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortLocalTest_Stop_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortLocal _forwardedPort; + private IPEndPoint _localEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _localEndpoint = new IPEndPoint(IPAddress.Loopback, 8122); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), + random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortLocal(_localEndpoint.Address.ToString(), (uint)_localEndpoint.Port, + _remoteEndpoint.Address.ToString(), (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRefuseNewConnections() + { + using (var client = new Socket(_localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)) + { + try + { + client.Connect(_localEndpoint); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(SocketError.ConnectionRefused, ex.SocketErrorCode); + } + } + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemote.NET40.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemote.NET40.cs index 6394ef0c..d57ec634 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemote.NET40.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemote.NET40.cs @@ -1,51 +1,51 @@ -using System; -using System.Diagnostics; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes -{ - public partial class ForwardedPortRemoteTest - { - [TestMethod] - [TestCategory("integration")] - public void Test_PortForwarding_Remote() - { - // ****************************************************************** - // ************* Tests are still in not finished ******************** - // ****************************************************************** - - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var port1 = new ForwardedPortRemote(8082, "www.renci.org", 80); - client.AddForwardedPort(port1); - port1.Exception += delegate(object sender, ExceptionEventArgs e) - { - Assert.Fail(e.Exception.ToString()); - }; - port1.Start(); - var boundport = port1.BoundPort; - - System.Threading.Tasks.Parallel.For(0, 5, - - //new ParallelOptions - //{ - // MaxDegreeOfParallelism = 1, - //}, - (counter) => - { - var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport)); - var result = cmd.Execute(); - var end = DateTime.Now; - Debug.WriteLine(string.Format("Length: {0}", result.Length)); - } - ); - Thread.Sleep(1000 * 100); - port1.Stop(); - } - } - } +using System; +using System.Diagnostics; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes +{ + public partial class ForwardedPortRemoteTest + { + [TestMethod] + [TestCategory("integration")] + public void Test_PortForwarding_Remote() + { + // ****************************************************************** + // ************* Tests are still in not finished ******************** + // ****************************************************************** + + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var port1 = new ForwardedPortRemote(8082, "www.renci.org", 80); + client.AddForwardedPort(port1); + port1.Exception += delegate(object sender, ExceptionEventArgs e) + { + Assert.Fail(e.Exception.ToString()); + }; + port1.Start(); + var boundport = port1.BoundPort; + + System.Threading.Tasks.Parallel.For(0, 5, + + //new ParallelOptions + //{ + // MaxDegreeOfParallelism = 1, + //}, + (counter) => + { + var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport)); + var result = cmd.Execute(); + var end = DateTime.Now; + Debug.WriteLine(string.Format("Length: {0}", result.Length)); + } + ); + Thread.Sleep(1000 * 100); + port1.Stop(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest.cs index 3b383c6d..7087e74b 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest.cs @@ -1,150 +1,150 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Net; -using System.Threading; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality for remote port forwarding - /// - [TestClass] - public partial class ForwardedPortRemoteTest : TestBase - { - [TestMethod] - [Description("Test passing null to AddForwardedPort hosts (remote).")] - [ExpectedException(typeof(ArgumentNullException))] - [TestCategory("integration")] - public void Test_AddForwardedPort_Remote_Hosts_Are_Null() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var port1 = new ForwardedPortRemote((string)null, 8080, (string)null, 80); - client.AddForwardedPort(port1); - client.Disconnect(); - } - } - - [TestMethod] - [Description("Test passing invalid port numbers to AddForwardedPort.")] - [ExpectedException(typeof(ArgumentOutOfRangeException))] - [TestCategory("integration")] - public void Test_AddForwardedPort_Invalid_PortNumber() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var port1 = new ForwardedPortRemote("localhost", IPEndPoint.MaxPort + 1, "www.renci.org", IPEndPoint.MaxPort + 1); - client.AddForwardedPort(port1); - client.Disconnect(); - } - } - - /// - ///A test for ForwardedPortRemote Constructor - /// - [TestMethod] - [TestCategory("integration")] - public void Test_ForwardedPortRemote() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshClient AddForwardedPort Start Stop ForwardedPortRemote - client.Connect(); - var port = new ForwardedPortRemote(8082, "www.cnn.com", 80); - client.AddForwardedPort(port); - port.Exception += delegate(object sender, ExceptionEventArgs e) - { - Console.WriteLine(e.Exception.ToString()); - }; - port.Start(); - - Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded - - port.Stop(); - #endregion - } - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - - /// - ///A test for Stop - /// - [TestMethod] - public void StopTest() - { - uint boundPort = 0; // TODO: Initialize to an appropriate value - string host = string.Empty; // TODO: Initialize to an appropriate value - uint port = 0; // TODO: Initialize to an appropriate value - ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value - target.Stop(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - [TestMethod] - public void Start_NotAddedToClient() - { - const int boundPort = 80; - string host = string.Empty; - const uint port = 22; - var target = new ForwardedPortRemote(boundPort, host, port); - - try - { - target.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Forwarded port is not added to a client.", ex.Message); - } - } - - /// - ///A test for Dispose - /// - [TestMethod] - public void DisposeTest() - { - uint boundPort = 0; // TODO: Initialize to an appropriate value - string host = string.Empty; // TODO: Initialize to an appropriate value - uint port = 0; // TODO: Initialize to an appropriate value - ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for ForwardedPortRemote Constructor - /// - [TestMethod] - public void ForwardedPortRemoteConstructorTest() - { - string boundHost = string.Empty; // TODO: Initialize to an appropriate value - uint boundPort = 0; // TODO: Initialize to an appropriate value - string host = string.Empty; // TODO: Initialize to an appropriate value - uint port = 0; // TODO: Initialize to an appropriate value - ForwardedPortRemote target = new ForwardedPortRemote(boundHost, boundPort, host, port); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ForwardedPortRemote Constructor - /// - [TestMethod] - public void ForwardedPortRemoteConstructorTest1() - { - uint boundPort = 0; // TODO: Initialize to an appropriate value - string host = string.Empty; // TODO: Initialize to an appropriate value - uint port = 0; // TODO: Initialize to an appropriate value - ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Net; +using System.Threading; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality for remote port forwarding + /// + [TestClass] + public partial class ForwardedPortRemoteTest : TestBase + { + [TestMethod] + [Description("Test passing null to AddForwardedPort hosts (remote).")] + [ExpectedException(typeof(ArgumentNullException))] + [TestCategory("integration")] + public void Test_AddForwardedPort_Remote_Hosts_Are_Null() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var port1 = new ForwardedPortRemote((string)null, 8080, (string)null, 80); + client.AddForwardedPort(port1); + client.Disconnect(); + } + } + + [TestMethod] + [Description("Test passing invalid port numbers to AddForwardedPort.")] + [ExpectedException(typeof(ArgumentOutOfRangeException))] + [TestCategory("integration")] + public void Test_AddForwardedPort_Invalid_PortNumber() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var port1 = new ForwardedPortRemote("localhost", IPEndPoint.MaxPort + 1, "www.renci.org", IPEndPoint.MaxPort + 1); + client.AddForwardedPort(port1); + client.Disconnect(); + } + } + + /// + ///A test for ForwardedPortRemote Constructor + /// + [TestMethod] + [TestCategory("integration")] + public void Test_ForwardedPortRemote() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshClient AddForwardedPort Start Stop ForwardedPortRemote + client.Connect(); + var port = new ForwardedPortRemote(8082, "www.cnn.com", 80); + client.AddForwardedPort(port); + port.Exception += delegate(object sender, ExceptionEventArgs e) + { + Console.WriteLine(e.Exception.ToString()); + }; + port.Start(); + + Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded + + port.Stop(); + #endregion + } + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + + /// + ///A test for Stop + /// + [TestMethod] + public void StopTest() + { + uint boundPort = 0; // TODO: Initialize to an appropriate value + string host = string.Empty; // TODO: Initialize to an appropriate value + uint port = 0; // TODO: Initialize to an appropriate value + ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value + target.Stop(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + [TestMethod] + public void Start_NotAddedToClient() + { + const int boundPort = 80; + string host = string.Empty; + const uint port = 22; + var target = new ForwardedPortRemote(boundPort, host, port); + + try + { + target.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Forwarded port is not added to a client.", ex.Message); + } + } + + /// + ///A test for Dispose + /// + [TestMethod] + public void DisposeTest() + { + uint boundPort = 0; // TODO: Initialize to an appropriate value + string host = string.Empty; // TODO: Initialize to an appropriate value + uint port = 0; // TODO: Initialize to an appropriate value + ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for ForwardedPortRemote Constructor + /// + [TestMethod] + public void ForwardedPortRemoteConstructorTest() + { + string boundHost = string.Empty; // TODO: Initialize to an appropriate value + uint boundPort = 0; // TODO: Initialize to an appropriate value + string host = string.Empty; // TODO: Initialize to an appropriate value + uint port = 0; // TODO: Initialize to an appropriate value + ForwardedPortRemote target = new ForwardedPortRemote(boundHost, boundPort, host, port); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ForwardedPortRemote Constructor + /// + [TestMethod] + public void ForwardedPortRemoteConstructorTest1() + { + uint boundPort = 0; // TODO: Initialize to an appropriate value + string host = string.Empty; // TODO: Initialize to an appropriate value + uint port = 0; // TODO: Initialize to an appropriate value + ForwardedPortRemote target = new ForwardedPortRemote(boundPort, host, port); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs index 5583e0c2..03d14da6 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortDisposed.cs @@ -1,72 +1,72 @@ -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Dispose_PortDisposed - { - private ForwardedPortRemote _forwardedPort; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint) _bindEndpoint.Port, _remoteEndpoint.Address, (uint) _remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Dispose_PortDisposed + { + private ForwardedPortRemote _forwardedPort; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint) _bindEndpoint.Port, _remoteEndpoint.Address, (uint) _remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs index fac6fd7c..1454ce2a 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortNeverStarted.cs @@ -1,110 +1,110 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Dispose_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreChannelOpenMessagesWhenDisposed() - { - var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); - _sessionMock.Setup( - p => - p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, - ChannelOpenFailureMessage.AdministrativelyProhibited))); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, new ChannelOpenMessage(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed, new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddressDisposed, originatorPortDisposed))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); - _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Dispose_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreChannelOpenMessagesWhenDisposed() + { + var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); + _sessionMock.Setup( + p => + p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, + ChannelOpenFailureMessage.AdministrativelyProhibited))); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, new ChannelOpenMessage(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed, new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddressDisposed, originatorPortDisposed))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); + _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs index 39cb851b..0ee818cc 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound.cs @@ -1,222 +1,222 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Mock _channelMock; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private TimeSpan _expectedElapsedTime; - private TimeSpan _elapsedTimeOfStop; - private uint _remoteChannelNumberWhileClosing; - private uint _remoteWindowSizeWhileClosing; - private uint _remotePacketSizeWhileClosing; - private uint _remoteChannelNumberStarted; - private uint _remoteWindowSizeStarted; - private uint _remotePacketSizeStarted; - private string _originatorAddress; - private uint _originatorPort; - - protected ForwardedPortRemote ForwardedPort { get; private set; } - - [TestInitialize] - public void Setup() - { - Arrange(); - - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Act(); - - stopwatch.Stop(); - _elapsedTimeOfStop = stopwatch.Elapsed; - } - - [TestCleanup] - public void Cleanup() - { - if (ForwardedPort != null) - { - ForwardedPort.Dispose(); - ForwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); - ForwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - _remoteChannelNumberWhileClosing = (uint) random.Next(0, 1000); - _remoteWindowSizeWhileClosing = (uint) random.Next(0, int.MaxValue); - _remotePacketSizeWhileClosing = (uint) random.Next(0, int.MaxValue); - _remoteChannelNumberStarted = (uint)random.Next(0, 1000); - _remoteWindowSizeStarted = (uint)random.Next(0, int.MaxValue); - _remotePacketSizeStarted = (uint)random.Next(0, int.MaxValue); - _originatorAddress = random.Next().ToString(CultureInfo.InvariantCulture); - _originatorPort = (uint)random.Next(0, int.MaxValue); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == ForwardedPort.BoundHost && - g.PortToBind == ForwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())); - _sessionMock.Setup(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumberWhileClosing && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == "en"))); - _sessionMock.Setup(p => p.CreateChannelForwardedTcpip(_remoteChannelNumberStarted, _remoteWindowSizeStarted, _remotePacketSizeStarted)).Returns(_channelMock.Object); - _channelMock.Setup( - p => - p.Bind( - It.Is( - ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), - ForwardedPort)).Callback(() => Thread.Sleep(_expectedElapsedTime)); - _channelMock.Setup(p => p.Close()); - _channelMock.Setup(p => p.Dispose()); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); - - ForwardedPort.Closing += (sender, args) => - { - _closingRegister.Add(args); - _sessionMock.Raise(p => p.ChannelOpenReceived += null, new MessageEventArgs(new ChannelOpenMessage(_remoteChannelNumberWhileClosing, _remoteWindowSizeWhileClosing, _remotePacketSizeWhileClosing, new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, _originatorAddress, _originatorPort)))); - }; - ForwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - ForwardedPort.Session = _sessionMock.Object; - ForwardedPort.Start(); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, new MessageEventArgs(new ChannelOpenMessage(_remoteChannelNumberStarted, _remoteWindowSizeStarted, _remotePacketSizeStarted, new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, _originatorAddress, _originatorPort)))); - } - - protected virtual void Act() - { - ForwardedPort.Dispose(); - } - - [TestMethod] - public void StopShouldBlockUntilBoundChannelHasClosed() - { - Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime, string.Format("Expected {0} or greater but was {1}.", _expectedElapsedTime.TotalMilliseconds, _elapsedTimeOfStop.TotalMilliseconds)); - Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(ForwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldRejectChannelOpenMessagesThatAreReceivedWhileTheSuccessMessageForTheCancelOfTheForwardedPortIsNotReceived() - { - _sessionMock.Verify(p => p.SendMessage(new ChannelOpenFailureMessage(_remoteChannelNumberWhileClosing, string.Empty, - ChannelOpenFailureMessage.AdministrativelyProhibited)), Times.Never); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreChannelOpenMessagesWhenDisposed() - { - var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); - _sessionMock.Setup( - p => - p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, - ChannelOpenFailureMessage.AdministrativelyProhibited))); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumberDisposed, - initialWindowSizeDisposed, maximumPacketSizeDisposed, - new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, - originatorAddressDisposed, originatorPortDisposed)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); - _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void BindOnChannelShouldBeInvokedOnceForChannelOpenedWhileStarted() - { - _channelMock.Verify( - c => - c.Bind( - It.Is( - ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), - ForwardedPort), Times.Once); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Mock _channelMock; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private TimeSpan _expectedElapsedTime; + private TimeSpan _elapsedTimeOfStop; + private uint _remoteChannelNumberWhileClosing; + private uint _remoteWindowSizeWhileClosing; + private uint _remotePacketSizeWhileClosing; + private uint _remoteChannelNumberStarted; + private uint _remoteWindowSizeStarted; + private uint _remotePacketSizeStarted; + private string _originatorAddress; + private uint _originatorPort; + + protected ForwardedPortRemote ForwardedPort { get; private set; } + + [TestInitialize] + public void Setup() + { + Arrange(); + + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Act(); + + stopwatch.Stop(); + _elapsedTimeOfStop = stopwatch.Elapsed; + } + + [TestCleanup] + public void Cleanup() + { + if (ForwardedPort != null) + { + ForwardedPort.Dispose(); + ForwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _expectedElapsedTime = TimeSpan.FromMilliseconds(random.Next(100, 500)); + ForwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + _remoteChannelNumberWhileClosing = (uint) random.Next(0, 1000); + _remoteWindowSizeWhileClosing = (uint) random.Next(0, int.MaxValue); + _remotePacketSizeWhileClosing = (uint) random.Next(0, int.MaxValue); + _remoteChannelNumberStarted = (uint)random.Next(0, 1000); + _remoteWindowSizeStarted = (uint)random.Next(0, int.MaxValue); + _remotePacketSizeStarted = (uint)random.Next(0, int.MaxValue); + _originatorAddress = random.Next().ToString(CultureInfo.InvariantCulture); + _originatorPort = (uint)random.Next(0, int.MaxValue); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == ForwardedPort.BoundHost && + g.PortToBind == ForwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())); + _sessionMock.Setup(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == _remoteChannelNumberWhileClosing && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == "en"))); + _sessionMock.Setup(p => p.CreateChannelForwardedTcpip(_remoteChannelNumberStarted, _remoteWindowSizeStarted, _remotePacketSizeStarted)).Returns(_channelMock.Object); + _channelMock.Setup( + p => + p.Bind( + It.Is( + ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), + ForwardedPort)).Callback(() => Thread.Sleep(_expectedElapsedTime)); + _channelMock.Setup(p => p.Close()); + _channelMock.Setup(p => p.Dispose()); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); + + ForwardedPort.Closing += (sender, args) => + { + _closingRegister.Add(args); + _sessionMock.Raise(p => p.ChannelOpenReceived += null, new MessageEventArgs(new ChannelOpenMessage(_remoteChannelNumberWhileClosing, _remoteWindowSizeWhileClosing, _remotePacketSizeWhileClosing, new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, _originatorAddress, _originatorPort)))); + }; + ForwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + ForwardedPort.Session = _sessionMock.Object; + ForwardedPort.Start(); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, new MessageEventArgs(new ChannelOpenMessage(_remoteChannelNumberStarted, _remoteWindowSizeStarted, _remotePacketSizeStarted, new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, _originatorAddress, _originatorPort)))); + } + + protected virtual void Act() + { + ForwardedPort.Dispose(); + } + + [TestMethod] + public void StopShouldBlockUntilBoundChannelHasClosed() + { + Assert.IsTrue(_elapsedTimeOfStop >= _expectedElapsedTime, string.Format("Expected {0} or greater but was {1}.", _expectedElapsedTime.TotalMilliseconds, _elapsedTimeOfStop.TotalMilliseconds)); + Assert.IsTrue(_elapsedTimeOfStop < _expectedElapsedTime.Add(TimeSpan.FromMilliseconds(200))); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(ForwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldRejectChannelOpenMessagesThatAreReceivedWhileTheSuccessMessageForTheCancelOfTheForwardedPortIsNotReceived() + { + _sessionMock.Verify(p => p.SendMessage(new ChannelOpenFailureMessage(_remoteChannelNumberWhileClosing, string.Empty, + ChannelOpenFailureMessage.AdministrativelyProhibited)), Times.Never); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreChannelOpenMessagesWhenDisposed() + { + var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); + _sessionMock.Setup( + p => + p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, + ChannelOpenFailureMessage.AdministrativelyProhibited))); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumberDisposed, + initialWindowSizeDisposed, maximumPacketSizeDisposed, + new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, + originatorAddressDisposed, originatorPortDisposed)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); + _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void BindOnChannelShouldBeInvokedOnceForChannelOpenedWhileStarted() + { + _channelMock.Verify( + c => + c.Bind( + It.Is( + ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), + ForwardedPort), Times.Once); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs index 409dc50f..8a9c99ac 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Dispose_PortStopped.cs @@ -1,141 +1,141 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Dispose_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - - protected ForwardedPortRemote ForwardedPort { get; private set; } - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (ForwardedPort != null) - { - ForwardedPort.Dispose(); - ForwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - ForwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == ForwardedPort.BoundHost && - g.PortToBind == ForwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(false)); - - ForwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - ForwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - ForwardedPort.Session = _sessionMock.Object; - ForwardedPort.Start(); - ForwardedPort.Stop(); - } - - protected virtual void Act() - { - ForwardedPort.Dispose(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(ForwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreChannelOpenMessagesWhenDisposed() - { - var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); - _sessionMock.Setup( - p => - p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, - ChannelOpenFailureMessage.AdministrativelyProhibited))); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, new ChannelOpenMessage(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed, new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, originatorAddressDisposed, originatorPortDisposed))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); - _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); - } - - [TestMethod] - public void ClosingShouldHaveFiredOnce() - { - Assert.AreEqual(1, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Dispose_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + + protected ForwardedPortRemote ForwardedPort { get; private set; } + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (ForwardedPort != null) + { + ForwardedPort.Dispose(); + ForwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + ForwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == ForwardedPort.BoundHost && + g.PortToBind == ForwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == ForwardedPort.BoundHost && g.PortToBind == ForwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(false)); + + ForwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + ForwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + ForwardedPort.Session = _sessionMock.Object; + ForwardedPort.Start(); + ForwardedPort.Stop(); + } + + protected virtual void Act() + { + ForwardedPort.Dispose(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(ForwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreChannelOpenMessagesWhenDisposed() + { + var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); + _sessionMock.Setup( + p => + p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, + ChannelOpenFailureMessage.AdministrativelyProhibited))); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, new ChannelOpenMessage(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed, new ForwardedTcpipChannelInfo(ForwardedPort.BoundHost, ForwardedPort.BoundPort, originatorAddressDisposed, originatorPortDisposed))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); + _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); + } + + [TestMethod] + public void ClosingShouldHaveFiredOnce() + { + Assert.AreEqual(1, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs index 99552e46..bb33584b 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortDisposed.cs @@ -1,82 +1,82 @@ -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Start_PortDisposed - { - private ForwardedPortRemote _forwardedPort; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Start_PortDisposed + { + private ForwardedPortRemote _forwardedPort; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs index c54ecba5..18bf3c8c 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortNeverStarted.cs @@ -1,145 +1,145 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Start_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && - g.PortToBind == _forwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(handle => handle.WaitOne()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Start(); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - channelMock.Setup( - p => - p.Bind( - It.Is( - ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), - _forwardedPort)); - channelMock.Setup(p => p.Close()); - channelMock.Setup(p => p.Dispose()); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); - channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); - channelMock.Verify(p => p.Close(), Times.Once); - channelMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void ClosingShouldNeverHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Start_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && + g.PortToBind == _forwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(handle => handle.WaitOne()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Start(); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + channelMock.Setup( + p => + p.Bind( + It.Is( + ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), + _forwardedPort)); + channelMock.Setup(p => p.Close()); + channelMock.Setup(p => p.Dispose()); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); + channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); + channelMock.Verify(p => p.Close(), Times.Once); + channelMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void ClosingShouldNeverHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs index 1e36552a..1860a7ed 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStarted.cs @@ -1,162 +1,162 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Start_PortStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private InvalidOperationException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && - g.PortToBind == _forwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(handle => handle.WaitOne()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowInvalidOperatationException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Forwarded port is already started.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - channelMock.Setup( - p => - p.Bind( - It.Is( - ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), - _forwardedPort)); - channelMock.Setup(p => p.Close()); - channelMock.Setup(p => p.Dispose()); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); - channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); - channelMock.Verify(p => p.Close(), Times.Once); - channelMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void ClosingShouldNeverHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Start_PortStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private InvalidOperationException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && + g.PortToBind == _forwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(handle => handle.WaitOne()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowInvalidOperatationException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Forwarded port is already started.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + channelMock.Setup( + p => + p.Bind( + It.Is( + ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), + _forwardedPort)); + channelMock.Setup(p => p.Close()); + channelMock.Setup(p => p.Dispose()); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); + channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); + channelMock.Verify(p => p.Close(), Times.Once); + channelMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void ClosingShouldNeverHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs index afee458f..3e4ea185 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_PortStopped.cs @@ -1,161 +1,161 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Start_PortStopped - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && - g.PortToBind == _forwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(handle => handle.WaitOne()); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(false)); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - _forwardedPort.Stop(); - - _closingRegister.Clear(); - } - - protected void Act() - { - _forwardedPort.Start(); - } - - [TestMethod] - public void IsStartedShouldReturnTrue() - { - Assert.IsTrue(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldAcceptNewConnections() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - channelMock.Setup( - p => - p.Bind( - It.Is( - ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), - _forwardedPort)); - channelMock.Setup(p => p.Close()); - channelMock.Setup(p => p.Dispose()); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); - channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); - channelMock.Verify(p => p.Close(), Times.Once); - channelMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void ClosingShouldNeverHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Start_PortStopped + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && + g.PortToBind == _forwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(handle => handle.WaitOne()); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(false)); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + _forwardedPort.Stop(); + + _closingRegister.Clear(); + } + + protected void Act() + { + _forwardedPort.Start(); + } + + [TestMethod] + public void IsStartedShouldReturnTrue() + { + Assert.IsTrue(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldAcceptNewConnections() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + channelMock.Setup( + p => + p.Bind( + It.Is( + ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), + _forwardedPort)); + channelMock.Setup(p => p.Close()); + channelMock.Setup(p => p.Dispose()); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); + channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); + channelMock.Verify(p => p.Close(), Times.Once); + channelMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void ClosingShouldNeverHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNotConnected.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNotConnected.cs index 56212f19..fc56157b 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNotConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNotConnected.cs @@ -1,127 +1,127 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Start_SessionNotConnected - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private SshConnectionException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup(p => p.IsConnected).Returns(false); - - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowSshConnectionException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Client not connected.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreReceivedSignalForNewConnection() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); - _sessionMock.Verify(p => p.SendMessage(new ChannelOpenFailureMessage(channelNumber, string.Empty, ChannelOpenFailureMessage.AdministrativelyProhibited)), Times.Never); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} - +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Start_SessionNotConnected + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private SshConnectionException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(1)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup(p => p.IsConnected).Returns(false); + + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowSshConnectionException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Client not connected.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreReceivedSignalForNewConnection() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); + _sessionMock.Verify(p => p.SendMessage(new ChannelOpenFailureMessage(channelNumber, string.Empty, ChannelOpenFailureMessage.AdministrativelyProhibited)), Times.Never); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} + diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs index e72f6f44..68931a0a 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Start_SessionNull.cs @@ -1,93 +1,93 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Start_SessionNull - { - private ForwardedPortRemote _forwardedPort; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private InvalidOperationException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - } - - protected void Act() - { - try - { - _forwardedPort.Start(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StartShouldThrowSshConnectionException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual("Forwarded port is not added to a client.", _actualException.Message); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} - +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Start_SessionNull + { + private ForwardedPortRemote _forwardedPort; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private InvalidOperationException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + } + + protected void Act() + { + try + { + _forwardedPort.Start(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StartShouldThrowSshConnectionException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual("Forwarded port is not added to a client.", _actualException.Message); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} + diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs index 32ca89e6..24fe4dd7 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Started.cs @@ -1,204 +1,204 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Started - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && - g.PortToBind == _forwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(handle => handle.WaitOne()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - _forwardedPort.Start(); - } - - protected void Act() - { - } - - [TestMethod] - public void ForwardedPortShouldAcceptChannelOpenMessageForBoundAddressAndBoundPort() - { - var channelNumber = (uint) new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint) new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint) new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint) new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - channelMock.Setup( - p => - p.Bind( - It.Is( - ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), - _forwardedPort)); - channelMock.Setup(p => p.Close()); - channelMock.Setup(p => p.Dispose()); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); - channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); - channelMock.Verify(p => p.Close(), Times.Once); - channelMock.Verify(p => p.Dispose(), Times.Once); - - Assert.AreEqual(0, _closingRegister.Count); - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreChannelOpenMessageForBoundHostAndOtherPort() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort + 1, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); - - Assert.AreEqual(0, _closingRegister.Count); - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreChannelOpenMessageForOtherHostAndBoundPort() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPort = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, - new ForwardedTcpipChannelInfo("111.111.111.111", _forwardedPort.BoundPort, originatorAddress, - originatorPort)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); - - Assert.AreEqual(0, _closingRegister.Count); - Assert.AreEqual(0, _exceptionRegister.Count); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreChannelOpenMessageWhenChannelOpenInfoIsNotForwardedTcpipChannelInfo() - { - var channelNumber = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, - new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, - maximumPacketSize, new DirectTcpipChannelInfo("HOST", 5, "ORIGIN", 4)))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); - - Assert.AreEqual(0, _closingRegister.Count); - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Started + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && + g.PortToBind == _forwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(handle => handle.WaitOne()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + _forwardedPort.Start(); + } + + protected void Act() + { + } + + [TestMethod] + public void ForwardedPortShouldAcceptChannelOpenMessageForBoundAddressAndBoundPort() + { + var channelNumber = (uint) new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint) new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint) new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint) new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + channelMock.Setup( + p => + p.Bind( + It.Is( + ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), + _forwardedPort)); + channelMock.Setup(p => p.Close()); + channelMock.Setup(p => p.Dispose()); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Once); + channelMock.Verify(p => p.Bind(It.Is(ep => ep.Address.Equals(_remoteEndpoint.Address) && ep.Port == _remoteEndpoint.Port), _forwardedPort), Times.Once); + channelMock.Verify(p => p.Close(), Times.Once); + channelMock.Verify(p => p.Dispose(), Times.Once); + + Assert.AreEqual(0, _closingRegister.Count); + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreChannelOpenMessageForBoundHostAndOtherPort() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort + 1, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); + + Assert.AreEqual(0, _closingRegister.Count); + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreChannelOpenMessageForOtherHostAndBoundPort() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var originatorAddress = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPort = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, + new ForwardedTcpipChannelInfo("111.111.111.111", _forwardedPort.BoundPort, originatorAddress, + originatorPort)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); + + Assert.AreEqual(0, _closingRegister.Count); + Assert.AreEqual(0, _exceptionRegister.Count); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreChannelOpenMessageWhenChannelOpenInfoIsNotForwardedTcpipChannelInfo() + { + var channelNumber = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSize = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSize = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize)).Returns(channelMock.Object); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, + new MessageEventArgs(new ChannelOpenMessage(channelNumber, initialWindowSize, + maximumPacketSize, new DirectTcpipChannelInfo("HOST", 5, "ORIGIN", 4)))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumber, initialWindowSize, maximumPacketSize), Times.Never); + + Assert.AreEqual(0, _closingRegister.Count); + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs index 50879819..033768d0 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortDisposed.cs @@ -1,88 +1,88 @@ -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Stop_PortDisposed - { - private ForwardedPortRemote _forwardedPort; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - private IList _closingRegister; - private IList _exceptionRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Dispose(); - } - - protected void Act() - { - try - { - _forwardedPort.Stop(); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void StopShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ClosingShouldNotHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Stop_PortDisposed + { + private ForwardedPortRemote _forwardedPort; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + private IList _closingRegister; + private IList _exceptionRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Dispose(); + } + + protected void Act() + { + try + { + _forwardedPort.Stop(); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void StopShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ClosingShouldNotHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortNeverStarted.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortNeverStarted.cs index 7153bb92..39e14359 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortNeverStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortNeverStarted.cs @@ -1,135 +1,135 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Stop_PortNeverStarted - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private ForwardedPortRemote _forwardedPort; - private IList _closingRegister; - private IList _exceptionRegister; - private IPEndPoint _bindEndpoint; - private IPEndPoint _remoteEndpoint; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - if (_forwardedPort != null) - { - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.CancelTcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); - _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); - _forwardedPort.Dispose(); - _forwardedPort = null; - } - } - - protected void Arrange() - { - var random = new Random(); - _closingRegister = new List(); - _exceptionRegister = new List(); - _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); - _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); - _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); - - _connectionInfoMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); - _sessionMock.Setup(p => p.IsConnected).Returns(true); - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); - _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); - _sessionMock.Setup( - p => - p.SendMessage( - It.Is( - g => - g.RequestName == GlobalRequestName.TcpIpForward && - g.AddressToBind == _forwardedPort.BoundHost && - g.PortToBind == _forwardedPort.BoundPort))) - .Callback( - () => - _sessionMock.Raise(s => s.RequestSuccessReceived += null, - new MessageEventArgs(new RequestSuccessMessage()))); - _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) - .Callback(handle => handle.WaitOne()); - - _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); - _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); - _forwardedPort.Session = _sessionMock.Object; - } - - protected void Act() - { - _forwardedPort.Stop(); - } - - [TestMethod] - public void IsStartedShouldReturnFalse() - { - Assert.IsFalse(_forwardedPort.IsStarted); - } - - [TestMethod] - public void ForwardedPortShouldIgnoreNewConnections() - { - var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); - var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); - var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); - var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); - var channelMock = new Mock(MockBehavior.Strict); - - _sessionMock.Setup( - p => - p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); - _sessionMock.Setup( - p => - p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, - ChannelOpenFailureMessage.AdministrativelyProhibited))); - - _sessionMock.Raise(p => p.ChannelOpenReceived += null, new ChannelOpenMessage(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed, new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddressDisposed, originatorPortDisposed))); - - _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); - _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); - } - - [TestMethod] - public void ClosingShouldNeverHaveFired() - { - Assert.AreEqual(0, _closingRegister.Count); - } - - [TestMethod] - public void ExceptionShouldNotHaveFired() - { - Assert.AreEqual(0, _exceptionRegister.Count); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Stop_PortNeverStarted + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private ForwardedPortRemote _forwardedPort; + private IList _closingRegister; + private IList _exceptionRegister; + private IPEndPoint _bindEndpoint; + private IPEndPoint _remoteEndpoint; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + if (_forwardedPort != null) + { + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.CancelTcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && g.PortToBind == _forwardedPort.BoundPort))); + _sessionMock.Setup(p => p.MessageListenerCompleted).Returns(new ManualResetEvent(true)); + _forwardedPort.Dispose(); + _forwardedPort = null; + } + } + + protected void Arrange() + { + var random = new Random(); + _closingRegister = new List(); + _exceptionRegister = new List(); + _bindEndpoint = new IPEndPoint(IPAddress.Any, random.Next(IPEndPoint.MinPort, 1000)); + _remoteEndpoint = new IPEndPoint(IPAddress.Parse("193.168.1.5"), random.Next(IPEndPoint.MinPort, IPEndPoint.MaxPort)); + _forwardedPort = new ForwardedPortRemote(_bindEndpoint.Address, (uint)_bindEndpoint.Port, _remoteEndpoint.Address, (uint)_remoteEndpoint.Port); + + _connectionInfoMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + _connectionInfoMock.Setup(p => p.Timeout).Returns(TimeSpan.FromSeconds(15)); + _sessionMock.Setup(p => p.IsConnected).Returns(true); + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_FAILURE")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_REQUEST_SUCCESS")); + _sessionMock.Setup(p => p.RegisterMessage("SSH_MSG_CHANNEL_OPEN")); + _sessionMock.Setup( + p => + p.SendMessage( + It.Is( + g => + g.RequestName == GlobalRequestName.TcpIpForward && + g.AddressToBind == _forwardedPort.BoundHost && + g.PortToBind == _forwardedPort.BoundPort))) + .Callback( + () => + _sessionMock.Raise(s => s.RequestSuccessReceived += null, + new MessageEventArgs(new RequestSuccessMessage()))); + _sessionMock.Setup(p => p.WaitOnHandle(It.IsAny())) + .Callback(handle => handle.WaitOne()); + + _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args); + _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args); + _forwardedPort.Session = _sessionMock.Object; + } + + protected void Act() + { + _forwardedPort.Stop(); + } + + [TestMethod] + public void IsStartedShouldReturnFalse() + { + Assert.IsFalse(_forwardedPort.IsStarted); + } + + [TestMethod] + public void ForwardedPortShouldIgnoreNewConnections() + { + var channelNumberDisposed = (uint)new Random().Next(1001, int.MaxValue); + var initialWindowSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var maximumPacketSizeDisposed = (uint)new Random().Next(0, int.MaxValue); + var originatorAddressDisposed = new Random().Next().ToString(CultureInfo.InvariantCulture); + var originatorPortDisposed = (uint)new Random().Next(0, int.MaxValue); + var channelMock = new Mock(MockBehavior.Strict); + + _sessionMock.Setup( + p => + p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed)).Returns(channelMock.Object); + _sessionMock.Setup( + p => + p.SendMessage(new ChannelOpenFailureMessage(channelNumberDisposed, string.Empty, + ChannelOpenFailureMessage.AdministrativelyProhibited))); + + _sessionMock.Raise(p => p.ChannelOpenReceived += null, new ChannelOpenMessage(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed, new ForwardedTcpipChannelInfo(_forwardedPort.BoundHost, _forwardedPort.BoundPort, originatorAddressDisposed, originatorPortDisposed))); + + _sessionMock.Verify(p => p.CreateChannelForwardedTcpip(channelNumberDisposed, initialWindowSizeDisposed, maximumPacketSizeDisposed), Times.Never); + _sessionMock.Verify(p => p.SendMessage(It.Is(c => c.LocalChannelNumber == channelNumberDisposed && c.ReasonCode == ChannelOpenFailureMessage.AdministrativelyProhibited && c.Description == string.Empty && c.Language == null)), Times.Never); + } + + [TestMethod] + public void ClosingShouldNeverHaveFired() + { + Assert.AreEqual(0, _closingRegister.Count); + } + + [TestMethod] + public void ExceptionShouldNotHaveFired() + { + Assert.AreEqual(0, _exceptionRegister.Count); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound.cs index bc457142..49424215 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound : ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound - { - protected override void Act() - { - ForwardedPort.Stop(); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Stop_PortStarted_ChannelBound : ForwardedPortRemoteTest_Dispose_PortStarted_ChannelBound + { + protected override void Act() + { + ForwardedPort.Stop(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStopped.cs b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStopped.cs index 64345c22..3fa442be 100644 --- a/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStopped.cs +++ b/src/Renci.SshNet.Tests/Classes/ForwardedPortRemoteTest_Stop_PortStopped.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class ForwardedPortRemoteTest_Stop_PortStopped : ForwardedPortRemoteTest_Dispose_PortStopped - { - protected override void Act() - { - ForwardedPort.Stop(); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class ForwardedPortRemoteTest_Stop_PortStopped : ForwardedPortRemoteTest_Dispose_PortStopped + { + protected override void Act() + { + ForwardedPort.Stop(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs b/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs index 70c68cf2..b85b88a8 100644 --- a/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs +++ b/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveAuthenticationMethodTest.cs @@ -1,89 +1,89 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality to perform keyboard interactive authentication. - /// - [TestClass] - public partial class KeyboardInteractiveAuthenticationMethodTest : TestBase - { - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("KeyboardInteractiveAuthenticationMethod: Pass null as username.")] - [ExpectedException(typeof(ArgumentException))] - public void Keyboard_Test_Pass_Null() - { - new KeyboardInteractiveAuthenticationMethod(null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("KeyboardInteractiveAuthenticationMethod: Pass String.Empty as username.")] - [ExpectedException(typeof(ArgumentException))] - public void Keyboard_Test_Pass_Whitespace() - { - new KeyboardInteractiveAuthenticationMethod(string.Empty); - } - - /// - ///A test for Name - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Authenticate - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AuthenticateTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value - AuthenticationResult actual; - actual = target.Authenticate(session); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for KeyboardInteractiveAuthenticationMethod Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveAuthenticationMethodConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality to perform keyboard interactive authentication. + /// + [TestClass] + public partial class KeyboardInteractiveAuthenticationMethodTest : TestBase + { + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("KeyboardInteractiveAuthenticationMethod: Pass null as username.")] + [ExpectedException(typeof(ArgumentException))] + public void Keyboard_Test_Pass_Null() + { + new KeyboardInteractiveAuthenticationMethod(null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("KeyboardInteractiveAuthenticationMethod: Pass String.Empty as username.")] + [ExpectedException(typeof(ArgumentException))] + public void Keyboard_Test_Pass_Whitespace() + { + new KeyboardInteractiveAuthenticationMethod(string.Empty); + } + + /// + ///A test for Name + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NameTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Authenticate + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AuthenticateTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value + AuthenticationResult actual; + actual = target.Authenticate(session); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for KeyboardInteractiveAuthenticationMethod Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveAuthenticationMethodConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveAuthenticationMethod target = new KeyboardInteractiveAuthenticationMethod(username); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveConnectionInfoTest.cs b/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveConnectionInfoTest.cs index 3f5cf2f1..0fc12c46 100644 --- a/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveConnectionInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/KeyboardInteractiveConnectionInfoTest.cs @@ -1,195 +1,195 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides connection information when keyboard interactive authentication method is used - /// - [TestClass] - public class KeyboardInteractiveConnectionInfoTest : TestBase - { - [TestMethod] - [TestCategory("KeyboardInteractiveConnectionInfo")] - [TestCategory("integration")] - public void Test_KeyboardInteractiveConnectionInfo() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example KeyboardInteractiveConnectionInfo AuthenticationPrompt - var connectionInfo = new KeyboardInteractiveConnectionInfo(host, username); - connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e) - { - System.Console.WriteLine(e.Instruction); - - foreach (var prompt in e.Prompts) - { - Console.WriteLine(prompt.Request); - prompt.Response = Console.ReadLine(); - } - }; - - using (var client = new SftpClient(connectionInfo)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username, proxyType, proxyHost, proxyPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest4() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest5() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest6() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyboardInteractiveConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyboardInteractiveConnectionInfoConstructorTest7() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides connection information when keyboard interactive authentication method is used + /// + [TestClass] + public class KeyboardInteractiveConnectionInfoTest : TestBase + { + [TestMethod] + [TestCategory("KeyboardInteractiveConnectionInfo")] + [TestCategory("integration")] + public void Test_KeyboardInteractiveConnectionInfo() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example KeyboardInteractiveConnectionInfo AuthenticationPrompt + var connectionInfo = new KeyboardInteractiveConnectionInfo(host, username); + connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e) + { + System.Console.WriteLine(e.Instruction); + + foreach (var prompt in e.Prompts) + { + Console.WriteLine(prompt.Request); + prompt.Response = Console.ReadLine(); + } + }; + + using (var client = new SftpClient(connectionInfo)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username, proxyType, proxyHost, proxyPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest4() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest5() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest6() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, port, username); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyboardInteractiveConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyboardInteractiveConnectionInfoConstructorTest7() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + KeyboardInteractiveConnectionInfo target = new KeyboardInteractiveConnectionInfo(host, username); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/MessageEventArgsTest.cs b/src/Renci.SshNet.Tests/Classes/MessageEventArgsTest.cs index a9f9463e..387b5b29 100644 --- a/src/Renci.SshNet.Tests/Classes/MessageEventArgsTest.cs +++ b/src/Renci.SshNet.Tests/Classes/MessageEventArgsTest.cs @@ -1,30 +1,30 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides data for message events. - /// - /// Message type - [TestClass] - public class MessageEventArgsTest : TestBase - { - /// - ///A test for MessageEventArgs`1 Constructor - /// - public void MessageEventArgsConstructorTestHelper() - { - T message = default(T); // TODO: Initialize to an appropriate value - MessageEventArgs target = new MessageEventArgs(message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - [TestMethod] - [Ignore] // placeholder for actual test - public void MessageEventArgsConstructorTest() - { - MessageEventArgsConstructorTestHelper(); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides data for message events. + /// + /// Message type + [TestClass] + public class MessageEventArgsTest : TestBase + { + /// + ///A test for MessageEventArgs`1 Constructor + /// + public void MessageEventArgsConstructorTestHelper() + { + T message = default(T); // TODO: Initialize to an appropriate value + MessageEventArgs target = new MessageEventArgs(message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + [TestMethod] + [Ignore] // placeholder for actual test + public void MessageEventArgsConstructorTest() + { + MessageEventArgsConstructorTestHelper(); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/BannerMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/BannerMessageTest.cs index ed764b4e..89826f39 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/BannerMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/BannerMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Authentication; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - ///This is a test class for BannerMessageTest and is intended - ///to contain all BannerMessageTest Unit Tests - /// - [TestClass()] - public class BannerMessageTest : TestBase - { - /// - ///A test for BannerMessage Constructor - /// - [TestMethod()] - public void BannerMessageConstructorTest() - { - BannerMessage target = new BannerMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + ///This is a test class for BannerMessageTest and is intended + ///to contain all BannerMessageTest Unit Tests + /// + [TestClass()] + public class BannerMessageTest : TestBase + { + /// + ///A test for BannerMessage Constructor + /// + [TestMethod()] + public void BannerMessageConstructorTest() + { + BannerMessage target = new BannerMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/FailureMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/FailureMessageTest.cs index 2c45fe72..859a4554 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/FailureMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/FailureMessageTest.cs @@ -1,40 +1,40 @@ -using Renci.SshNet.Messages.Authentication; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - ///This is a test class for FailureMessageTest and is intended - ///to contain all FailureMessageTest Unit Tests - /// - [TestClass()] - public class FailureMessageTest : TestBase - { - /// - ///A test for FailureMessage Constructor - /// - [TestMethod()] - public void FailureMessageConstructorTest() - { - FailureMessage target = new FailureMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for AllowedAuthentications - /// - [TestMethod()] - public void AllowedAuthenticationsTest() - { - FailureMessage target = new FailureMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.AllowedAuthentications = expected; - actual = target.AllowedAuthentications; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + ///This is a test class for FailureMessageTest and is intended + ///to contain all FailureMessageTest Unit Tests + /// + [TestClass()] + public class FailureMessageTest : TestBase + { + /// + ///A test for FailureMessage Constructor + /// + [TestMethod()] + public void FailureMessageConstructorTest() + { + FailureMessage target = new FailureMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for AllowedAuthentications + /// + [TestMethod()] + public void AllowedAuthenticationsTest() + { + FailureMessage target = new FailureMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.AllowedAuthentications = expected; + actual = target.AllowedAuthentications; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationRequestMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationRequestMessageTest.cs index e2bb6d33..31dbd4e6 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationRequestMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationRequestMessageTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents SSH_MSG_USERAUTH_INFO_REQUEST message. - /// - [TestClass] - public class InformationRequestMessageTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents SSH_MSG_USERAUTH_INFO_REQUEST message. + /// + [TestClass] + public class InformationRequestMessageTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationResponseMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationResponseMessageTest.cs index c28b18d5..f5d0f0ae 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationResponseMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/InformationResponseMessageTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents SSH_MSG_USERAUTH_INFO_RESPONSE message. - /// - [TestClass] - public class InformationResponseMessageTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents SSH_MSG_USERAUTH_INFO_RESPONSE message. + /// + [TestClass] + public class InformationResponseMessageTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PasswordChangeRequiredMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PasswordChangeRequiredMessageTest.cs index b679161b..3d876373 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PasswordChangeRequiredMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PasswordChangeRequiredMessageTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents SSH_MSG_USERAUTH_PASSWD_CHANGEREQ message. - /// - [TestClass] - public class PasswordChangeRequiredMessageTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents SSH_MSG_USERAUTH_PASSWD_CHANGEREQ message. + /// + [TestClass] + public class PasswordChangeRequiredMessageTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PublicKeyMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PublicKeyMessageTest.cs index c07d7302..1ab45398 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PublicKeyMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/PublicKeyMessageTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents SSH_MSG_USERAUTH_PK_OK message. - /// - [TestClass] - public class PublicKeyMessageTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents SSH_MSG_USERAUTH_PK_OK message. + /// + [TestClass] + public class PublicKeyMessageTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageHostTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageHostTest.cs index 66c5f675..e50ee295 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageHostTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageHostTest.cs @@ -1,11 +1,11 @@ -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents "hostbased" SSH_MSG_USERAUTH_REQUEST message. - /// - public class RequestMessageHostTest : TestBase - { - } +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents "hostbased" SSH_MSG_USERAUTH_REQUEST message. + /// + public class RequestMessageHostTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageKeyboardInteractiveTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageKeyboardInteractiveTest.cs index 7214ee81..b038ed9d 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageKeyboardInteractiveTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageKeyboardInteractiveTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents "keyboard-interactive" SSH_MSG_USERAUTH_REQUEST message. - /// - [TestClass] - public class RequestMessageKeyboardInteractiveTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents "keyboard-interactive" SSH_MSG_USERAUTH_REQUEST message. + /// + [TestClass] + public class RequestMessageKeyboardInteractiveTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageNoneTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageNoneTest.cs index 02f53e82..cfae6875 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageNoneTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessageNoneTest.cs @@ -1,11 +1,11 @@ -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents "none" SSH_MSG_USERAUTH_REQUEST message. - /// - public class RequestMessageNoneTest : TestBase - { - } +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents "none" SSH_MSG_USERAUTH_REQUEST message. + /// + public class RequestMessageNoneTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePasswordTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePasswordTest.cs index f342ddda..47ca635d 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePasswordTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePasswordTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - /// Represents "password" SSH_MSG_USERAUTH_REQUEST message. - /// - [TestClass] - public class RequestMessagePasswordTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + /// Represents "password" SSH_MSG_USERAUTH_REQUEST message. + /// + [TestClass] + public class RequestMessagePasswordTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePublicKeyTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePublicKeyTest.cs index 304f3bf1..f63e9977 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePublicKeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/RequestMessagePublicKeyTest.cs @@ -1,80 +1,80 @@ -using Renci.SshNet.Messages.Authentication; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Messages; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - ///This is a test class for RequestMessagePublicKeyTest and is intended - ///to contain all RequestMessagePublicKeyTest Unit Tests - /// - [TestClass()] - public class RequestMessagePublicKeyTest : TestBase - { - /// - ///A test for RequestMessagePublicKey Constructor - /// - [TestMethod()] - public void RequestMessagePublicKeyConstructorTest() - { - ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value - byte[] keyData = null; // TODO: Initialize to an appropriate value - RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for RequestMessagePublicKey Constructor - /// - [TestMethod()] - public void RequestMessagePublicKeyConstructorTest1() - { - ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value - byte[] keyData = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData, signature); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for MethodName - /// - [TestMethod()] - public void MethodNameTest() - { - ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value - byte[] keyData = null; // TODO: Initialize to an appropriate value - RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData); // TODO: Initialize to an appropriate value - string actual; - actual = target.MethodName; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Signature - /// - [TestMethod()] - public void SignatureTest() - { - ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value - byte[] keyData = null; // TODO: Initialize to an appropriate value - RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData); // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - target.Signature = expected; - actual = target.Signature; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Messages; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + ///This is a test class for RequestMessagePublicKeyTest and is intended + ///to contain all RequestMessagePublicKeyTest Unit Tests + /// + [TestClass()] + public class RequestMessagePublicKeyTest : TestBase + { + /// + ///A test for RequestMessagePublicKey Constructor + /// + [TestMethod()] + public void RequestMessagePublicKeyConstructorTest() + { + ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value + byte[] keyData = null; // TODO: Initialize to an appropriate value + RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for RequestMessagePublicKey Constructor + /// + [TestMethod()] + public void RequestMessagePublicKeyConstructorTest1() + { + ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value + byte[] keyData = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData, signature); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for MethodName + /// + [TestMethod()] + public void MethodNameTest() + { + ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value + byte[] keyData = null; // TODO: Initialize to an appropriate value + RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData); // TODO: Initialize to an appropriate value + string actual; + actual = target.MethodName; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Signature + /// + [TestMethod()] + public void SignatureTest() + { + ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string keyAlgorithmName = string.Empty; // TODO: Initialize to an appropriate value + byte[] keyData = null; // TODO: Initialize to an appropriate value + RequestMessagePublicKey target = new RequestMessagePublicKey(serviceName, username, keyAlgorithmName, keyData); // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + target.Signature = expected; + actual = target.Signature; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/SuccessMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/SuccessMessageTest.cs index 424d5f04..41659b1a 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Authentication/SuccessMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Authentication/SuccessMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Authentication; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Messages.Authentication -{ - /// - ///This is a test class for SuccessMessageTest and is intended - ///to contain all SuccessMessageTest Unit Tests - /// - [TestClass()] - public class SuccessMessageTest : TestBase - { - /// - ///A test for SuccessMessage Constructor - /// - [TestMethod()] - public void SuccessMessageConstructorTest() - { - SuccessMessage target = new SuccessMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Authentication; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Messages.Authentication +{ + /// + ///This is a test class for SuccessMessageTest and is intended + ///to contain all SuccessMessageTest Unit Tests + /// + [TestClass()] + public class SuccessMessageTest : TestBase + { + /// + ///A test for SuccessMessage Constructor + /// + [TestMethod()] + public void SuccessMessageConstructorTest() + { + SuccessMessage target = new SuccessMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelCloseMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelCloseMessageTest.cs index b863b20e..505c2622 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelCloseMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelCloseMessageTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelCloseMessageTest and is intended - ///to contain all ChannelCloseMessageTest Unit Tests - /// - [TestClass()] - public class ChannelCloseMessageTest : TestBase - { - /// - ///A test for ChannelCloseMessage Constructor - /// - [TestMethod()] - public void ChannelCloseMessageConstructorTest() - { - ChannelCloseMessage target = new ChannelCloseMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelCloseMessage Constructor - /// - [TestMethod()] - public void ChannelCloseMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - ChannelCloseMessage target = new ChannelCloseMessage(localChannelNumber); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelCloseMessageTest and is intended + ///to contain all ChannelCloseMessageTest Unit Tests + /// + [TestClass()] + public class ChannelCloseMessageTest : TestBase + { + /// + ///A test for ChannelCloseMessage Constructor + /// + [TestMethod()] + public void ChannelCloseMessageConstructorTest() + { + ChannelCloseMessage target = new ChannelCloseMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelCloseMessage Constructor + /// + [TestMethod()] + public void ChannelCloseMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + ChannelCloseMessage target = new ChannelCloseMessage(localChannelNumber); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelDataMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelDataMessageTest.cs index 8f442018..5ef88c29 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelDataMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelDataMessageTest.cs @@ -1,152 +1,152 @@ -using System.Linq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelDataMessageTest and is intended - ///to contain all ChannelDataMessageTest Unit Tests - /// - [TestClass] - public class ChannelDataMessageTest : TestBase - { - [TestMethod] - public void DefaultConstructor() - { - var target = new ChannelDataMessage(); - - Assert.IsNull(target.Data); - Assert.AreEqual(0, target.Offset); - Assert.AreEqual(0, target.Size); - } - - [TestMethod] - public void Constructor_LocalChannelNumberAndData() - { - var random = new Random(); - - var localChannelNumber = (uint)random.Next(0, int.MaxValue); - var data = new byte[3]; - - var target = new ChannelDataMessage(localChannelNumber, data); - - Assert.AreSame(data, target.Data); - Assert.AreEqual(0, target.Offset); - Assert.AreEqual(data.Length, target.Size); - } - - [TestMethod] - public void Constructor_LocalChannelNumberAndData_ShouldThrowArgumentNullExceptionWhenDataIsNull() - { - var localChannelNumber = (uint) new Random().Next(0, int.MaxValue); - byte[] data = null; - - try - { - new ChannelDataMessage(localChannelNumber, data); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("data", ex.ParamName); - } - } - - [TestMethod] - public void Constructor_LocalChannelNumberAndDataAndOffsetAndSize() - { - var localChannelNumber = (uint) new Random().Next(0, int.MaxValue); - var data = new byte[4]; - const int offset = 2; - const int size = 1; - - var target = new ChannelDataMessage(localChannelNumber, data, offset, size); - - Assert.AreSame(data, target.Data); - Assert.AreEqual(offset, target.Offset); - Assert.AreEqual(size, target.Size); - } - - [TestMethod] - public void Constructor_LocalChannelNumberAndDataAndOffsetAndSize_ShouldThrowArgumentNullExceptionWhenDataIsNull() - { - var localChannelNumber = (uint) new Random().Next(0, int.MaxValue); - const byte[] data = null; - const int offset = 0; - const int size = 0; - - try - { - new ChannelDataMessage(localChannelNumber, data, offset, size); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("data", ex.ParamName); - } - } - - [TestMethod] - public void GetBytes() - { - var random = new Random(); - - var localChannelNumber = (uint) random.Next(0, int.MaxValue); - var data = new byte[random.Next(10, 20)]; - random.NextBytes(data); - var offset = random.Next(2, 4); - var size = random.Next(5, 9); - - var target = new ChannelDataMessage(localChannelNumber, data, offset, size); - - var bytes = target.GetBytes(); - - var expectedBytesLength = 1; // Type - expectedBytesLength += 4; // LocalChannelNumber - expectedBytesLength += 4; // Data length - expectedBytesLength += size; // Data - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual(ChannelDataMessage.MessageNumber, sshDataStream.ReadByte()); - Assert.AreEqual(localChannelNumber, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) size, sshDataStream.ReadUInt32()); - - var actualData = new byte[size]; - sshDataStream.Read(actualData, 0, size); - Assert.IsTrue(actualData.SequenceEqual(data.Take(offset, size))); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - - [TestMethod] - public void Load() - { - var random = new Random(); - - var localChannelNumber = (uint) random.Next(0, int.MaxValue); - var data = new byte[random.Next(10, 20)]; - random.NextBytes(data); - - var offset = random.Next(2, 4); - var size = random.Next(5, 9); - var channelDataMessage = new ChannelDataMessage(localChannelNumber, data, offset, size); - var bytes = channelDataMessage.GetBytes(); - var target = new ChannelDataMessage(); - - target.Load(bytes); - - Assert.IsTrue(target.Data.SequenceEqual(data.Take(offset, size))); - Assert.AreEqual(0, target.Offset); - Assert.AreEqual(size, target.Size); - } - } -} +using System.Linq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelDataMessageTest and is intended + ///to contain all ChannelDataMessageTest Unit Tests + /// + [TestClass] + public class ChannelDataMessageTest : TestBase + { + [TestMethod] + public void DefaultConstructor() + { + var target = new ChannelDataMessage(); + + Assert.IsNull(target.Data); + Assert.AreEqual(0, target.Offset); + Assert.AreEqual(0, target.Size); + } + + [TestMethod] + public void Constructor_LocalChannelNumberAndData() + { + var random = new Random(); + + var localChannelNumber = (uint)random.Next(0, int.MaxValue); + var data = new byte[3]; + + var target = new ChannelDataMessage(localChannelNumber, data); + + Assert.AreSame(data, target.Data); + Assert.AreEqual(0, target.Offset); + Assert.AreEqual(data.Length, target.Size); + } + + [TestMethod] + public void Constructor_LocalChannelNumberAndData_ShouldThrowArgumentNullExceptionWhenDataIsNull() + { + var localChannelNumber = (uint) new Random().Next(0, int.MaxValue); + byte[] data = null; + + try + { + new ChannelDataMessage(localChannelNumber, data); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("data", ex.ParamName); + } + } + + [TestMethod] + public void Constructor_LocalChannelNumberAndDataAndOffsetAndSize() + { + var localChannelNumber = (uint) new Random().Next(0, int.MaxValue); + var data = new byte[4]; + const int offset = 2; + const int size = 1; + + var target = new ChannelDataMessage(localChannelNumber, data, offset, size); + + Assert.AreSame(data, target.Data); + Assert.AreEqual(offset, target.Offset); + Assert.AreEqual(size, target.Size); + } + + [TestMethod] + public void Constructor_LocalChannelNumberAndDataAndOffsetAndSize_ShouldThrowArgumentNullExceptionWhenDataIsNull() + { + var localChannelNumber = (uint) new Random().Next(0, int.MaxValue); + const byte[] data = null; + const int offset = 0; + const int size = 0; + + try + { + new ChannelDataMessage(localChannelNumber, data, offset, size); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("data", ex.ParamName); + } + } + + [TestMethod] + public void GetBytes() + { + var random = new Random(); + + var localChannelNumber = (uint) random.Next(0, int.MaxValue); + var data = new byte[random.Next(10, 20)]; + random.NextBytes(data); + var offset = random.Next(2, 4); + var size = random.Next(5, 9); + + var target = new ChannelDataMessage(localChannelNumber, data, offset, size); + + var bytes = target.GetBytes(); + + var expectedBytesLength = 1; // Type + expectedBytesLength += 4; // LocalChannelNumber + expectedBytesLength += 4; // Data length + expectedBytesLength += size; // Data + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual(ChannelDataMessage.MessageNumber, sshDataStream.ReadByte()); + Assert.AreEqual(localChannelNumber, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) size, sshDataStream.ReadUInt32()); + + var actualData = new byte[size]; + sshDataStream.Read(actualData, 0, size); + Assert.IsTrue(actualData.SequenceEqual(data.Take(offset, size))); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + + [TestMethod] + public void Load() + { + var random = new Random(); + + var localChannelNumber = (uint) random.Next(0, int.MaxValue); + var data = new byte[random.Next(10, 20)]; + random.NextBytes(data); + + var offset = random.Next(2, 4); + var size = random.Next(5, 9); + var channelDataMessage = new ChannelDataMessage(localChannelNumber, data, offset, size); + var bytes = channelDataMessage.GetBytes(); + var target = new ChannelDataMessage(); + + target.Load(bytes); + + Assert.IsTrue(target.Data.SequenceEqual(data.Take(offset, size))); + Assert.AreEqual(0, target.Offset); + Assert.AreEqual(size, target.Size); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelEofMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelEofMessageTest.cs index e26a468d..6b3cbc21 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelEofMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelEofMessageTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelEofMessageTest and is intended - ///to contain all ChannelEofMessageTest Unit Tests - /// - [TestClass()] - public class ChannelEofMessageTest : TestBase - { - /// - ///A test for ChannelEofMessage Constructor - /// - [TestMethod()] - public void ChannelEofMessageConstructorTest() - { - ChannelEofMessage target = new ChannelEofMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelEofMessage Constructor - /// - [TestMethod()] - public void ChannelEofMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - ChannelEofMessage target = new ChannelEofMessage(localChannelNumber); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelEofMessageTest and is intended + ///to contain all ChannelEofMessageTest Unit Tests + /// + [TestClass()] + public class ChannelEofMessageTest : TestBase + { + /// + ///A test for ChannelEofMessage Constructor + /// + [TestMethod()] + public void ChannelEofMessageConstructorTest() + { + ChannelEofMessage target = new ChannelEofMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelEofMessage Constructor + /// + [TestMethod()] + public void ChannelEofMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + ChannelEofMessage target = new ChannelEofMessage(localChannelNumber); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelExtendedDataMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelExtendedDataMessageTest.cs index c111bf9b..8b7409ee 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelExtendedDataMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelExtendedDataMessageTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelExtendedDataMessageTest and is intended - ///to contain all ChannelExtendedDataMessageTest Unit Tests - /// - [TestClass()] - public class ChannelExtendedDataMessageTest : TestBase - { - /// - ///A test for ChannelExtendedDataMessage Constructor - /// - [TestMethod()] - public void ChannelExtendedDataMessageConstructorTest() - { - ChannelExtendedDataMessage target = new ChannelExtendedDataMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelExtendedDataMessage Constructor - /// - [TestMethod()] - public void ChannelExtendedDataMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - //ChannelExtendedDataMessage target = new ChannelExtendedDataMessage(localChannelNumber, null, null); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelExtendedDataMessageTest and is intended + ///to contain all ChannelExtendedDataMessageTest Unit Tests + /// + [TestClass()] + public class ChannelExtendedDataMessageTest : TestBase + { + /// + ///A test for ChannelExtendedDataMessage Constructor + /// + [TestMethod()] + public void ChannelExtendedDataMessageConstructorTest() + { + ChannelExtendedDataMessage target = new ChannelExtendedDataMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelExtendedDataMessage Constructor + /// + [TestMethod()] + public void ChannelExtendedDataMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + //ChannelExtendedDataMessage target = new ChannelExtendedDataMessage(localChannelNumber, null, null); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelFailureMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelFailureMessageTest.cs index 8c021b80..5b7acf5a 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelFailureMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelFailureMessageTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelFailureMessageTest and is intended - ///to contain all ChannelFailureMessageTest Unit Tests - /// - [TestClass()] - public class ChannelFailureMessageTest : TestBase - { - /// - ///A test for ChannelFailureMessage Constructor - /// - [TestMethod()] - public void ChannelFailureMessageConstructorTest() - { - ChannelFailureMessage target = new ChannelFailureMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelFailureMessage Constructor - /// - [TestMethod()] - public void ChannelFailureMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - ChannelFailureMessage target = new ChannelFailureMessage(localChannelNumber); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelFailureMessageTest and is intended + ///to contain all ChannelFailureMessageTest Unit Tests + /// + [TestClass()] + public class ChannelFailureMessageTest : TestBase + { + /// + ///A test for ChannelFailureMessage Constructor + /// + [TestMethod()] + public void ChannelFailureMessageConstructorTest() + { + ChannelFailureMessage target = new ChannelFailureMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelFailureMessage Constructor + /// + [TestMethod()] + public void ChannelFailureMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + ChannelFailureMessage target = new ChannelFailureMessage(localChannelNumber); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelMessageTest.cs index d90edbb4..baa4a7fc 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelMessageTest.cs @@ -1,37 +1,37 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelMessageTest and is intended - ///to contain all ChannelMessageTest Unit Tests - /// - [TestClass] - [Ignore] // placeholders only - public class ChannelMessageTest : TestBase - { - internal virtual ChannelMessage CreateChannelMessage() - { - // TODO: Instantiate an appropriate concrete class. - ChannelMessage target = null; - return target; - } - - /// - ///A test for ToString - /// - [TestMethod()] - public void ToStringTest() - { - ChannelMessage target = CreateChannelMessage(); // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.ToString(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelMessageTest and is intended + ///to contain all ChannelMessageTest Unit Tests + /// + [TestClass] + [Ignore] // placeholders only + public class ChannelMessageTest : TestBase + { + internal virtual ChannelMessage CreateChannelMessage() + { + // TODO: Instantiate an appropriate concrete class. + ChannelMessage target = null; + return target; + } + + /// + ///A test for ToString + /// + [TestMethod()] + public void ToStringTest() + { + ChannelMessage target = CreateChannelMessage(); // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.ToString(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ChannelOpenMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ChannelOpenMessageTest.cs index b1a66bf9..4cd7191b 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ChannelOpenMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ChannelOpenMessageTest.cs @@ -1,251 +1,251 @@ -using System.Globalization; -using System.Linq; -using System.Text; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - [TestClass] - public class ChannelOpenMessageTest - { - private Random _random; - private Encoding _ascii; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _ascii = Encoding.ASCII; - } - - [TestMethod] - public void DefaultConstructor() - { - var target = new ChannelOpenMessage(); - - Assert.IsNull(target.ChannelType); - Assert.IsNull(target.Info); - Assert.AreEqual(default(uint), target.InitialWindowSize); - Assert.AreEqual(default(uint), target.LocalChannelNumber); - Assert.AreEqual(default(uint), target.MaximumPacketSize); - } - - [TestMethod] - public void Constructor_LocalChannelNumberAndInitialWindowSizeAndMaximumPacketSizeAndInfo() - { - var localChannelNumber = (uint) _random.Next(0, int.MaxValue); - var initialWindowSize = (uint) _random.Next(0, int.MaxValue); - var maximumPacketSize = (uint) _random.Next(0, int.MaxValue); - var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); - - var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - - Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); - Assert.AreSame(info, target.Info); - Assert.AreEqual(initialWindowSize, target.InitialWindowSize); - Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); - Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); - } - - [TestMethod] - public void Constructor_LocalChannelNumberAndInitialWindowSizeAndMaximumPacketSizeAndInfo_ShouldThrowArgumentNullExceptionWhenInfoIsNull() - { - var localChannelNumber = (uint) _random.Next(0, int.MaxValue); - var initialWindowSize = (uint) _random.Next(0, int.MaxValue); - var maximumPacketSize = (uint) _random.Next(0, int.MaxValue); - ChannelOpenInfo info = null; - - try - { - new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("info", ex.ParamName); - } - } - - [TestMethod] - public void GetBytes() - { - var localChannelNumber = (uint)_random.Next(0, int.MaxValue); - var initialWindowSize = (uint)_random.Next(0, int.MaxValue); - var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); - var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); - var infoBytes = info.GetBytes(); - var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - - var bytes = target.GetBytes(); - - var expectedBytesLength = 1; // Type - expectedBytesLength += 4; // ChannelType length - expectedBytesLength += target.ChannelType.Length; // ChannelType - expectedBytesLength += 4; // LocalChannelNumber - expectedBytesLength += 4; // InitialWindowSize - expectedBytesLength += 4; // MaximumPacketSize - expectedBytesLength += infoBytes.Length; // Info - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual(ChannelOpenMessage.MessageNumber, sshDataStream.ReadByte()); - - var actualChannelTypeLength = sshDataStream.ReadUInt32(); - Assert.AreEqual((uint) target.ChannelType.Length, actualChannelTypeLength); - - var actualChannelType = new byte[actualChannelTypeLength]; - sshDataStream.Read(actualChannelType, 0, (int) actualChannelTypeLength); - Assert.IsTrue(target.ChannelType.SequenceEqual(actualChannelType)); - - Assert.AreEqual(localChannelNumber, sshDataStream.ReadUInt32()); - Assert.AreEqual(initialWindowSize, sshDataStream.ReadUInt32()); - Assert.AreEqual(maximumPacketSize, sshDataStream.ReadUInt32()); - - var actualInfo = new byte[infoBytes.Length]; - sshDataStream.Read(actualInfo, 0, actualInfo.Length); - Assert.IsTrue(infoBytes.SequenceEqual(actualInfo)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - - [TestMethod] - public void Load_DirectTcpipChannelInfo() - { - var localChannelNumber = (uint)_random.Next(0, int.MaxValue); - var initialWindowSize = (uint)_random.Next(0, int.MaxValue); - var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); - var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); - var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - var bytes = target.GetBytes(); - - target.Load(bytes); - - Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); - Assert.IsNotNull(target.Info); - Assert.AreEqual(initialWindowSize, target.InitialWindowSize); - Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); - Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); - - var directTcpChannelInfo = target.Info as DirectTcpipChannelInfo; - Assert.IsNotNull(directTcpChannelInfo); - Assert.AreEqual(info.ChannelType, directTcpChannelInfo.ChannelType); - Assert.AreEqual(info.HostToConnect, directTcpChannelInfo.HostToConnect); - Assert.AreEqual(info.OriginatorAddress, directTcpChannelInfo.OriginatorAddress); - Assert.AreEqual(info.OriginatorPort, directTcpChannelInfo.OriginatorPort); - Assert.AreEqual(info.PortToConnect, directTcpChannelInfo.PortToConnect); - } - - [TestMethod] - public void Load_ForwardedTcpipChannelInfo() - { - var localChannelNumber = (uint)_random.Next(0, int.MaxValue); - var initialWindowSize = (uint)_random.Next(0, int.MaxValue); - var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); - var info = new ForwardedTcpipChannelInfo("connected", 25, "originator", 21); - var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - var bytes = target.GetBytes(); - - target.Load(bytes); - - Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); - Assert.IsNotNull(target.Info); - Assert.AreEqual(initialWindowSize, target.InitialWindowSize); - Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); - Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); - - var forwardedTcpipChannelInfo = target.Info as ForwardedTcpipChannelInfo; - Assert.IsNotNull(forwardedTcpipChannelInfo); - Assert.AreEqual(info.ChannelType, forwardedTcpipChannelInfo.ChannelType); - Assert.AreEqual(info.ConnectedAddress, forwardedTcpipChannelInfo.ConnectedAddress); - Assert.AreEqual(info.ConnectedPort, forwardedTcpipChannelInfo.ConnectedPort); - Assert.AreEqual(info.OriginatorAddress, forwardedTcpipChannelInfo.OriginatorAddress); - Assert.AreEqual(info.OriginatorPort, forwardedTcpipChannelInfo.OriginatorPort); - } - - [TestMethod] - public void Load_SessionChannelOpenInfo() - { - var localChannelNumber = (uint)_random.Next(0, int.MaxValue); - var initialWindowSize = (uint)_random.Next(0, int.MaxValue); - var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); - var info = new SessionChannelOpenInfo(); - var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - var bytes = target.GetBytes(); - - target.Load(bytes); - - Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); - Assert.IsNotNull(target.Info); - Assert.AreEqual(initialWindowSize, target.InitialWindowSize); - Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); - Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); - - var sessionChannelOpenInfo = target.Info as SessionChannelOpenInfo; - Assert.IsNotNull(sessionChannelOpenInfo); - Assert.AreEqual(info.ChannelType, sessionChannelOpenInfo.ChannelType); - } - - - [TestMethod] - public void Load_X11ChannelOpenInfo() - { - var localChannelNumber = (uint)_random.Next(0, int.MaxValue); - var initialWindowSize = (uint)_random.Next(0, int.MaxValue); - var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); - var info = new X11ChannelOpenInfo("address", 26); - var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); - var bytes = target.GetBytes(); - - target.Load(bytes); - - Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); - Assert.IsNotNull(target.Info); - Assert.AreEqual(initialWindowSize, target.InitialWindowSize); - Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); - Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); - - var x11ChannelOpenInfo = target.Info as X11ChannelOpenInfo; - Assert.IsNotNull(x11ChannelOpenInfo); - Assert.AreEqual(info.ChannelType, x11ChannelOpenInfo.ChannelType); - Assert.AreEqual(info.OriginatorAddress, x11ChannelOpenInfo.OriginatorAddress); - Assert.AreEqual(info.OriginatorPort, x11ChannelOpenInfo.OriginatorPort); - } - - [TestMethod] - public void Load_ShouldThrowNotSupportedExceptionWhenChannelTypeIsNotSupported() - { - var localChannelNumber = (uint)_random.Next(0, int.MaxValue); - var initialWindowSize = (uint)_random.Next(0, int.MaxValue); - var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); - var channelName = "dunno_" + _random.Next().ToString(CultureInfo.InvariantCulture); - var channelType = _ascii.GetBytes(channelName); - - var sshDataStream = new SshDataStream(1 + 4 + channelType.Length + 4 + 4 + 4); - sshDataStream.WriteByte(ChannelOpenMessage.MessageNumber); - sshDataStream.Write((uint) channelType.Length); - sshDataStream.Write(channelType, 0, channelType.Length); - sshDataStream.Write(localChannelNumber); - sshDataStream.Write(initialWindowSize); - sshDataStream.Write(maximumPacketSize); - var bytes = sshDataStream.ToArray(); - var target = new ChannelOpenMessage(); - - try - { - target.Load(bytes); - Assert.Fail(); - } - catch (NotSupportedException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format("Channel type '{0}' is not supported.", channelName), ex.Message); - } - } - } -} +using System.Globalization; +using System.Linq; +using System.Text; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + [TestClass] + public class ChannelOpenMessageTest + { + private Random _random; + private Encoding _ascii; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _ascii = Encoding.ASCII; + } + + [TestMethod] + public void DefaultConstructor() + { + var target = new ChannelOpenMessage(); + + Assert.IsNull(target.ChannelType); + Assert.IsNull(target.Info); + Assert.AreEqual(default(uint), target.InitialWindowSize); + Assert.AreEqual(default(uint), target.LocalChannelNumber); + Assert.AreEqual(default(uint), target.MaximumPacketSize); + } + + [TestMethod] + public void Constructor_LocalChannelNumberAndInitialWindowSizeAndMaximumPacketSizeAndInfo() + { + var localChannelNumber = (uint) _random.Next(0, int.MaxValue); + var initialWindowSize = (uint) _random.Next(0, int.MaxValue); + var maximumPacketSize = (uint) _random.Next(0, int.MaxValue); + var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); + + var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + + Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); + Assert.AreSame(info, target.Info); + Assert.AreEqual(initialWindowSize, target.InitialWindowSize); + Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); + Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); + } + + [TestMethod] + public void Constructor_LocalChannelNumberAndInitialWindowSizeAndMaximumPacketSizeAndInfo_ShouldThrowArgumentNullExceptionWhenInfoIsNull() + { + var localChannelNumber = (uint) _random.Next(0, int.MaxValue); + var initialWindowSize = (uint) _random.Next(0, int.MaxValue); + var maximumPacketSize = (uint) _random.Next(0, int.MaxValue); + ChannelOpenInfo info = null; + + try + { + new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("info", ex.ParamName); + } + } + + [TestMethod] + public void GetBytes() + { + var localChannelNumber = (uint)_random.Next(0, int.MaxValue); + var initialWindowSize = (uint)_random.Next(0, int.MaxValue); + var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); + var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); + var infoBytes = info.GetBytes(); + var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + + var bytes = target.GetBytes(); + + var expectedBytesLength = 1; // Type + expectedBytesLength += 4; // ChannelType length + expectedBytesLength += target.ChannelType.Length; // ChannelType + expectedBytesLength += 4; // LocalChannelNumber + expectedBytesLength += 4; // InitialWindowSize + expectedBytesLength += 4; // MaximumPacketSize + expectedBytesLength += infoBytes.Length; // Info + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual(ChannelOpenMessage.MessageNumber, sshDataStream.ReadByte()); + + var actualChannelTypeLength = sshDataStream.ReadUInt32(); + Assert.AreEqual((uint) target.ChannelType.Length, actualChannelTypeLength); + + var actualChannelType = new byte[actualChannelTypeLength]; + sshDataStream.Read(actualChannelType, 0, (int) actualChannelTypeLength); + Assert.IsTrue(target.ChannelType.SequenceEqual(actualChannelType)); + + Assert.AreEqual(localChannelNumber, sshDataStream.ReadUInt32()); + Assert.AreEqual(initialWindowSize, sshDataStream.ReadUInt32()); + Assert.AreEqual(maximumPacketSize, sshDataStream.ReadUInt32()); + + var actualInfo = new byte[infoBytes.Length]; + sshDataStream.Read(actualInfo, 0, actualInfo.Length); + Assert.IsTrue(infoBytes.SequenceEqual(actualInfo)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + + [TestMethod] + public void Load_DirectTcpipChannelInfo() + { + var localChannelNumber = (uint)_random.Next(0, int.MaxValue); + var initialWindowSize = (uint)_random.Next(0, int.MaxValue); + var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); + var info = new DirectTcpipChannelInfo("host", 22, "originator", 25); + var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + var bytes = target.GetBytes(); + + target.Load(bytes); + + Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); + Assert.IsNotNull(target.Info); + Assert.AreEqual(initialWindowSize, target.InitialWindowSize); + Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); + Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); + + var directTcpChannelInfo = target.Info as DirectTcpipChannelInfo; + Assert.IsNotNull(directTcpChannelInfo); + Assert.AreEqual(info.ChannelType, directTcpChannelInfo.ChannelType); + Assert.AreEqual(info.HostToConnect, directTcpChannelInfo.HostToConnect); + Assert.AreEqual(info.OriginatorAddress, directTcpChannelInfo.OriginatorAddress); + Assert.AreEqual(info.OriginatorPort, directTcpChannelInfo.OriginatorPort); + Assert.AreEqual(info.PortToConnect, directTcpChannelInfo.PortToConnect); + } + + [TestMethod] + public void Load_ForwardedTcpipChannelInfo() + { + var localChannelNumber = (uint)_random.Next(0, int.MaxValue); + var initialWindowSize = (uint)_random.Next(0, int.MaxValue); + var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); + var info = new ForwardedTcpipChannelInfo("connected", 25, "originator", 21); + var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + var bytes = target.GetBytes(); + + target.Load(bytes); + + Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); + Assert.IsNotNull(target.Info); + Assert.AreEqual(initialWindowSize, target.InitialWindowSize); + Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); + Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); + + var forwardedTcpipChannelInfo = target.Info as ForwardedTcpipChannelInfo; + Assert.IsNotNull(forwardedTcpipChannelInfo); + Assert.AreEqual(info.ChannelType, forwardedTcpipChannelInfo.ChannelType); + Assert.AreEqual(info.ConnectedAddress, forwardedTcpipChannelInfo.ConnectedAddress); + Assert.AreEqual(info.ConnectedPort, forwardedTcpipChannelInfo.ConnectedPort); + Assert.AreEqual(info.OriginatorAddress, forwardedTcpipChannelInfo.OriginatorAddress); + Assert.AreEqual(info.OriginatorPort, forwardedTcpipChannelInfo.OriginatorPort); + } + + [TestMethod] + public void Load_SessionChannelOpenInfo() + { + var localChannelNumber = (uint)_random.Next(0, int.MaxValue); + var initialWindowSize = (uint)_random.Next(0, int.MaxValue); + var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); + var info = new SessionChannelOpenInfo(); + var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + var bytes = target.GetBytes(); + + target.Load(bytes); + + Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); + Assert.IsNotNull(target.Info); + Assert.AreEqual(initialWindowSize, target.InitialWindowSize); + Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); + Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); + + var sessionChannelOpenInfo = target.Info as SessionChannelOpenInfo; + Assert.IsNotNull(sessionChannelOpenInfo); + Assert.AreEqual(info.ChannelType, sessionChannelOpenInfo.ChannelType); + } + + + [TestMethod] + public void Load_X11ChannelOpenInfo() + { + var localChannelNumber = (uint)_random.Next(0, int.MaxValue); + var initialWindowSize = (uint)_random.Next(0, int.MaxValue); + var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); + var info = new X11ChannelOpenInfo("address", 26); + var target = new ChannelOpenMessage(localChannelNumber, initialWindowSize, maximumPacketSize, info); + var bytes = target.GetBytes(); + + target.Load(bytes); + + Assert.AreEqual(info.ChannelType, _ascii.GetString(target.ChannelType)); + Assert.IsNotNull(target.Info); + Assert.AreEqual(initialWindowSize, target.InitialWindowSize); + Assert.AreEqual(localChannelNumber, target.LocalChannelNumber); + Assert.AreEqual(maximumPacketSize, target.MaximumPacketSize); + + var x11ChannelOpenInfo = target.Info as X11ChannelOpenInfo; + Assert.IsNotNull(x11ChannelOpenInfo); + Assert.AreEqual(info.ChannelType, x11ChannelOpenInfo.ChannelType); + Assert.AreEqual(info.OriginatorAddress, x11ChannelOpenInfo.OriginatorAddress); + Assert.AreEqual(info.OriginatorPort, x11ChannelOpenInfo.OriginatorPort); + } + + [TestMethod] + public void Load_ShouldThrowNotSupportedExceptionWhenChannelTypeIsNotSupported() + { + var localChannelNumber = (uint)_random.Next(0, int.MaxValue); + var initialWindowSize = (uint)_random.Next(0, int.MaxValue); + var maximumPacketSize = (uint)_random.Next(0, int.MaxValue); + var channelName = "dunno_" + _random.Next().ToString(CultureInfo.InvariantCulture); + var channelType = _ascii.GetBytes(channelName); + + var sshDataStream = new SshDataStream(1 + 4 + channelType.Length + 4 + 4 + 4); + sshDataStream.WriteByte(ChannelOpenMessage.MessageNumber); + sshDataStream.Write((uint) channelType.Length); + sshDataStream.Write(channelType, 0, channelType.Length); + sshDataStream.Write(localChannelNumber); + sshDataStream.Write(initialWindowSize); + sshDataStream.Write(maximumPacketSize); + var bytes = sshDataStream.ToArray(); + var target = new ChannelOpenMessage(); + + try + { + target.Load(bytes); + Assert.Fail(); + } + catch (NotSupportedException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format("Channel type '{0}' is not supported.", channelName), ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/DirectTcpipChannelInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/DirectTcpipChannelInfoTest.cs index 366924de..8cda173b 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/DirectTcpipChannelInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/DirectTcpipChannelInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Used to open "direct-tcpip" channel type - /// - [TestClass] - public class DirectTcpipChannelInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Used to open "direct-tcpip" channel type + /// + [TestClass] + public class DirectTcpipChannelInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ForwardedTcpipChannelInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ForwardedTcpipChannelInfoTest.cs index 91cc8877..df38576a 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ForwardedTcpipChannelInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/ForwardedTcpipChannelInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Used to open "forwarded-tcpip" channel type - /// - [TestClass] - public class ForwardedTcpipChannelInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Used to open "forwarded-tcpip" channel type + /// + [TestClass] + public class ForwardedTcpipChannelInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/SessionChannelOpenInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/SessionChannelOpenInfoTest.cs index a67229a7..f647ed5c 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/SessionChannelOpenInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/SessionChannelOpenInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Used to open "session" channel type - /// - [TestClass] - public class SessionChannelOpenInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Used to open "session" channel type + /// + [TestClass] + public class SessionChannelOpenInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/X11ChannelOpenInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/X11ChannelOpenInfoTest.cs index 42ec7998..44f34829 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/X11ChannelOpenInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpen/X11ChannelOpenInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Used to open "x11" channel type - /// - [TestClass] - public class X11ChannelOpenInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Used to open "x11" channel type + /// + [TestClass] + public class X11ChannelOpenInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenConfirmationMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenConfirmationMessageTest.cs index 54716ca0..6c71ae89 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenConfirmationMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenConfirmationMessageTest.cs @@ -1,39 +1,39 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelOpenConfirmationMessageTest and is intended - ///to contain all ChannelOpenConfirmationMessageTest Unit Tests - /// - [TestClass()] - public class ChannelOpenConfirmationMessageTest : TestBase - { - /// - ///A test for ChannelOpenConfirmationMessage Constructor - /// - [TestMethod()] - public void ChannelOpenConfirmationMessageConstructorTest() - { - ChannelOpenConfirmationMessage target = new ChannelOpenConfirmationMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelOpenConfirmationMessage Constructor - /// - [TestMethod()] - public void ChannelOpenConfirmationMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - uint initialWindowSize = 0; // TODO: Initialize to an appropriate value - uint maximumPacketSize = 0; // TODO: Initialize to an appropriate value - uint remoteChannelNumber = 0; // TODO: Initialize to an appropriate value - ChannelOpenConfirmationMessage target = new ChannelOpenConfirmationMessage(localChannelNumber, initialWindowSize, maximumPacketSize, remoteChannelNumber); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelOpenConfirmationMessageTest and is intended + ///to contain all ChannelOpenConfirmationMessageTest Unit Tests + /// + [TestClass()] + public class ChannelOpenConfirmationMessageTest : TestBase + { + /// + ///A test for ChannelOpenConfirmationMessage Constructor + /// + [TestMethod()] + public void ChannelOpenConfirmationMessageConstructorTest() + { + ChannelOpenConfirmationMessage target = new ChannelOpenConfirmationMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelOpenConfirmationMessage Constructor + /// + [TestMethod()] + public void ChannelOpenConfirmationMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + uint initialWindowSize = 0; // TODO: Initialize to an appropriate value + uint maximumPacketSize = 0; // TODO: Initialize to an appropriate value + uint remoteChannelNumber = 0; // TODO: Initialize to an appropriate value + ChannelOpenConfirmationMessage target = new ChannelOpenConfirmationMessage(localChannelNumber, initialWindowSize, maximumPacketSize, remoteChannelNumber); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenFailureMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenFailureMessageTest.cs index b9276fd0..ef1cf238 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenFailureMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenFailureMessageTest.cs @@ -1,38 +1,38 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelOpenFailureMessageTest and is intended - ///to contain all ChannelOpenFailureMessageTest Unit Tests - /// - [TestClass()] - public class ChannelOpenFailureMessageTest : TestBase - { - /// - ///A test for ChannelOpenFailureMessage Constructor - /// - [TestMethod()] - public void ChannelOpenFailureMessageConstructorTest() - { - ChannelOpenFailureMessage target = new ChannelOpenFailureMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelOpenFailureMessage Constructor - /// - [TestMethod()] - public void ChannelOpenFailureMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - string description = string.Empty; // TODO: Initialize to an appropriate value - uint reasonCode = 0; // TODO: Initialize to an appropriate value - ChannelOpenFailureMessage target = new ChannelOpenFailureMessage(localChannelNumber, description, reasonCode); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelOpenFailureMessageTest and is intended + ///to contain all ChannelOpenFailureMessageTest Unit Tests + /// + [TestClass()] + public class ChannelOpenFailureMessageTest : TestBase + { + /// + ///A test for ChannelOpenFailureMessage Constructor + /// + [TestMethod()] + public void ChannelOpenFailureMessageConstructorTest() + { + ChannelOpenFailureMessage target = new ChannelOpenFailureMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelOpenFailureMessage Constructor + /// + [TestMethod()] + public void ChannelOpenFailureMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + string description = string.Empty; // TODO: Initialize to an appropriate value + uint reasonCode = 0; // TODO: Initialize to an appropriate value + ChannelOpenFailureMessage target = new ChannelOpenFailureMessage(localChannelNumber, description, reasonCode); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenInfoTest.cs index 50cbbe8e..845cc8c0 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelOpenInfoTest.cs @@ -1,35 +1,35 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelOpenInfoTest and is intended - ///to contain all ChannelOpenInfoTest Unit Tests - /// - [TestClass] - [Ignore] // placeholders only - public class ChannelOpenInfoTest : TestBase - { - internal virtual ChannelOpenInfo CreateChannelOpenInfo() - { - // TODO: Instantiate an appropriate concrete class. - ChannelOpenInfo target = null; - return target; - } - - /// - ///A test for ChannelType - /// - [TestMethod()] - public void ChannelTypeTest() - { - ChannelOpenInfo target = CreateChannelOpenInfo(); // TODO: Initialize to an appropriate value - string actual; - actual = target.ChannelType; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelOpenInfoTest and is intended + ///to contain all ChannelOpenInfoTest Unit Tests + /// + [TestClass] + [Ignore] // placeholders only + public class ChannelOpenInfoTest : TestBase + { + internal virtual ChannelOpenInfo CreateChannelOpenInfo() + { + // TODO: Instantiate an appropriate concrete class. + ChannelOpenInfo target = null; + return target; + } + + /// + ///A test for ChannelType + /// + [TestMethod()] + public void ChannelTypeTest() + { + ChannelOpenInfo target = CreateChannelOpenInfo(); // TODO: Initialize to an appropriate value + string actual; + actual = target.ChannelType; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/BreakRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/BreakRequestInfoTest.cs index c71af390..dd8d7b28 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/BreakRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/BreakRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "break" type channel request information - /// - [TestClass] - public class BreakRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "break" type channel request information + /// + [TestClass] + public class BreakRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ChannelRequestMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ChannelRequestMessageTest.cs index a6449e24..0c559997 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ChannelRequestMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ChannelRequestMessageTest.cs @@ -1,36 +1,36 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Connection; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents SSH_MSG_CHANNEL_REQUEST message. - /// - [TestClass] - [Ignore] // placeholders only - public class ChannelRequestMessageTest : TestBase - { - /// - ///A test for ChannelRequestMessage Constructor - /// - [TestMethod()] - public void ChannelRequestMessageConstructorTest() - { - ChannelRequestMessage target = new ChannelRequestMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelRequestMessage Constructor - /// - [TestMethod()] - public void ChannelRequestMessageConstructorTest1() - { - uint localChannelName = 0; // TODO: Initialize to an appropriate value - RequestInfo info = null; // TODO: Initialize to an appropriate value - ChannelRequestMessage target = new ChannelRequestMessage(localChannelName, info); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Connection; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents SSH_MSG_CHANNEL_REQUEST message. + /// + [TestClass] + [Ignore] // placeholders only + public class ChannelRequestMessageTest : TestBase + { + /// + ///A test for ChannelRequestMessage Constructor + /// + [TestMethod()] + public void ChannelRequestMessageConstructorTest() + { + ChannelRequestMessage target = new ChannelRequestMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelRequestMessage Constructor + /// + [TestMethod()] + public void ChannelRequestMessageConstructorTest1() + { + uint localChannelName = 0; // TODO: Initialize to an appropriate value + RequestInfo info = null; // TODO: Initialize to an appropriate value + ChannelRequestMessage target = new ChannelRequestMessage(localChannelName, info); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EndOfWriteRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EndOfWriteRequestInfoTest.cs index 4242951a..153f4bbc 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EndOfWriteRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EndOfWriteRequestInfoTest.cs @@ -1,37 +1,37 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for EndOfWriteRequestInfoTest and is intended - ///to contain all EndOfWriteRequestInfoTest Unit Tests - /// - [TestClass()] - public class EndOfWriteRequestInfoTest : TestBase - { - /// - ///A test for EndOfWriteRequestInfo Constructor - /// - [TestMethod()] - public void EndOfWriteRequestInfoConstructorTest() - { - EndOfWriteRequestInfo target = new EndOfWriteRequestInfo(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for RequestName - /// - [TestMethod()] - public void RequestNameTest() - { - EndOfWriteRequestInfo target = new EndOfWriteRequestInfo(); // TODO: Initialize to an appropriate value - string actual; - actual = target.RequestName; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for EndOfWriteRequestInfoTest and is intended + ///to contain all EndOfWriteRequestInfoTest Unit Tests + /// + [TestClass()] + public class EndOfWriteRequestInfoTest : TestBase + { + /// + ///A test for EndOfWriteRequestInfo Constructor + /// + [TestMethod()] + public void EndOfWriteRequestInfoConstructorTest() + { + EndOfWriteRequestInfo target = new EndOfWriteRequestInfo(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for RequestName + /// + [TestMethod()] + public void RequestNameTest() + { + EndOfWriteRequestInfo target = new EndOfWriteRequestInfo(); // TODO: Initialize to an appropriate value + string actual; + actual = target.RequestName; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EnvironmentVariableRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EnvironmentVariableRequestInfoTest.cs index 687b4dd7..78899d9d 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EnvironmentVariableRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/EnvironmentVariableRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "env" type channel request information - /// - [TestClass] - public class EnvironmentVariableRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "env" type channel request information + /// + [TestClass] + public class EnvironmentVariableRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExecRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExecRequestInfoTest.cs index 0eb8bc8c..ed030011 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExecRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExecRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "exec" type channel request information - /// - [TestClass] - public class ExecRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "exec" type channel request information + /// + [TestClass] + public class ExecRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitSignalRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitSignalRequestInfoTest.cs index 17f7a4b2..81c00444 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitSignalRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitSignalRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "exit-signal" type channel request information - /// - [TestClass] - public class ExitSignalRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "exit-signal" type channel request information + /// + [TestClass] + public class ExitSignalRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitStatusRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitStatusRequestInfoTest.cs index 91b8b7bf..dd17e684 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitStatusRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ExitStatusRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "exit-status" type channel request information - /// - [TestClass] - public class ExitStatusRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "exit-status" type channel request information + /// + [TestClass] + public class ExitStatusRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/KeepAliveRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/KeepAliveRequestInfoTest.cs index 312e21b4..ba5e8bfa 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/KeepAliveRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/KeepAliveRequestInfoTest.cs @@ -1,37 +1,37 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for KeepAliveRequestInfoTest and is intended - ///to contain all KeepAliveRequestInfoTest Unit Tests - /// - [TestClass()] - public class KeepAliveRequestInfoTest : TestBase - { - /// - ///A test for KeepAliveRequestInfo Constructor - /// - [TestMethod()] - public void KeepAliveRequestInfoConstructorTest() - { - KeepAliveRequestInfo target = new KeepAliveRequestInfo(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for RequestName - /// - [TestMethod()] - public void RequestNameTest() - { - KeepAliveRequestInfo target = new KeepAliveRequestInfo(); // TODO: Initialize to an appropriate value - string actual; - actual = target.RequestName; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for KeepAliveRequestInfoTest and is intended + ///to contain all KeepAliveRequestInfoTest Unit Tests + /// + [TestClass()] + public class KeepAliveRequestInfoTest : TestBase + { + /// + ///A test for KeepAliveRequestInfo Constructor + /// + [TestMethod()] + public void KeepAliveRequestInfoConstructorTest() + { + KeepAliveRequestInfo target = new KeepAliveRequestInfo(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for RequestName + /// + [TestMethod()] + public void RequestNameTest() + { + KeepAliveRequestInfo target = new KeepAliveRequestInfo(); // TODO: Initialize to an appropriate value + string actual; + actual = target.RequestName; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs index 0476e2ed..96936530 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/PseudoTerminalInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "pty-req" type channel request information - /// - [TestClass] - public class PseudoTerminalRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "pty-req" type channel request information + /// + [TestClass] + public class PseudoTerminalRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ShellRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ShellRequestInfoTest.cs index 209be376..26ef2e97 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ShellRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/ShellRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "shell" type channel request information - /// - [TestClass] - public class ShellRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "shell" type channel request information + /// + [TestClass] + public class ShellRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SignalRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SignalRequestInfoTest.cs index 6abdcb9b..31df7359 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SignalRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SignalRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "signal" type channel request information - /// - [TestClass] - public class SignalRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "signal" type channel request information + /// + [TestClass] + public class SignalRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SubsystemRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SubsystemRequestInfoTest.cs index 10500f26..5beaa074 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SubsystemRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/SubsystemRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "subsystem" type channel request information - /// - [TestClass] - public class SubsystemRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "subsystem" type channel request information + /// + [TestClass] + public class SubsystemRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/WindowChangeRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/WindowChangeRequestInfoTest.cs index 529efef8..15cd2d33 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/WindowChangeRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/WindowChangeRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "window-change" type channel request information - /// - [TestClass] - public class WindowChangeRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "window-change" type channel request information + /// + [TestClass] + public class WindowChangeRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/X11ForwardingRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/X11ForwardingRequestInfoTest.cs index 1d6337f8..c5fab8a1 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/X11ForwardingRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/X11ForwardingRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "x11-req" type channel request information - /// - [TestClass] - public class X11ForwardingRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "x11-req" type channel request information + /// + [TestClass] + public class X11ForwardingRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/XonXoffRequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/XonXoffRequestInfoTest.cs index cbad2a48..f6ef5fc5 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/XonXoffRequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelRequest/XonXoffRequestInfoTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - /// Represents "xon-xoff" type channel request information - /// - [TestClass] - public class XonXoffRequestInfoTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + /// Represents "xon-xoff" type channel request information + /// + [TestClass] + public class XonXoffRequestInfoTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelSuccessMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelSuccessMessageTest.cs index 888b7b59..67353b5e 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelSuccessMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelSuccessMessageTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelSuccessMessageTest and is intended - ///to contain all ChannelSuccessMessageTest Unit Tests - /// - [TestClass()] - public class ChannelSuccessMessageTest : TestBase - { - /// - ///A test for ChannelSuccessMessage Constructor - /// - [TestMethod()] - public void ChannelSuccessMessageConstructorTest() - { - ChannelSuccessMessage target = new ChannelSuccessMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelSuccessMessage Constructor - /// - [TestMethod()] - public void ChannelSuccessMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - ChannelSuccessMessage target = new ChannelSuccessMessage(localChannelNumber); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelSuccessMessageTest and is intended + ///to contain all ChannelSuccessMessageTest Unit Tests + /// + [TestClass()] + public class ChannelSuccessMessageTest : TestBase + { + /// + ///A test for ChannelSuccessMessage Constructor + /// + [TestMethod()] + public void ChannelSuccessMessageConstructorTest() + { + ChannelSuccessMessage target = new ChannelSuccessMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelSuccessMessage Constructor + /// + [TestMethod()] + public void ChannelSuccessMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + ChannelSuccessMessage target = new ChannelSuccessMessage(localChannelNumber); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelWindowAdjustMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelWindowAdjustMessageTest.cs index 520ccdde..df35c303 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelWindowAdjustMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/ChannelWindowAdjustMessageTest.cs @@ -1,37 +1,37 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for ChannelWindowAdjustMessageTest and is intended - ///to contain all ChannelWindowAdjustMessageTest Unit Tests - /// - [TestClass()] - public class ChannelWindowAdjustMessageTest : TestBase - { - /// - ///A test for ChannelWindowAdjustMessage Constructor - /// - [TestMethod()] - public void ChannelWindowAdjustMessageConstructorTest() - { - ChannelWindowAdjustMessage target = new ChannelWindowAdjustMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChannelWindowAdjustMessage Constructor - /// - [TestMethod()] - public void ChannelWindowAdjustMessageConstructorTest1() - { - uint localChannelNumber = 0; // TODO: Initialize to an appropriate value - uint bytesToAdd = 0; // TODO: Initialize to an appropriate value - ChannelWindowAdjustMessage target = new ChannelWindowAdjustMessage(localChannelNumber, bytesToAdd); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for ChannelWindowAdjustMessageTest and is intended + ///to contain all ChannelWindowAdjustMessageTest Unit Tests + /// + [TestClass()] + public class ChannelWindowAdjustMessageTest : TestBase + { + /// + ///A test for ChannelWindowAdjustMessage Constructor + /// + [TestMethod()] + public void ChannelWindowAdjustMessageConstructorTest() + { + ChannelWindowAdjustMessage target = new ChannelWindowAdjustMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChannelWindowAdjustMessage Constructor + /// + [TestMethod()] + public void ChannelWindowAdjustMessageConstructorTest1() + { + uint localChannelNumber = 0; // TODO: Initialize to an appropriate value + uint bytesToAdd = 0; // TODO: Initialize to an appropriate value + ChannelWindowAdjustMessage target = new ChannelWindowAdjustMessage(localChannelNumber, bytesToAdd); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/GlobalRequestMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/GlobalRequestMessageTest.cs index f77dd4ab..9e116e23 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/GlobalRequestMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/GlobalRequestMessageTest.cs @@ -1,39 +1,39 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for GlobalRequestMessageTest and is intended - ///to contain all GlobalRequestMessageTest Unit Tests - /// - [TestClass()] - public class GlobalRequestMessageTest : TestBase - { - /// - ///A test for GlobalRequestMessage Constructor - /// - [TestMethod()] - public void GlobalRequestMessageConstructorTest() - { - GlobalRequestMessage target = new GlobalRequestMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for GlobalRequestMessage Constructor - /// - [TestMethod()] - public void GlobalRequestMessageConstructorTest2() - { - GlobalRequestName requestName = new GlobalRequestName(); // TODO: Initialize to an appropriate value - bool wantReply = false; // TODO: Initialize to an appropriate value - string addressToBind = string.Empty; // TODO: Initialize to an appropriate value - uint portToBind = 0; // TODO: Initialize to an appropriate value - GlobalRequestMessage target = new GlobalRequestMessage(requestName, wantReply, addressToBind, portToBind); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for GlobalRequestMessageTest and is intended + ///to contain all GlobalRequestMessageTest Unit Tests + /// + [TestClass()] + public class GlobalRequestMessageTest : TestBase + { + /// + ///A test for GlobalRequestMessage Constructor + /// + [TestMethod()] + public void GlobalRequestMessageConstructorTest() + { + GlobalRequestMessage target = new GlobalRequestMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for GlobalRequestMessage Constructor + /// + [TestMethod()] + public void GlobalRequestMessageConstructorTest2() + { + GlobalRequestName requestName = new GlobalRequestName(); // TODO: Initialize to an appropriate value + bool wantReply = false; // TODO: Initialize to an appropriate value + string addressToBind = string.Empty; // TODO: Initialize to an appropriate value + uint portToBind = 0; // TODO: Initialize to an appropriate value + GlobalRequestMessage target = new GlobalRequestMessage(requestName, wantReply, addressToBind, portToBind); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestFailureMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestFailureMessageTest.cs index 3ff7e203..c75c49d0 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestFailureMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestFailureMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for RequestFailureMessageTest and is intended - ///to contain all RequestFailureMessageTest Unit Tests - /// - [TestClass()] - public class RequestFailureMessageTest : TestBase - { - /// - ///A test for RequestFailureMessage Constructor - /// - [TestMethod()] - public void RequestFailureMessageConstructorTest() - { - RequestFailureMessage target = new RequestFailureMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for RequestFailureMessageTest and is intended + ///to contain all RequestFailureMessageTest Unit Tests + /// + [TestClass()] + public class RequestFailureMessageTest : TestBase + { + /// + ///A test for RequestFailureMessage Constructor + /// + [TestMethod()] + public void RequestFailureMessageConstructorTest() + { + RequestFailureMessage target = new RequestFailureMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestInfoTest.cs index ebeaf704..fdf6d534 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestInfoTest.cs @@ -1,35 +1,35 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for RequestInfoTest and is intended - ///to contain all RequestInfoTest Unit Tests - /// - [TestClass] - [Ignore] // placeholders only - public class RequestInfoTest : TestBase - { - internal virtual RequestInfo CreateRequestInfo() - { - // TODO: Instantiate an appropriate concrete class. - RequestInfo target = null; - return target; - } - - /// - ///A test for RequestName - /// - [TestMethod()] - public void RequestNameTest() - { - RequestInfo target = CreateRequestInfo(); // TODO: Initialize to an appropriate value - string actual; - actual = target.RequestName; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for RequestInfoTest and is intended + ///to contain all RequestInfoTest Unit Tests + /// + [TestClass] + [Ignore] // placeholders only + public class RequestInfoTest : TestBase + { + internal virtual RequestInfo CreateRequestInfo() + { + // TODO: Instantiate an appropriate concrete class. + RequestInfo target = null; + return target; + } + + /// + ///A test for RequestName + /// + [TestMethod()] + public void RequestNameTest() + { + RequestInfo target = CreateRequestInfo(); // TODO: Initialize to an appropriate value + string actual; + actual = target.RequestName; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestSuccessMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestSuccessMessageTest.cs index a42dd267..c125f8f9 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestSuccessMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Connection/RequestSuccessMessageTest.cs @@ -1,36 +1,36 @@ -using Renci.SshNet.Messages.Connection; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Connection -{ - /// - ///This is a test class for RequestSuccessMessageTest and is intended - ///to contain all RequestSuccessMessageTest Unit Tests - /// - [TestClass()] - public class RequestSuccessMessageTest : TestBase - { - /// - ///A test for RequestSuccessMessage Constructor - /// - [TestMethod()] - public void RequestSuccessMessageConstructorTest() - { - RequestSuccessMessage target = new RequestSuccessMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for RequestSuccessMessage Constructor - /// - [TestMethod()] - public void RequestSuccessMessageConstructorTest1() - { - uint boundPort = 0; // TODO: Initialize to an appropriate value - RequestSuccessMessage target = new RequestSuccessMessage(boundPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Connection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Connection +{ + /// + ///This is a test class for RequestSuccessMessageTest and is intended + ///to contain all RequestSuccessMessageTest Unit Tests + /// + [TestClass()] + public class RequestSuccessMessageTest : TestBase + { + /// + ///A test for RequestSuccessMessage Constructor + /// + [TestMethod()] + public void RequestSuccessMessageConstructorTest() + { + RequestSuccessMessage target = new RequestSuccessMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for RequestSuccessMessage Constructor + /// + [TestMethod()] + public void RequestSuccessMessageConstructorTest1() + { + uint boundPort = 0; // TODO: Initialize to an appropriate value + RequestSuccessMessage target = new RequestSuccessMessage(boundPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/MessageAttributeTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/MessageAttributeTest.cs index c77d9f29..5df04d32 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/MessageAttributeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/MessageAttributeTest.cs @@ -1,61 +1,61 @@ -using Renci.SshNet.Messages; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages -{ - /// - ///This is a test class for MessageAttributeTest and is intended - ///to contain all MessageAttributeTest Unit Tests - /// - [TestClass()] - public class MessageAttributeTest : TestBase - { - /// - ///A test for MessageAttribute Constructor - /// - [TestMethod()] - public void MessageAttributeConstructorTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - byte number = 0; // TODO: Initialize to an appropriate value - MessageAttribute target = new MessageAttribute(name, number); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Name - /// - [TestMethod()] - public void NameTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - byte number = 0; // TODO: Initialize to an appropriate value - MessageAttribute target = new MessageAttribute(name, number); // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - target.Name = expected; - actual = target.Name; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Number - /// - [TestMethod()] - public void NumberTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - byte number = 0; // TODO: Initialize to an appropriate value - MessageAttribute target = new MessageAttribute(name, number); // TODO: Initialize to an appropriate value - byte expected = 0; // TODO: Initialize to an appropriate value - byte actual; - target.Number = expected; - actual = target.Number; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages +{ + /// + ///This is a test class for MessageAttributeTest and is intended + ///to contain all MessageAttributeTest Unit Tests + /// + [TestClass()] + public class MessageAttributeTest : TestBase + { + /// + ///A test for MessageAttribute Constructor + /// + [TestMethod()] + public void MessageAttributeConstructorTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + byte number = 0; // TODO: Initialize to an appropriate value + MessageAttribute target = new MessageAttribute(name, number); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Name + /// + [TestMethod()] + public void NameTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + byte number = 0; // TODO: Initialize to an appropriate value + MessageAttribute target = new MessageAttribute(name, number); // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + target.Name = expected; + actual = target.Name; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Number + /// + [TestMethod()] + public void NumberTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + byte number = 0; // TODO: Initialize to an appropriate value + MessageAttribute target = new MessageAttribute(name, number); // TODO: Initialize to an appropriate value + byte expected = 0; // TODO: Initialize to an appropriate value + byte actual; + target.Number = expected; + actual = target.Number; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/MessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/MessageTest.cs index 154f715c..d79dabd9 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/MessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/MessageTest.cs @@ -1,51 +1,51 @@ -using Renci.SshNet.Messages; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages -{ - /// - ///This is a test class for MessageTest and is intended - ///to contain all MessageTest Unit Tests - /// - [TestClass] - [Ignore] // placeholders only - public class MessageTest : TestBase - { - internal virtual Message CreateMessage() - { - // TODO: Instantiate an appropriate concrete class. - Message target = null; - return target; - } - - /// - ///A test for GetBytes - /// - [TestMethod()] - public void GetBytesTest() - { - Message target = CreateMessage(); // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.GetBytes(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ToString - /// - [TestMethod()] - public void ToStringTest() - { - Message target = CreateMessage(); // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.ToString(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Messages; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages +{ + /// + ///This is a test class for MessageTest and is intended + ///to contain all MessageTest Unit Tests + /// + [TestClass] + [Ignore] // placeholders only + public class MessageTest : TestBase + { + internal virtual Message CreateMessage() + { + // TODO: Instantiate an appropriate concrete class. + Message target = null; + return target; + } + + /// + ///A test for GetBytes + /// + [TestMethod()] + public void GetBytesTest() + { + Message target = CreateMessage(); // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.GetBytes(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ToString + /// + [TestMethod()] + public void ToStringTest() + { + Message target = CreateMessage(); // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.ToString(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/DebugMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/DebugMessageTest.cs index c958bbf2..794ca083 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/DebugMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/DebugMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for DebugMessageTest and is intended - ///to contain all DebugMessageTest Unit Tests - /// - [TestClass()] - public class DebugMessageTest : TestBase - { - /// - ///A test for DebugMessage Constructor - /// - [TestMethod()] - public void DebugMessageConstructorTest() - { - DebugMessage target = new DebugMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for DebugMessageTest and is intended + ///to contain all DebugMessageTest Unit Tests + /// + [TestClass()] + public class DebugMessageTest : TestBase + { + /// + ///A test for DebugMessage Constructor + /// + [TestMethod()] + public void DebugMessageConstructorTest() + { + DebugMessage target = new DebugMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/DisconnectMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/DisconnectMessageTest.cs index 3474b330..659ea72f 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/DisconnectMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/DisconnectMessageTest.cs @@ -1,37 +1,37 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for DisconnectMessageTest and is intended - ///to contain all DisconnectMessageTest Unit Tests - /// - [TestClass()] - public class DisconnectMessageTest : TestBase - { - /// - ///A test for DisconnectMessage Constructor - /// - [TestMethod()] - public void DisconnectMessageConstructorTest() - { - DisconnectMessage target = new DisconnectMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DisconnectMessage Constructor - /// - [TestMethod()] - public void DisconnectMessageConstructorTest1() - { - DisconnectReason reasonCode = new DisconnectReason(); // TODO: Initialize to an appropriate value - string message = string.Empty; // TODO: Initialize to an appropriate value - DisconnectMessage target = new DisconnectMessage(reasonCode, message); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for DisconnectMessageTest and is intended + ///to contain all DisconnectMessageTest Unit Tests + /// + [TestClass()] + public class DisconnectMessageTest : TestBase + { + /// + ///A test for DisconnectMessage Constructor + /// + [TestMethod()] + public void DisconnectMessageConstructorTest() + { + DisconnectMessage target = new DisconnectMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DisconnectMessage Constructor + /// + [TestMethod()] + public void DisconnectMessageConstructorTest1() + { + DisconnectReason reasonCode = new DisconnectReason(); // TODO: Initialize to an appropriate value + string message = string.Empty; // TODO: Initialize to an appropriate value + DisconnectMessage target = new DisconnectMessage(reasonCode, message); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/IgnoreMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/IgnoreMessageTest.cs index 5d893589..619e0a6f 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/IgnoreMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/IgnoreMessageTest.cs @@ -1,95 +1,95 @@ -using System; -using System.Linq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - [TestClass] - public class IgnoreMessageTest - { - private Random _random; - private byte[] _data; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _data = new byte[_random.Next(1, 10)]; - _random.NextBytes(_data); - } - - [TestMethod] - public void DefaultConstructor() - { - var target = new IgnoreMessage(); - Assert.IsNotNull(target.Data); - Assert.AreEqual(0, target.Data.Length); - } - - [TestMethod] - public void Constructor_Data() - { - var target = new IgnoreMessage(_data); - Assert.AreSame(_data, target.Data); - } - - [TestMethod] - public void Constructor_Data_ShouldThrowArgumentNullExceptionWhenDataIsNull() - { - byte[] data = null; - - try - { - new IgnoreMessage(data); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("data", ex.ParamName); - } - } - - [TestMethod] - public void GetBytes() - { - var request = new IgnoreMessage(_data); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // Data length - expectedBytesLength += _data.Length; // Data - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual(IgnoreMessage.MessageNumber, sshDataStream.ReadByte()); - Assert.AreEqual((uint) _data.Length, sshDataStream.ReadUInt32()); - - var actualData = new byte[_data.Length]; - sshDataStream.Read(actualData, 0, actualData.Length); - Assert.IsTrue(_data.SequenceEqual(actualData)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - - [TestMethod] - public void Load() - { - var ignoreMessage = new IgnoreMessage(_data); - var bytes = ignoreMessage.GetBytes(); - var target = new IgnoreMessage(); - - target.Load(bytes); - - Assert.IsNotNull(target.Data); - Assert.AreEqual(_data.Length, target.Data.Length); - Assert.IsTrue(target.Data.SequenceEqual(_data)); - } - } -} +using System; +using System.Linq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + [TestClass] + public class IgnoreMessageTest + { + private Random _random; + private byte[] _data; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _data = new byte[_random.Next(1, 10)]; + _random.NextBytes(_data); + } + + [TestMethod] + public void DefaultConstructor() + { + var target = new IgnoreMessage(); + Assert.IsNotNull(target.Data); + Assert.AreEqual(0, target.Data.Length); + } + + [TestMethod] + public void Constructor_Data() + { + var target = new IgnoreMessage(_data); + Assert.AreSame(_data, target.Data); + } + + [TestMethod] + public void Constructor_Data_ShouldThrowArgumentNullExceptionWhenDataIsNull() + { + byte[] data = null; + + try + { + new IgnoreMessage(data); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("data", ex.ParamName); + } + } + + [TestMethod] + public void GetBytes() + { + var request = new IgnoreMessage(_data); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // Data length + expectedBytesLength += _data.Length; // Data + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual(IgnoreMessage.MessageNumber, sshDataStream.ReadByte()); + Assert.AreEqual((uint) _data.Length, sshDataStream.ReadUInt32()); + + var actualData = new byte[_data.Length]; + sshDataStream.Read(actualData, 0, actualData.Length); + Assert.IsTrue(_data.SequenceEqual(actualData)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + + [TestMethod] + public void Load() + { + var ignoreMessage = new IgnoreMessage(_data); + var bytes = ignoreMessage.GetBytes(); + var target = new IgnoreMessage(); + + target.Load(bytes); + + Assert.IsNotNull(target.Data); + Assert.AreEqual(_data.Length, target.Data.Length); + Assert.IsTrue(target.Data.SequenceEqual(_data)); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupBuilder.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupBuilder.cs index d6a42886..4e71bbec 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupBuilder.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupBuilder.cs @@ -1,32 +1,32 @@ -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - public class KeyExchangeDhGroupExchangeGroupBuilder - { - private BigInteger _safePrime; - private BigInteger _subGroup; - - public KeyExchangeDhGroupExchangeGroupBuilder WithSafePrime(BigInteger safePrime) - { - _safePrime = safePrime; - return this; - } - - public KeyExchangeDhGroupExchangeGroupBuilder WithSubGroup(BigInteger subGroup) - { - _subGroup = subGroup; - return this; - } - - public byte[] Build() - { - var sshDataStream = new SshDataStream(0); - sshDataStream.WriteByte(KeyExchangeDhGroupExchangeGroup.MessageNumber); - sshDataStream.Write(_safePrime); - sshDataStream.Write(_subGroup); - return sshDataStream.ToArray(); - } - } -} +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + public class KeyExchangeDhGroupExchangeGroupBuilder + { + private BigInteger _safePrime; + private BigInteger _subGroup; + + public KeyExchangeDhGroupExchangeGroupBuilder WithSafePrime(BigInteger safePrime) + { + _safePrime = safePrime; + return this; + } + + public KeyExchangeDhGroupExchangeGroupBuilder WithSubGroup(BigInteger subGroup) + { + _subGroup = subGroup; + return this; + } + + public byte[] Build() + { + var sshDataStream = new SshDataStream(0); + sshDataStream.WriteByte(KeyExchangeDhGroupExchangeGroup.MessageNumber); + sshDataStream.Write(_safePrime); + sshDataStream.Write(_subGroup); + return sshDataStream.ToArray(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupTest.cs index f17a460c..71617961 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeGroupTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for KeyExchangeDhGroupExchangeGroupTest and is intended - ///to contain all KeyExchangeDhGroupExchangeGroupTest Unit Tests - /// - [TestClass()] - public class KeyExchangeDhGroupExchangeGroupTest : TestBase - { - /// - ///A test for KeyExchangeDhGroupExchangeGroup Constructor - /// - [TestMethod()] - public void KeyExchangeDhGroupExchangeGroupConstructorTest() - { - KeyExchangeDhGroupExchangeGroup target = new KeyExchangeDhGroupExchangeGroup(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for KeyExchangeDhGroupExchangeGroupTest and is intended + ///to contain all KeyExchangeDhGroupExchangeGroupTest Unit Tests + /// + [TestClass()] + public class KeyExchangeDhGroupExchangeGroupTest : TestBase + { + /// + ///A test for KeyExchangeDhGroupExchangeGroup Constructor + /// + [TestMethod()] + public void KeyExchangeDhGroupExchangeGroupConstructorTest() + { + KeyExchangeDhGroupExchangeGroup target = new KeyExchangeDhGroupExchangeGroup(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeInitTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeInitTest.cs index 3663b1c2..0cd39a0e 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeInitTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeInitTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - /// Represents SSH_MSG_KEX_DH_GEX_INIT message. - /// - [TestClass] - public class KeyExchangeDhGroupExchangeInitTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + /// Represents SSH_MSG_KEX_DH_GEX_INIT message. + /// + [TestClass] + public class KeyExchangeDhGroupExchangeInitTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyBuilder.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyBuilder.cs index a3ebe0dc..0f229a07 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyBuilder.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyBuilder.cs @@ -1,52 +1,52 @@ -using System.Collections.Generic; -using System.Text; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - public class KeyExchangeDhGroupExchangeReplyBuilder - { - private byte[] _hostKeyAlgorithm; - private byte[] _hostKeys; - private BigInteger _f; - private byte[] _signature; - - public KeyExchangeDhGroupExchangeReplyBuilder WithHostKey(string hostKeyAlgorithm, params BigInteger[] hostKeys) - { - _hostKeyAlgorithm = Encoding.UTF8.GetBytes(hostKeyAlgorithm); - - var sshDataStream = new SshDataStream(0); - foreach (var hostKey in hostKeys) - sshDataStream.Write(hostKey); - _hostKeys = sshDataStream.ToArray(); - - return this; - } - - public KeyExchangeDhGroupExchangeReplyBuilder WithF(BigInteger f) - { - _f = f; - return this; - } - - public KeyExchangeDhGroupExchangeReplyBuilder WithSignature(byte[] signature) - { - _signature = signature; - return this; - } - - public byte[] Build() - { - var sshDataStream = new SshDataStream(0); - sshDataStream.WriteByte(KeyExchangeDhGroupExchangeReply.MessageNumber); - sshDataStream.Write((uint)(4 + _hostKeyAlgorithm.Length + _hostKeys.Length)); - sshDataStream.Write((uint) _hostKeyAlgorithm.Length); - sshDataStream.Write(_hostKeyAlgorithm, 0, _hostKeyAlgorithm.Length); - sshDataStream.Write(_hostKeys, 0, _hostKeys.Length); - sshDataStream.Write(_f); - sshDataStream.WriteBinary(_signature); - return sshDataStream.ToArray(); - } - } -} +using System.Collections.Generic; +using System.Text; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + public class KeyExchangeDhGroupExchangeReplyBuilder + { + private byte[] _hostKeyAlgorithm; + private byte[] _hostKeys; + private BigInteger _f; + private byte[] _signature; + + public KeyExchangeDhGroupExchangeReplyBuilder WithHostKey(string hostKeyAlgorithm, params BigInteger[] hostKeys) + { + _hostKeyAlgorithm = Encoding.UTF8.GetBytes(hostKeyAlgorithm); + + var sshDataStream = new SshDataStream(0); + foreach (var hostKey in hostKeys) + sshDataStream.Write(hostKey); + _hostKeys = sshDataStream.ToArray(); + + return this; + } + + public KeyExchangeDhGroupExchangeReplyBuilder WithF(BigInteger f) + { + _f = f; + return this; + } + + public KeyExchangeDhGroupExchangeReplyBuilder WithSignature(byte[] signature) + { + _signature = signature; + return this; + } + + public byte[] Build() + { + var sshDataStream = new SshDataStream(0); + sshDataStream.WriteByte(KeyExchangeDhGroupExchangeReply.MessageNumber); + sshDataStream.Write((uint)(4 + _hostKeyAlgorithm.Length + _hostKeys.Length)); + sshDataStream.Write((uint) _hostKeyAlgorithm.Length); + sshDataStream.Write(_hostKeyAlgorithm, 0, _hostKeyAlgorithm.Length); + sshDataStream.Write(_hostKeys, 0, _hostKeys.Length); + sshDataStream.Write(_f); + sshDataStream.WriteBinary(_signature); + return sshDataStream.ToArray(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyTest.cs index 31750145..786541c8 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeReplyTest.cs @@ -1,31 +1,31 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Tests.Common; -using System.Globalization; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - /// Represents SSH_MSG_KEX_DH_GEX_REPLY message. - /// - [TestClass] - public class KeyExchangeDhGroupExchangeReplyTest : TestBase - { - [TestMethod] - [TestCategory("KeyExchangeInitMessage")] - [Owner("olegkap")] - [Description("Validates KeyExchangeInitMessage message serialization.")] - public void Test_KeyExchangeDhGroupExchangeReply_Load() - { - var m = new KeyExchangeDhGroupExchangeReply(); - var input = new byte[] { 0x21, 0x00, 0x00, 0x01, 0x17, 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0xce, 0x38, 0xdf, 0x0d, 0x04, 0x2c, 0x10, 0x45, 0x8f, 0x5e, 0xeb, 0xc2, 0x35, 0x01, 0xd5, 0x4d, 0x09, 0xa3, 0xee, 0x74, 0x3d, 0x75, 0xcf, 0xf4, 0xf3, 0x4f, 0xc9, 0xf9, 0x2e, 0x59, 0xd6, 0xb8, 0x69, 0x85, 0x16, 0xac, 0x33, 0x5b, 0x2a, 0x2a, 0xf8, 0x9c, 0xc4, 0xc3, 0x87, 0xd6, 0xb8, 0x50, 0x6c, 0xed, 0x60, 0x9c, 0x0f, 0x83, 0x37, 0xb3, 0xa2, 0x25, 0xbe, 0x07, 0xde, 0xb6, 0x1f, 0x28, 0xab, 0x05, 0x21, 0xc0, 0x23, 0xf7, 0xd6, 0xca, 0xcb, 0x03, 0x42, 0x69, 0x31, 0x93, 0x2b, 0x3b, 0x94, 0xb8, 0x3b, 0x90, 0xe6, 0x25, 0x7c, 0x23, 0xc5, 0x24, 0x89, 0x65, 0x37, 0x7b, 0x56, 0x54, 0xa2, 0x23, 0xcb, 0xeb, 0xf0, 0xe9, 0xd1, 0x07, 0x88, 0x36, 0x8f, 0xef, 0x65, 0x71, 0xac, 0x80, 0x5c, 0x81, 0x0a, 0x95, 0x1c, 0xf5, 0xc0, 0x5d, 0xd3, 0xd4, 0x10, 0x0e, 0x4f, 0xcf, 0x87, 0x80, 0xa5, 0xde, 0x6e, 0xff, 0x89, 0x9c, 0xfc, 0x2f, 0x85, 0xf5, 0x93, 0xff, 0x70, 0x8e, 0x48, 0xb6, 0x6e, 0x6e, 0x0a, 0x18, 0xa3, 0xbb, 0x1c, 0x56, 0x60, 0xf1, 0x9d, 0x2a, 0xca, 0xbf, 0xa0, 0x84, 0x73, 0xb1, 0x6d, 0x10, 0x75, 0xcc, 0xa3, 0x20, 0xed, 0x00, 0x52, 0xd0, 0x84, 0x5a, 0xc9, 0xbb, 0x17, 0x84, 0x96, 0x40, 0x48, 0xe2, 0x8e, 0x84, 0x30, 0x82, 0x3b, 0x87, 0xa4, 0x54, 0x55, 0x8c, 0xb5, 0x62, 0x97, 0xd7, 0xf1, 0xa3, 0x8b, 0x44, 0xaa, 0x34, 0xfd, 0xe9, 0xad, 0xda, 0xeb, 0x45, 0x27, 0xfb, 0xad, 0xea, 0x9a, 0x0c, 0x38, 0x30, 0x27, 0x6a, 0x82, 0xc2, 0xc2, 0x0a, 0xa0, 0xed, 0x30, 0x2f, 0x50, 0x9f, 0xdb, 0x1a, 0xfb, 0x29, 0x1c, 0x8a, 0x28, 0x3f, 0xd6, 0xf6, 0xa9, 0xeb, 0x76, 0x60, 0xa2, 0x56, 0xa2, 0x90, 0x32, 0xcd, 0x25, 0x41, 0xb7, 0xc0, 0x9e, 0x13, 0x97, 0xaf, 0x00, 0x00, 0x00, 0x81, 0x00, 0xc6, 0x58, 0xb9, 0xa8, 0x11, 0xfd, 0xb6, 0xd6, 0xe9, 0x0c, 0x51, 0x45, 0xac, 0x51, 0x8a, 0x25, 0x6e, 0x1d, 0x9e, 0xbb, 0x7f, 0x98, 0xe3, 0x94, 0xd5, 0xac, 0x97, 0xd6, 0x35, 0x2e, 0xcc, 0x34, 0x85, 0xe2, 0x29, 0x2c, 0xba, 0x45, 0x6b, 0x39, 0xce, 0xd2, 0xae, 0x2e, 0x9a, 0x30, 0x43, 0x45, 0x09, 0xd2, 0xeb, 0x21, 0x46, 0x95, 0xa8, 0xb9, 0xbc, 0xb4, 0x21, 0xcd, 0x65, 0xeb, 0x0f, 0x48, 0x3c, 0x82, 0xdb, 0x52, 0x0e, 0xa5, 0xa8, 0xca, 0x29, 0x2d, 0xf8, 0x54, 0x38, 0xe4, 0x8f, 0x2c, 0x2d, 0x45, 0x2d, 0x2c, 0xf7, 0x1a, 0x41, 0xef, 0xd4, 0xec, 0x0f, 0xa5, 0xa8, 0xa7, 0x64, 0xb3, 0xe8, 0x7b, 0xa1, 0x40, 0x41, 0x69, 0x70, 0x4d, 0x95, 0x91, 0x8b, 0x5f, 0x28, 0xa2, 0xfc, 0xa7, 0x12, 0x2b, 0x94, 0xf0, 0x0a, 0x82, 0x92, 0x65, 0xdf, 0x8a, 0x35, 0xfb, 0xcc, 0xbe, 0xbd, 0x2d, 0x00, 0x00, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x67, 0x83, 0xa1, 0xb8, 0x0c, 0x65, 0xb8, 0xd3, 0x76, 0x5f, 0x5f, 0x05, 0x51, 0x8c, 0xb3, 0x2d, 0x1e, 0x95, 0x67, 0xd6, 0xe2, 0xe4, 0x86, 0x49, 0x11, 0xca, 0x83, 0xab, 0xdb, 0x80, 0x75, 0x4e, 0x89, 0xa7, 0x3d, 0xb6, 0xc2, 0x92, 0xbb, 0x40, 0x00, 0xb9, 0xb3, 0x03, 0x86, 0x19, 0x9d, 0x67, 0x29, 0x2b, 0x5a, 0xc9, 0x0a, 0x6c, 0xa3, 0x21, 0xaf, 0xd8, 0xd4, 0xa7, 0x84, 0x6a, 0xe5, 0x36, 0x3e, 0xa5, 0x58, 0xd6, 0x36, 0x33, 0x12, 0x2e, 0xf9, 0x22, 0x10, 0xff, 0xae, 0x0e, 0xee, 0xfa, 0xdf, 0x1f, 0xf8, 0x70, 0xfe, 0xc0, 0x30, 0x1d, 0x23, 0xbf, 0x99, 0x20, 0x22, 0x18, 0x78, 0xab, 0x5f, 0xd5, 0xfa, 0x5f, 0xf1, 0x18, 0xc2, 0x20, 0xc5, 0x58, 0x90, 0x63, 0x4b, 0x12, 0xf3, 0xa4, 0xe9, 0x20, 0x03, 0x8f, 0x5a, 0x2d, 0x17, 0xbd, 0x75, 0x0a, 0xaf, 0x6d, 0xc5, 0x15, 0x8a, 0x14, 0x74, 0x7f, 0xa0, 0xd2, 0x0f, 0x6f, 0x96, 0xa5, 0x60, 0xb1, 0xb7, 0x65, 0x0f, 0x48, 0x67, 0x5d, 0x32, 0x0a, 0xcb, 0x8e, 0xdf, 0x0c, 0xa9, 0xd5, 0x14, 0x0b, 0x6d, 0xfb, 0x8b, 0xef, 0xa3, 0x79, 0xaf, 0xdb, 0xa3, 0xb4, 0x6d, 0xbb, 0x40, 0x9e, 0xb3, 0x45, 0x04, 0x7f, 0xd1, 0x84, 0xad, 0x90, 0x8b, 0x2d, 0xb6, 0x13, 0xfb, 0x7a, 0xf5, 0xad, 0xbf, 0xa6, 0x74, 0x75, 0xfa, 0x70, 0x59, 0xae, 0x22, 0xbb, 0xfb, 0x09, 0x68, 0xae, 0xe5, 0x26, 0x5c, 0xbd, 0xe0, 0xae, 0x39, 0xbb, 0xaa, 0x59, 0x4c, 0x73, 0x11, 0x01, 0x64, 0x6d, 0xc1, 0x95, 0x1b, 0x93, 0x6b, 0x14, 0x83, 0x4a, 0xdc, 0x16, 0x67, 0x7b, 0x85, 0xd0, 0x89, 0x2e, 0x3c, 0xa1, 0x05, 0x34, 0xf0, 0xd2, 0xb9, 0x3b, 0x83, 0xf4, 0x02, 0xd4, 0x7f, 0x73, 0x76, 0x5d, 0xc2, 0x67, 0xb9, 0xac, 0x8a, 0xd1, 0xab, 0xd4, 0x82 }; - m.Load(input); - - Assert.IsTrue(m.HostKey.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0xce, 0x38, 0xdf, 0x0d, 0x04, 0x2c, 0x10, 0x45, 0x8f, 0x5e, 0xeb, 0xc2, 0x35, 0x01, 0xd5, 0x4d, 0x09, 0xa3, 0xee, 0x74, 0x3d, 0x75, 0xcf, 0xf4, 0xf3, 0x4f, 0xc9, 0xf9, 0x2e, 0x59, 0xd6, 0xb8, 0x69, 0x85, 0x16, 0xac, 0x33, 0x5b, 0x2a, 0x2a, 0xf8, 0x9c, 0xc4, 0xc3, 0x87, 0xd6, 0xb8, 0x50, 0x6c, 0xed, 0x60, 0x9c, 0x0f, 0x83, 0x37, 0xb3, 0xa2, 0x25, 0xbe, 0x07, 0xde, 0xb6, 0x1f, 0x28, 0xab, 0x05, 0x21, 0xc0, 0x23, 0xf7, 0xd6, 0xca, 0xcb, 0x03, 0x42, 0x69, 0x31, 0x93, 0x2b, 0x3b, 0x94, 0xb8, 0x3b, 0x90, 0xe6, 0x25, 0x7c, 0x23, 0xc5, 0x24, 0x89, 0x65, 0x37, 0x7b, 0x56, 0x54, 0xa2, 0x23, 0xcb, 0xeb, 0xf0, 0xe9, 0xd1, 0x07, 0x88, 0x36, 0x8f, 0xef, 0x65, 0x71, 0xac, 0x80, 0x5c, 0x81, 0x0a, 0x95, 0x1c, 0xf5, 0xc0, 0x5d, 0xd3, 0xd4, 0x10, 0x0e, 0x4f, 0xcf, 0x87, 0x80, 0xa5, 0xde, 0x6e, 0xff, 0x89, 0x9c, 0xfc, 0x2f, 0x85, 0xf5, 0x93, 0xff, 0x70, 0x8e, 0x48, 0xb6, 0x6e, 0x6e, 0x0a, 0x18, 0xa3, 0xbb, 0x1c, 0x56, 0x60, 0xf1, 0x9d, 0x2a, 0xca, 0xbf, 0xa0, 0x84, 0x73, 0xb1, 0x6d, 0x10, 0x75, 0xcc, 0xa3, 0x20, 0xed, 0x00, 0x52, 0xd0, 0x84, 0x5a, 0xc9, 0xbb, 0x17, 0x84, 0x96, 0x40, 0x48, 0xe2, 0x8e, 0x84, 0x30, 0x82, 0x3b, 0x87, 0xa4, 0x54, 0x55, 0x8c, 0xb5, 0x62, 0x97, 0xd7, 0xf1, 0xa3, 0x8b, 0x44, 0xaa, 0x34, 0xfd, 0xe9, 0xad, 0xda, 0xeb, 0x45, 0x27, 0xfb, 0xad, 0xea, 0x9a, 0x0c, 0x38, 0x30, 0x27, 0x6a, 0x82, 0xc2, 0xc2, 0x0a, 0xa0, 0xed, 0x30, 0x2f, 0x50, 0x9f, 0xdb, 0x1a, 0xfb, 0x29, 0x1c, 0x8a, 0x28, 0x3f, 0xd6, 0xf6, 0xa9, 0xeb, 0x76, 0x60, 0xa2, 0x56, 0xa2, 0x90, 0x32, 0xcd, 0x25, 0x41, 0xb7, 0xc0, 0x9e, 0x13, 0x97, 0xaf })); - Assert.IsTrue(m.Signature.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x67, 0x83, 0xa1, 0xb8, 0x0c, 0x65, 0xb8, 0xd3, 0x76, 0x5f, 0x5f, 0x05, 0x51, 0x8c, 0xb3, 0x2d, 0x1e, 0x95, 0x67, 0xd6, 0xe2, 0xe4, 0x86, 0x49, 0x11, 0xca, 0x83, 0xab, 0xdb, 0x80, 0x75, 0x4e, 0x89, 0xa7, 0x3d, 0xb6, 0xc2, 0x92, 0xbb, 0x40, 0x00, 0xb9, 0xb3, 0x03, 0x86, 0x19, 0x9d, 0x67, 0x29, 0x2b, 0x5a, 0xc9, 0x0a, 0x6c, 0xa3, 0x21, 0xaf, 0xd8, 0xd4, 0xa7, 0x84, 0x6a, 0xe5, 0x36, 0x3e, 0xa5, 0x58, 0xd6, 0x36, 0x33, 0x12, 0x2e, 0xf9, 0x22, 0x10, 0xff, 0xae, 0x0e, 0xee, 0xfa, 0xdf, 0x1f, 0xf8, 0x70, 0xfe, 0xc0, 0x30, 0x1d, 0x23, 0xbf, 0x99, 0x20, 0x22, 0x18, 0x78, 0xab, 0x5f, 0xd5, 0xfa, 0x5f, 0xf1, 0x18, 0xc2, 0x20, 0xc5, 0x58, 0x90, 0x63, 0x4b, 0x12, 0xf3, 0xa4, 0xe9, 0x20, 0x03, 0x8f, 0x5a, 0x2d, 0x17, 0xbd, 0x75, 0x0a, 0xaf, 0x6d, 0xc5, 0x15, 0x8a, 0x14, 0x74, 0x7f, 0xa0, 0xd2, 0x0f, 0x6f, 0x96, 0xa5, 0x60, 0xb1, 0xb7, 0x65, 0x0f, 0x48, 0x67, 0x5d, 0x32, 0x0a, 0xcb, 0x8e, 0xdf, 0x0c, 0xa9, 0xd5, 0x14, 0x0b, 0x6d, 0xfb, 0x8b, 0xef, 0xa3, 0x79, 0xaf, 0xdb, 0xa3, 0xb4, 0x6d, 0xbb, 0x40, 0x9e, 0xb3, 0x45, 0x04, 0x7f, 0xd1, 0x84, 0xad, 0x90, 0x8b, 0x2d, 0xb6, 0x13, 0xfb, 0x7a, 0xf5, 0xad, 0xbf, 0xa6, 0x74, 0x75, 0xfa, 0x70, 0x59, 0xae, 0x22, 0xbb, 0xfb, 0x09, 0x68, 0xae, 0xe5, 0x26, 0x5c, 0xbd, 0xe0, 0xae, 0x39, 0xbb, 0xaa, 0x59, 0x4c, 0x73, 0x11, 0x01, 0x64, 0x6d, 0xc1, 0x95, 0x1b, 0x93, 0x6b, 0x14, 0x83, 0x4a, 0xdc, 0x16, 0x67, 0x7b, 0x85, 0xd0, 0x89, 0x2e, 0x3c, 0xa1, 0x05, 0x34, 0xf0, 0xd2, 0xb9, 0x3b, 0x83, 0xf4, 0x02, 0xd4, 0x7f, 0x73, 0x76, 0x5d, 0xc2, 0x67, 0xb9, 0xac, 0x8a, 0xd1, 0xab, 0xd4, 0x82 })); - Assert.IsTrue(m.F.Equals(BigInteger.Parse("139283707184174223973094328642546470115773370503206784462562067731214352325418848176518987606406368553205415627101408281035430394244245366884121855956041981785619368311948822371849754297010084387209814408417993188610908497995240761565618964080251146407679074869975343762660867551322434680855150842669738933549", System.Globalization.NumberStyles.None, CultureInfo.CurrentCulture))); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Tests.Common; +using System.Globalization; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + /// Represents SSH_MSG_KEX_DH_GEX_REPLY message. + /// + [TestClass] + public class KeyExchangeDhGroupExchangeReplyTest : TestBase + { + [TestMethod] + [TestCategory("KeyExchangeInitMessage")] + [Owner("olegkap")] + [Description("Validates KeyExchangeInitMessage message serialization.")] + public void Test_KeyExchangeDhGroupExchangeReply_Load() + { + var m = new KeyExchangeDhGroupExchangeReply(); + var input = new byte[] { 0x21, 0x00, 0x00, 0x01, 0x17, 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0xce, 0x38, 0xdf, 0x0d, 0x04, 0x2c, 0x10, 0x45, 0x8f, 0x5e, 0xeb, 0xc2, 0x35, 0x01, 0xd5, 0x4d, 0x09, 0xa3, 0xee, 0x74, 0x3d, 0x75, 0xcf, 0xf4, 0xf3, 0x4f, 0xc9, 0xf9, 0x2e, 0x59, 0xd6, 0xb8, 0x69, 0x85, 0x16, 0xac, 0x33, 0x5b, 0x2a, 0x2a, 0xf8, 0x9c, 0xc4, 0xc3, 0x87, 0xd6, 0xb8, 0x50, 0x6c, 0xed, 0x60, 0x9c, 0x0f, 0x83, 0x37, 0xb3, 0xa2, 0x25, 0xbe, 0x07, 0xde, 0xb6, 0x1f, 0x28, 0xab, 0x05, 0x21, 0xc0, 0x23, 0xf7, 0xd6, 0xca, 0xcb, 0x03, 0x42, 0x69, 0x31, 0x93, 0x2b, 0x3b, 0x94, 0xb8, 0x3b, 0x90, 0xe6, 0x25, 0x7c, 0x23, 0xc5, 0x24, 0x89, 0x65, 0x37, 0x7b, 0x56, 0x54, 0xa2, 0x23, 0xcb, 0xeb, 0xf0, 0xe9, 0xd1, 0x07, 0x88, 0x36, 0x8f, 0xef, 0x65, 0x71, 0xac, 0x80, 0x5c, 0x81, 0x0a, 0x95, 0x1c, 0xf5, 0xc0, 0x5d, 0xd3, 0xd4, 0x10, 0x0e, 0x4f, 0xcf, 0x87, 0x80, 0xa5, 0xde, 0x6e, 0xff, 0x89, 0x9c, 0xfc, 0x2f, 0x85, 0xf5, 0x93, 0xff, 0x70, 0x8e, 0x48, 0xb6, 0x6e, 0x6e, 0x0a, 0x18, 0xa3, 0xbb, 0x1c, 0x56, 0x60, 0xf1, 0x9d, 0x2a, 0xca, 0xbf, 0xa0, 0x84, 0x73, 0xb1, 0x6d, 0x10, 0x75, 0xcc, 0xa3, 0x20, 0xed, 0x00, 0x52, 0xd0, 0x84, 0x5a, 0xc9, 0xbb, 0x17, 0x84, 0x96, 0x40, 0x48, 0xe2, 0x8e, 0x84, 0x30, 0x82, 0x3b, 0x87, 0xa4, 0x54, 0x55, 0x8c, 0xb5, 0x62, 0x97, 0xd7, 0xf1, 0xa3, 0x8b, 0x44, 0xaa, 0x34, 0xfd, 0xe9, 0xad, 0xda, 0xeb, 0x45, 0x27, 0xfb, 0xad, 0xea, 0x9a, 0x0c, 0x38, 0x30, 0x27, 0x6a, 0x82, 0xc2, 0xc2, 0x0a, 0xa0, 0xed, 0x30, 0x2f, 0x50, 0x9f, 0xdb, 0x1a, 0xfb, 0x29, 0x1c, 0x8a, 0x28, 0x3f, 0xd6, 0xf6, 0xa9, 0xeb, 0x76, 0x60, 0xa2, 0x56, 0xa2, 0x90, 0x32, 0xcd, 0x25, 0x41, 0xb7, 0xc0, 0x9e, 0x13, 0x97, 0xaf, 0x00, 0x00, 0x00, 0x81, 0x00, 0xc6, 0x58, 0xb9, 0xa8, 0x11, 0xfd, 0xb6, 0xd6, 0xe9, 0x0c, 0x51, 0x45, 0xac, 0x51, 0x8a, 0x25, 0x6e, 0x1d, 0x9e, 0xbb, 0x7f, 0x98, 0xe3, 0x94, 0xd5, 0xac, 0x97, 0xd6, 0x35, 0x2e, 0xcc, 0x34, 0x85, 0xe2, 0x29, 0x2c, 0xba, 0x45, 0x6b, 0x39, 0xce, 0xd2, 0xae, 0x2e, 0x9a, 0x30, 0x43, 0x45, 0x09, 0xd2, 0xeb, 0x21, 0x46, 0x95, 0xa8, 0xb9, 0xbc, 0xb4, 0x21, 0xcd, 0x65, 0xeb, 0x0f, 0x48, 0x3c, 0x82, 0xdb, 0x52, 0x0e, 0xa5, 0xa8, 0xca, 0x29, 0x2d, 0xf8, 0x54, 0x38, 0xe4, 0x8f, 0x2c, 0x2d, 0x45, 0x2d, 0x2c, 0xf7, 0x1a, 0x41, 0xef, 0xd4, 0xec, 0x0f, 0xa5, 0xa8, 0xa7, 0x64, 0xb3, 0xe8, 0x7b, 0xa1, 0x40, 0x41, 0x69, 0x70, 0x4d, 0x95, 0x91, 0x8b, 0x5f, 0x28, 0xa2, 0xfc, 0xa7, 0x12, 0x2b, 0x94, 0xf0, 0x0a, 0x82, 0x92, 0x65, 0xdf, 0x8a, 0x35, 0xfb, 0xcc, 0xbe, 0xbd, 0x2d, 0x00, 0x00, 0x01, 0x0f, 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x67, 0x83, 0xa1, 0xb8, 0x0c, 0x65, 0xb8, 0xd3, 0x76, 0x5f, 0x5f, 0x05, 0x51, 0x8c, 0xb3, 0x2d, 0x1e, 0x95, 0x67, 0xd6, 0xe2, 0xe4, 0x86, 0x49, 0x11, 0xca, 0x83, 0xab, 0xdb, 0x80, 0x75, 0x4e, 0x89, 0xa7, 0x3d, 0xb6, 0xc2, 0x92, 0xbb, 0x40, 0x00, 0xb9, 0xb3, 0x03, 0x86, 0x19, 0x9d, 0x67, 0x29, 0x2b, 0x5a, 0xc9, 0x0a, 0x6c, 0xa3, 0x21, 0xaf, 0xd8, 0xd4, 0xa7, 0x84, 0x6a, 0xe5, 0x36, 0x3e, 0xa5, 0x58, 0xd6, 0x36, 0x33, 0x12, 0x2e, 0xf9, 0x22, 0x10, 0xff, 0xae, 0x0e, 0xee, 0xfa, 0xdf, 0x1f, 0xf8, 0x70, 0xfe, 0xc0, 0x30, 0x1d, 0x23, 0xbf, 0x99, 0x20, 0x22, 0x18, 0x78, 0xab, 0x5f, 0xd5, 0xfa, 0x5f, 0xf1, 0x18, 0xc2, 0x20, 0xc5, 0x58, 0x90, 0x63, 0x4b, 0x12, 0xf3, 0xa4, 0xe9, 0x20, 0x03, 0x8f, 0x5a, 0x2d, 0x17, 0xbd, 0x75, 0x0a, 0xaf, 0x6d, 0xc5, 0x15, 0x8a, 0x14, 0x74, 0x7f, 0xa0, 0xd2, 0x0f, 0x6f, 0x96, 0xa5, 0x60, 0xb1, 0xb7, 0x65, 0x0f, 0x48, 0x67, 0x5d, 0x32, 0x0a, 0xcb, 0x8e, 0xdf, 0x0c, 0xa9, 0xd5, 0x14, 0x0b, 0x6d, 0xfb, 0x8b, 0xef, 0xa3, 0x79, 0xaf, 0xdb, 0xa3, 0xb4, 0x6d, 0xbb, 0x40, 0x9e, 0xb3, 0x45, 0x04, 0x7f, 0xd1, 0x84, 0xad, 0x90, 0x8b, 0x2d, 0xb6, 0x13, 0xfb, 0x7a, 0xf5, 0xad, 0xbf, 0xa6, 0x74, 0x75, 0xfa, 0x70, 0x59, 0xae, 0x22, 0xbb, 0xfb, 0x09, 0x68, 0xae, 0xe5, 0x26, 0x5c, 0xbd, 0xe0, 0xae, 0x39, 0xbb, 0xaa, 0x59, 0x4c, 0x73, 0x11, 0x01, 0x64, 0x6d, 0xc1, 0x95, 0x1b, 0x93, 0x6b, 0x14, 0x83, 0x4a, 0xdc, 0x16, 0x67, 0x7b, 0x85, 0xd0, 0x89, 0x2e, 0x3c, 0xa1, 0x05, 0x34, 0xf0, 0xd2, 0xb9, 0x3b, 0x83, 0xf4, 0x02, 0xd4, 0x7f, 0x73, 0x76, 0x5d, 0xc2, 0x67, 0xb9, 0xac, 0x8a, 0xd1, 0xab, 0xd4, 0x82 }; + m.Load(input); + + Assert.IsTrue(m.HostKey.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0xce, 0x38, 0xdf, 0x0d, 0x04, 0x2c, 0x10, 0x45, 0x8f, 0x5e, 0xeb, 0xc2, 0x35, 0x01, 0xd5, 0x4d, 0x09, 0xa3, 0xee, 0x74, 0x3d, 0x75, 0xcf, 0xf4, 0xf3, 0x4f, 0xc9, 0xf9, 0x2e, 0x59, 0xd6, 0xb8, 0x69, 0x85, 0x16, 0xac, 0x33, 0x5b, 0x2a, 0x2a, 0xf8, 0x9c, 0xc4, 0xc3, 0x87, 0xd6, 0xb8, 0x50, 0x6c, 0xed, 0x60, 0x9c, 0x0f, 0x83, 0x37, 0xb3, 0xa2, 0x25, 0xbe, 0x07, 0xde, 0xb6, 0x1f, 0x28, 0xab, 0x05, 0x21, 0xc0, 0x23, 0xf7, 0xd6, 0xca, 0xcb, 0x03, 0x42, 0x69, 0x31, 0x93, 0x2b, 0x3b, 0x94, 0xb8, 0x3b, 0x90, 0xe6, 0x25, 0x7c, 0x23, 0xc5, 0x24, 0x89, 0x65, 0x37, 0x7b, 0x56, 0x54, 0xa2, 0x23, 0xcb, 0xeb, 0xf0, 0xe9, 0xd1, 0x07, 0x88, 0x36, 0x8f, 0xef, 0x65, 0x71, 0xac, 0x80, 0x5c, 0x81, 0x0a, 0x95, 0x1c, 0xf5, 0xc0, 0x5d, 0xd3, 0xd4, 0x10, 0x0e, 0x4f, 0xcf, 0x87, 0x80, 0xa5, 0xde, 0x6e, 0xff, 0x89, 0x9c, 0xfc, 0x2f, 0x85, 0xf5, 0x93, 0xff, 0x70, 0x8e, 0x48, 0xb6, 0x6e, 0x6e, 0x0a, 0x18, 0xa3, 0xbb, 0x1c, 0x56, 0x60, 0xf1, 0x9d, 0x2a, 0xca, 0xbf, 0xa0, 0x84, 0x73, 0xb1, 0x6d, 0x10, 0x75, 0xcc, 0xa3, 0x20, 0xed, 0x00, 0x52, 0xd0, 0x84, 0x5a, 0xc9, 0xbb, 0x17, 0x84, 0x96, 0x40, 0x48, 0xe2, 0x8e, 0x84, 0x30, 0x82, 0x3b, 0x87, 0xa4, 0x54, 0x55, 0x8c, 0xb5, 0x62, 0x97, 0xd7, 0xf1, 0xa3, 0x8b, 0x44, 0xaa, 0x34, 0xfd, 0xe9, 0xad, 0xda, 0xeb, 0x45, 0x27, 0xfb, 0xad, 0xea, 0x9a, 0x0c, 0x38, 0x30, 0x27, 0x6a, 0x82, 0xc2, 0xc2, 0x0a, 0xa0, 0xed, 0x30, 0x2f, 0x50, 0x9f, 0xdb, 0x1a, 0xfb, 0x29, 0x1c, 0x8a, 0x28, 0x3f, 0xd6, 0xf6, 0xa9, 0xeb, 0x76, 0x60, 0xa2, 0x56, 0xa2, 0x90, 0x32, 0xcd, 0x25, 0x41, 0xb7, 0xc0, 0x9e, 0x13, 0x97, 0xaf })); + Assert.IsTrue(m.Signature.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x67, 0x83, 0xa1, 0xb8, 0x0c, 0x65, 0xb8, 0xd3, 0x76, 0x5f, 0x5f, 0x05, 0x51, 0x8c, 0xb3, 0x2d, 0x1e, 0x95, 0x67, 0xd6, 0xe2, 0xe4, 0x86, 0x49, 0x11, 0xca, 0x83, 0xab, 0xdb, 0x80, 0x75, 0x4e, 0x89, 0xa7, 0x3d, 0xb6, 0xc2, 0x92, 0xbb, 0x40, 0x00, 0xb9, 0xb3, 0x03, 0x86, 0x19, 0x9d, 0x67, 0x29, 0x2b, 0x5a, 0xc9, 0x0a, 0x6c, 0xa3, 0x21, 0xaf, 0xd8, 0xd4, 0xa7, 0x84, 0x6a, 0xe5, 0x36, 0x3e, 0xa5, 0x58, 0xd6, 0x36, 0x33, 0x12, 0x2e, 0xf9, 0x22, 0x10, 0xff, 0xae, 0x0e, 0xee, 0xfa, 0xdf, 0x1f, 0xf8, 0x70, 0xfe, 0xc0, 0x30, 0x1d, 0x23, 0xbf, 0x99, 0x20, 0x22, 0x18, 0x78, 0xab, 0x5f, 0xd5, 0xfa, 0x5f, 0xf1, 0x18, 0xc2, 0x20, 0xc5, 0x58, 0x90, 0x63, 0x4b, 0x12, 0xf3, 0xa4, 0xe9, 0x20, 0x03, 0x8f, 0x5a, 0x2d, 0x17, 0xbd, 0x75, 0x0a, 0xaf, 0x6d, 0xc5, 0x15, 0x8a, 0x14, 0x74, 0x7f, 0xa0, 0xd2, 0x0f, 0x6f, 0x96, 0xa5, 0x60, 0xb1, 0xb7, 0x65, 0x0f, 0x48, 0x67, 0x5d, 0x32, 0x0a, 0xcb, 0x8e, 0xdf, 0x0c, 0xa9, 0xd5, 0x14, 0x0b, 0x6d, 0xfb, 0x8b, 0xef, 0xa3, 0x79, 0xaf, 0xdb, 0xa3, 0xb4, 0x6d, 0xbb, 0x40, 0x9e, 0xb3, 0x45, 0x04, 0x7f, 0xd1, 0x84, 0xad, 0x90, 0x8b, 0x2d, 0xb6, 0x13, 0xfb, 0x7a, 0xf5, 0xad, 0xbf, 0xa6, 0x74, 0x75, 0xfa, 0x70, 0x59, 0xae, 0x22, 0xbb, 0xfb, 0x09, 0x68, 0xae, 0xe5, 0x26, 0x5c, 0xbd, 0xe0, 0xae, 0x39, 0xbb, 0xaa, 0x59, 0x4c, 0x73, 0x11, 0x01, 0x64, 0x6d, 0xc1, 0x95, 0x1b, 0x93, 0x6b, 0x14, 0x83, 0x4a, 0xdc, 0x16, 0x67, 0x7b, 0x85, 0xd0, 0x89, 0x2e, 0x3c, 0xa1, 0x05, 0x34, 0xf0, 0xd2, 0xb9, 0x3b, 0x83, 0xf4, 0x02, 0xd4, 0x7f, 0x73, 0x76, 0x5d, 0xc2, 0x67, 0xb9, 0xac, 0x8a, 0xd1, 0xab, 0xd4, 0x82 })); + Assert.IsTrue(m.F.Equals(BigInteger.Parse("139283707184174223973094328642546470115773370503206784462562067731214352325418848176518987606406368553205415627101408281035430394244245366884121855956041981785619368311948822371849754297010084387209814408417993188610908497995240761565618964080251146407679074869975343762660867551322434680855150842669738933549", System.Globalization.NumberStyles.None, CultureInfo.CurrentCulture))); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeRequestTest.cs index 09b946b5..f0562b8c 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhGroupExchangeRequestTest.cs @@ -1,70 +1,70 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - /// Represents SSH_MSG_KEX_DH_GEX_REQUEST message. - /// - [TestClass] - public class KeyExchangeDhGroupExchangeRequestTest - { - private uint _minimum; - private uint _preferred; - private uint _maximum; - - public void Init() - { - var random = new Random(); - _minimum = (uint) random.Next(1, int.MaxValue); - _preferred = (uint) random.Next(1, int.MaxValue); - _maximum = (uint) random.Next(1, int.MaxValue); - } - - - [TestMethod] - [TestCategory("KeyExchangeInitMessage")] - [Owner("olegkap")] - [Description("Validates KeyExchangeInitMessage message serialization.")] - public void Test_KeyExchangeDhGroupExchangeRequest_GetBytes() - { - var request = new KeyExchangeDhGroupExchangeRequest(_minimum, _preferred, _maximum); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // Minimum - expectedBytesLength += 4; // Preferred - expectedBytesLength += 4; // Maximum - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual(KeyExchangeDhGroupExchangeRequest.MessageNumber, sshDataStream.ReadByte()); - Assert.AreEqual(_minimum, sshDataStream.ReadUInt32()); - Assert.AreEqual(_preferred, sshDataStream.ReadUInt32()); - Assert.AreEqual(_maximum, sshDataStream.ReadUInt32()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - - [TestMethod] - public void Load() - { - var request = new KeyExchangeDhGroupExchangeRequest(_minimum, _preferred, _maximum); - var bytes = request.GetBytes(); - var target = new KeyExchangeDhGroupExchangeRequest(0, 0, 0); - - target.Load(bytes); - - Assert.AreEqual(_minimum, target.Minimum); - Assert.AreEqual(_preferred, target.Preferred); - Assert.AreEqual(_maximum, target.Maximum); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + /// Represents SSH_MSG_KEX_DH_GEX_REQUEST message. + /// + [TestClass] + public class KeyExchangeDhGroupExchangeRequestTest + { + private uint _minimum; + private uint _preferred; + private uint _maximum; + + public void Init() + { + var random = new Random(); + _minimum = (uint) random.Next(1, int.MaxValue); + _preferred = (uint) random.Next(1, int.MaxValue); + _maximum = (uint) random.Next(1, int.MaxValue); + } + + + [TestMethod] + [TestCategory("KeyExchangeInitMessage")] + [Owner("olegkap")] + [Description("Validates KeyExchangeInitMessage message serialization.")] + public void Test_KeyExchangeDhGroupExchangeRequest_GetBytes() + { + var request = new KeyExchangeDhGroupExchangeRequest(_minimum, _preferred, _maximum); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // Minimum + expectedBytesLength += 4; // Preferred + expectedBytesLength += 4; // Maximum + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual(KeyExchangeDhGroupExchangeRequest.MessageNumber, sshDataStream.ReadByte()); + Assert.AreEqual(_minimum, sshDataStream.ReadUInt32()); + Assert.AreEqual(_preferred, sshDataStream.ReadUInt32()); + Assert.AreEqual(_maximum, sshDataStream.ReadUInt32()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + + [TestMethod] + public void Load() + { + var request = new KeyExchangeDhGroupExchangeRequest(_minimum, _preferred, _maximum); + var bytes = request.GetBytes(); + var target = new KeyExchangeDhGroupExchangeRequest(0, 0, 0); + + target.Load(bytes); + + Assert.AreEqual(_minimum, target.Minimum); + Assert.AreEqual(_preferred, target.Preferred); + Assert.AreEqual(_maximum, target.Maximum); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhInitMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhInitMessageTest.cs index 53ad23b8..01fd5515 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhInitMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhInitMessageTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - /// Represents SSH_MSG_KEXDH_INIT message. - /// - [TestClass] - public class KeyExchangeDhInitMessageTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + /// Represents SSH_MSG_KEXDH_INIT message. + /// + [TestClass] + public class KeyExchangeDhInitMessageTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhReplyMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhReplyMessageTest.cs index 75bba64d..845c1cd0 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhReplyMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeDhReplyMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for KeyExchangeDhReplyMessageTest and is intended - ///to contain all KeyExchangeDhReplyMessageTest Unit Tests - /// - [TestClass()] - public class KeyExchangeDhReplyMessageTest : TestBase - { - /// - ///A test for KeyExchangeDhReplyMessage Constructor - /// - [TestMethod()] - public void KeyExchangeDhReplyMessageConstructorTest() - { - KeyExchangeDhReplyMessage target = new KeyExchangeDhReplyMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for KeyExchangeDhReplyMessageTest and is intended + ///to contain all KeyExchangeDhReplyMessageTest Unit Tests + /// + [TestClass()] + public class KeyExchangeDhReplyMessageTest : TestBase + { + /// + ///A test for KeyExchangeDhReplyMessage Constructor + /// + [TestMethod()] + public void KeyExchangeDhReplyMessageConstructorTest() + { + KeyExchangeDhReplyMessage target = new KeyExchangeDhReplyMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs index 904b8540..4b75050f 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/KeyExchangeInitMessageTest.cs @@ -1,258 +1,258 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Tests.Common; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - /// Represents SSH_MSG_KEXINIT message. - /// - [TestClass] - public class KeyExchangeInitMessageTest : TestBase - { - [TestMethod] - [TestCategory("KeyExchangeInitMessage")] - [Owner("olegkap")] - [Description("Validates KeyExchangeInitMessage message deserialization.")] - public void Test_KeyExchangeInitMessage_Load() - { - var m = new KeyExchangeInitMessage(); - var input = new byte[] { 0x14, 0xc9, 0x58, 0x3f, 0x44, 0x54, 0xb4, 0x58, 0x48, 0x5f, 0xf8, 0x7d, 0xb8, 0x2d, 0x54, 0x11, 0xbf, 0x00, 0x00, 0x00, 0xb7, 0x65, 0x63, 0x64, 0x68, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x32, 0x35, 0x36, 0x2c, 0x65, 0x63, 0x64, 0x68, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x33, 0x38, 0x34, 0x2c, 0x65, 0x63, 0x64, 0x68, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x35, 0x32, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x35, 0x36, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x34, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x23, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x2c, 0x73, 0x73, 0x68, 0x2d, 0x64, 0x73, 0x73, 0x2c, 0x65, 0x63, 0x64, 0x73, 0x61, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x32, 0x35, 0x36, 0x00, 0x00, 0x00, 0x9d, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x32, 0x35, 0x36, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x31, 0x32, 0x38, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x2c, 0x72, 0x69, 0x6a, 0x6e, 0x64, 0x61, 0x65, 0x6c, 0x2d, 0x63, 0x62, 0x63, 0x40, 0x6c, 0x79, 0x73, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x6c, 0x69, 0x75, 0x2e, 0x73, 0x65, 0x00, 0x00, 0x00, 0x9d, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x32, 0x35, 0x36, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x31, 0x32, 0x38, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x2c, 0x72, 0x69, 0x6a, 0x6e, 0x64, 0x61, 0x65, 0x6c, 0x2d, 0x63, 0x62, 0x63, 0x40, 0x6c, 0x79, 0x73, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x6c, 0x69, 0x75, 0x2e, 0x73, 0x65, 0x00, 0x00, 0x00, 0xa7, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x75, 0x6d, 0x61, 0x63, 0x2d, 0x36, 0x34, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2d, 0x39, 0x36, 0x00, 0x00, 0x00, 0xa7, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x75, 0x6d, 0x61, 0x63, 0x2d, 0x36, 0x34, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2d, 0x39, 0x36, 0x00, 0x00, 0x00, 0x15, 0x6e, 0x6f, 0x6e, 0x65, 0x2c, 0x7a, 0x6c, 0x69, 0x62, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x15, 0x6e, 0x6f, 0x6e, 0x65, 0x2c, 0x7a, 0x6c, 0x69, 0x62, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - m.Load(input); - - Assert.IsFalse(m.FirstKexPacketFollows); - Assert.IsTrue(m.Reserved == 0); - Assert.IsTrue(m.CompressionAlgorithmsClientToServer.SequenceEqual(new string[] { "none", "zlib@openssh.com" })); - Assert.IsTrue(m.CompressionAlgorithmsServerToClient.SequenceEqual(new string[] { "none", "zlib@openssh.com" })); - Assert.IsTrue(m.EncryptionAlgorithmsClientToServer.SequenceEqual(new string[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "rijndael-cbc@lysator.liu.se" })); - Assert.IsTrue(m.EncryptionAlgorithmsServerToClient.SequenceEqual(new string[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "rijndael-cbc@lysator.liu.se" })); - Assert.IsTrue(m.KeyExchangeAlgorithms.SequenceEqual(new string[] { "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521", "diffie-hellman-group-exchange-sha256", "diffie-hellman-group-exchange-sha1", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1" })); - Assert.IsTrue(m.LanguagesClientToServer.SequenceEqual(new string[] { "" })); - Assert.IsTrue(m.LanguagesServerToClient.SequenceEqual(new string[] { "" })); - Assert.IsTrue(m.MacAlgorithmsClientToServer.SequenceEqual(new string[] { "hmac-md5", "hmac-sha1", "umac-64@openssh.com", "hmac-sha2-256", "hmac-sha2-256-96", "hmac-sha2-512", "hmac-sha2-512-96", "hmac-ripemd160", "hmac-ripemd160@openssh.com", "hmac-sha1-96", "hmac-md5-96" })); - Assert.IsTrue(m.MacAlgorithmsServerToClient.SequenceEqual(new string[] { "hmac-md5", "hmac-sha1", "umac-64@openssh.com", "hmac-sha2-256", "hmac-sha2-256-96", "hmac-sha2-512", "hmac-sha2-512-96", "hmac-ripemd160", "hmac-ripemd160@openssh.com", "hmac-sha1-96", "hmac-md5-96" })); - Assert.IsTrue(m.ServerHostKeyAlgorithms.SequenceEqual(new string[] { "ssh-rsa", "ssh-dss", "ecdsa-sha2-nistp256" })); - } - - [TestMethod] - [TestCategory("KeyExchangeInitMessage")] - [Owner("olegkap")] - [Description("Validates KeyExchangeInitMessage message serialization.")] - public void Test_KeyExchangeInitMessage_GetBytes() - { - var m = new KeyExchangeInitMessage() - { - KeyExchangeAlgorithms = new string[] { "diffie-hellman-group-exchange-sha256", "diffie-hellman-group-exchange-sha1", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1" }, - ServerHostKeyAlgorithms = new string[] { "ssh-rsa", "ssh-dss" }, - EncryptionAlgorithmsClientToServer = new string[] { "aes256-ctr", "3des-cbc", "aes128-cbc", "aes192-cbc", "aes256-cbc", "blowfish-cbc", "cast128-cbc", "aes128-ctr", "aes192-ctr" }, - EncryptionAlgorithmsServerToClient = new string[] { "aes256-ctr", "3des-cbc", "aes128-cbc", "aes192-cbc", "aes256-cbc", "blowfish-cbc", "cast128-cbc", "aes128-ctr", "aes192-ctr" }, - MacAlgorithmsClientToServer = new string[] { "hmac-md5", "hmac-sha1", }, - MacAlgorithmsServerToClient = new string[] { "hmac-md5", "hmac-sha1", }, - CompressionAlgorithmsClientToServer = new string[] { "none" }, - CompressionAlgorithmsServerToClient = new string[] { "none" }, - LanguagesClientToServer = new string[] { string.Empty }, - LanguagesServerToClient = new string[] { string.Empty }, - FirstKexPacketFollows = false, - Reserved = 0, - }; - - var input = new byte[] { 0x14, 0xf3, 0x3b, 0xf9, 0x5e, 0x70, 0x18, 0x6a, 0x43, 0x3d, 0x93, 0x9e, 0x1c, 0x50, 0x4a, 0x8a, 0x33, 0x00, 0x00, 0x00, 0x7e, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x35, 0x36, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x34, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x0f, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x2c, 0x73, 0x73, 0x68, 0x2d, 0x64, 0x73, 0x73, 0x00, 0x00, 0x00, 0x63, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x00, 0x00, 0x00, 0x63, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x00, 0x00, 0x00, 0x12, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x12, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - var output = m.GetBytes(); - - // Skip first 17 bytes since 16 bytes are randomly generated - Assert.IsTrue(input.Skip(17).SequenceEqual(output.Skip(17))); - - } - - /// - ///A test for KeyExchangeInitMessage Constructor - /// - [TestMethod()] - public void KeyExchangeInitMessageConstructorTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for CompressionAlgorithmsClientToServer - /// - [TestMethod()] - public void CompressionAlgorithmsClientToServerTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.CompressionAlgorithmsClientToServer = expected; - actual = target.CompressionAlgorithmsClientToServer; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CompressionAlgorithmsServerToClient - /// - [TestMethod()] - public void CompressionAlgorithmsServerToClientTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.CompressionAlgorithmsServerToClient = expected; - actual = target.CompressionAlgorithmsServerToClient; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptionAlgorithmsClientToServer - /// - [TestMethod()] - public void EncryptionAlgorithmsClientToServerTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.EncryptionAlgorithmsClientToServer = expected; - actual = target.EncryptionAlgorithmsClientToServer; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptionAlgorithmsServerToClient - /// - [TestMethod()] - public void EncryptionAlgorithmsServerToClientTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.EncryptionAlgorithmsServerToClient = expected; - actual = target.EncryptionAlgorithmsServerToClient; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for FirstKexPacketFollows - /// - [TestMethod()] - public void FirstKexPacketFollowsTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.FirstKexPacketFollows = expected; - actual = target.FirstKexPacketFollows; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for KeyExchangeAlgorithms - /// - [TestMethod()] - public void KeyExchangeAlgorithmsTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.KeyExchangeAlgorithms = expected; - actual = target.KeyExchangeAlgorithms; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for LanguagesClientToServer - /// - [TestMethod()] - public void LanguagesClientToServerTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.LanguagesClientToServer = expected; - actual = target.LanguagesClientToServer; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for LanguagesServerToClient - /// - [TestMethod()] - public void LanguagesServerToClientTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.LanguagesServerToClient = expected; - actual = target.LanguagesServerToClient; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for MacAlgorithmsClientToServer - /// - [TestMethod()] - public void MacAlgorithmsClientToServerTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.MacAlgorithmsClientToServer = expected; - actual = target.MacAlgorithmsClientToServer; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for MacAlgorithmsServerToClient - /// - [TestMethod()] - public void MacAlgorithmsServerToClientTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.MacAlgorithmsServerToClient = expected; - actual = target.MacAlgorithmsServerToClient; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Reserved - /// - [TestMethod()] - public void ReservedTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - uint expected = 0; // TODO: Initialize to an appropriate value - uint actual; - target.Reserved = expected; - actual = target.Reserved; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ServerHostKeyAlgorithms - /// - [TestMethod()] - public void ServerHostKeyAlgorithmsTest() - { - KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - target.ServerHostKeyAlgorithms = expected; - actual = target.ServerHostKeyAlgorithms; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Tests.Common; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + /// Represents SSH_MSG_KEXINIT message. + /// + [TestClass] + public class KeyExchangeInitMessageTest : TestBase + { + [TestMethod] + [TestCategory("KeyExchangeInitMessage")] + [Owner("olegkap")] + [Description("Validates KeyExchangeInitMessage message deserialization.")] + public void Test_KeyExchangeInitMessage_Load() + { + var m = new KeyExchangeInitMessage(); + var input = new byte[] { 0x14, 0xc9, 0x58, 0x3f, 0x44, 0x54, 0xb4, 0x58, 0x48, 0x5f, 0xf8, 0x7d, 0xb8, 0x2d, 0x54, 0x11, 0xbf, 0x00, 0x00, 0x00, 0xb7, 0x65, 0x63, 0x64, 0x68, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x32, 0x35, 0x36, 0x2c, 0x65, 0x63, 0x64, 0x68, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x33, 0x38, 0x34, 0x2c, 0x65, 0x63, 0x64, 0x68, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x35, 0x32, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x35, 0x36, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x34, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x23, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x2c, 0x73, 0x73, 0x68, 0x2d, 0x64, 0x73, 0x73, 0x2c, 0x65, 0x63, 0x64, 0x73, 0x61, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x6e, 0x69, 0x73, 0x74, 0x70, 0x32, 0x35, 0x36, 0x00, 0x00, 0x00, 0x9d, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x32, 0x35, 0x36, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x31, 0x32, 0x38, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x2c, 0x72, 0x69, 0x6a, 0x6e, 0x64, 0x61, 0x65, 0x6c, 0x2d, 0x63, 0x62, 0x63, 0x40, 0x6c, 0x79, 0x73, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x6c, 0x69, 0x75, 0x2e, 0x73, 0x65, 0x00, 0x00, 0x00, 0x9d, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x32, 0x35, 0x36, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x31, 0x32, 0x38, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x72, 0x63, 0x66, 0x6f, 0x75, 0x72, 0x2c, 0x72, 0x69, 0x6a, 0x6e, 0x64, 0x61, 0x65, 0x6c, 0x2d, 0x63, 0x62, 0x63, 0x40, 0x6c, 0x79, 0x73, 0x61, 0x74, 0x6f, 0x72, 0x2e, 0x6c, 0x69, 0x75, 0x2e, 0x73, 0x65, 0x00, 0x00, 0x00, 0xa7, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x75, 0x6d, 0x61, 0x63, 0x2d, 0x36, 0x34, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2d, 0x39, 0x36, 0x00, 0x00, 0x00, 0xa7, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x75, 0x6d, 0x61, 0x63, 0x2d, 0x36, 0x34, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x32, 0x35, 0x36, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x2d, 0x35, 0x31, 0x32, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x72, 0x69, 0x70, 0x65, 0x6d, 0x64, 0x31, 0x36, 0x30, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2d, 0x39, 0x36, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2d, 0x39, 0x36, 0x00, 0x00, 0x00, 0x15, 0x6e, 0x6f, 0x6e, 0x65, 0x2c, 0x7a, 0x6c, 0x69, 0x62, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x15, 0x6e, 0x6f, 0x6e, 0x65, 0x2c, 0x7a, 0x6c, 0x69, 0x62, 0x40, 0x6f, 0x70, 0x65, 0x6e, 0x73, 0x73, 0x68, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + m.Load(input); + + Assert.IsFalse(m.FirstKexPacketFollows); + Assert.IsTrue(m.Reserved == 0); + Assert.IsTrue(m.CompressionAlgorithmsClientToServer.SequenceEqual(new string[] { "none", "zlib@openssh.com" })); + Assert.IsTrue(m.CompressionAlgorithmsServerToClient.SequenceEqual(new string[] { "none", "zlib@openssh.com" })); + Assert.IsTrue(m.EncryptionAlgorithmsClientToServer.SequenceEqual(new string[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "rijndael-cbc@lysator.liu.se" })); + Assert.IsTrue(m.EncryptionAlgorithmsServerToClient.SequenceEqual(new string[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "rijndael-cbc@lysator.liu.se" })); + Assert.IsTrue(m.KeyExchangeAlgorithms.SequenceEqual(new string[] { "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521", "diffie-hellman-group-exchange-sha256", "diffie-hellman-group-exchange-sha1", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1" })); + Assert.IsTrue(m.LanguagesClientToServer.SequenceEqual(new string[] { "" })); + Assert.IsTrue(m.LanguagesServerToClient.SequenceEqual(new string[] { "" })); + Assert.IsTrue(m.MacAlgorithmsClientToServer.SequenceEqual(new string[] { "hmac-md5", "hmac-sha1", "umac-64@openssh.com", "hmac-sha2-256", "hmac-sha2-256-96", "hmac-sha2-512", "hmac-sha2-512-96", "hmac-ripemd160", "hmac-ripemd160@openssh.com", "hmac-sha1-96", "hmac-md5-96" })); + Assert.IsTrue(m.MacAlgorithmsServerToClient.SequenceEqual(new string[] { "hmac-md5", "hmac-sha1", "umac-64@openssh.com", "hmac-sha2-256", "hmac-sha2-256-96", "hmac-sha2-512", "hmac-sha2-512-96", "hmac-ripemd160", "hmac-ripemd160@openssh.com", "hmac-sha1-96", "hmac-md5-96" })); + Assert.IsTrue(m.ServerHostKeyAlgorithms.SequenceEqual(new string[] { "ssh-rsa", "ssh-dss", "ecdsa-sha2-nistp256" })); + } + + [TestMethod] + [TestCategory("KeyExchangeInitMessage")] + [Owner("olegkap")] + [Description("Validates KeyExchangeInitMessage message serialization.")] + public void Test_KeyExchangeInitMessage_GetBytes() + { + var m = new KeyExchangeInitMessage() + { + KeyExchangeAlgorithms = new string[] { "diffie-hellman-group-exchange-sha256", "diffie-hellman-group-exchange-sha1", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1" }, + ServerHostKeyAlgorithms = new string[] { "ssh-rsa", "ssh-dss" }, + EncryptionAlgorithmsClientToServer = new string[] { "aes256-ctr", "3des-cbc", "aes128-cbc", "aes192-cbc", "aes256-cbc", "blowfish-cbc", "cast128-cbc", "aes128-ctr", "aes192-ctr" }, + EncryptionAlgorithmsServerToClient = new string[] { "aes256-ctr", "3des-cbc", "aes128-cbc", "aes192-cbc", "aes256-cbc", "blowfish-cbc", "cast128-cbc", "aes128-ctr", "aes192-ctr" }, + MacAlgorithmsClientToServer = new string[] { "hmac-md5", "hmac-sha1", }, + MacAlgorithmsServerToClient = new string[] { "hmac-md5", "hmac-sha1", }, + CompressionAlgorithmsClientToServer = new string[] { "none" }, + CompressionAlgorithmsServerToClient = new string[] { "none" }, + LanguagesClientToServer = new string[] { string.Empty }, + LanguagesServerToClient = new string[] { string.Empty }, + FirstKexPacketFollows = false, + Reserved = 0, + }; + + var input = new byte[] { 0x14, 0xf3, 0x3b, 0xf9, 0x5e, 0x70, 0x18, 0x6a, 0x43, 0x3d, 0x93, 0x9e, 0x1c, 0x50, 0x4a, 0x8a, 0x33, 0x00, 0x00, 0x00, 0x7e, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x32, 0x35, 0x36, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x2d, 0x65, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x34, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x2c, 0x64, 0x69, 0x66, 0x66, 0x69, 0x65, 0x2d, 0x68, 0x65, 0x6c, 0x6c, 0x6d, 0x61, 0x6e, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x31, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x0f, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x2c, 0x73, 0x73, 0x68, 0x2d, 0x64, 0x73, 0x73, 0x00, 0x00, 0x00, 0x63, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x00, 0x00, 0x00, 0x63, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x33, 0x64, 0x65, 0x73, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x32, 0x35, 0x36, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x62, 0x6c, 0x6f, 0x77, 0x66, 0x69, 0x73, 0x68, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x63, 0x61, 0x73, 0x74, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x62, 0x63, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x32, 0x38, 0x2d, 0x63, 0x74, 0x72, 0x2c, 0x61, 0x65, 0x73, 0x31, 0x39, 0x32, 0x2d, 0x63, 0x74, 0x72, 0x00, 0x00, 0x00, 0x12, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x12, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x6d, 0x64, 0x35, 0x2c, 0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x68, 0x61, 0x31, 0x00, 0x00, 0x00, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x04, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + var output = m.GetBytes(); + + // Skip first 17 bytes since 16 bytes are randomly generated + Assert.IsTrue(input.Skip(17).SequenceEqual(output.Skip(17))); + + } + + /// + ///A test for KeyExchangeInitMessage Constructor + /// + [TestMethod()] + public void KeyExchangeInitMessageConstructorTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for CompressionAlgorithmsClientToServer + /// + [TestMethod()] + public void CompressionAlgorithmsClientToServerTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.CompressionAlgorithmsClientToServer = expected; + actual = target.CompressionAlgorithmsClientToServer; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CompressionAlgorithmsServerToClient + /// + [TestMethod()] + public void CompressionAlgorithmsServerToClientTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.CompressionAlgorithmsServerToClient = expected; + actual = target.CompressionAlgorithmsServerToClient; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptionAlgorithmsClientToServer + /// + [TestMethod()] + public void EncryptionAlgorithmsClientToServerTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.EncryptionAlgorithmsClientToServer = expected; + actual = target.EncryptionAlgorithmsClientToServer; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptionAlgorithmsServerToClient + /// + [TestMethod()] + public void EncryptionAlgorithmsServerToClientTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.EncryptionAlgorithmsServerToClient = expected; + actual = target.EncryptionAlgorithmsServerToClient; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for FirstKexPacketFollows + /// + [TestMethod()] + public void FirstKexPacketFollowsTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.FirstKexPacketFollows = expected; + actual = target.FirstKexPacketFollows; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for KeyExchangeAlgorithms + /// + [TestMethod()] + public void KeyExchangeAlgorithmsTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.KeyExchangeAlgorithms = expected; + actual = target.KeyExchangeAlgorithms; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for LanguagesClientToServer + /// + [TestMethod()] + public void LanguagesClientToServerTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.LanguagesClientToServer = expected; + actual = target.LanguagesClientToServer; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for LanguagesServerToClient + /// + [TestMethod()] + public void LanguagesServerToClientTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.LanguagesServerToClient = expected; + actual = target.LanguagesServerToClient; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for MacAlgorithmsClientToServer + /// + [TestMethod()] + public void MacAlgorithmsClientToServerTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.MacAlgorithmsClientToServer = expected; + actual = target.MacAlgorithmsClientToServer; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for MacAlgorithmsServerToClient + /// + [TestMethod()] + public void MacAlgorithmsServerToClientTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.MacAlgorithmsServerToClient = expected; + actual = target.MacAlgorithmsServerToClient; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Reserved + /// + [TestMethod()] + public void ReservedTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + uint expected = 0; // TODO: Initialize to an appropriate value + uint actual; + target.Reserved = expected; + actual = target.Reserved; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ServerHostKeyAlgorithms + /// + [TestMethod()] + public void ServerHostKeyAlgorithmsTest() + { + KeyExchangeInitMessage target = new KeyExchangeInitMessage(); // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + target.ServerHostKeyAlgorithms = expected; + actual = target.ServerHostKeyAlgorithms; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/NewKeysMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/NewKeysMessageTest.cs index deadebc5..2b586048 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/NewKeysMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/NewKeysMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for NewKeysMessageTest and is intended - ///to contain all NewKeysMessageTest Unit Tests - /// - [TestClass()] - public class NewKeysMessageTest : TestBase - { - /// - ///A test for NewKeysMessage Constructor - /// - [TestMethod()] - public void NewKeysMessageConstructorTest() - { - NewKeysMessage target = new NewKeysMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for NewKeysMessageTest and is intended + ///to contain all NewKeysMessageTest Unit Tests + /// + [TestClass()] + public class NewKeysMessageTest : TestBase + { + /// + ///A test for NewKeysMessage Constructor + /// + [TestMethod()] + public void NewKeysMessageConstructorTest() + { + NewKeysMessage target = new NewKeysMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceAcceptMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceAcceptMessageTest.cs index 29311901..a0880a97 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceAcceptMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceAcceptMessageTest.cs @@ -1,24 +1,24 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for ServiceAcceptMessageTest and is intended - ///to contain all ServiceAcceptMessageTest Unit Tests - /// - [TestClass()] - public class ServiceAcceptMessageTest - { - /// - ///A test for ServiceAcceptMessage Constructor - /// - [TestMethod()] - public void ServiceAcceptMessageConstructorTest() - { - ServiceAcceptMessage target = new ServiceAcceptMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for ServiceAcceptMessageTest and is intended + ///to contain all ServiceAcceptMessageTest Unit Tests + /// + [TestClass()] + public class ServiceAcceptMessageTest + { + /// + ///A test for ServiceAcceptMessage Constructor + /// + [TestMethod()] + public void ServiceAcceptMessageConstructorTest() + { + ServiceAcceptMessage target = new ServiceAcceptMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceRequestMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceRequestMessageTest.cs index ffbeeef5..a352f046 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceRequestMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/ServiceRequestMessageTest.cs @@ -1,26 +1,26 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Messages; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for ServiceRequestMessageTest and is intended - ///to contain all ServiceRequestMessageTest Unit Tests - /// - [TestClass()] - public class ServiceRequestMessageTest - { - /// - ///A test for ServiceRequestMessage Constructor - /// - [TestMethod()] - public void ServiceRequestMessageConstructorTest() - { - ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value - ServiceRequestMessage target = new ServiceRequestMessage(serviceName); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Messages; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for ServiceRequestMessageTest and is intended + ///to contain all ServiceRequestMessageTest Unit Tests + /// + [TestClass()] + public class ServiceRequestMessageTest + { + /// + ///A test for ServiceRequestMessage Constructor + /// + [TestMethod()] + public void ServiceRequestMessageConstructorTest() + { + ServiceName serviceName = new ServiceName(); // TODO: Initialize to an appropriate value + ServiceRequestMessage target = new ServiceRequestMessage(serviceName); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Messages/Transport/UnimplementedMessageTest.cs b/src/Renci.SshNet.Tests/Classes/Messages/Transport/UnimplementedMessageTest.cs index f305223a..bad4b4c4 100644 --- a/src/Renci.SshNet.Tests/Classes/Messages/Transport/UnimplementedMessageTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Messages/Transport/UnimplementedMessageTest.cs @@ -1,25 +1,25 @@ -using Renci.SshNet.Messages.Transport; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Messages.Transport -{ - /// - ///This is a test class for UnimplementedMessageTest and is intended - ///to contain all UnimplementedMessageTest Unit Tests - /// - [TestClass()] - public class UnimplementedMessageTest : TestBase - { - /// - ///A test for UnimplementedMessage Constructor - /// - [TestMethod()] - public void UnimplementedMessageConstructorTest() - { - UnimplementedMessage target = new UnimplementedMessage(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Messages.Transport; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Messages.Transport +{ + /// + ///This is a test class for UnimplementedMessageTest and is intended + ///to contain all UnimplementedMessageTest Unit Tests + /// + [TestClass()] + public class UnimplementedMessageTest : TestBase + { + /// + ///A test for UnimplementedMessage Constructor + /// + [TestMethod()] + public void UnimplementedMessageConstructorTest() + { + UnimplementedMessage target = new UnimplementedMessage(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/NetConfClientTest.cs b/src/Renci.SshNet.Tests/Classes/NetConfClientTest.cs index 3c4fb924..f58fd0d0 100644 --- a/src/Renci.SshNet.Tests/Classes/NetConfClientTest.cs +++ b/src/Renci.SshNet.Tests/Classes/NetConfClientTest.cs @@ -1,197 +1,197 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using System; -using System.Xml; - -namespace Renci.SshNet.Tests.Classes -{ - // TODO: Please help with documentation here, as I don't know the details, specially for the methods not documented. - /// - /// - /// - [TestClass] - public partial class NetConfClientTest : TestBase - { - /// - ///A test for NetConfClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NetConfClientConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NetConfClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NetConfClientConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NetConfClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NetConfClientConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NetConfClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NetConfClientConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for NetConfClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NetConfClientConstructorTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SendReceiveRpc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SendReceiveRpcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - string xml = string.Empty; // TODO: Initialize to an appropriate value - XmlDocument expected = null; // TODO: Initialize to an appropriate value - XmlDocument actual; - actual = target.SendReceiveRpc(xml); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for SendReceiveRpc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SendReceiveRpcTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - XmlDocument rpc = null; // TODO: Initialize to an appropriate value - XmlDocument expected = null; // TODO: Initialize to an appropriate value - XmlDocument actual; - actual = target.SendReceiveRpc(rpc); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for SendCloseRpc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SendCloseRpcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - XmlDocument expected = null; // TODO: Initialize to an appropriate value - XmlDocument actual; - actual = target.SendCloseRpc(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ServerCapabilities - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ServerCapabilitiesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - XmlDocument actual; - actual = target.ServerCapabilities; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OperationTimeout - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OperationTimeoutTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value - TimeSpan actual; - target.OperationTimeout = expected; - actual = target.OperationTimeout; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ClientCapabilities - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ClientCapabilitiesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - XmlDocument actual; - actual = target.ClientCapabilities; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AutomaticMessageIdHandling - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AutomaticMessageIdHandlingTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.AutomaticMessageIdHandling = expected; - actual = target.AutomaticMessageIdHandling; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using System; +using System.Xml; + +namespace Renci.SshNet.Tests.Classes +{ + // TODO: Please help with documentation here, as I don't know the details, specially for the methods not documented. + /// + /// + /// + [TestClass] + public partial class NetConfClientTest : TestBase + { + /// + ///A test for NetConfClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NetConfClientConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NetConfClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NetConfClientConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NetConfClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NetConfClientConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NetConfClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NetConfClientConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for NetConfClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NetConfClientConstructorTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SendReceiveRpc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SendReceiveRpcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + string xml = string.Empty; // TODO: Initialize to an appropriate value + XmlDocument expected = null; // TODO: Initialize to an appropriate value + XmlDocument actual; + actual = target.SendReceiveRpc(xml); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for SendReceiveRpc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SendReceiveRpcTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + XmlDocument rpc = null; // TODO: Initialize to an appropriate value + XmlDocument expected = null; // TODO: Initialize to an appropriate value + XmlDocument actual; + actual = target.SendReceiveRpc(rpc); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for SendCloseRpc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SendCloseRpcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + XmlDocument expected = null; // TODO: Initialize to an appropriate value + XmlDocument actual; + actual = target.SendCloseRpc(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ServerCapabilities + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ServerCapabilitiesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + XmlDocument actual; + actual = target.ServerCapabilities; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OperationTimeout + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OperationTimeoutTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value + TimeSpan actual; + target.OperationTimeout = expected; + actual = target.OperationTimeout; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ClientCapabilities + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ClientCapabilitiesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + XmlDocument actual; + actual = target.ClientCapabilities; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AutomaticMessageIdHandling + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AutomaticMessageIdHandlingTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + NetConfClient target = new NetConfClient(connectionInfo); // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.AutomaticMessageIdHandling = expected; + actual = target.AutomaticMessageIdHandling; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.cs index 871187bc..4cc9d33b 100644 --- a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Connected.cs @@ -1,102 +1,102 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.NetConf; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class NetConfClientTest_Dispose_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private NetConfClient _netConfClient; - private ConnectionInfo _connectionInfo; - private Mock _netConfSessionMock; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _netConfSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) - .Returns(_netConfSessionMock.Object); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _netConfClient.Connect(); - } - - protected void Act() - { - _netConfClient.Dispose(); - } - - [TestMethod] - public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout), Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.NetConf; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class NetConfClientTest_Dispose_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private NetConfClient _netConfClient; + private ConnectionInfo _connectionInfo; + private Mock _netConfSessionMock; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _netConfSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) + .Returns(_netConfSessionMock.Object); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _netConfClient.Connect(); + } + + protected void Act() + { + _netConfClient.Dispose(); + } + + [TestMethod] + public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout), Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disconnected.cs index bb845a72..64d7d232 100644 --- a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disconnected.cs @@ -1,104 +1,104 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.NetConf; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class NetConfClientTest_Dispose_Disconnected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private NetConfClient _netConfClient; - private ConnectionInfo _connectionInfo; - private Mock _netConfSessionMock; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _netConfSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) - .Returns(_netConfSessionMock.Object); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _netConfClient.Connect(); - _netConfClient.Disconnect(); - } - - protected void Act() - { - _netConfClient.Dispose(); - } - - [TestMethod] - public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout), Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedTwice() - { - _netConfSessionMock.Verify(p => p.Disconnect(), Times.Exactly(2)); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.NetConf; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class NetConfClientTest_Dispose_Disconnected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private NetConfClient _netConfClient; + private ConnectionInfo _connectionInfo; + private Mock _netConfSessionMock; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _netConfSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) + .Returns(_netConfSessionMock.Object); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _netConfClient.Connect(); + _netConfClient.Disconnect(); + } + + protected void Act() + { + _netConfClient.Dispose(); + } + + [TestMethod] + public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout), Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedTwice() + { + _netConfSessionMock.Verify(p => p.Disconnect(), Times.Exactly(2)); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disposed.cs index ba0a0cb2..b91ee4bb 100644 --- a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Dispose_Disposed.cs @@ -1,103 +1,103 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.NetConf; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class NetConfClientTest_Dispose_Disposed - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private NetConfClient _netConfClient; - private ConnectionInfo _connectionInfo; - private Mock _netConfSessionMock; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _netConfSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) - .Returns(_netConfSessionMock.Object); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _netConfClient.Connect(); - _netConfClient.Dispose(); - } - - protected void Act() - { - _netConfClient.Dispose(); - } - - [TestMethod] - public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout), Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.NetConf; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class NetConfClientTest_Dispose_Disposed + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private NetConfClient _netConfClient; + private ConnectionInfo _connectionInfo; + private Mock _netConfSessionMock; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _netConfSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) + .Returns(_netConfSessionMock.Object); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _netConfClient.Connect(); + _netConfClient.Dispose(); + } + + protected void Act() + { + _netConfClient.Dispose(); + } + + [TestMethod] + public void CreateNetConfSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout), Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Finalize_Connected.cs b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Finalize_Connected.cs index 6df3a7a9..726d9e3e 100644 --- a/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Finalize_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/NetConfClientTest_Finalize_Connected.cs @@ -1,71 +1,71 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.NetConf; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class NetConfClientTest_Finalize_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private NetConfClient _netConfClient; - private ConnectionInfo _connectionInfo; - private Mock _netConfSessionMock; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Loose); - _sessionMock = new Mock(MockBehavior.Loose); - _netConfSessionMock = new Mock(MockBehavior.Loose); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) - .Returns(_netConfSessionMock.Object); - _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); - - _netConfClient.Connect(); - _netConfClient = null; - - // we need to dereference all other mocks as they might otherwise hold the target alive - _sessionMock = null; - _connectionInfo = null; - _serviceFactoryMock = null; - - } - - protected void Act() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Disconnect(), Times.Never); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _netConfSessionMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.NetConf; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class NetConfClientTest_Finalize_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private NetConfClient _netConfClient; + private ConnectionInfo _connectionInfo; + private Mock _netConfSessionMock; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Loose); + _sessionMock = new Mock(MockBehavior.Loose); + _netConfSessionMock = new Mock(MockBehavior.Loose); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _netConfClient = new NetConfClient(_connectionInfo, false, _serviceFactoryMock.Object); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateNetConfSession(_sessionMock.Object, _netConfClient.OperationTimeout)) + .Returns(_netConfSessionMock.Object); + _netConfSessionMock.InSequence(sequence).Setup(p => p.Connect()); + + _netConfClient.Connect(); + _netConfClient = null; + + // we need to dereference all other mocks as they might otherwise hold the target alive + _sessionMock = null; + _connectionInfo = null; + _serviceFactoryMock = null; + + } + + protected void Act() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Disconnect(), Times.Never); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _netConfSessionMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs b/src/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs index 93e01f39..3dc69e31 100644 --- a/src/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs +++ b/src/Renci.SshNet.Tests/Classes/NoneAuthenticationMethodTest.cs @@ -1,94 +1,94 @@ -using System.Globalization; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality for "none" authentication method - /// - [TestClass] - public class NoneAuthenticationMethodTest : TestBase - { - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("NoneAuthenticationMethod: Pass null as username.")] - [ExpectedException(typeof(ArgumentException))] - public void None_Test_Pass_Null() - { - new NoneAuthenticationMethod(null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("NoneAuthenticationMethod: Pass String.Empty as username.")] - [ExpectedException(typeof(ArgumentException))] - public void None_Test_Pass_Whitespace() - { - new NoneAuthenticationMethod(string.Empty); - } - - [TestMethod] - public void Name() - { - var username = new Random().Next().ToString(CultureInfo.InvariantCulture); - var target = new NoneAuthenticationMethod(username); - - Assert.AreEqual("none", target.Name); - } - - [TestMethod] - public void Username() - { - var username = new Random().Next().ToString(CultureInfo.InvariantCulture); - var target = new NoneAuthenticationMethod(username); - - Assert.AreSame(username, target.Username); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - NoneAuthenticationMethod target = new NoneAuthenticationMethod(username); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Authenticate - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AuthenticateTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - NoneAuthenticationMethod target = new NoneAuthenticationMethod(username); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value - AuthenticationResult actual; - actual = target.Authenticate(session); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for NoneAuthenticationMethod Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NoneAuthenticationMethodConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - NoneAuthenticationMethod target = new NoneAuthenticationMethod(username); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using System.Globalization; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality for "none" authentication method + /// + [TestClass] + public class NoneAuthenticationMethodTest : TestBase + { + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("NoneAuthenticationMethod: Pass null as username.")] + [ExpectedException(typeof(ArgumentException))] + public void None_Test_Pass_Null() + { + new NoneAuthenticationMethod(null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("NoneAuthenticationMethod: Pass String.Empty as username.")] + [ExpectedException(typeof(ArgumentException))] + public void None_Test_Pass_Whitespace() + { + new NoneAuthenticationMethod(string.Empty); + } + + [TestMethod] + public void Name() + { + var username = new Random().Next().ToString(CultureInfo.InvariantCulture); + var target = new NoneAuthenticationMethod(username); + + Assert.AreEqual("none", target.Name); + } + + [TestMethod] + public void Username() + { + var username = new Random().Next().ToString(CultureInfo.InvariantCulture); + var target = new NoneAuthenticationMethod(username); + + Assert.AreSame(username, target.Username); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + NoneAuthenticationMethod target = new NoneAuthenticationMethod(username); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Authenticate + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AuthenticateTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + NoneAuthenticationMethod target = new NoneAuthenticationMethod(username); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value + AuthenticationResult actual; + actual = target.Authenticate(session); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for NoneAuthenticationMethod Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NoneAuthenticationMethodConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + NoneAuthenticationMethod target = new NoneAuthenticationMethod(username); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs b/src/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs index 9bdf26f8..ec0d3fef 100644 --- a/src/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PasswordAuthenticationMethodTest.cs @@ -1,161 +1,161 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality to perform password authentication. - /// - [TestClass] - public partial class PasswordAuthenticationMethodTest : TestBase - { - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PasswordAuthenticationMethod: Pass null as username, \"valid\" as password.")] - [ExpectedException(typeof(ArgumentException))] - public void Password_Test_Pass_Null_Username() - { - new PasswordAuthenticationMethod(null, "valid"); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, null as password.")] - [ExpectedException(typeof(ArgumentNullException))] - public void Password_Test_Pass_Null_Password() - { - new PasswordAuthenticationMethod("valid", (string)null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, \"valid\" as password.")] - public void Password_Test_Pass_Valid_Username_And_Password() - { - new PasswordAuthenticationMethod("valid", "valid"); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PasswordAuthenticationMethod: Pass String.Empty as username, \"valid\" as password.")] - [ExpectedException(typeof(ArgumentException))] - public void Password_Test_Pass_Whitespace() - { - new PasswordAuthenticationMethod(string.Empty, "valid"); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, String.Empty as password.")] - public void Password_Test_Pass_Valid() - { - new PasswordAuthenticationMethod("valid", string.Empty); - } - - [TestMethod] - [WorkItem(1140)] - [TestCategory("BaseClient")] - [TestCategory("integration")] - [Description("Test whether IsConnected is false after disconnect.")] - [Owner("Kenneth_aa")] - public void Test_BaseClient_IsConnected_True_After_Disconnect() - { - // 2012-04-29 - Kenneth_aa - // The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait - // for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning - // anything about Socket's either. - - var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD); - - using (SftpClient client = new SftpClient(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - Assert.AreEqual(true, client.IsConnected, "IsConnected is not true after Connect() was called."); - - client.Disconnect(); - - Assert.AreEqual(false, client.IsConnected, "IsConnected is true after Disconnect() was called."); - } - } - - /// - ///A test for Name - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Authenticate - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AuthenticateTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value - AuthenticationResult actual; - actual = target.Authenticate(session); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PasswordAuthenticationMethod Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordAuthenticationMethodConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordAuthenticationMethod Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordAuthenticationMethodConstructorTest1() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality to perform password authentication. + /// + [TestClass] + public partial class PasswordAuthenticationMethodTest : TestBase + { + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PasswordAuthenticationMethod: Pass null as username, \"valid\" as password.")] + [ExpectedException(typeof(ArgumentException))] + public void Password_Test_Pass_Null_Username() + { + new PasswordAuthenticationMethod(null, "valid"); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, null as password.")] + [ExpectedException(typeof(ArgumentNullException))] + public void Password_Test_Pass_Null_Password() + { + new PasswordAuthenticationMethod("valid", (string)null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, \"valid\" as password.")] + public void Password_Test_Pass_Valid_Username_And_Password() + { + new PasswordAuthenticationMethod("valid", "valid"); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PasswordAuthenticationMethod: Pass String.Empty as username, \"valid\" as password.")] + [ExpectedException(typeof(ArgumentException))] + public void Password_Test_Pass_Whitespace() + { + new PasswordAuthenticationMethod(string.Empty, "valid"); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PasswordAuthenticationMethod: Pass \"valid\" as username, String.Empty as password.")] + public void Password_Test_Pass_Valid() + { + new PasswordAuthenticationMethod("valid", string.Empty); + } + + [TestMethod] + [WorkItem(1140)] + [TestCategory("BaseClient")] + [TestCategory("integration")] + [Description("Test whether IsConnected is false after disconnect.")] + [Owner("Kenneth_aa")] + public void Test_BaseClient_IsConnected_True_After_Disconnect() + { + // 2012-04-29 - Kenneth_aa + // The problem with this test, is that after SSH Net calls .Disconnect(), the library doesn't wait + // for the server to confirm disconnect before IsConnected is checked. And now I'm not mentioning + // anything about Socket's either. + + var connectionInfo = new PasswordAuthenticationMethod(Resources.USERNAME, Resources.PASSWORD); + + using (SftpClient client = new SftpClient(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + Assert.AreEqual(true, client.IsConnected, "IsConnected is not true after Connect() was called."); + + client.Disconnect(); + + Assert.AreEqual(false, client.IsConnected, "IsConnected is true after Disconnect() was called."); + } + } + + /// + ///A test for Name + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NameTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Authenticate + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AuthenticateTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value + AuthenticationResult actual; + actual = target.Authenticate(session); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PasswordAuthenticationMethod Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordAuthenticationMethodConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordAuthenticationMethod Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordAuthenticationMethodConstructorTest1() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + PasswordAuthenticationMethod target = new PasswordAuthenticationMethod(username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs b/src/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs index 61cafbf0..52088160 100644 --- a/src/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PasswordConnectionInfoTest.cs @@ -1,481 +1,481 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Net; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides connection information when password authentication method is used - /// - [TestClass] - public class PasswordConnectionInfoTest : TestBase - { - [TestMethod] - [TestCategory("PasswordConnectionInfo")] - [TestCategory("integration")] - public void Test_PasswordConnectionInfo() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example PasswordConnectionInfo - var connectionInfo = new PasswordConnectionInfo(host, username, password); - using (var client = new SftpClient(connectionInfo)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - [TestMethod] - [TestCategory("PasswordConnectionInfo")] - [TestCategory("integration")] - public void Test_PasswordConnectionInfo_PasswordExpired() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example PasswordConnectionInfo PasswordExpired - var connectionInfo = new PasswordConnectionInfo("host", "username", "password"); - var encoding = SshData.Ascii; - connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e) - { - e.NewPassword = encoding.GetBytes("123456"); - }; - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - - client.Disconnect(); - } - #endregion - - Assert.Inconclusive(); - } - [TestMethod] - [TestCategory("PasswordConnectionInfo")] - [TestCategory("integration")] - public void Test_PasswordConnectionInfo_AuthenticationBanner() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example PasswordConnectionInfo AuthenticationBanner - var connectionInfo = new PasswordConnectionInfo(host, username, password); - connectionInfo.AuthenticationBanner += delegate(object sender, AuthenticationBannerEventArgs e) - { - Console.WriteLine(e.BannerMessage); - }; - using (var client = new SftpClient(connectionInfo)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - - [WorkItem(703), TestMethod] - [TestCategory("PasswordConnectionInfo")] - public void Test_ConnectionInfo_Host_Is_Null() - { - try - { - new PasswordConnectionInfo(null, Resources.USERNAME, Resources.PASSWORD); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("host", ex.ParamName); - } - - } - - [WorkItem(703), TestMethod] - [TestCategory("PasswordConnectionInfo")] - [ExpectedException(typeof(ArgumentException))] - public void Test_ConnectionInfo_Username_Is_Null() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD); - } - - [WorkItem(703), TestMethod] - [TestCategory("PasswordConnectionInfo")] - [ExpectedException(typeof(ArgumentNullException))] - public void Test_ConnectionInfo_Password_Is_Null() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null); - } - - [TestMethod] - [TestCategory("PasswordConnectionInfo")] - [Description("Test passing whitespace to username parameter.")] - [ExpectedException(typeof(ArgumentException))] - public void Test_ConnectionInfo_Username_Is_Whitespace() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD); - } - - [WorkItem(703), TestMethod] - [TestCategory("PasswordConnectionInfo")] - [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void Test_ConnectionInfo_SmallPortNumber() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD); - } - - [WorkItem(703), TestMethod] - [TestCategory("PasswordConnectionInfo")] - [ExpectedException(typeof(ArgumentOutOfRangeException))] - public void Test_ConnectionInfo_BigPortNumber() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD); - } - - [TestMethod] - [Owner("Kenneth_aa")] - [Description("Test connect to remote server via a SOCKS4 proxy server.")] - [TestCategory("Proxy")] - [TestCategory("integration")] - public void Test_Ssh_Connect_Via_Socks4() - { - var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks4, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT)); - using (var client = new SshClient(connInfo)) - { - client.Connect(); - - var ret = client.RunCommand("ls -la"); - - client.Disconnect(); - } - } - - [TestMethod] - [Owner("Kenneth_aa")] - [Description("Test connect to remote server via a TCP SOCKS5 proxy server.")] - [TestCategory("Proxy")] - [TestCategory("integration")] - public void Test_Ssh_Connect_Via_TcpSocks5() - { - var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks5, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT)); - using (var client = new SshClient(connInfo)) - { - client.Connect(); - - var ret = client.RunCommand("ls -la"); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("Kenneth_aa")] - [Description("Test connect to remote server via a HTTP proxy server.")] - [TestCategory("Proxy")] - [TestCategory("integration")] - public void Test_Ssh_Connect_Via_HttpProxy() - { - var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Http, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT)); - using (var client = new SshClient(connInfo)) - { - client.Connect(); - - var ret = client.RunCommand("ls -la"); - - client.Disconnect(); - } - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest4() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest5() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest6() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest7() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - byte[] password = null; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest8() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest9() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest10() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest11() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest12() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest13() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PasswordConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PasswordConnectionInfoConstructorTest14() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Net; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides connection information when password authentication method is used + /// + [TestClass] + public class PasswordConnectionInfoTest : TestBase + { + [TestMethod] + [TestCategory("PasswordConnectionInfo")] + [TestCategory("integration")] + public void Test_PasswordConnectionInfo() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example PasswordConnectionInfo + var connectionInfo = new PasswordConnectionInfo(host, username, password); + using (var client = new SftpClient(connectionInfo)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + [TestMethod] + [TestCategory("PasswordConnectionInfo")] + [TestCategory("integration")] + public void Test_PasswordConnectionInfo_PasswordExpired() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example PasswordConnectionInfo PasswordExpired + var connectionInfo = new PasswordConnectionInfo("host", "username", "password"); + var encoding = SshData.Ascii; + connectionInfo.PasswordExpired += delegate(object sender, AuthenticationPasswordChangeEventArgs e) + { + e.NewPassword = encoding.GetBytes("123456"); + }; + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + + client.Disconnect(); + } + #endregion + + Assert.Inconclusive(); + } + [TestMethod] + [TestCategory("PasswordConnectionInfo")] + [TestCategory("integration")] + public void Test_PasswordConnectionInfo_AuthenticationBanner() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example PasswordConnectionInfo AuthenticationBanner + var connectionInfo = new PasswordConnectionInfo(host, username, password); + connectionInfo.AuthenticationBanner += delegate(object sender, AuthenticationBannerEventArgs e) + { + Console.WriteLine(e.BannerMessage); + }; + using (var client = new SftpClient(connectionInfo)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + + [WorkItem(703), TestMethod] + [TestCategory("PasswordConnectionInfo")] + public void Test_ConnectionInfo_Host_Is_Null() + { + try + { + new PasswordConnectionInfo(null, Resources.USERNAME, Resources.PASSWORD); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("host", ex.ParamName); + } + + } + + [WorkItem(703), TestMethod] + [TestCategory("PasswordConnectionInfo")] + [ExpectedException(typeof(ArgumentException))] + public void Test_ConnectionInfo_Username_Is_Null() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD); + } + + [WorkItem(703), TestMethod] + [TestCategory("PasswordConnectionInfo")] + [ExpectedException(typeof(ArgumentNullException))] + public void Test_ConnectionInfo_Password_Is_Null() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null); + } + + [TestMethod] + [TestCategory("PasswordConnectionInfo")] + [Description("Test passing whitespace to username parameter.")] + [ExpectedException(typeof(ArgumentException))] + public void Test_ConnectionInfo_Username_Is_Whitespace() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD); + } + + [WorkItem(703), TestMethod] + [TestCategory("PasswordConnectionInfo")] + [ExpectedException(typeof(ArgumentOutOfRangeException))] + public void Test_ConnectionInfo_SmallPortNumber() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD); + } + + [WorkItem(703), TestMethod] + [TestCategory("PasswordConnectionInfo")] + [ExpectedException(typeof(ArgumentOutOfRangeException))] + public void Test_ConnectionInfo_BigPortNumber() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD); + } + + [TestMethod] + [Owner("Kenneth_aa")] + [Description("Test connect to remote server via a SOCKS4 proxy server.")] + [TestCategory("Proxy")] + [TestCategory("integration")] + public void Test_Ssh_Connect_Via_Socks4() + { + var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks4, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT)); + using (var client = new SshClient(connInfo)) + { + client.Connect(); + + var ret = client.RunCommand("ls -la"); + + client.Disconnect(); + } + } + + [TestMethod] + [Owner("Kenneth_aa")] + [Description("Test connect to remote server via a TCP SOCKS5 proxy server.")] + [TestCategory("Proxy")] + [TestCategory("integration")] + public void Test_Ssh_Connect_Via_TcpSocks5() + { + var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Socks5, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT)); + using (var client = new SshClient(connInfo)) + { + client.Connect(); + + var ret = client.RunCommand("ls -la"); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("Kenneth_aa")] + [Description("Test connect to remote server via a HTTP proxy server.")] + [TestCategory("Proxy")] + [TestCategory("integration")] + public void Test_Ssh_Connect_Via_HttpProxy() + { + var connInfo = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, Resources.PASSWORD, ProxyTypes.Http, Resources.PROXY_HOST, int.Parse(Resources.PROXY_PORT)); + using (var client = new SshClient(connInfo)) + { + client.Connect(); + + var ret = client.RunCommand("ls -la"); + + client.Disconnect(); + } + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest4() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest5() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest6() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest7() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + byte[] password = null; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest8() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest9() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort, proxyUsername); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest10() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password, proxyType, proxyHost, proxyPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest11() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort, proxyUsername); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest12() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password, proxyType, proxyHost, proxyPort); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest13() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PasswordConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PasswordConnectionInfoConstructorTest14() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + PasswordConnectionInfo target = new PasswordConnectionInfo(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs b/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs index 6634c0ef..6ea7a33f 100644 --- a/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PrivateKeyAuthenticationMethodTest.cs @@ -1,106 +1,106 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality to perform private key authentication. - /// - [TestClass] - public class PrivateKeyAuthenticationMethodTest : TestBase - { - [TestMethod] - [TestCategory("AuthenticationMethod")] - [TestCategory("PrivateKeyAuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PrivateKeyAuthenticationMethod: Pass null as username, null as password.")] - [ExpectedException(typeof(ArgumentException))] - public void PrivateKey_Test_Pass_Null() - { - new PrivateKeyAuthenticationMethod(null, null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [TestCategory("PrivateKeyAuthenticationMethod")] - [Owner("olegkap")] - [Description("PrivateKeyAuthenticationMethod: Pass valid username, null as password.")] - [ExpectedException(typeof(ArgumentNullException))] - public void PrivateKey_Test_Pass_PrivateKey_Null() - { - new PrivateKeyAuthenticationMethod("username", null); - } - - [TestMethod] - [TestCategory("AuthenticationMethod")] - [TestCategory("PrivateKeyAuthenticationMethod")] - [Owner("Kenneth_aa")] - [Description("PrivateKeyAuthenticationMethod: Pass String.Empty as username, null as password.")] - [ExpectedException(typeof(ArgumentException))] - public void PrivateKey_Test_Pass_Whitespace() - { - new PrivateKeyAuthenticationMethod(string.Empty, null); - } - - /// - ///A test for Name - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Authenticate - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AuthenticateTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value - AuthenticationResult actual; - actual = target.Authenticate(session); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PrivateKeyAuthenticationMethod Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyAuthenticationMethodConstructorTest() - { - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality to perform private key authentication. + /// + [TestClass] + public class PrivateKeyAuthenticationMethodTest : TestBase + { + [TestMethod] + [TestCategory("AuthenticationMethod")] + [TestCategory("PrivateKeyAuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PrivateKeyAuthenticationMethod: Pass null as username, null as password.")] + [ExpectedException(typeof(ArgumentException))] + public void PrivateKey_Test_Pass_Null() + { + new PrivateKeyAuthenticationMethod(null, null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [TestCategory("PrivateKeyAuthenticationMethod")] + [Owner("olegkap")] + [Description("PrivateKeyAuthenticationMethod: Pass valid username, null as password.")] + [ExpectedException(typeof(ArgumentNullException))] + public void PrivateKey_Test_Pass_PrivateKey_Null() + { + new PrivateKeyAuthenticationMethod("username", null); + } + + [TestMethod] + [TestCategory("AuthenticationMethod")] + [TestCategory("PrivateKeyAuthenticationMethod")] + [Owner("Kenneth_aa")] + [Description("PrivateKeyAuthenticationMethod: Pass String.Empty as username, null as password.")] + [ExpectedException(typeof(ArgumentException))] + public void PrivateKey_Test_Pass_Whitespace() + { + new PrivateKeyAuthenticationMethod(string.Empty, null); + } + + /// + ///A test for Name + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NameTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Authenticate + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AuthenticateTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + AuthenticationResult expected = new AuthenticationResult(); // TODO: Initialize to an appropriate value + AuthenticationResult actual; + actual = target.Authenticate(session); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PrivateKeyAuthenticationMethod Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyAuthenticationMethodConstructorTest() + { + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyAuthenticationMethod target = new PrivateKeyAuthenticationMethod(username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs b/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs index cee67e17..f8c863ba 100644 --- a/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PrivateKeyConnectionInfoTest.cs @@ -1,217 +1,217 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.IO; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides connection information when private key authentication method is used - /// - [TestClass] - public class PrivateKeyConnectionInfoTest : TestBase - { - [TestMethod] - [TestCategory("PrivateKeyConnectionInfo")] - [TestCategory("integration")] - public void Test_PrivateKeyConnectionInfo() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - - #region Example PrivateKeyConnectionInfo PrivateKeyFile - var connectionInfo = new PrivateKeyConnectionInfo(host, username, new PrivateKeyFile(keyFileStream)); - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - [TestMethod] - [TestCategory("PrivateKeyConnectionInfo")] - [TestCategory("integration")] - public void Test_PrivateKeyConnectionInfo_MultiplePrivateKey() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - MemoryStream keyFileStream1 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - MemoryStream keyFileStream2 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - - #region Example PrivateKeyConnectionInfo PrivateKeyFile Multiple - var connectionInfo = new PrivateKeyConnectionInfo(host, username, - new PrivateKeyFile(keyFileStream1), - new PrivateKeyFile(keyFileStream2)); - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - #endregion - - Assert.AreEqual(connectionInfo.Host, Resources.HOST); - Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest4() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest5() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value - string proxyHost = string.Empty; // TODO: Initialize to an appropriate value - int proxyPort = 0; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest6() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for PrivateKeyConnectionInfo Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PrivateKeyConnectionInfoConstructorTest7() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.IO; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides connection information when private key authentication method is used + /// + [TestClass] + public class PrivateKeyConnectionInfoTest : TestBase + { + [TestMethod] + [TestCategory("PrivateKeyConnectionInfo")] + [TestCategory("integration")] + public void Test_PrivateKeyConnectionInfo() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + + #region Example PrivateKeyConnectionInfo PrivateKeyFile + var connectionInfo = new PrivateKeyConnectionInfo(host, username, new PrivateKeyFile(keyFileStream)); + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + [TestMethod] + [TestCategory("PrivateKeyConnectionInfo")] + [TestCategory("integration")] + public void Test_PrivateKeyConnectionInfo_MultiplePrivateKey() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + MemoryStream keyFileStream1 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + MemoryStream keyFileStream2 = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + + #region Example PrivateKeyConnectionInfo PrivateKeyFile Multiple + var connectionInfo = new PrivateKeyConnectionInfo(host, username, + new PrivateKeyFile(keyFileStream1), + new PrivateKeyFile(keyFileStream2)); + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + #endregion + + Assert.AreEqual(connectionInfo.Host, Resources.HOST); + Assert.AreEqual(connectionInfo.Username, Resources.USERNAME); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + string proxyPassword = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, proxyType, proxyHost, proxyPort, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest4() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + string proxyUsername = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest5() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + ProxyTypes proxyType = new ProxyTypes(); // TODO: Initialize to an appropriate value + string proxyHost = string.Empty; // TODO: Initialize to an appropriate value + int proxyPort = 0; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, proxyType, proxyHost, proxyPort, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest6() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for PrivateKeyConnectionInfo Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PrivateKeyConnectionInfoConstructorTest7() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + PrivateKeyConnectionInfo target = new PrivateKeyConnectionInfo(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs b/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs index 8c979848..77efff4a 100644 --- a/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs +++ b/src/Renci.SshNet.Tests/Classes/PrivateKeyFileTest.cs @@ -1,504 +1,504 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using System; -using System.IO; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// old private key information/ - /// - [TestClass] - public class PrivateKeyFileTest : TestBase - { - private string _temporaryFile; - - [TestInitialize] - public void SetUp() - { - _temporaryFile = GetTempFileName(); - } - - [TestCleanup] - public void TearDown() - { - if (_temporaryFile != null) - File.Delete(_temporaryFile); - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsNull() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName, "12345"); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - /// - /// A test for ctor. - /// - [WorkItem(703), TestMethod] - public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsNull() - { - var fileName = string.Empty; - try - { - new PrivateKeyFile(fileName, "12345"); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("fileName", ex.ParamName); - } - } - - [WorkItem(703), TestMethod] - public void ConstructorWithPrivateKeyShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() - { - Stream privateKey = null; - try - { - new PrivateKeyFile(privateKey); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("privateKey", ex.ParamName); - } - } - - [WorkItem(703), TestMethod] - public void ConstructorWithPrivateKeyAndPassphraseShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() - { - Stream privateKey = null; - try - { - new PrivateKeyFile(privateKey, "12345"); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("privateKey", ex.ParamName); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA() - { - using (var stream = this.GetData("Key.RSA.txt")) - { - new PrivateKeyFile(stream); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_DSA() - { - using (var stream = this.GetData("Key.SSH2.DSA.txt")) - { - new PrivateKeyFile(stream); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_RSA() - { - using (var stream = this.GetData("Key.SSH2.RSA.txt")) - { - new PrivateKeyFile(stream); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_DSA_DES_CBC() - { - using (var stream = this.GetData("Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_RSA_DES_CBC() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshExceptionWhenPassphraseIsWrong() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - try - { - new PrivateKeyFile(stream, "34567"); - Assert.Fail(); - } - catch (SshException ex) - { - Assert.IsInstanceOfType(ex, typeof(SshException)); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Invalid passphrase.", ex.Message); - } - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - try - { - new PrivateKeyFile(stream, null); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - } - - [TestMethod] - [Owner("drieseng")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsEmpty() - { - using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) - { - try - { - new PrivateKeyFile(stream, string.Empty); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_DES_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Des.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_DES_EDE3_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_AES_128_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_AES_192_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Aes.192.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_AES_256_CBC() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Aes.256.CBC.12345.txt")) - { - new PrivateKeyFile(stream, "12345"); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("PrivateKey")] - public void Test_PrivateKey_RSA_DES_EDE3_CFB() - { - using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt")) - { - new PrivateKeyFile(stream, "1234567890"); - } - } - - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - using (var privateKeyStream = GetData("Key.RSA.txt")) - { - var target = new PrivateKeyFile(privateKeyStream); - target.Dispose(); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithStreamAndPassphrase() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - var privateKeyFile = new PrivateKeyFile(stream, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileNameAndPassphrase() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - - fs.Close(); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsEmpty() - { - var passphrase = string.Empty; - - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - try - { - new PrivateKeyFile(_temporaryFile, passphrase); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsNull() - { - string passphrase = null; - - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - try - { - new PrivateKeyFile(_temporaryFile, passphrase); - Assert.Fail(); - } - catch (SshPassPhraseNullOrEmptyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); - } - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithFileName() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - } - - /// - /// A test for ctor. - /// - [TestMethod()] - public void ConstructorWithStream() - { - using (var stream = GetData("Key.RSA.txt")) - { - var privateKeyFile = new PrivateKeyFile(stream); - Assert.IsNotNull(privateKeyFile.HostKey); - } - } - - [TestMethod] - [TestCategory("PrivateKey")] - public void ConstructorWithFileNameShouldBeAbleToReadFileThatIsSharedForReadAccess() - { - using (var stream = GetData("Key.RSA.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var privateKeyFile = new PrivateKeyFile(_temporaryFile); - Assert.IsNotNull(privateKeyFile.HostKey); - - fs.Close(); - } - } - - [TestMethod] - [TestCategory("PrivateKey")] - public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsSharedForReadAccess() - { - using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) - { - SaveStreamToFile(stream, _temporaryFile); - } - - using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); - Assert.IsNotNull(privateKeyFile.HostKey); - - fs.Close(); - } - } - - private void SaveStreamToFile(Stream stream, string fileName) - { - var buffer = new byte[4000]; - - using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) - { - var bytesRead = stream.Read(buffer, 0, buffer.Length); - while (bytesRead > 0) - { - fs.Write(buffer, 0, bytesRead); - bytesRead = stream.Read(buffer, 0, buffer.Length); - } - } - } - - private string GetTempFileName() - { - var tempFile = Path.GetTempFileName(); - File.Delete(tempFile); - return tempFile; - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using System; +using System.IO; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// old private key information/ + /// + [TestClass] + public class PrivateKeyFileTest : TestBase + { + private string _temporaryFile; + + [TestInitialize] + public void SetUp() + { + _temporaryFile = GetTempFileName(); + } + + [TestCleanup] + public void TearDown() + { + if (_temporaryFile != null) + File.Delete(_temporaryFile); + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameShouldThrowArgumentNullExceptionWhenFileNameIsNull() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsEmpty() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName, "12345"); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + /// + /// A test for ctor. + /// + [WorkItem(703), TestMethod] + public void ConstructorWithFileNameAndPassphraseShouldThrowArgumentNullExceptionWhenFileNameIsNull() + { + var fileName = string.Empty; + try + { + new PrivateKeyFile(fileName, "12345"); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("fileName", ex.ParamName); + } + } + + [WorkItem(703), TestMethod] + public void ConstructorWithPrivateKeyShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() + { + Stream privateKey = null; + try + { + new PrivateKeyFile(privateKey); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("privateKey", ex.ParamName); + } + } + + [WorkItem(703), TestMethod] + public void ConstructorWithPrivateKeyAndPassphraseShouldThrowArgumentNullExceptionWhenPrivateKeyIsNull() + { + Stream privateKey = null; + try + { + new PrivateKeyFile(privateKey, "12345"); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("privateKey", ex.ParamName); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA() + { + using (var stream = this.GetData("Key.RSA.txt")) + { + new PrivateKeyFile(stream); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_DSA() + { + using (var stream = this.GetData("Key.SSH2.DSA.txt")) + { + new PrivateKeyFile(stream); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_RSA() + { + using (var stream = this.GetData("Key.SSH2.RSA.txt")) + { + new PrivateKeyFile(stream); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_DSA_DES_CBC() + { + using (var stream = this.GetData("Key.SSH2.DSA.Encrypted.Des.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_RSA_DES_CBC() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshExceptionWhenPassphraseIsWrong() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + try + { + new PrivateKeyFile(stream, "34567"); + Assert.Fail(); + } + catch (SshException ex) + { + Assert.IsInstanceOfType(ex, typeof(SshException)); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Invalid passphrase.", ex.Message); + } + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + try + { + new PrivateKeyFile(stream, null); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + } + + [TestMethod] + [Owner("drieseng")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsEmpty() + { + using (var stream = this.GetData("Key.SSH2.RSA.Encrypted.Des.CBC.12345.txt")) + { + try + { + new PrivateKeyFile(stream, string.Empty); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsInstanceOfType(ex, typeof(SshPassPhraseNullOrEmptyException)); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_DES_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Des.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_DES_EDE3_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_AES_128_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_AES_192_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Aes.192.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_AES_256_CBC() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Aes.256.CBC.12345.txt")) + { + new PrivateKeyFile(stream, "12345"); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("PrivateKey")] + public void Test_PrivateKey_RSA_DES_EDE3_CFB() + { + using (var stream = this.GetData("Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt")) + { + new PrivateKeyFile(stream, "1234567890"); + } + } + + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + using (var privateKeyStream = GetData("Key.RSA.txt")) + { + var target = new PrivateKeyFile(privateKeyStream); + target.Dispose(); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithStreamAndPassphrase() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + var privateKeyFile = new PrivateKeyFile(stream, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileNameAndPassphrase() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + + fs.Close(); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsEmpty() + { + var passphrase = string.Empty; + + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + try + { + new PrivateKeyFile(_temporaryFile, passphrase); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileNameAndPassphraseShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPrivateKeyIsEncryptedAndPassphraseIsNull() + { + string passphrase = null; + + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + try + { + new PrivateKeyFile(_temporaryFile, passphrase); + Assert.Fail(); + } + catch (SshPassPhraseNullOrEmptyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Private key is encrypted but passphrase is empty.", ex.Message); + } + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithFileName() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + } + + /// + /// A test for ctor. + /// + [TestMethod()] + public void ConstructorWithStream() + { + using (var stream = GetData("Key.RSA.txt")) + { + var privateKeyFile = new PrivateKeyFile(stream); + Assert.IsNotNull(privateKeyFile.HostKey); + } + } + + [TestMethod] + [TestCategory("PrivateKey")] + public void ConstructorWithFileNameShouldBeAbleToReadFileThatIsSharedForReadAccess() + { + using (var stream = GetData("Key.RSA.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var privateKeyFile = new PrivateKeyFile(_temporaryFile); + Assert.IsNotNull(privateKeyFile.HostKey); + + fs.Close(); + } + } + + [TestMethod] + [TestCategory("PrivateKey")] + public void ConstructorWithFileNameAndPassPhraseShouldBeAbleToReadFileThatIsSharedForReadAccess() + { + using (var stream = GetData("Key.RSA.Encrypted.Aes.128.CBC.12345.txt")) + { + SaveStreamToFile(stream, _temporaryFile); + } + + using (var fs = File.Open(_temporaryFile, FileMode.Open, FileAccess.Read, FileShare.Read)) + { + var privateKeyFile = new PrivateKeyFile(_temporaryFile, "12345"); + Assert.IsNotNull(privateKeyFile.HostKey); + + fs.Close(); + } + } + + private void SaveStreamToFile(Stream stream, string fileName) + { + var buffer = new byte[4000]; + + using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) + { + var bytesRead = stream.Read(buffer, 0, buffer.Length); + while (bytesRead > 0) + { + fs.Write(buffer, 0, bytesRead); + bytesRead = stream.Read(buffer, 0, buffer.Length); + } + } + } + + private string GetTempFileName() + { + var tempFile = Path.GetTempFileName(); + File.Delete(tempFile); + return tempFile; + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs index 26c9c134..00c9d5d2 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/AlgorithmTest.cs @@ -1,34 +1,34 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for AlgorithmTest and is intended - ///to contain all AlgorithmTest Unit Tests - /// - [TestClass()] - public class AlgorithmTest : TestBase - { - internal virtual Algorithm CreateAlgorithm() - { - // TODO: Instantiate an appropriate concrete class. - Algorithm target = null; - return target; - } - - /// - ///A test for Name - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void NameTest() - { - Algorithm target = CreateAlgorithm(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for AlgorithmTest and is intended + ///to contain all AlgorithmTest Unit Tests + /// + [TestClass()] + public class AlgorithmTest : TestBase + { + internal virtual Algorithm CreateAlgorithm() + { + // TODO: Instantiate an appropriate concrete class. + Algorithm target = null; + return target; + } + + /// + ///A test for Name + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void NameTest() + { + Algorithm target = CreateAlgorithm(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs index 049a31ff..813fec59 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/CertificateHostAlgorithmTest.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for CertificateHostAlgorithmTest and is intended - ///to contain all CertificateHostAlgorithmTest Unit Tests - /// - [TestClass()] - public class CertificateHostAlgorithmTest : TestBase - { - /// - ///A test for CertificateHostAlgorithm Constructor - /// - [TestMethod] - public void CertificateHostAlgorithmConstructorTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Data - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DataTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Data; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for CertificateHostAlgorithmTest and is intended + ///to contain all CertificateHostAlgorithmTest Unit Tests + /// + [TestClass()] + public class CertificateHostAlgorithmTest : TestBase + { + /// + ///A test for CertificateHostAlgorithm Constructor + /// + [TestMethod] + public void CertificateHostAlgorithmConstructorTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Data + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DataTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + CertificateHostAlgorithm target = new CertificateHostAlgorithm(name); // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Data; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs index 6442b4ea..49546d61 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/BlockCipherTest.cs @@ -1,77 +1,77 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - [TestClass] - public class BlockCipherTest : TestBase - { - [TestMethod] - public void EncryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToEncryptBlock() - { - var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; - var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) - { - EncryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => - { - Assert.AreEqual(8, outputBuffer.Length); - Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); - return inputBuffer.Length; - } - }; - - var actual = blockCipher.Encrypt(input); - - Assert.IsTrue(output.SequenceEqual(actual)); - } - - [TestMethod] - public void DecryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToDecryptBlock() - { - var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; - var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) - { - DecryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => - { - Assert.AreEqual(8, outputBuffer.Length); - Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); - return inputBuffer.Length; - } - }; - - var actual = blockCipher.Decrypt(input); - - Assert.IsTrue(output.SequenceEqual(actual)); - } - - - private class BlockCipherStub : BlockCipher - { - public Func EncryptBlockDelegate; - public Func DecryptBlockDelegate; - - public BlockCipherStub(byte[] key, byte blockSize, CipherMode mode, CipherPadding padding) : base(key, blockSize, mode, padding) - { - } - - public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) - { - return EncryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - } - - public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) - { - return DecryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - } - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + [TestClass] + public class BlockCipherTest : TestBase + { + [TestMethod] + public void EncryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToEncryptBlock() + { + var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; + var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) + { + EncryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => + { + Assert.AreEqual(8, outputBuffer.Length); + Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); + return inputBuffer.Length; + } + }; + + var actual = blockCipher.Encrypt(input); + + Assert.IsTrue(output.SequenceEqual(actual)); + } + + [TestMethod] + public void DecryptShouldTakeIntoAccountPaddingForLengthOfOutputBufferPassedToDecryptBlock() + { + var input = new byte[] { 0x2c, 0x1a, 0x05, 0x00, 0x68 }; + var output = new byte[] { 0x0a, 0x00, 0x03, 0x02, 0x06, 0x08, 0x07, 0x05 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var blockCipher = new BlockCipherStub(key, 8, null, new PKCS5Padding()) + { + DecryptBlockDelegate = (inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset) => + { + Assert.AreEqual(8, outputBuffer.Length); + Buffer.BlockCopy(output, 0, outputBuffer, 0, output.Length); + return inputBuffer.Length; + } + }; + + var actual = blockCipher.Decrypt(input); + + Assert.IsTrue(output.SequenceEqual(actual)); + } + + + private class BlockCipherStub : BlockCipher + { + public Func EncryptBlockDelegate; + public Func DecryptBlockDelegate; + + public BlockCipherStub(byte[] key, byte blockSize, CipherMode mode, CipherPadding padding) : base(key, blockSize, mode, padding) + { + } + + public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { + return EncryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + } + + public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { + return DecryptBlockDelegate(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs index cbc5a65a..2bdce8e1 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherDigitalSignatureTest.cs @@ -1,54 +1,54 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for CipherDigitalSignatureTest and is intended - ///to contain all CipherDigitalSignatureTest Unit Tests - /// - [TestClass()] - public class CipherDigitalSignatureTest : TestBase - { - internal virtual CipherDigitalSignature CreateCipherDigitalSignature() - { - // TODO: Instantiate an appropriate concrete class. - CipherDigitalSignature target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Verify - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifyTest() - { - CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Verify(input, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for CipherDigitalSignatureTest and is intended + ///to contain all CipherDigitalSignatureTest Unit Tests + /// + [TestClass()] + public class CipherDigitalSignatureTest : TestBase + { + internal virtual CipherDigitalSignature CreateCipherDigitalSignature() + { + // TODO: Instantiate an appropriate concrete class. + CipherDigitalSignature target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Verify + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifyTest() + { + CipherDigitalSignature target = CreateCipherDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Verify(input, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs index c5f4a2b5..8af4f653 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/CipherTest.cs @@ -1,53 +1,53 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for CipherTest and is intended - ///to contain all CipherTest Unit Tests - /// - [TestClass()] - public class CipherTest : TestBase - { - internal virtual Cipher CreateCipher() - { - // TODO: Instantiate an appropriate concrete class. - Cipher target = null; - return target; - } - - /// - ///A test for Decrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptTest() - { - Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Decrypt(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Encrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptTest() - { - Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Encrypt(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for CipherTest and is intended + ///to contain all CipherTest Unit Tests + /// + [TestClass()] + public class CipherTest : TestBase + { + internal virtual Cipher CreateCipher() + { + // TODO: Instantiate an appropriate concrete class. + Cipher target = null; + return target; + } + + /// + ///A test for Decrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptTest() + { + Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Decrypt(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Encrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptTest() + { + Cipher target = CreateCipher(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Encrypt(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs index 5d16c7b9..deeb0cb5 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs @@ -1,239 +1,239 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// - /// - [TestClass] - public class AesCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_AES_128_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; - var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; - var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; - var output = new byte[] { 0x19, 0x7f, 0x80, 0xd8, 0xc9, 0x89, 0xc4, 0xa7, 0xc6, 0xc6, 0x3f, 0x9f, 0x1e, 0x00, 0x1f, 0x72, 0xa7, 0x5e, 0xde, 0x40, 0x88, 0xa2, 0x72, 0xf2, 0xed, 0x3f, 0x81, 0x45, 0xb6, 0xbd, 0x45, 0x87, 0x15, 0xa5, 0x10, 0x92, 0x4a, 0x37, 0x9e, 0xa9, 0x80, 0x1c, 0x14, 0x83, 0xa3, 0x39, 0x45, 0x28 }; - var testCipher = new AesCipher(key, new CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - public void Test_Cipher_AES_128_CTR() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; - var expected = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; - var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); - - var actual = testCipher.Encrypt(input); - - Assert.IsTrue(actual.IsEqualTo(expected)); - } - - [TestMethod] - public void Decrypt_AES_128_CTR() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; - var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; - var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; - var output = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; - var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); - - var actual = testCipher.Decrypt(output); - - Assert.IsTrue(input.IsEqualTo(actual)); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_AEes128CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes192CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes256CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes128CTR_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes192CTR_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Aes256CTR_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Arcfour_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("arcfour", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, false); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AesCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AesCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - AesCipher target = new AesCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// + /// + [TestClass] + public class AesCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_AES_128_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; + var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; + var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; + var output = new byte[] { 0x19, 0x7f, 0x80, 0xd8, 0xc9, 0x89, 0xc4, 0xa7, 0xc6, 0xc6, 0x3f, 0x9f, 0x1e, 0x00, 0x1f, 0x72, 0xa7, 0x5e, 0xde, 0x40, 0x88, 0xa2, 0x72, 0xf2, 0xed, 0x3f, 0x81, 0x45, 0xb6, 0xbd, 0x45, 0x87, 0x15, 0xa5, 0x10, 0x92, 0x4a, 0x37, 0x9e, 0xa9, 0x80, 0x1c, 0x14, 0x83, 0xa3, 0x39, 0x45, 0x28 }; + var testCipher = new AesCipher(key, new CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + public void Test_Cipher_AES_128_CTR() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; + var expected = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; + var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); + + var actual = testCipher.Encrypt(input); + + Assert.IsTrue(actual.IsEqualTo(expected)); + } + + [TestMethod] + public void Decrypt_AES_128_CTR() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; + var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; + var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; + var output = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; + var testCipher = new AesCipher(key, new CtrCipherMode(iv), null); + + var actual = testCipher.Decrypt(output); + + Assert.IsTrue(input.IsEqualTo(actual)); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_AEes128CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes128-cbc", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes192CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes192-cbc", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes256CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes256-cbc", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes128CTR_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes128-ctr", new CipherInfo(128, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes192CTR_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes192-ctr", new CipherInfo(192, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Aes256CTR_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("aes256-ctr", new CipherInfo(256, (key, iv) => { return new AesCipher(key, new CtrCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Arcfour_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("arcfour", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, false); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AesCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AesCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + AesCipher target = new AesCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + AesCipher target = new AesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs index addbfbf5..1bdcf837 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Arc4CipherTest.cs @@ -1,177 +1,177 @@ -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements ARCH4 cipher algorithm - /// - [TestClass] - public class Arc4CipherTest : TestBase - { - /// - ///A test for Arc4Cipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void Arc4CipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - Arc4Cipher target = new Arc4Cipher(key, true); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - [TestMethod] - public void Decrypt_DischargeFirstBytes_False1() - { - const string key = "Key"; - const string expectedPlainText = "Plaintext"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var cipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; - - var actualPlainText = cipher.Decrypt(cipherText); - - Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); - } - - [TestMethod] - public void Decrypt_DischargeFirstBytes_False2() - { - const string key = "Wiki"; - const string expectedPlainText = "pedia"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var cipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; - - var actualPlainText = cipher.Decrypt(cipherText); - - Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void Encrypt_DischargeFirstBytes_False1() - { - const string key = "Key"; - const string plainText = "Plaintext"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var expectedCipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; - - var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); - - Assert.IsNotNull(actualCipherText); - Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); - Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); - Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); - Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); - Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); - Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); - Assert.AreEqual(expectedCipherText[5], actualCipherText[5]); - Assert.AreEqual(expectedCipherText[6], actualCipherText[6]); - Assert.AreEqual(expectedCipherText[7], actualCipherText[7]); - Assert.AreEqual(expectedCipherText[8], actualCipherText[8]); - } - - [TestMethod] - public void Encrypt_DischargeFirstBytes_False2() - { - const string key = "Wiki"; - const string plainText = "pedia"; - var encoding = Encoding.ASCII; - var cipher = new Arc4Cipher(encoding.GetBytes(key), false); - var expectedCipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; - - var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); - - Assert.IsNotNull(actualCipherText); - Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); - Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); - Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); - Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); - Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); - Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Arcfour128_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("arcfour128", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, true); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Arcfour256_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("arcfour256", new CipherInfo(256, (key, iv) => { return new Arc4Cipher(key, true); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - } +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements ARCH4 cipher algorithm + /// + [TestClass] + public class Arc4CipherTest : TestBase + { + /// + ///A test for Arc4Cipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void Arc4CipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + Arc4Cipher target = new Arc4Cipher(key, true); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + [TestMethod] + public void Decrypt_DischargeFirstBytes_False1() + { + const string key = "Key"; + const string expectedPlainText = "Plaintext"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var cipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; + + var actualPlainText = cipher.Decrypt(cipherText); + + Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); + } + + [TestMethod] + public void Decrypt_DischargeFirstBytes_False2() + { + const string key = "Wiki"; + const string expectedPlainText = "pedia"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var cipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; + + var actualPlainText = cipher.Decrypt(cipherText); + + Assert.AreEqual(expectedPlainText, encoding.GetString(actualPlainText)); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void Encrypt_DischargeFirstBytes_False1() + { + const string key = "Key"; + const string plainText = "Plaintext"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var expectedCipherText = new byte[] { 0xBB, 0xF3, 0x16, 0xE8, 0xD9, 0x40, 0xAF, 0x0A, 0xD3 }; + + var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); + + Assert.IsNotNull(actualCipherText); + Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); + Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); + Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); + Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); + Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); + Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); + Assert.AreEqual(expectedCipherText[5], actualCipherText[5]); + Assert.AreEqual(expectedCipherText[6], actualCipherText[6]); + Assert.AreEqual(expectedCipherText[7], actualCipherText[7]); + Assert.AreEqual(expectedCipherText[8], actualCipherText[8]); + } + + [TestMethod] + public void Encrypt_DischargeFirstBytes_False2() + { + const string key = "Wiki"; + const string plainText = "pedia"; + var encoding = Encoding.ASCII; + var cipher = new Arc4Cipher(encoding.GetBytes(key), false); + var expectedCipherText = new byte[] { 0x10, 0X21, 0xBF, 0x04, 0x20 }; + + var actualCipherText = cipher.Encrypt(encoding.GetBytes(plainText)); + + Assert.IsNotNull(actualCipherText); + Assert.AreEqual(expectedCipherText.Length, actualCipherText.Length); + Assert.AreEqual(expectedCipherText[0], actualCipherText[0]); + Assert.AreEqual(expectedCipherText[1], actualCipherText[1]); + Assert.AreEqual(expectedCipherText[2], actualCipherText[2]); + Assert.AreEqual(expectedCipherText[3], actualCipherText[3]); + Assert.AreEqual(expectedCipherText[4], actualCipherText[4]); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + Arc4Cipher target = new Arc4Cipher(key, true); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Arcfour128_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("arcfour128", new CipherInfo(128, (key, iv) => { return new Arc4Cipher(key, true); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Arcfour256_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("arcfour256", new CipherInfo(256, (key, iv) => { return new Arc4Cipher(key, true); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs index 780a697b..1fd7b7d1 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/BlowfishCipherTest.cs @@ -1,108 +1,108 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// - /// - [TestClass] - public class BlowfishCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_Blowfish_128_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; - var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; - var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; - var output = new byte[] { 0x50, 0x49, 0xe0, 0xce, 0x98, 0x93, 0x8b, 0xec, 0x82, 0x7d, 0x14, 0x1b, 0x3e, 0xdc, 0xca, 0x63, 0xef, 0x36, 0x20, 0x67, 0x58, 0x63, 0x1f, 0x9c, 0xd2, 0x12, 0x6b, 0xca, 0xea, 0xd0, 0x78, 0x8b, 0x61, 0x50, 0x4f, 0xc4, 0x5b, 0x32, 0x91, 0xd6, 0x65, 0xcb, 0x74, 0xe5, 0x6e, 0xf5, 0xde, 0x14 }; - var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_BlowfishCBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => { return new BlowfishCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - /// - ///A test for BlowfishCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BlowfishCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - BlowfishCipher target = new BlowfishCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// + /// + [TestClass] + public class BlowfishCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_Blowfish_128_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; + var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; + var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; + var output = new byte[] { 0x50, 0x49, 0xe0, 0xce, 0x98, 0x93, 0x8b, 0xec, 0x82, 0x7d, 0x14, 0x1b, 0x3e, 0xdc, 0xca, 0x63, 0xef, 0x36, 0x20, 0x67, 0x58, 0x63, 0x1f, 0x9c, 0xd2, 0x12, 0x6b, 0xca, 0xea, 0xd0, 0x78, 0x8b, 0x61, 0x50, 0x4f, 0xc4, 0x5b, 0x32, 0x91, 0xd6, 0x65, 0xcb, 0x74, 0xe5, 0x6e, 0xf5, 0xde, 0x14 }; + var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_BlowfishCBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("blowfish-cbc", new CipherInfo(128, (key, iv) => { return new BlowfishCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + /// + ///A test for BlowfishCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BlowfishCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + BlowfishCipher target = new BlowfishCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + BlowfishCipher target = new BlowfishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs index f0cc6313..d65d9673 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CastCipherTest.cs @@ -1,106 +1,106 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements CAST cipher algorithm - /// - [TestClass] - public class CastCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_CastCipher_128_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; - var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; - var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; - var output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d }; - var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_Cast128CBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - /// - ///A test for CastCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CastCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - CastCipher target = new CastCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements CAST cipher algorithm + /// + [TestClass] + public class CastCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_CastCipher_128_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 }; + var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; + var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; + var output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d }; + var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_Cast128CBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + /// + ///A test for CastCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CastCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + CastCipher target = new CastCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs index 23a0ff0c..d3b4c0ad 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherModeTest.cs @@ -1,61 +1,61 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - ///This is a test class for CipherModeTest and is intended - ///to contain all CipherModeTest Unit Tests - /// - [TestClass()] - public class CipherModeTest : TestBase - { - internal virtual CipherMode CreateCipherMode() - { - // TODO: Instantiate an appropriate concrete class. - CipherMode target = null; - return target; - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + ///This is a test class for CipherModeTest and is intended + ///to contain all CipherModeTest Unit Tests + /// + [TestClass()] + public class CipherModeTest : TestBase + { + internal virtual CipherMode CreateCipherMode() + { + // TODO: Instantiate an appropriate concrete class. + CipherMode target = null; + return target; + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + CipherMode target = CreateCipherMode(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs index de720376..c923584a 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/CipherPaddingTest.cs @@ -1,38 +1,38 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - ///This is a test class for CipherPaddingTest and is intended - ///to contain all CipherPaddingTest Unit Tests - /// - [TestClass()] - public class CipherPaddingTest : TestBase - { - internal virtual CipherPadding CreateCipherPadding() - { - // TODO: Instantiate an appropriate concrete class. - CipherPadding target = null; - return target; - } - - /// - ///A test for Pad - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PadTest() - { - CipherPadding target = CreateCipherPadding(); // TODO: Initialize to an appropriate value - int blockSize = 0; // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Pad(blockSize, input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + ///This is a test class for CipherPaddingTest and is intended + ///to contain all CipherPaddingTest Unit Tests + /// + [TestClass()] + public class CipherPaddingTest : TestBase + { + internal virtual CipherPadding CreateCipherPadding() + { + // TODO: Instantiate an appropriate concrete class. + CipherPadding target = null; + return target; + } + + /// + ///A test for Pad + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PadTest() + { + CipherPadding target = CreateCipherPadding(); // TODO: Initialize to an appropriate value + int blockSize = 0; // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Pad(blockSize, input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs index 6511d3fc..cff5b9db 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/DesCipherTest.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements DES cipher algorithm. - /// - [TestClass] - public class DesCipherTest : TestBase - { - /// - ///A test for DesCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DesCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - DesCipher target = new DesCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements DES cipher algorithm. + /// + [TestClass] + public class DesCipherTest : TestBase + { + /// + ///A test for DesCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DesCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + DesCipher target = new DesCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + DesCipher target = new DesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs index 230dce65..c43191c2 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CbcCipherModeTest.cs @@ -1,67 +1,67 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for CbcCipherModeTest and is intended - ///to contain all CbcCipherModeTest Unit Tests - /// - [TestClass()] - public class CbcCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CbcCipherMode Constructor - /// - [TestMethod()] - public void CbcCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CbcCipherMode target = new CbcCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for CbcCipherModeTest and is intended + ///to contain all CbcCipherModeTest Unit Tests + /// + [TestClass()] + public class CbcCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CbcCipherMode target = new CbcCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CbcCipherMode Constructor + /// + [TestMethod()] + public void CbcCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CbcCipherMode target = new CbcCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs index 8a4a2b27..f7dd046d 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CfbCipherModeTest.cs @@ -1,68 +1,68 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for CfbCipherModeTest and is intended - ///to contain all CfbCipherModeTest Unit Tests - /// - [TestClass()] - public class CfbCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CfbCipherMode Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CfbCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CfbCipherMode target = new CfbCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for CfbCipherModeTest and is intended + ///to contain all CfbCipherModeTest Unit Tests + /// + [TestClass()] + public class CfbCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CfbCipherMode target = new CfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CfbCipherMode Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CfbCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CfbCipherMode target = new CfbCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs index 76e6bae9..23e0391e 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/CtrCipherModeTest.cs @@ -1,68 +1,68 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for CtrCipherModeTest and is intended - ///to contain all CtrCipherModeTest Unit Tests - /// - [TestClass()] - public class CtrCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CtrCipherMode Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CtrCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - CtrCipherMode target = new CtrCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for CtrCipherModeTest and is intended + ///to contain all CtrCipherModeTest Unit Tests + /// + [TestClass()] + public class CtrCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CtrCipherMode target = new CtrCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CtrCipherMode Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CtrCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + CtrCipherMode target = new CtrCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs index 5444be0d..d4719e25 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Modes/OfbCipherModeTest.cs @@ -1,68 +1,68 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes -{ - /// - ///This is a test class for OfbCipherModeTest and is intended - ///to contain all OfbCipherModeTest Unit Tests - /// - [TestClass()] - public class OfbCipherModeTest : TestBase - { - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OfbCipherMode Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OfbCipherModeConstructorTest() - { - byte[] iv = null; // TODO: Initialize to an appropriate value - OfbCipherMode target = new OfbCipherMode(iv); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Modes +{ + /// + ///This is a test class for OfbCipherModeTest and is intended + ///to contain all OfbCipherModeTest Unit Tests + /// + [TestClass()] + public class OfbCipherModeTest : TestBase + { + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + OfbCipherMode target = new OfbCipherMode(iv); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OfbCipherMode Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OfbCipherModeConstructorTest() + { + byte[] iv = null; // TODO: Initialize to an appropriate value + OfbCipherMode target = new OfbCipherMode(iv); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs index 205feb4e..554d4b6a 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS5PaddingTest.cs @@ -1,41 +1,41 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings -{ - /// - ///This is a test class for PKCS5PaddingTest and is intended - ///to contain all PKCS5PaddingTest Unit Tests - /// - [TestClass()] - public class PKCS5PaddingTest : TestBase - { - /// - ///A test for Pad - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PadTest() - { - PKCS5Padding target = new PKCS5Padding(); // TODO: Initialize to an appropriate value - int blockSize = 0; // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Pad(blockSize, input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PKCS5Padding Constructor - /// - [TestMethod()] - public void PKCS5PaddingConstructorTest() - { - PKCS5Padding target = new PKCS5Padding(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings +{ + /// + ///This is a test class for PKCS5PaddingTest and is intended + ///to contain all PKCS5PaddingTest Unit Tests + /// + [TestClass()] + public class PKCS5PaddingTest : TestBase + { + /// + ///A test for Pad + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PadTest() + { + PKCS5Padding target = new PKCS5Padding(); // TODO: Initialize to an appropriate value + int blockSize = 0; // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Pad(blockSize, input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PKCS5Padding Constructor + /// + [TestMethod()] + public void PKCS5PaddingConstructorTest() + { + PKCS5Padding target = new PKCS5Padding(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs index e20be109..e39ec7a7 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/Paddings/PKCS7PaddingTest.cs @@ -1,41 +1,41 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings -{ - /// - ///This is a test class for PKCS7PaddingTest and is intended - ///to contain all PKCS7PaddingTest Unit Tests - /// - [TestClass()] - public class PKCS7PaddingTest : TestBase - { - /// - ///A test for Pad - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PadTest() - { - PKCS7Padding target = new PKCS7Padding(); // TODO: Initialize to an appropriate value - int blockSize = 0; // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Pad(blockSize, input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for PKCS7Padding Constructor - /// - [TestMethod()] - public void PKCS7PaddingConstructorTest() - { - PKCS7Padding target = new PKCS7Padding(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers.Paddings; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers.Paddings +{ + /// + ///This is a test class for PKCS7PaddingTest and is intended + ///to contain all PKCS7PaddingTest Unit Tests + /// + [TestClass()] + public class PKCS7PaddingTest : TestBase + { + /// + ///A test for Pad + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PadTest() + { + PKCS7Padding target = new PKCS7Padding(); // TODO: Initialize to an appropriate value + int blockSize = 0; // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Pad(blockSize, input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for PKCS7Padding Constructor + /// + [TestMethod()] + public void PKCS7PaddingConstructorTest() + { + PKCS7Padding target = new PKCS7Padding(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs index 423288b2..2de87cdd 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/RsaCipherTest.cs @@ -1,60 +1,60 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements RSA cipher algorithm. - /// - [TestClass] - public class RsaCipherTest : TestBase - { - /// - ///A test for RsaCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RsaCipherConstructorTest() - { - RsaKey key = null; // TODO: Initialize to an appropriate value - RsaCipher target = new RsaCipher(key); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Decrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptTest() - { - RsaKey key = null; // TODO: Initialize to an appropriate value - RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Decrypt(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Encrypt - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptTest() - { - RsaKey key = null; // TODO: Initialize to an appropriate value - RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Encrypt(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements RSA cipher algorithm. + /// + [TestClass] + public class RsaCipherTest : TestBase + { + /// + ///A test for RsaCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RsaCipherConstructorTest() + { + RsaKey key = null; // TODO: Initialize to an appropriate value + RsaCipher target = new RsaCipher(key); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Decrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptTest() + { + RsaKey key = null; // TODO: Initialize to an appropriate value + RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Decrypt(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Encrypt + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptTest() + { + RsaKey key = null; // TODO: Initialize to an appropriate value + RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Encrypt(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs index ac79b452..f604f5dc 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/SerpentCipherTest.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements Serpent cipher algorithm. - /// - [TestClass] - public class SerpentCipherTest : TestBase - { - /// - ///A test for SerpentCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SerpentCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - SerpentCipher target = new SerpentCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements Serpent cipher algorithm. + /// + [TestClass] + public class SerpentCipherTest : TestBase + { + /// + ///A test for SerpentCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SerpentCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + SerpentCipher target = new SerpentCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + SerpentCipher target = new SerpentCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs index 9ba70c14..3a410514 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TripleDesCipherTest.cs @@ -1,106 +1,106 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Security.Cryptography.Ciphers.Modes; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements 3DES cipher algorithm. - /// - [TestClass] - public class TripleDesCipherTest : TestBase - { - [TestMethod] - public void Test_Cipher_3DES_CBC() - { - var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 }; - var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 }; - var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 }; - var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b }; - var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); - var r = testCipher.Encrypt(input); - - if (!r.SequenceEqual(output)) - Assert.Fail("Invalid encryption"); - } - - [TestMethod] - [Owner("olegkap")] - [TestCategory("Cipher")] - [TestCategory("integration")] - public void Test_Cipher_TripleDESCBC_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.Encryptions.Clear(); - connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); })); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - /// - ///A test for TripleDesCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void TripleDesCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TripleDesCipher target = new TripleDesCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Security.Cryptography.Ciphers.Modes; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements 3DES cipher algorithm. + /// + [TestClass] + public class TripleDesCipherTest : TestBase + { + [TestMethod] + public void Test_Cipher_3DES_CBC() + { + var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 }; + var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 }; + var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 }; + var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b }; + var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null); + var r = testCipher.Encrypt(input); + + if (!r.SequenceEqual(output)) + Assert.Fail("Invalid encryption"); + } + + [TestMethod] + [Owner("olegkap")] + [TestCategory("Cipher")] + [TestCategory("integration")] + public void Test_Cipher_TripleDESCBC_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.Encryptions.Clear(); + connectionInfo.Encryptions.Add("3des-cbc", new CipherInfo(192, (key, iv) => { return new TripleDesCipher(key, new CbcCipherMode(iv), null); })); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + /// + ///A test for TripleDesCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void TripleDesCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TripleDesCipher target = new TripleDesCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TripleDesCipher target = new TripleDesCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs index abb2b35d..e0693e97 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/TwofishCipherTest.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography.Ciphers; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers -{ - /// - /// Implements Twofish cipher algorithm - /// - [TestClass] - public class TwofishCipherTest : TestBase - { - /// - ///A test for TwofishCipher Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void TwofishCipherConstructorTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TwofishCipher target = new TwofishCipher(key, mode, padding); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - byte[] key = null; // TODO: Initialize to an appropriate value - CipherMode mode = null; // TODO: Initialize to an appropriate value - CipherPadding padding = null; // TODO: Initialize to an appropriate value - TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography.Ciphers; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers +{ + /// + /// Implements Twofish cipher algorithm + /// + [TestClass] + public class TwofishCipherTest : TestBase + { + /// + ///A test for TwofishCipher Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void TwofishCipherConstructorTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TwofishCipher target = new TwofishCipher(key, mode, padding); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + byte[] key = null; // TODO: Initialize to an appropriate value + CipherMode mode = null; // TODO: Initialize to an appropriate value + CipherPadding padding = null; // TODO: Initialize to an appropriate value + TwofishCipher target = new TwofishCipher(key, mode, padding); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs index a8733300..efe45c9c 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DigitalSignatureTest.cs @@ -1,54 +1,54 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for DigitalSignatureTest and is intended - ///to contain all DigitalSignatureTest Unit Tests - /// - [TestClass()] - public class DigitalSignatureTest : TestBase - { - internal virtual DigitalSignature CreateDigitalSignature() - { - // TODO: Instantiate an appropriate concrete class. - DigitalSignature target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Verify - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifyTest() - { - DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Verify(input, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for DigitalSignatureTest and is intended + ///to contain all DigitalSignatureTest Unit Tests + /// + [TestClass()] + public class DigitalSignatureTest : TestBase + { + internal virtual DigitalSignature CreateDigitalSignature() + { + // TODO: Instantiate an appropriate concrete class. + DigitalSignature target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Verify + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifyTest() + { + DigitalSignature target = CreateDigitalSignature(); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Verify(input, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs index 93bc28c8..0d3423c9 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaDigitalSignatureTest.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - /// Implements DSA digital signature algorithm. - /// - [TestClass] - public class DsaDigitalSignatureTest : TestBase - { - /// - ///A test for DsaDigitalSignature Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DsaDigitalSignatureConstructorTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(input); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Verify - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifyTest() - { - DsaKey key = null; // TODO: Initialize to an appropriate value - DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value - byte[] input = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Verify(input, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + /// Implements DSA digital signature algorithm. + /// + [TestClass] + public class DsaDigitalSignatureTest : TestBase + { + /// + ///A test for DsaDigitalSignature Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DsaDigitalSignatureConstructorTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(input); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Verify + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifyTest() + { + DsaKey key = null; // TODO: Initialize to an appropriate value + DsaDigitalSignature target = new DsaDigitalSignature(key); // TODO: Initialize to an appropriate value + byte[] input = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Verify(input, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs index 033af1f7..2e4c22ee 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/DsaKeyTest.cs @@ -1,151 +1,151 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - ///This is a test class for DsaKeyTest and is intended - ///to contain all DsaKeyTest Unit Tests - /// - [TestClass()] - public class DsaKeyTest : TestBase - { - /// - ///A test for DsaKey Constructor - /// - [TestMethod()] - public void DsaKeyConstructorTest() - { - DsaKey target = new DsaKey(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DsaKey Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DsaKeyConstructorTest1() - { - byte[] data = null; // TODO: Initialize to an appropriate value - DsaKey target = new DsaKey(data); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for DsaKey Constructor - /// - [TestMethod()] - public void DsaKeyConstructorTest2() - { - BigInteger p = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger q = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger g = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger y = new BigInteger(); // TODO: Initialize to an appropriate value - BigInteger x = new BigInteger(); // TODO: Initialize to an appropriate value - DsaKey target = new DsaKey(p, q, g, y, x); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for G - /// - [TestMethod()] - public void GTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.G; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for KeyLength - /// - [TestMethod()] - public void KeyLengthTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - int actual; - actual = target.KeyLength; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for P - /// - [TestMethod()] - public void PTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.P; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Public - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PublicTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger[] expected = null; // TODO: Initialize to an appropriate value - BigInteger[] actual; - target.Public = expected; - actual = target.Public; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Q - /// - [TestMethod()] - public void QTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.Q; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for X - /// - [TestMethod()] - public void XTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.X; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Y - /// - [TestMethod()] - public void YTest() - { - DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.Y; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + ///This is a test class for DsaKeyTest and is intended + ///to contain all DsaKeyTest Unit Tests + /// + [TestClass()] + public class DsaKeyTest : TestBase + { + /// + ///A test for DsaKey Constructor + /// + [TestMethod()] + public void DsaKeyConstructorTest() + { + DsaKey target = new DsaKey(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DsaKey Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DsaKeyConstructorTest1() + { + byte[] data = null; // TODO: Initialize to an appropriate value + DsaKey target = new DsaKey(data); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for DsaKey Constructor + /// + [TestMethod()] + public void DsaKeyConstructorTest2() + { + BigInteger p = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger q = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger g = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger y = new BigInteger(); // TODO: Initialize to an appropriate value + BigInteger x = new BigInteger(); // TODO: Initialize to an appropriate value + DsaKey target = new DsaKey(p, q, g, y, x); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for G + /// + [TestMethod()] + public void GTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.G; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for KeyLength + /// + [TestMethod()] + public void KeyLengthTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + int actual; + actual = target.KeyLength; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for P + /// + [TestMethod()] + public void PTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.P; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Public + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PublicTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger[] expected = null; // TODO: Initialize to an appropriate value + BigInteger[] actual; + target.Public = expected; + actual = target.Public; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Q + /// + [TestMethod()] + public void QTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.Q; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for X + /// + [TestMethod()] + public void XTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.X; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Y + /// + [TestMethod()] + public void YTest() + { + DsaKey target = new DsaKey(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.Y; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs index 6c5311be..d36f9629 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/HMacTest.cs @@ -1,136 +1,136 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System.Security.Cryptography; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - /// Provides HMAC algorithm implementation. - /// - /// - [TestClass] - public class HMacTest : TestBase - { - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_MD5_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, HashAlgorithmFactory.CreateHMACMD5)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha1_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, HashAlgorithmFactory.CreateHMACSHA1)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_MD5_96_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, key => HashAlgorithmFactory.CreateHMACMD5(key, 96))); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha1_96_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, key => HashAlgorithmFactory.CreateHMACSHA1(key, 96))); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha256_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, HashAlgorithmFactory.CreateHMACSHA256)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_Sha256_96_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-sha2-256-96", new HashInfo(32 * 8, (key) => HashAlgorithmFactory.CreateHMACSHA256(key, 96))); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_RIPEMD160_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-ripemd160", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HMac_RIPEMD160_OPENSSH_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HmacAlgorithms.Clear(); - connectionInfo.HmacAlgorithms.Add("hmac-ripemd160@openssh.com", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System.Security.Cryptography; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + /// Provides HMAC algorithm implementation. + /// + /// + [TestClass] + public class HMacTest : TestBase + { + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_MD5_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, HashAlgorithmFactory.CreateHMACMD5)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha1_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, HashAlgorithmFactory.CreateHMACSHA1)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_MD5_96_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-md5", new HashInfo(16 * 8, key => HashAlgorithmFactory.CreateHMACMD5(key, 96))); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha1_96_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha1", new HashInfo(20 * 8, key => HashAlgorithmFactory.CreateHMACSHA1(key, 96))); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha256_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha2-256", new HashInfo(32 * 8, HashAlgorithmFactory.CreateHMACSHA256)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_Sha256_96_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-sha2-256-96", new HashInfo(32 * 8, (key) => HashAlgorithmFactory.CreateHMACSHA256(key, 96))); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_RIPEMD160_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-ripemd160", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HMac_RIPEMD160_OPENSSH_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HmacAlgorithms.Clear(); + connectionInfo.HmacAlgorithms.Add("hmac-ripemd160@openssh.com", new HashInfo(160, HashAlgorithmFactory.CreateHMACRIPEMD160)); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs index 917ee730..93a76bbe 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaDigitalSignatureTest.cs @@ -1,40 +1,40 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security.Cryptography -{ - /// - /// Implements RSA digital signature algorithm. - /// - [TestClass] - public class RsaDigitalSignatureTest : TestBase - { - - /// - ///A test for RsaDigitalSignature Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RsaDigitalSignatureConstructorTest() - { - RsaKey rsaKey = null; // TODO: Initialize to an appropriate value - RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Dispose - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DisposeTest() - { - RsaKey rsaKey = null; // TODO: Initialize to an appropriate value - RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security.Cryptography +{ + /// + /// Implements RSA digital signature algorithm. + /// + [TestClass] + public class RsaDigitalSignatureTest : TestBase + { + + /// + ///A test for RsaDigitalSignature Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RsaDigitalSignatureConstructorTest() + { + RsaKey rsaKey = null; // TODO: Initialize to an appropriate value + RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Dispose + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DisposeTest() + { + RsaKey rsaKey = null; // TODO: Initialize to an appropriate value + RsaDigitalSignature target = new RsaDigitalSignature(rsaKey); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs index 2725511c..89323337 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/RsaKeyTest.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Contains RSA private and public key - /// - [TestClass] - public class RsaKeyTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Contains RSA private and public key + /// + [TestClass] + public class RsaKeyTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs index 45939e45..8dce8881 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/Cryptography/SymmetricCipherTest.cs @@ -1,62 +1,62 @@ -using Renci.SshNet.Security.Cryptography; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for SymmetricCipherTest and is intended - ///to contain all SymmetricCipherTest Unit Tests - /// - [TestClass()] - public class SymmetricCipherTest : TestBase - { - internal virtual SymmetricCipher CreateSymmetricCipher() - { - // TODO: Instantiate an appropriate concrete class. - SymmetricCipher target = null; - return target; - } - - /// - ///A test for DecryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DecryptBlockTest() - { - SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EncryptBlock - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EncryptBlockTest() - { - SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value - byte[] inputBuffer = null; // TODO: Initialize to an appropriate value - int inputOffset = 0; // TODO: Initialize to an appropriate value - int inputCount = 0; // TODO: Initialize to an appropriate value - byte[] outputBuffer = null; // TODO: Initialize to an appropriate value - int outputOffset = 0; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Security.Cryptography; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for SymmetricCipherTest and is intended + ///to contain all SymmetricCipherTest Unit Tests + /// + [TestClass()] + public class SymmetricCipherTest : TestBase + { + internal virtual SymmetricCipher CreateSymmetricCipher() + { + // TODO: Instantiate an appropriate concrete class. + SymmetricCipher target = null; + return target; + } + + /// + ///A test for DecryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DecryptBlockTest() + { + SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EncryptBlock + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EncryptBlockTest() + { + SymmetricCipher target = CreateSymmetricCipher(); // TODO: Initialize to an appropriate value + byte[] inputBuffer = null; // TODO: Initialize to an appropriate value + int inputOffset = 0; // TODO: Initialize to an appropriate value + int inputCount = 0; // TODO: Initialize to an appropriate value + byte[] outputBuffer = null; // TODO: Initialize to an appropriate value + int outputOffset = 0; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs index 5e2825be..a9547a54 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/HostAlgorithmTest.cs @@ -1,67 +1,67 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for HostAlgorithmTest and is intended - ///to contain all HostAlgorithmTest Unit Tests - /// - [TestClass()] - public class HostAlgorithmTest : TestBase - { - internal virtual HostAlgorithm CreateHostAlgorithm() - { - // TODO: Instantiate an appropriate concrete class. - HostAlgorithm target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Data - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DataTest() - { - HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Data; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for HostAlgorithmTest and is intended + ///to contain all HostAlgorithmTest Unit Tests + /// + [TestClass()] + public class HostAlgorithmTest : TestBase + { + internal virtual HostAlgorithm CreateHostAlgorithm() + { + // TODO: Instantiate an appropriate concrete class. + HostAlgorithm target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Data + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DataTest() + { + HostAlgorithm target = CreateHostAlgorithm(); // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Data; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs index afa838ee..f4fcb91f 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup14Sha1Test.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Represents "diffie-hellman-group14-sha1" algorithm implementation. - /// - [TestClass] - public class KeyExchangeDiffieHellmanGroup14Sha1Test : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Represents "diffie-hellman-group14-sha1" algorithm implementation. + /// + [TestClass] + public class KeyExchangeDiffieHellmanGroup14Sha1Test : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs index 0c729810..a06f8760 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroup1Sha1Test.cs @@ -1,49 +1,49 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanGroup1Sha1Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroup1Sha1Test Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanGroup1Sha1Test : TestBase - { - /// - ///A test for KeyExchangeDiffieHellmanGroup1Sha1 Constructor - /// - [TestMethod()] - public void KeyExchangeDiffieHellmanGroup1Sha1ConstructorTest() - { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for GroupPrime - /// - [TestMethod()] - public void GroupPrimeTest() - { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.GroupPrime; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Name - /// - [TestMethod()] - public void NameTest() - { - KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanGroup1Sha1Test and is intended + ///to contain all KeyExchangeDiffieHellmanGroup1Sha1Test Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanGroup1Sha1Test : TestBase + { + /// + ///A test for KeyExchangeDiffieHellmanGroup1Sha1 Constructor + /// + [TestMethod()] + public void KeyExchangeDiffieHellmanGroup1Sha1ConstructorTest() + { + KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for GroupPrime + /// + [TestMethod()] + public void GroupPrimeTest() + { + KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.GroupPrime; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Name + /// + [TestMethod()] + public void NameTest() + { + KeyExchangeDiffieHellmanGroup1Sha1 target = new KeyExchangeDiffieHellmanGroup1Sha1(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs index 87c45b60..980733e0 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha1Test.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Represents "diffie-hellman-group-exchange-sha1" algorithm implementation. - /// - [TestClass] - public class KeyExchangeDiffieHellmanGroupExchangeSha1Test : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Represents "diffie-hellman-group-exchange-sha1" algorithm implementation. + /// + [TestClass] + public class KeyExchangeDiffieHellmanGroupExchangeSha1Test : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs index 1fdd96ae..d6b5cfef 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupExchangeSha256Test.cs @@ -1,63 +1,63 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanGroupExchangeSha256Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroupExchangeSha256Test Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanGroupExchangeSha256Test : TestBase - { - /// - ///A test for KeyExchangeDiffieHellmanGroupExchangeSha256 Constructor - /// - [TestMethod()] - public void KeyExchangeDiffieHellmanGroupExchangeSha256ConstructorTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Finish - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void FinishTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value - target.Finish(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Start - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void StartTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value - target.Start(session, message); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Name - /// - [TestMethod()] - public void NameTest() - { - KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value - string actual; - actual = target.Name; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanGroupExchangeSha256Test and is intended + ///to contain all KeyExchangeDiffieHellmanGroupExchangeSha256Test Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanGroupExchangeSha256Test : TestBase + { + /// + ///A test for KeyExchangeDiffieHellmanGroupExchangeSha256 Constructor + /// + [TestMethod()] + public void KeyExchangeDiffieHellmanGroupExchangeSha256ConstructorTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Finish + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void FinishTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value + target.Finish(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Start + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void StartTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value + target.Start(session, message); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Name + /// + [TestMethod()] + public void NameTest() + { + KeyExchangeDiffieHellmanGroupExchangeSha256 target = new KeyExchangeDiffieHellmanGroupExchangeSha256(); // TODO: Initialize to an appropriate value + string actual; + actual = target.Name; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs index 8ad08550..40d6b3b8 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanGroupSha1Test.cs @@ -1,62 +1,62 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanGroupSha1Test and is intended - ///to contain all KeyExchangeDiffieHellmanGroupSha1Test Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanGroupSha1Test : TestBase - { - internal virtual KeyExchangeDiffieHellmanGroupSha1 CreateKeyExchangeDiffieHellmanGroupSha1() - { - // TODO: Instantiate an appropriate concrete class. - KeyExchangeDiffieHellmanGroupSha1 target = null; - return target; - } - - /// - ///A test for Finish - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void FinishTest() - { - KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value - target.Finish(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Start - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void StartTest() - { - KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value - target.Start(session, message); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GroupPrime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GroupPrimeTest() - { - KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value - BigInteger actual; - actual = target.GroupPrime; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanGroupSha1Test and is intended + ///to contain all KeyExchangeDiffieHellmanGroupSha1Test Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanGroupSha1Test : TestBase + { + internal virtual KeyExchangeDiffieHellmanGroupSha1 CreateKeyExchangeDiffieHellmanGroupSha1() + { + // TODO: Instantiate an appropriate concrete class. + KeyExchangeDiffieHellmanGroupSha1 target = null; + return target; + } + + /// + ///A test for Finish + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void FinishTest() + { + KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value + target.Finish(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Start + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void StartTest() + { + KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value + target.Start(session, message); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GroupPrime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GroupPrimeTest() + { + KeyExchangeDiffieHellmanGroupSha1 target = CreateKeyExchangeDiffieHellmanGroupSha1(); // TODO: Initialize to an appropriate value + BigInteger actual; + actual = target.GroupPrime; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs index 95d98e77..98b73858 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeDiffieHellmanTest.cs @@ -1,36 +1,36 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyExchangeDiffieHellmanTest and is intended - ///to contain all KeyExchangeDiffieHellmanTest Unit Tests - /// - [TestClass()] - public class KeyExchangeDiffieHellmanTest : TestBase - { - internal virtual KeyExchangeDiffieHellman CreateKeyExchangeDiffieHellman() - { - // TODO: Instantiate an appropriate concrete class. - KeyExchangeDiffieHellman target = null; - return target; - } - - /// - ///A test for Start - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void StartTest() - { - KeyExchangeDiffieHellman target = CreateKeyExchangeDiffieHellman(); // TODO: Initialize to an appropriate value - Session session = null; // TODO: Initialize to an appropriate value - KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value - target.Start(session, message); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyExchangeDiffieHellmanTest and is intended + ///to contain all KeyExchangeDiffieHellmanTest Unit Tests + /// + [TestClass()] + public class KeyExchangeDiffieHellmanTest : TestBase + { + internal virtual KeyExchangeDiffieHellman CreateKeyExchangeDiffieHellman() + { + // TODO: Instantiate an appropriate concrete class. + KeyExchangeDiffieHellman target = null; + return target; + } + + /// + ///A test for Start + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void StartTest() + { + KeyExchangeDiffieHellman target = CreateKeyExchangeDiffieHellman(); // TODO: Initialize to an appropriate value + Session session = null; // TODO: Initialize to an appropriate value + KeyExchangeInitMessage message = null; // TODO: Initialize to an appropriate value + target.Start(session, message); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs index d1bab190..839394e6 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyExchangeTest.cs @@ -1,16 +1,16 @@ -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for KeyExchangeTest and is intended - ///to contain all KeyExchangeTest Unit Tests - /// - [TestClass()] - public class KeyExchangeTest : TestBase - { - - } -} +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for KeyExchangeTest and is intended + ///to contain all KeyExchangeTest Unit Tests + /// + [TestClass()] + public class KeyExchangeTest : TestBase + { + + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs index 01c69c69..9bd5d10c 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyHostAlgorithmTest.cs @@ -1,123 +1,123 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - /// Implements key support for host algorithm. - /// - [TestClass] - public class KeyHostAlgorithmTest : TestBase - { - [TestMethod] - [TestCategory("integration")] - public void Test_HostKey_SshRsa_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HostKeyAlgorithms.Clear(); - connectionInfo.HostKeyAlgorithms.Add("ssh-rsa", (data) => { return new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data); }); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_HostKey_SshDss_Connection() - { - var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); - connectionInfo.HostKeyAlgorithms.Clear(); - connectionInfo.HostKeyAlgorithms.Add("ssh-dss", (data) => { return new KeyHostAlgorithm("ssh-dss", new DsaKey(), data); }); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - client.Disconnect(); - } - } - - /// - ///A test for KeyHostAlgorithm Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyHostAlgorithmConstructorTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for KeyHostAlgorithm Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyHostAlgorithmConstructorTest1() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key, data); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Data - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DataTest() - { - string name = string.Empty; // TODO: Initialize to an appropriate value - Key key = null; // TODO: Initialize to an appropriate value - KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Data; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + /// Implements key support for host algorithm. + /// + [TestClass] + public class KeyHostAlgorithmTest : TestBase + { + [TestMethod] + [TestCategory("integration")] + public void Test_HostKey_SshRsa_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HostKeyAlgorithms.Clear(); + connectionInfo.HostKeyAlgorithms.Add("ssh-rsa", (data) => { return new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data); }); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_HostKey_SshDss_Connection() + { + var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); + connectionInfo.HostKeyAlgorithms.Clear(); + connectionInfo.HostKeyAlgorithms.Add("ssh-dss", (data) => { return new KeyHostAlgorithm("ssh-dss", new DsaKey(), data); }); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + client.Disconnect(); + } + } + + /// + ///A test for KeyHostAlgorithm Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyHostAlgorithmConstructorTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for KeyHostAlgorithm Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyHostAlgorithmConstructorTest1() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key, data); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Data + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DataTest() + { + string name = string.Empty; // TODO: Initialize to an appropriate value + Key key = null; // TODO: Initialize to an appropriate value + KeyHostAlgorithm target = new KeyHostAlgorithm(name, key); // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Data; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs b/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs index 81339921..bbbbacff 100644 --- a/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Security/KeyTest.cs @@ -1,84 +1,84 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Security; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Security -{ - /// - ///This is a test class for KeyTest and is intended - ///to contain all KeyTest Unit Tests - /// - [TestClass()] - public class KeyTest : TestBase - { - internal virtual Key CreateKey() - { - // TODO: Instantiate an appropriate concrete class. - Key target = null; - return target; - } - - /// - ///A test for Sign - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SignTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.Sign(data); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for VerifySignature - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void VerifySignatureTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - byte[] data = null; // TODO: Initialize to an appropriate value - byte[] signature = null; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.VerifySignature(data, signature); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for KeyLength - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void KeyLengthTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - int actual; - actual = target.KeyLength; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Public - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void PublicTest() - { - Key target = CreateKey(); // TODO: Initialize to an appropriate value - BigInteger[] expected = null; // TODO: Initialize to an appropriate value - BigInteger[] actual; - target.Public = expected; - actual = target.Public; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Security; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Security +{ + /// + ///This is a test class for KeyTest and is intended + ///to contain all KeyTest Unit Tests + /// + [TestClass()] + public class KeyTest : TestBase + { + internal virtual Key CreateKey() + { + // TODO: Instantiate an appropriate concrete class. + Key target = null; + return target; + } + + /// + ///A test for Sign + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SignTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.Sign(data); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for VerifySignature + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void VerifySignatureTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + byte[] data = null; // TODO: Initialize to an appropriate value + byte[] signature = null; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.VerifySignature(data, signature); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for KeyLength + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void KeyLengthTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + int actual; + actual = target.KeyLength; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Public + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void PublicTest() + { + Key target = CreateKey(); // TODO: Initialize to an appropriate value + BigInteger[] expected = null; // TODO: Initialize to an appropriate value + BigInteger[] actual; + target.Public = expected; + actual = target.Public; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs b/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs index af54db1b..7780d2d8 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest.HttpProxy.cs @@ -1,263 +1,263 @@ -using System; -using System.Net; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - public partial class SessionTest - { - [TestMethod] - public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Whatever\r\n")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("HTTP response does not contain status line.", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("HTTP: Status code 501, \"Custom\"", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldSkipContentWhenHttpProxyReturnsHttpStatus200() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Length: 13\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("DUMMY_CONTENT")); - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - } - } - } - } - - [TestMethod] - public void ConnectShouldWriteConnectMethodToHttpProxy() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - Assert.AreEqual(string.Format("CONNECT {0} HTTP/1.0", serverEndPoint), proxyStub.HttpRequest.RequestLine); - } - } - - [TestMethod] - public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"); - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - var expectedProxyAuthorizationHeader = CreateProxyAuthorizationHeader(connectionInfo); - Assert.IsNotNull(proxyStub.HttpRequest.Headers.SingleOrDefault(p => p == expectedProxyAuthorizationHeader)); - } - } - - [TestMethod] - public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsEmpty() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, string.Empty); - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); - } - } - - [TestMethod] - public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNull() - { - var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - using (var proxyStub = new HttpProxyStub(proxyEndPoint)) - { - proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); - proxyStub.Start(); - - var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, null); - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (ProxyException) - { - } - } - - Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); - } - } - - private static ConnectionInfo CreateConnectionInfoWithProxy(IPEndPoint proxyEndPoint, IPEndPoint serverEndPoint, string proxyUserName) - { - return new ConnectionInfo( - serverEndPoint.Address.ToString(), - serverEndPoint.Port, - "eric", - ProxyTypes.Http, - proxyEndPoint.Address.ToString(), - proxyEndPoint.Port, - proxyUserName, - "proxypwd", - new NoneAuthenticationMethod("eric")); - } - - private static string CreateProxyAuthorizationHeader(ConnectionInfo connectionInfo) - { - return string.Format("Proxy-Authorization: Basic {0}", - Convert.ToBase64String( - Encoding.ASCII.GetBytes(string.Format("{0}:{1}", connectionInfo.ProxyUsername, - connectionInfo.ProxyPassword)))); - } - } -} +using System; +using System.Net; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + public partial class SessionTest + { + [TestMethod] + public void ConnectShouldThrowProxyExceptionWhenHttpProxyResponseDoesNotContainStatusLine() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Whatever\r\n")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("HTTP response does not contain status line.", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldThrowProxyExceptionWhenHttpProxyReturnsHttpStatusOtherThan200() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("HTTP: Status code 501, \"Custom\"", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldSkipHeadersWhenHttpProxyReturnsHttpStatus200() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldSkipContentWhenHttpProxyReturnsHttpStatus200() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Length: 13\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("Content-Type: application/octet-stream\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("\r\n")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("DUMMY_CONTENT")); + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("SSH-666-SshStub")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + } + } + } + } + + [TestMethod] + public void ConnectShouldWriteConnectMethodToHttpProxy() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + using (var session = new Session(CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + Assert.AreEqual(string.Format("CONNECT {0} HTTP/1.0", serverEndPoint), proxyStub.HttpRequest.RequestLine); + } + } + + [TestMethod] + public void ConnectShouldWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNotNullAndNotEmpty() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, "anon"); + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + var expectedProxyAuthorizationHeader = CreateProxyAuthorizationHeader(connectionInfo); + Assert.IsNotNull(proxyStub.HttpRequest.Headers.SingleOrDefault(p => p == expectedProxyAuthorizationHeader)); + } + } + + [TestMethod] + public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsEmpty() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, string.Empty); + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); + } + } + + [TestMethod] + public void ConnectShouldNotWriteProxyAuthorizationToHttpProxyWhenProxyUserNameIsNull() + { + var proxyEndPoint = new IPEndPoint(IPAddress.Loopback, 8123); + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + using (var proxyStub = new HttpProxyStub(proxyEndPoint)) + { + proxyStub.Responses.Add(Encoding.ASCII.GetBytes("HTTP/1.0 501 Custom\r\n")); + proxyStub.Start(); + + var connectionInfo = CreateConnectionInfoWithProxy(proxyEndPoint, serverEndPoint, null); + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (ProxyException) + { + } + } + + Assert.IsFalse(proxyStub.HttpRequest.Headers.Any(p => p.StartsWith("Proxy-Authorization:"))); + } + } + + private static ConnectionInfo CreateConnectionInfoWithProxy(IPEndPoint proxyEndPoint, IPEndPoint serverEndPoint, string proxyUserName) + { + return new ConnectionInfo( + serverEndPoint.Address.ToString(), + serverEndPoint.Port, + "eric", + ProxyTypes.Http, + proxyEndPoint.Address.ToString(), + proxyEndPoint.Port, + proxyUserName, + "proxypwd", + new NoneAuthenticationMethod("eric")); + } + + private static string CreateProxyAuthorizationHeader(ConnectionInfo connectionInfo) + { + return string.Format("Proxy-Authorization: Basic {0}", + Convert.ToBase64String( + Encoding.ASCII.GetBytes(string.Format("{0}:{1}", connectionInfo.ProxyUsername, + connectionInfo.ProxyPassword)))); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest.cs b/src/Renci.SshNet.Tests/Classes/SessionTest.cs index c94bfe56..29e88746 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest.cs @@ -1,363 +1,363 @@ -using System; -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides functionality to connect and interact with SSH server. - /// - [TestClass] - public partial class SessionTest : TestBase - { - private Mock _serviceFactoryMock; - - protected override void OnInit() - { - base.OnInit(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - } - - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull() - { - ConnectionInfo connectionInfo = null; - var serviceFactory = new Mock(MockBehavior.Strict).Object; - - try - { - new Session(connectionInfo, serviceFactory); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("connectionInfo", ex.ParamName); - } - } - - [TestMethod] - public void ConstructorShouldThrowArgumentNullExceptionWhenServiceFactoryIsNull() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - IServiceFactory serviceFactory = null; - - try - { - new Session(connectionInfo, serviceFactory); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("serviceFactory", ex.ParamName); - } - } - - [TestMethod] - public void ConnectShouldSkipLinesBeforeProtocolIdentificationString() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub\r\n")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - - Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); - } - } - } - } - - [TestMethod] - public void ConnectShouldSupportProtocolIdentificationStringThatDoesNotEndWithCrlf() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server version '666' is not supported.", ex.Message); - - Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); - } - } - } - } - - [TestMethod] - public void ConnectShouldThrowSshOperationExceptionWhenServerDoesNotRespondWithinConnectionTimeout() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - var timeout = TimeSpan.FromMilliseconds(500); - Socket clientSocket = null; - - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - clientSocket = socket; - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshOperationTimeoutException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds), ex.Message); - - Assert.IsNotNull(clientSocket); - Assert.IsTrue(clientSocket.Connected); - - // shut down socket - clientSocket.Shutdown(SocketShutdown.Send); - } - } - } - } - - [TestMethod] - public void ConnectShouldSshConnectionExceptionWhenServerResponseDoesNotContainProtocolIdentificationString() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - - // response ends with CRLF - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); - } - } - } - - // response does not end with CRLF - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); - } - } - } - - // last line is empty - using (var serverStub = new AsyncSocketListener(serverEndPoint)) - { - serverStub.Connected += socket => - { - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Shutdown(SocketShutdown.Send); - }; - serverStub.Start(); - - using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) - { - try - { - session.Connect(); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); - } - } - } - } - - [TestMethod] - public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("invalid.", 40, "user", - new KeyboardInteractiveAuthenticationMethod("user")); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); - } - } - - [TestMethod] - public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, - "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); - } - } - - [TestMethod] - public void DisconnectShouldNotThrowExceptionWhenSocketIsNotConnected() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException) - { - session.Disconnect(); - } - } - - [TestMethod] - public void DisconnectShouldNotThrowExceptionWhenConnectHasNotBeenInvoked() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - session.Disconnect(); - } - - [TestMethod] - public void DisposeShouldNotThrowExceptionWhenSocketIsNotConnected() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - try - { - session.Connect(); - Assert.Fail(); - } - catch (SocketException) - { - session.Dispose(); - } - } - - [TestMethod] - public void DisposeShouldNotThrowExceptionWhenConenectHasNotBeenInvoked() - { - var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, - new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); - var session = new Session(connectionInfo, _serviceFactoryMock.Object); - - session.Disconnect(); - } - - private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) - { - var connectionInfo = new ConnectionInfo( - serverEndPoint.Address.ToString(), - serverEndPoint.Port, - "eric", - new NoneAuthenticationMethod("eric")); - connectionInfo.Timeout = timeout; - return connectionInfo; - } - } +using System; +using System.Globalization; +using System.Net; +using System.Net.Sockets; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides functionality to connect and interact with SSH server. + /// + [TestClass] + public partial class SessionTest : TestBase + { + private Mock _serviceFactoryMock; + + protected override void OnInit() + { + base.OnInit(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + } + + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenConnectionInfoIsNull() + { + ConnectionInfo connectionInfo = null; + var serviceFactory = new Mock(MockBehavior.Strict).Object; + + try + { + new Session(connectionInfo, serviceFactory); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("connectionInfo", ex.ParamName); + } + } + + [TestMethod] + public void ConstructorShouldThrowArgumentNullExceptionWhenServiceFactoryIsNull() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + IServiceFactory serviceFactory = null; + + try + { + new Session(connectionInfo, serviceFactory); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("serviceFactory", ex.ParamName); + } + } + + [TestMethod] + public void ConnectShouldSkipLinesBeforeProtocolIdentificationString() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub\r\n")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + + Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); + } + } + } + } + + [TestMethod] + public void ConnectShouldSupportProtocolIdentificationStringThatDoesNotEndWithCrlf() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-666-SshStub")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(connectionInfo, _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server version '666' is not supported.", ex.Message); + + Assert.AreEqual("SSH-666-SshStub", connectionInfo.ServerVersion); + } + } + } + } + + [TestMethod] + public void ConnectShouldThrowSshOperationExceptionWhenServerDoesNotRespondWithinConnectionTimeout() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + var timeout = TimeSpan.FromMilliseconds(500); + Socket clientSocket = null; + + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + clientSocket = socket; + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromMilliseconds(500)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshOperationTimeoutException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Socket read operation has timed out after {0:F0} milliseconds.", timeout.TotalMilliseconds), ex.Message); + + Assert.IsNotNull(clientSocket); + Assert.IsTrue(clientSocket.Connected); + + // shut down socket + clientSocket.Shutdown(SocketShutdown.Send); + } + } + } + } + + [TestMethod] + public void ConnectShouldSshConnectionExceptionWhenServerResponseDoesNotContainProtocolIdentificationString() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + + // response ends with CRLF + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); + } + } + } + + // response does not end with CRLF + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); + } + } + } + + // last line is empty + using (var serverStub = new AsyncSocketListener(serverEndPoint)) + { + serverStub.Connected += socket => + { + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Shutdown(SocketShutdown.Send); + }; + serverStub.Start(); + + using (var session = new Session(CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)), _serviceFactoryMock.Object)) + { + try + { + session.Connect(); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Server response does not contain SSH protocol identification.", ex.Message); + } + } + } + } + + [TestMethod] + public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("invalid.", 40, "user", + new KeyboardInteractiveAuthenticationMethod("user")); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); + } + } + + [TestMethod] + public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, + "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); + } + } + + [TestMethod] + public void DisconnectShouldNotThrowExceptionWhenSocketIsNotConnected() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException) + { + session.Disconnect(); + } + } + + [TestMethod] + public void DisconnectShouldNotThrowExceptionWhenConnectHasNotBeenInvoked() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + session.Disconnect(); + } + + [TestMethod] + public void DisposeShouldNotThrowExceptionWhenSocketIsNotConnected() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + try + { + session.Connect(); + Assert.Fail(); + } + catch (SocketException) + { + session.Dispose(); + } + } + + [TestMethod] + public void DisposeShouldNotThrowExceptionWhenConenectHasNotBeenInvoked() + { + var connectionInfo = new ConnectionInfo("localhost", 6767, Resources.USERNAME, + new KeyboardInteractiveAuthenticationMethod(Resources.USERNAME)); + var session = new Session(connectionInfo, _serviceFactoryMock.Object); + + session.Disconnect(); + } + + private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) + { + var connectionInfo = new ConnectionInfo( + serverEndPoint.Address.ToString(), + serverEndPoint.Port, + "eric", + new NoneAuthenticationMethod("eric")); + connectionInfo.Timeout = timeout; + return connectionInfo; + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs index b92c2f0e..829bac3d 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected.cs @@ -1,169 +1,169 @@ -using System; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected : SessionTest_ConnectedBase - { - private IgnoreMessage _ignoreMessage; - - protected override void Arrange() - { - base.Arrange(); - - var data = new byte[10]; - Random.NextBytes(data); - _ignoreMessage = new IgnoreMessage(data); - } - - protected override void Act() - { - } - - [TestMethod] - public void ClientVersionIsRenciSshNet() - { - Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", Session.ClientVersion); - } - - [TestMethod] - public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - Assert.AreSame(ConnectionInfo, Session.ConnectionInfo); - } - - [TestMethod] - public void IsConnectedShouldReturnTrue() - { - Assert.IsTrue(Session.IsConnected); - } - - [TestMethod] - public void SendMessageShouldSendPacketToServer() - { - ServerBytesReceivedRegister.Clear(); - - Session.SendMessage(_ignoreMessage); - - // give session time to process message - Thread.Sleep(100); - - Assert.AreEqual(1, ServerBytesReceivedRegister.Count); - } - - [TestMethod] - public void SessionIdShouldReturnExchangeHashCalculatedFromKeyExchangeInitMessage() - { - Assert.IsNotNull(Session.SessionId); - Assert.AreSame(SessionId, Session.SessionId); - } - - [TestMethod] - public void ServerVersionShouldNotReturnNull() - { - Assert.IsNotNull(Session.ServerVersion); - Assert.AreEqual("SSH-2.0-SshStub", Session.ServerVersion); - } - - [TestMethod] - public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - - try - { - Session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var timeout = TimeSpan.FromMinutes(5); - - try - { - Session.WaitOnHandle(waitHandle, timeout); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - var session = (ISession) Session; - Assert.AreSame(ConnectionInfo, session.ConnectionInfo); - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldNotBeSignaled() - { - var session = (ISession) Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsFalse(session.MessageListenerCompleted.WaitOne(0)); - } - - [TestMethod] - public void ISession_SendMessageShouldSendPacketToServer() - { - var session = (ISession) Session; - ServerBytesReceivedRegister.Clear(); - - session.SendMessage(_ignoreMessage); - - // give session time to process message - Thread.Sleep(100); - - Assert.AreEqual(1, ServerBytesReceivedRegister.Count); - } - - [TestMethod] - public void ISession_TrySendMessageShouldSendPacketToServerAndReturnTrue() - { - var session = (ISession) Session; - ServerBytesReceivedRegister.Clear(); - - var actual = session.TrySendMessage(new IgnoreMessage()); - - // give session time to process message - Thread.Sleep(100); - - Assert.IsTrue(actual); - Assert.AreEqual(1, ServerBytesReceivedRegister.Count); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var session = (ISession) Session; - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - } -} +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected : SessionTest_ConnectedBase + { + private IgnoreMessage _ignoreMessage; + + protected override void Arrange() + { + base.Arrange(); + + var data = new byte[10]; + Random.NextBytes(data); + _ignoreMessage = new IgnoreMessage(data); + } + + protected override void Act() + { + } + + [TestMethod] + public void ClientVersionIsRenciSshNet() + { + Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", Session.ClientVersion); + } + + [TestMethod] + public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + Assert.AreSame(ConnectionInfo, Session.ConnectionInfo); + } + + [TestMethod] + public void IsConnectedShouldReturnTrue() + { + Assert.IsTrue(Session.IsConnected); + } + + [TestMethod] + public void SendMessageShouldSendPacketToServer() + { + ServerBytesReceivedRegister.Clear(); + + Session.SendMessage(_ignoreMessage); + + // give session time to process message + Thread.Sleep(100); + + Assert.AreEqual(1, ServerBytesReceivedRegister.Count); + } + + [TestMethod] + public void SessionIdShouldReturnExchangeHashCalculatedFromKeyExchangeInitMessage() + { + Assert.IsNotNull(Session.SessionId); + Assert.AreSame(SessionId, Session.SessionId); + } + + [TestMethod] + public void ServerVersionShouldNotReturnNull() + { + Assert.IsNotNull(Session.ServerVersion); + Assert.AreEqual("SSH-2.0-SshStub", Session.ServerVersion); + } + + [TestMethod] + public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + + try + { + Session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var timeout = TimeSpan.FromMinutes(5); + + try + { + Session.WaitOnHandle(waitHandle, timeout); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + var session = (ISession) Session; + Assert.AreSame(ConnectionInfo, session.ConnectionInfo); + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldNotBeSignaled() + { + var session = (ISession) Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsFalse(session.MessageListenerCompleted.WaitOne(0)); + } + + [TestMethod] + public void ISession_SendMessageShouldSendPacketToServer() + { + var session = (ISession) Session; + ServerBytesReceivedRegister.Clear(); + + session.SendMessage(_ignoreMessage); + + // give session time to process message + Thread.Sleep(100); + + Assert.AreEqual(1, ServerBytesReceivedRegister.Count); + } + + [TestMethod] + public void ISession_TrySendMessageShouldSendPacketToServerAndReturnTrue() + { + var session = (ISession) Session; + ServerBytesReceivedRegister.Clear(); + + var actual = session.TrySendMessage(new IgnoreMessage()); + + // give session time to process message + Thread.Sleep(100); + + Assert.IsTrue(actual); + Assert.AreEqual(1, ServerBytesReceivedRegister.Count); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var session = (ISession) Session; + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs index 56b03d85..9584d0c0 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_ConnectedBase.cs @@ -1,192 +1,192 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net; -using System.Net.Sockets; -using System.Security.Cryptography; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Compression; -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Security; -using Renci.SshNet.Security.Cryptography; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public abstract class SessionTest_ConnectedBase - { - private Mock _serviceFactoryMock; - private Mock _keyExchangeMock; - private Mock _clientAuthenticationMock; - private IPEndPoint _serverEndPoint; - private string _keyExchangeAlgorithm; - - protected Random Random { get; private set; } - protected byte[] SessionId { get; private set; } - protected ConnectionInfo ConnectionInfo { get; private set; } - protected IList DisconnectedRegister { get; private set; } - protected IList> DisconnectReceivedRegister { get; private set; } - protected IList ErrorOccurredRegister { get; private set; } - protected AsyncSocketListener ServerListener { get; private set; } - protected IList ServerBytesReceivedRegister { get; private set; } - protected Session Session { get; private set; } - protected Socket ServerSocket { get; private set; } - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void TearDown() - { - if (ServerListener != null) - { - ServerListener.Dispose(); - } - - if (Session != null) - { - Session.Dispose(); - } - } - - protected virtual void Arrange() - { - Random = new Random(); - - _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - ConnectionInfo = new ConnectionInfo( - _serverEndPoint.Address.ToString(), - _serverEndPoint.Port, - "user", - new PasswordAuthenticationMethod("user", "password")); - ConnectionInfo.Timeout = TimeSpan.FromSeconds(20); - _keyExchangeAlgorithm = Random.Next().ToString(CultureInfo.InvariantCulture); - SessionId = new byte[10]; - Random.NextBytes(SessionId); - DisconnectedRegister = new List(); - DisconnectReceivedRegister = new List>(); - ErrorOccurredRegister = new List(); - ServerBytesReceivedRegister = new List(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _keyExchangeMock = new Mock(MockBehavior.Strict); - _clientAuthenticationMock = new Mock(MockBehavior.Strict); - - Session = new Session(ConnectionInfo, _serviceFactoryMock.Object); - Session.Disconnected += (sender, args) => DisconnectedRegister.Add(args); - Session.DisconnectReceived += (sender, args) => DisconnectReceivedRegister.Add(args); - Session.ErrorOccured += (sender, args) => ErrorOccurredRegister.Add(args); - Session.KeyExchangeInitReceived += (sender, args) => - { - var newKeysMessage = new NewKeysMessage(); - var newKeys = newKeysMessage.GetPacket(8, null); - ServerSocket.Send(newKeys, 4, newKeys.Length - 4, SocketFlags.None); - }; - - _serviceFactoryMock.Setup( - p => - p.CreateKeyExchange(ConnectionInfo.KeyExchangeAlgorithms, new[] {_keyExchangeAlgorithm})).Returns(_keyExchangeMock.Object); - _keyExchangeMock.Setup(p => p.Name).Returns(_keyExchangeAlgorithm); - _keyExchangeMock.Setup(p => p.Start(Session, It.IsAny())); - _keyExchangeMock.Setup(p => p.ExchangeHash).Returns(SessionId); - _keyExchangeMock.Setup(p => p.CreateServerCipher()).Returns((Cipher) null); - _keyExchangeMock.Setup(p => p.CreateClientCipher()).Returns((Cipher) null); - _keyExchangeMock.Setup(p => p.CreateServerHash()).Returns((HashAlgorithm) null); - _keyExchangeMock.Setup(p => p.CreateClientHash()).Returns((HashAlgorithm) null); - _keyExchangeMock.Setup(p => p.CreateCompressor()).Returns((Compressor) null); - _keyExchangeMock.Setup(p => p.CreateDecompressor()).Returns((Compressor) null); - _keyExchangeMock.Setup(p => p.Dispose()); - _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Callback(ClientAuthentication_Callback).Returns(_clientAuthenticationMock.Object); - _clientAuthenticationMock.Setup(p => p.Authenticate(ConnectionInfo, Session)); - - ServerListener = new AsyncSocketListener(_serverEndPoint); - ServerListener.Connected += socket => - { - ServerSocket = socket; - - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); - }; - - var counter = 0; - - ServerListener.BytesReceived += (received, socket) => - { - ServerBytesReceivedRegister.Add(received); - - switch (counter++) - { - case 0: - var keyExchangeInitMessage = new KeyExchangeInitMessage - { - CompressionAlgorithmsClientToServer = new string[0], - CompressionAlgorithmsServerToClient = new string[0], - EncryptionAlgorithmsClientToServer = new string[0], - EncryptionAlgorithmsServerToClient = new string[0], - KeyExchangeAlgorithms = new[] {_keyExchangeAlgorithm}, - LanguagesClientToServer = new string[0], - LanguagesServerToClient = new string[0], - MacAlgorithmsClientToServer = new string[0], - MacAlgorithmsServerToClient = new string[0], - ServerHostKeyAlgorithms = new string[0] - }; - var keyExchangeInit = keyExchangeInitMessage.GetPacket(8, null); - ServerSocket.Send(keyExchangeInit, 4, keyExchangeInit.Length - 4, SocketFlags.None); - break; - case 1: - var serviceAcceptMessage = - ServiceAcceptMessageBuilder.Create(ServiceName.UserAuthentication) - .Build(); - ServerSocket.Send(serviceAcceptMessage, 0, serviceAcceptMessage.Length, SocketFlags.None); - break; - } - }; - ServerListener.Start(); - - Session.Connect(); - } - - protected virtual void ClientAuthentication_Callback() - { - } - - protected abstract void Act(); - - private class ServiceAcceptMessageBuilder - { - private readonly ServiceName _serviceName; - - private ServiceAcceptMessageBuilder(ServiceName serviceName) - { - _serviceName = serviceName; - } - - public static ServiceAcceptMessageBuilder Create(ServiceName serviceName) - { - return new ServiceAcceptMessageBuilder(serviceName); - } - - public byte[] Build() - { - var serviceName = _serviceName.ToArray(); - - var sshDataStream = new SshDataStream(4 + 1 + 1 + 4 + serviceName.Length); - sshDataStream.Write((uint)(sshDataStream.Capacity - 4)); // packet length - sshDataStream.WriteByte(0); // padding length - sshDataStream.WriteByte(ServiceAcceptMessage.MessageNumber); - sshDataStream.WriteBinary(serviceName); - return sshDataStream.ToArray(); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Net; +using System.Net.Sockets; +using System.Security.Cryptography; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Compression; +using Renci.SshNet.Messages; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Security; +using Renci.SshNet.Security.Cryptography; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public abstract class SessionTest_ConnectedBase + { + private Mock _serviceFactoryMock; + private Mock _keyExchangeMock; + private Mock _clientAuthenticationMock; + private IPEndPoint _serverEndPoint; + private string _keyExchangeAlgorithm; + + protected Random Random { get; private set; } + protected byte[] SessionId { get; private set; } + protected ConnectionInfo ConnectionInfo { get; private set; } + protected IList DisconnectedRegister { get; private set; } + protected IList> DisconnectReceivedRegister { get; private set; } + protected IList ErrorOccurredRegister { get; private set; } + protected AsyncSocketListener ServerListener { get; private set; } + protected IList ServerBytesReceivedRegister { get; private set; } + protected Session Session { get; private set; } + protected Socket ServerSocket { get; private set; } + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void TearDown() + { + if (ServerListener != null) + { + ServerListener.Dispose(); + } + + if (Session != null) + { + Session.Dispose(); + } + } + + protected virtual void Arrange() + { + Random = new Random(); + + _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + ConnectionInfo = new ConnectionInfo( + _serverEndPoint.Address.ToString(), + _serverEndPoint.Port, + "user", + new PasswordAuthenticationMethod("user", "password")); + ConnectionInfo.Timeout = TimeSpan.FromSeconds(20); + _keyExchangeAlgorithm = Random.Next().ToString(CultureInfo.InvariantCulture); + SessionId = new byte[10]; + Random.NextBytes(SessionId); + DisconnectedRegister = new List(); + DisconnectReceivedRegister = new List>(); + ErrorOccurredRegister = new List(); + ServerBytesReceivedRegister = new List(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _keyExchangeMock = new Mock(MockBehavior.Strict); + _clientAuthenticationMock = new Mock(MockBehavior.Strict); + + Session = new Session(ConnectionInfo, _serviceFactoryMock.Object); + Session.Disconnected += (sender, args) => DisconnectedRegister.Add(args); + Session.DisconnectReceived += (sender, args) => DisconnectReceivedRegister.Add(args); + Session.ErrorOccured += (sender, args) => ErrorOccurredRegister.Add(args); + Session.KeyExchangeInitReceived += (sender, args) => + { + var newKeysMessage = new NewKeysMessage(); + var newKeys = newKeysMessage.GetPacket(8, null); + ServerSocket.Send(newKeys, 4, newKeys.Length - 4, SocketFlags.None); + }; + + _serviceFactoryMock.Setup( + p => + p.CreateKeyExchange(ConnectionInfo.KeyExchangeAlgorithms, new[] {_keyExchangeAlgorithm})).Returns(_keyExchangeMock.Object); + _keyExchangeMock.Setup(p => p.Name).Returns(_keyExchangeAlgorithm); + _keyExchangeMock.Setup(p => p.Start(Session, It.IsAny())); + _keyExchangeMock.Setup(p => p.ExchangeHash).Returns(SessionId); + _keyExchangeMock.Setup(p => p.CreateServerCipher()).Returns((Cipher) null); + _keyExchangeMock.Setup(p => p.CreateClientCipher()).Returns((Cipher) null); + _keyExchangeMock.Setup(p => p.CreateServerHash()).Returns((HashAlgorithm) null); + _keyExchangeMock.Setup(p => p.CreateClientHash()).Returns((HashAlgorithm) null); + _keyExchangeMock.Setup(p => p.CreateCompressor()).Returns((Compressor) null); + _keyExchangeMock.Setup(p => p.CreateDecompressor()).Returns((Compressor) null); + _keyExchangeMock.Setup(p => p.Dispose()); + _serviceFactoryMock.Setup(p => p.CreateClientAuthentication()).Callback(ClientAuthentication_Callback).Returns(_clientAuthenticationMock.Object); + _clientAuthenticationMock.Setup(p => p.Authenticate(ConnectionInfo, Session)); + + ServerListener = new AsyncSocketListener(_serverEndPoint); + ServerListener.Connected += socket => + { + ServerSocket = socket; + + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); + }; + + var counter = 0; + + ServerListener.BytesReceived += (received, socket) => + { + ServerBytesReceivedRegister.Add(received); + + switch (counter++) + { + case 0: + var keyExchangeInitMessage = new KeyExchangeInitMessage + { + CompressionAlgorithmsClientToServer = new string[0], + CompressionAlgorithmsServerToClient = new string[0], + EncryptionAlgorithmsClientToServer = new string[0], + EncryptionAlgorithmsServerToClient = new string[0], + KeyExchangeAlgorithms = new[] {_keyExchangeAlgorithm}, + LanguagesClientToServer = new string[0], + LanguagesServerToClient = new string[0], + MacAlgorithmsClientToServer = new string[0], + MacAlgorithmsServerToClient = new string[0], + ServerHostKeyAlgorithms = new string[0] + }; + var keyExchangeInit = keyExchangeInitMessage.GetPacket(8, null); + ServerSocket.Send(keyExchangeInit, 4, keyExchangeInit.Length - 4, SocketFlags.None); + break; + case 1: + var serviceAcceptMessage = + ServiceAcceptMessageBuilder.Create(ServiceName.UserAuthentication) + .Build(); + ServerSocket.Send(serviceAcceptMessage, 0, serviceAcceptMessage.Length, SocketFlags.None); + break; + } + }; + ServerListener.Start(); + + Session.Connect(); + } + + protected virtual void ClientAuthentication_Callback() + { + } + + protected abstract void Act(); + + private class ServiceAcceptMessageBuilder + { + private readonly ServiceName _serviceName; + + private ServiceAcceptMessageBuilder(ServiceName serviceName) + { + _serviceName = serviceName; + } + + public static ServiceAcceptMessageBuilder Create(ServiceName serviceName) + { + return new ServiceAcceptMessageBuilder(serviceName); + } + + public byte[] Build() + { + var serviceName = _serviceName.ToArray(); + + var sshDataStream = new SshDataStream(4 + 1 + 1 + 4 + serviceName.Length); + sshDataStream.Write((uint)(sshDataStream.Capacity - 4)); // packet length + sshDataStream.WriteByte(0); // padding length + sshDataStream.WriteByte(ServiceAcceptMessage.MessageNumber); + sshDataStream.WriteBinary(serviceName); + return sshDataStream.ToArray(); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs index bd94eba1..6587a710 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ConnectionReset.cs @@ -1,168 +1,168 @@ -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ConnectionReset : SessionTest_ConnectedBase - { - protected override void Act() - { - ServerSocket.Close(); - - // give session some time to react to connection reset - Thread.Sleep(200); - } - - [TestMethodAttribute] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethodAttribute] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsRaisedOnce() - { - Assert.AreEqual(1, ErrorOccurredRegister.Count); - - var errorOccurred = ErrorOccurredRegister[0]; - Assert.IsNotNull(errorOccurred); - - var exception = errorOccurred.Exception; - Assert.IsNotNull(exception); - Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); - - var connectionException = (SshConnectionException) exception; - Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); - - var innerException = exception.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException) innerException; - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); - - Assert.AreSame(innerException.Message, connectionException.Message); - } - - [TestMethodAttribute] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethodAttribute] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethodAttribute] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession) Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethodAttribute] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethodAttribute] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingConnectionReset() - { - var session = (ISession) Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason); - - var innerException = ex.InnerException; - Assert.IsNotNull(innerException); - Assert.AreEqual(typeof(SocketException), innerException.GetType()); - - var socketException = (SocketException)ex.InnerException; - Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); - - Assert.AreSame(innerException.Message, ex.Message); - - } - } - } -} +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ConnectionReset : SessionTest_ConnectedBase + { + protected override void Act() + { + ServerSocket.Close(); + + // give session some time to react to connection reset + Thread.Sleep(200); + } + + [TestMethodAttribute] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethodAttribute] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsRaisedOnce() + { + Assert.AreEqual(1, ErrorOccurredRegister.Count); + + var errorOccurred = ErrorOccurredRegister[0]; + Assert.IsNotNull(errorOccurred); + + var exception = errorOccurred.Exception; + Assert.IsNotNull(exception); + Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); + + var connectionException = (SshConnectionException) exception; + Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); + + var innerException = exception.InnerException; + Assert.IsNotNull(innerException); + Assert.AreEqual(typeof(SocketException), innerException.GetType()); + + var socketException = (SocketException) innerException; + Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); + + Assert.AreSame(innerException.Message, connectionException.Message); + } + + [TestMethodAttribute] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethodAttribute] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethodAttribute] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession) Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethodAttribute] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethodAttribute] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingConnectionReset() + { + var session = (ISession) Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ConnectionLost, ex.DisconnectReason); + + var innerException = ex.InnerException; + Assert.IsNotNull(innerException); + Assert.AreEqual(typeof(SocketException), innerException.GetType()); + + var socketException = (SocketException)ex.InnerException; + Assert.AreEqual(SocketError.ConnectionReset, socketException.SocketErrorCode); + + Assert.AreSame(innerException.Message, ex.Message); + + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs index 99f676f7..cf2827cc 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_Disconnect.cs @@ -1,148 +1,148 @@ -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_Disconnect : SessionTest_ConnectedBase - { - protected override void Act() - { - Session.Disconnect(); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsNeverRaised() - { - Assert.AreEqual(0, ErrorOccurredRegister.Count); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() - { - var session = (ISession) Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_Disconnect : SessionTest_ConnectedBase + { + protected override void Act() + { + Session.Disconnect(); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsNeverRaised() + { + Assert.AreEqual(0, ErrorOccurredRegister.Count); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() + { + var session = (ISession) Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs index 6b29f75f..b55f87c4 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsBadPacket.cs @@ -1,164 +1,164 @@ -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerSendsBadPacket : SessionTest_ConnectedBase - { - protected override void Act() - { - var badPacket = new byte[] { 0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 }; - ServerSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); - - // give session some time to react to bad packet - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsRaisedOnce() - { - Assert.AreEqual(1, ErrorOccurredRegister.Count); - - var errorOccurred = ErrorOccurredRegister[0]; - Assert.IsNotNull(errorOccurred); - - var exception = errorOccurred.Exception; - Assert.IsNotNull(exception); - Assert.AreEqual(typeof (SshConnectionException), exception.GetType()); - - var connectionException = (SshConnectionException) exception; - Assert.AreEqual(DisconnectReason.ProtocolError, connectionException.DisconnectReason); - Assert.IsNull(connectionException.InnerException); - Assert.AreEqual("Bad packet length: 168101125.", connectionException.Message); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() - { - var session = (ISession) Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ProtocolError, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Bad packet length: 168101125.", ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerSendsBadPacket : SessionTest_ConnectedBase + { + protected override void Act() + { + var badPacket = new byte[] { 0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05 }; + ServerSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); + + // give session some time to react to bad packet + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsRaisedOnce() + { + Assert.AreEqual(1, ErrorOccurredRegister.Count); + + var errorOccurred = ErrorOccurredRegister[0]; + Assert.IsNotNull(errorOccurred); + + var exception = errorOccurred.Exception; + Assert.IsNotNull(exception); + Assert.AreEqual(typeof (SshConnectionException), exception.GetType()); + + var connectionException = (SshConnectionException) exception; + Assert.AreEqual(DisconnectReason.ProtocolError, connectionException.DisconnectReason); + Assert.IsNull(connectionException.InnerException); + Assert.AreEqual("Bad packet length: 168101125.", connectionException.Message); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingBadPacket() + { + var session = (ISession) Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ProtocolError, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Bad packet length: 168101125.", ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs index 4a69acbd..c47b444e 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessage.cs @@ -1,168 +1,168 @@ -using System.Diagnostics; -using System.Globalization; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerSendsDisconnectMessage : SessionTest_ConnectedBase - { - private DisconnectMessage _disconnectMessage; - - protected override void Arrange() - { - _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); - - base.Arrange(); - } - - protected override void Act() - { - var disconnect = _disconnectMessage.GetPacket(8, null); - ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); - - // give session some time to process DisconnectMessage - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectReceivedRegister.Count); - - var disconnectMessage = DisconnectReceivedRegister[0].Message; - Assert.IsNotNull(disconnectMessage); - Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); - Assert.AreEqual("en", disconnectMessage.Language); - Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); - } - - [TestMethod] - public void ErrorOccurredIsNeverRaised() - { - Assert.AreEqual(0, ErrorOccurredRegister.Count); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession) Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() - { - var session = (ISession)Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Globalization; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerSendsDisconnectMessage : SessionTest_ConnectedBase + { + private DisconnectMessage _disconnectMessage; + + protected override void Arrange() + { + _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); + + base.Arrange(); + } + + protected override void Act() + { + var disconnect = _disconnectMessage.GetPacket(8, null); + ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); + + // give session some time to process DisconnectMessage + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectReceivedRegister.Count); + + var disconnectMessage = DisconnectReceivedRegister[0].Message; + Assert.IsNotNull(disconnectMessage); + Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); + Assert.AreEqual("en", disconnectMessage.Language); + Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); + } + + [TestMethod] + public void ErrorOccurredIsNeverRaised() + { + Assert.AreEqual(0, ErrorOccurredRegister.Count); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession) Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() + { + var session = (ISession)Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs index b1e073c9..f6c9152f 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket.cs @@ -1,172 +1,172 @@ -using System.Diagnostics; -using System.Globalization; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket : SessionTest_ConnectedBase - { - private DisconnectMessage _disconnectMessage; - - protected override void Arrange() - { - _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); - - base.Arrange(); - } - - protected override void Act() - { - // server sends SSH_MSG_DISCONNECT - var disconnect = _disconnectMessage.GetPacket(8, null); - ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); - - // server shuts down the socket - ServerSocket.Shutdown(SocketShutdown.Send); - - // give session some time to process DisconnectMessage and socket shutdown - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsRaisedOnce() - { - Assert.AreEqual(1, DisconnectReceivedRegister.Count); - - var disconnectMessage = DisconnectReceivedRegister[0].Message; - Assert.IsNotNull(disconnectMessage); - Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); - Assert.AreEqual("en", disconnectMessage.Language); - Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); - } - - [TestMethod] - public void ErrorOccurredIsNeverRaised() - { - Assert.AreEqual(0, ErrorOccurredRegister.Count); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession)Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() - { - var session = (ISession)Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); - } - } - } -} +using System.Diagnostics; +using System.Globalization; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerSendsDisconnectMessageAndShutsDownSocket : SessionTest_ConnectedBase + { + private DisconnectMessage _disconnectMessage; + + protected override void Arrange() + { + _disconnectMessage = new DisconnectMessage(DisconnectReason.ServiceNotAvailable, "Not today!"); + + base.Arrange(); + } + + protected override void Act() + { + // server sends SSH_MSG_DISCONNECT + var disconnect = _disconnectMessage.GetPacket(8, null); + ServerSocket.Send(disconnect, 4, disconnect.Length - 4, SocketFlags.None); + + // server shuts down the socket + ServerSocket.Shutdown(SocketShutdown.Send); + + // give session some time to process DisconnectMessage and socket shutdown + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsRaisedOnce() + { + Assert.AreEqual(1, DisconnectReceivedRegister.Count); + + var disconnectMessage = DisconnectReceivedRegister[0].Message; + Assert.IsNotNull(disconnectMessage); + Assert.AreEqual(_disconnectMessage.Description, disconnectMessage.Description); + Assert.AreEqual("en", disconnectMessage.Language); + Assert.AreEqual(_disconnectMessage.ReasonCode, disconnectMessage.ReasonCode); + } + + [TestMethod] + public void ErrorOccurredIsNeverRaised() + { + Assert.AreEqual(0, ErrorOccurredRegister.Count); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession)Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingDisconnectReason() + { + var session = (ISession)Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.ServiceNotAvailable, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "The connection was closed by the server: {0} ({1}).", _disconnectMessage.Description, _disconnectMessage.ReasonCode), ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs index a7a7867c..fd6755f4 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_Connected_ServerShutsDownSocket.cs @@ -1,161 +1,161 @@ -using System; -using System.Diagnostics; -using System.Net.Sockets; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_Connected_ServerShutsDownSocket : SessionTest_ConnectedBase - { - protected override void Act() - { - ServerSocket.Shutdown(SocketShutdown.Send); - - // give session some time to process socket shutdown - Thread.Sleep(200); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(Session.IsConnected); - } - - [TestMethod] - public void DisconnectShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Disconnect(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void DisconnectedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectedRegister.Count); - } - - [TestMethod] - public void DisconnectReceivedIsNeverRaised() - { - Assert.AreEqual(0, DisconnectReceivedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredIsRaisedOnce() - { - Assert.AreEqual(1, ErrorOccurredRegister.Count); - - var errorOccurred = ErrorOccurredRegister[0]; - Assert.IsNotNull(errorOccurred); - - var exception = errorOccurred.Exception; - Assert.IsNotNull(exception); - Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); - - var connectionException = (SshConnectionException) exception; - Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); - Assert.IsNull(connectionException.InnerException); - Assert.AreEqual("An established connection was aborted by the server.", connectionException.Message); - } - - [TestMethod] - public void DisposeShouldFinishImmediately() - { - var stopwatch = new Stopwatch(); - stopwatch.Start(); - - Session.Dispose(); - - stopwatch.Stop(); - Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); - } - - [TestMethod] - public void ReceiveOnServerSocketShouldReturnZero() - { - var buffer = new byte[1]; - - var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); - - Assert.AreEqual(0, actual); - } - - [TestMethod] - public void SendMessageShouldThrowSshConnectionException() - { - try - { - Session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession)Session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); - } - - [TestMethodAttribute] - public void ISession_SendMessageShouldThrowSshConnectionException() - { - var session = (ISession) Session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession)Session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingAbortedConnection() - { - var session = (ISession)Session; - var waitHandle = new ManualResetEvent(false); - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("An established connection was aborted by the server.", ex.Message); - } - } - } -} +using System; +using System.Diagnostics; +using System.Net.Sockets; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_Connected_ServerShutsDownSocket : SessionTest_ConnectedBase + { + protected override void Act() + { + ServerSocket.Shutdown(SocketShutdown.Send); + + // give session some time to process socket shutdown + Thread.Sleep(200); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(Session.IsConnected); + } + + [TestMethod] + public void DisconnectShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Disconnect(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void DisconnectedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectedRegister.Count); + } + + [TestMethod] + public void DisconnectReceivedIsNeverRaised() + { + Assert.AreEqual(0, DisconnectReceivedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredIsRaisedOnce() + { + Assert.AreEqual(1, ErrorOccurredRegister.Count); + + var errorOccurred = ErrorOccurredRegister[0]; + Assert.IsNotNull(errorOccurred); + + var exception = errorOccurred.Exception; + Assert.IsNotNull(exception); + Assert.AreEqual(typeof(SshConnectionException), exception.GetType()); + + var connectionException = (SshConnectionException) exception; + Assert.AreEqual(DisconnectReason.ConnectionLost, connectionException.DisconnectReason); + Assert.IsNull(connectionException.InnerException); + Assert.AreEqual("An established connection was aborted by the server.", connectionException.Message); + } + + [TestMethod] + public void DisposeShouldFinishImmediately() + { + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + Session.Dispose(); + + stopwatch.Stop(); + Assert.IsTrue(stopwatch.ElapsedMilliseconds < 500); + } + + [TestMethod] + public void ReceiveOnServerSocketShouldReturnZero() + { + var buffer = new byte[1]; + + var actual = ServerSocket.Receive(buffer, 0, buffer.Length, SocketFlags.None); + + Assert.AreEqual(0, actual); + } + + [TestMethod] + public void SendMessageShouldThrowSshConnectionException() + { + try + { + Session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession)Session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne()); + } + + [TestMethodAttribute] + public void ISession_SendMessageShouldThrowSshConnectionException() + { + var session = (ISession) Session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession)Session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowSshConnectionExceptionDetailingAbortedConnection() + { + var session = (ISession)Session; + var waitHandle = new ManualResetEvent(false); + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("An established connection was aborted by the server.", ex.Message); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs index 44cbd7d6..4638b698 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_NotConnected.cs @@ -1,191 +1,191 @@ -using System; -using System.Net; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_NotConnected - { - private ConnectionInfo _connectionInfo; - private IServiceFactory _serviceFactory; - private Session _session; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - _connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); - _serviceFactory = new Mock(MockBehavior.Strict).Object; - } - - protected void Act() - { - _session = new Session(_connectionInfo, _serviceFactory); - } - - [TestMethod] - public void ClientVersionIsRenciSshNet() - { - Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion); - } - - [TestMethod] - public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - Assert.AreSame(_connectionInfo, _session.ConnectionInfo); - } - - [TestMethod] - public void IsConnectedShouldReturnFalse() - { - Assert.IsFalse(_session.IsConnected); - } - - [TestMethod] - public void SendMessageShouldThrowShhConnectionException() - { - try - { - _session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void SessionIdShouldReturnNull() - { - Assert.IsNull(_session.SessionId); - } - - [TestMethod] - public void ServerVersionShouldReturnNull() - { - Assert.IsNull(_session.ServerVersion); - } - - [TestMethod] - public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - - try - { - _session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var timeout = TimeSpan.FromMinutes(5); - - try - { - _session.WaitOnHandle(waitHandle, timeout); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - [TestMethod] - public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() - { - var session = (ISession)_session; - Assert.AreSame(_connectionInfo, session.ConnectionInfo); - } - - [TestMethod] - public void ISession_MessageListenerCompletedShouldBeSignaled() - { - var session = (ISession) _session; - - Assert.IsNotNull(session.MessageListenerCompleted); - Assert.IsTrue(session.MessageListenerCompleted.WaitOne(0)); - } - - [TestMethod] - public void ISession_SendMessageShouldThrowShhConnectionException() - { - var session = (ISession)_session; - - try - { - session.SendMessage(new IgnoreMessage()); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - - [TestMethod] - public void ISession_TrySendMessageShouldReturnFalse() - { - var session = (ISession)_session; - - var actual = session.TrySendMessage(new IgnoreMessage()); - - Assert.IsFalse(actual); - } - - [TestMethod] - public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() - { - WaitHandle waitHandle = null; - var session = (ISession)_session; - - try - { - session.WaitOnHandle(waitHandle); - Assert.Fail(); - } - catch (ArgumentNullException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("waitHandle", ex.ParamName); - } - } - - private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) - { - var connectionInfo = new ConnectionInfo( - serverEndPoint.Address.ToString(), - serverEndPoint.Port, - "eric", - new NoneAuthenticationMethod("eric")); - connectionInfo.Timeout = timeout; - return connectionInfo; - } - } -} +using System; +using System.Net; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_NotConnected + { + private ConnectionInfo _connectionInfo; + private IServiceFactory _serviceFactory; + private Session _session; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + _connectionInfo = CreateConnectionInfo(serverEndPoint, TimeSpan.FromSeconds(5)); + _serviceFactory = new Mock(MockBehavior.Strict).Object; + } + + protected void Act() + { + _session = new Session(_connectionInfo, _serviceFactory); + } + + [TestMethod] + public void ClientVersionIsRenciSshNet() + { + Assert.AreEqual("SSH-2.0-Renci.SshNet.SshClient.0.0.1", _session.ClientVersion); + } + + [TestMethod] + public void ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + Assert.AreSame(_connectionInfo, _session.ConnectionInfo); + } + + [TestMethod] + public void IsConnectedShouldReturnFalse() + { + Assert.IsFalse(_session.IsConnected); + } + + [TestMethod] + public void SendMessageShouldThrowShhConnectionException() + { + try + { + _session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void SessionIdShouldReturnNull() + { + Assert.IsNull(_session.SessionId); + } + + [TestMethod] + public void ServerVersionShouldReturnNull() + { + Assert.IsNull(_session.ServerVersion); + } + + [TestMethod] + public void WaitOnHandle_WaitHandle_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + + try + { + _session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void WaitOnHandle_WaitHandleAndTimeout_ShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var timeout = TimeSpan.FromMinutes(5); + + try + { + _session.WaitOnHandle(waitHandle, timeout); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + [TestMethod] + public void ISession_ConnectionInfoShouldReturnConnectionInfoPassedThroughConstructor() + { + var session = (ISession)_session; + Assert.AreSame(_connectionInfo, session.ConnectionInfo); + } + + [TestMethod] + public void ISession_MessageListenerCompletedShouldBeSignaled() + { + var session = (ISession) _session; + + Assert.IsNotNull(session.MessageListenerCompleted); + Assert.IsTrue(session.MessageListenerCompleted.WaitOne(0)); + } + + [TestMethod] + public void ISession_SendMessageShouldThrowShhConnectionException() + { + var session = (ISession)_session; + + try + { + session.SendMessage(new IgnoreMessage()); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.AreEqual(DisconnectReason.None, ex.DisconnectReason); + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + + [TestMethod] + public void ISession_TrySendMessageShouldReturnFalse() + { + var session = (ISession)_session; + + var actual = session.TrySendMessage(new IgnoreMessage()); + + Assert.IsFalse(actual); + } + + [TestMethod] + public void ISession_WaitOnHandleShouldThrowArgumentNullExceptionWhenWaitHandleIsNull() + { + WaitHandle waitHandle = null; + var session = (ISession)_session; + + try + { + session.WaitOnHandle(waitHandle); + Assert.Fail(); + } + catch (ArgumentNullException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("waitHandle", ex.ParamName); + } + } + + private static ConnectionInfo CreateConnectionInfo(IPEndPoint serverEndPoint, TimeSpan timeout) + { + var connectionInfo = new ConnectionInfo( + serverEndPoint.Address.ToString(), + serverEndPoint.Port, + "eric", + new NoneAuthenticationMethod("eric")); + connectionInfo.Timeout = timeout; + return connectionInfo; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs b/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs index 985e5087..a13de281 100644 --- a/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs +++ b/src/Renci.SshNet.Tests/Classes/SessionTest_SocketConnected_BadPacketAndDispose.cs @@ -1,95 +1,95 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SessionTest_SocketConnected_BadPacketAndDispose - { - private Mock _serviceFactoryMock; - private ConnectionInfo _connectionInfo; - private Session _session; - private AsyncSocketListener _serverListener; - private IPEndPoint _serverEndPoint; - private Socket _serverSocket; - private SshConnectionException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void TearDown() - { - if (_serverListener != null) - { - _serverListener.Dispose(); - } - } - - protected void Arrange() - { - _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); - _connectionInfo = new ConnectionInfo( - _serverEndPoint.Address.ToString(), - _serverEndPoint.Port, - "user", - new PasswordAuthenticationMethod("user", "password")); - _connectionInfo.Timeout = TimeSpan.FromMilliseconds(200); - _actualException = null; - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - - _serverListener = new AsyncSocketListener(_serverEndPoint); - _serverListener.Connected += (socket) => - { - _serverSocket = socket; - - socket.Send(Encoding.ASCII.GetBytes("\r\n")); - socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); - socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); - }; - _serverListener.BytesReceived += (received, socket) => - { - var badPacket = new byte[] {0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}; - _serverSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); - _serverSocket.Shutdown(SocketShutdown.Send); - }; - _serverListener.Start(); - } - - protected virtual void Act() - { - try - { - using (_session = new Session(_connectionInfo, _serviceFactoryMock.Object)) - { - _session.Connect(); - } - } - catch (SshConnectionException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void ConnectShouldThrowSshConnectionException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual(DisconnectReason.ProtocolError, _actualException.DisconnectReason); - Assert.AreEqual("Bad packet length: 168101125.", _actualException.Message); - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SessionTest_SocketConnected_BadPacketAndDispose + { + private Mock _serviceFactoryMock; + private ConnectionInfo _connectionInfo; + private Session _session; + private AsyncSocketListener _serverListener; + private IPEndPoint _serverEndPoint; + private Socket _serverSocket; + private SshConnectionException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void TearDown() + { + if (_serverListener != null) + { + _serverListener.Dispose(); + } + } + + protected void Arrange() + { + _serverEndPoint = new IPEndPoint(IPAddress.Loopback, 8122); + _connectionInfo = new ConnectionInfo( + _serverEndPoint.Address.ToString(), + _serverEndPoint.Port, + "user", + new PasswordAuthenticationMethod("user", "password")); + _connectionInfo.Timeout = TimeSpan.FromMilliseconds(200); + _actualException = null; + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + + _serverListener = new AsyncSocketListener(_serverEndPoint); + _serverListener.Connected += (socket) => + { + _serverSocket = socket; + + socket.Send(Encoding.ASCII.GetBytes("\r\n")); + socket.Send(Encoding.ASCII.GetBytes("WELCOME banner\r\n")); + socket.Send(Encoding.ASCII.GetBytes("SSH-2.0-SshStub\r\n")); + }; + _serverListener.BytesReceived += (received, socket) => + { + var badPacket = new byte[] {0x0a, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}; + _serverSocket.Send(badPacket, 0, badPacket.Length, SocketFlags.None); + _serverSocket.Shutdown(SocketShutdown.Send); + }; + _serverListener.Start(); + } + + protected virtual void Act() + { + try + { + using (_session = new Session(_connectionInfo, _serviceFactoryMock.Object)) + { + _session.Connect(); + } + } + catch (SshConnectionException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void ConnectShouldThrowSshConnectionException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual(DisconnectReason.ProtocolError, _actualException.DisconnectReason); + Assert.AreEqual("Bad packet length: 168101125.", _actualException.Message); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs index ba139e9d..bad627f2 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/FStatVfsRequestTest.cs @@ -1,123 +1,123 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class FStatVfsRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private string _name; - private byte[] _nameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - - _name = "fstatvfs@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, extendedReplyActionInvocations.Count); - } - - [TestMethod] - public void Complete_SftpExtendedReplyResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); - - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); - - request.Complete(extendedReplyResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, extendedReplyActionInvocations.Count); - Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class FStatVfsRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private string _name; + private byte[] _nameBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + + _name = "fstatvfs@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, extendedReplyActionInvocations.Count); + } + + [TestMethod] + public void Complete_SftpExtendedReplyResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); + + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, extendedAction, statusAction); + + request.Complete(extendedReplyResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, extendedReplyActionInvocations.Count); + Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new FStatVfsRequest(_protocolVersion, _requestId, _handle, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs index 8282f52d..787f9904 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/HardLinkRequestTest.cs @@ -1,116 +1,116 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class HardLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - private byte[] _nameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = Encoding.UTF8.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = Encoding.UTF8.GetBytes(_newPath); - - _name = "hardlink@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); - - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualOldPath = new byte[_oldPathBytes.Length]; - sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); - - Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualNewPath = new byte[_newPathBytes.Length]; - sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class HardLinkRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _name; + private string _oldPath; + private byte[] _oldPathBytes; + private string _newPath; + private byte[] _newPathBytes; + private byte[] _nameBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); + _oldPathBytes = Encoding.UTF8.GetBytes(_oldPath); + _newPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newPathBytes = Encoding.UTF8.GetBytes(_newPath); + + _name = "hardlink@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); + + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_newPath, request.NewPath); + Assert.AreEqual(_oldPath, request.OldPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new HardLinkRequest(_protocolVersion, _requestId, _oldPath, _newPath, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // OldPath length + expectedBytesLength += _oldPathBytes.Length; // OldPath + expectedBytesLength += 4; // NewPath length + expectedBytesLength += _newPathBytes.Length; // NewPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualOldPath = new byte[_oldPathBytes.Length]; + sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); + Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); + + Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualNewPath = new byte[_newPathBytes.Length]; + sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); + Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs index c9edf3bd..60cc1d03 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/PosixRenameRequestTest.cs @@ -1,120 +1,120 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class PosixRenameRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - private byte[] _nameBytes; - private Encoding _encoding; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _encoding = Encoding.Unicode; - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = _encoding.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = _encoding.GetBytes(_newPath); - - _name = "posix-rename@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualOldPath = new byte[_oldPathBytes.Length]; - sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); - - Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); - - var actualNewPath = new byte[_newPathBytes.Length]; - sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class PosixRenameRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _name; + private string _oldPath; + private byte[] _oldPathBytes; + private string _newPath; + private byte[] _newPathBytes; + private byte[] _nameBytes; + private Encoding _encoding; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _encoding = Encoding.Unicode; + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); + _oldPathBytes = _encoding.GetBytes(_oldPath); + _newPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newPathBytes = _encoding.GetBytes(_newPath); + + _name = "posix-rename@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_newPath, request.NewPath); + Assert.AreEqual(_oldPath, request.OldPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new PosixRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // OldPath length + expectedBytesLength += _oldPathBytes.Length; // OldPath + expectedBytesLength += 4; // NewPath length + expectedBytesLength += _newPathBytes.Length; // NewPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualOldPath = new byte[_oldPathBytes.Length]; + sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); + Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); + + Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); + + var actualNewPath = new byte[_newPathBytes.Length]; + sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); + Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs index 5dd1e9a8..89d315f3 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/ExtendedRequests/StatVfsRequestTest.cs @@ -1,129 +1,129 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests -{ - [TestClass] - public class StatVfsRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _name; - private string _path; - private byte[] _pathBytes; - private byte[] _nameBytes; - private Encoding _encoding; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _encoding = Encoding.Unicode; - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - - _name = "statvfs@openssh.com"; - _nameBytes = Encoding.UTF8.GetBytes(_name); - } - - [TestMethod] - public void Constructor() - { - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_name, request.Name); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, extendedReplyActionInvocations.Count); - } - - [TestMethod] - public void Complete_SftpExtendedReplyResponse() - { - IList statusActionInvocations = new List(); - IList extendedReplyActionInvocations = new List(); - - Action extendedAction = extendedReplyActionInvocations.Add; - Action statusAction = statusActionInvocations.Add; - var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); - - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); - - request.Complete(extendedReplyResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, extendedReplyActionInvocations.Count); - Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Name length - expectedBytesLength += _nameBytes.Length; // Name - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); - - var actualNameBytes = new byte[_nameBytes.Length]; - sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); - Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests.ExtendedRequests +{ + [TestClass] + public class StatVfsRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _name; + private string _path; + private byte[] _pathBytes; + private byte[] _nameBytes; + private Encoding _encoding; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _encoding = Encoding.Unicode; + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + + _name = "statvfs@openssh.com"; + _nameBytes = Encoding.UTF8.GetBytes(_name); + } + + [TestMethod] + public void Constructor() + { + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_name, request.Name); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Extended, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, extendedReplyActionInvocations.Count); + } + + [TestMethod] + public void Complete_SftpExtendedReplyResponse() + { + IList statusActionInvocations = new List(); + IList extendedReplyActionInvocations = new List(); + + Action extendedAction = extendedReplyActionInvocations.Add; + Action statusAction = statusActionInvocations.Add; + var extendedReplyResponse = new SftpExtendedReplyResponse(_protocolVersion); + + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, extendedAction, statusAction); + + request.Complete(extendedReplyResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, extendedReplyActionInvocations.Count); + Assert.AreSame(extendedReplyResponse, extendedReplyActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new StatVfsRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Name length + expectedBytesLength += _nameBytes.Length; // Name + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Extended, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + Assert.AreEqual((uint) _nameBytes.Length, sshDataStream.ReadUInt32()); + + var actualNameBytes = new byte[_nameBytes.Length]; + sshDataStream.Read(actualNameBytes, 0, actualNameBytes.Length); + Assert.IsTrue(_nameBytes.SequenceEqual(actualNameBytes)); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs index a62472ff..22100993 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpBlockRequestTest.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpBlockRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private ulong _length; - private uint _lockMask; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _length = (ulong) random.Next(0, int.MaxValue); - _lockMask = (uint) random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_lockMask, request.LockMask); - Assert.AreEqual(_offset, request.Offset); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Block, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 8; // Length - expectedBytesLength += 4; // LockMask - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Block, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt64()); - Assert.AreEqual(_lockMask, sshDataStream.ReadUInt32()); - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpBlockRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private ulong _length; + private uint _lockMask; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _length = (ulong) random.Next(0, int.MaxValue); + _lockMask = (uint) random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_length, request.Length); + Assert.AreEqual(_lockMask, request.LockMask); + Assert.AreEqual(_offset, request.Offset); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Block, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpBlockRequest(_protocolVersion, _requestId, _handle, _offset, _length, _lockMask, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 8; // Length + expectedBytesLength += 4; // LockMask + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Block, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + Assert.AreEqual(_length, sshDataStream.ReadUInt64()); + Assert.AreEqual(_lockMask, sshDataStream.ReadUInt32()); + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs index 8fe79c6f..3959af33 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpCloseRequestTest.cs @@ -1,87 +1,87 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpCloseRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Close, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Close, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpCloseRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Close, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpCloseRequest(_protocolVersion, _requestId, _handle, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint)bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Close, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs index 01b81331..a91797ed 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFSetStatRequestTest.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpFSetStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.FSetStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - IList statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.FSetStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpFSetStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.FSetStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + IList statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpFSetStatRequest(_protocolVersion, _requestId, _handle, _attributes, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.FSetStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs index 5ff1dd04..03cf64a9 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpFStatRequestTest.cs @@ -1,109 +1,109 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpFStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.FStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var attrsResponse = new SftpAttrsResponse(_protocolVersion); - - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); - - request.Complete(attrsResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, attrsActionInvocations.Count); - Assert.AreSame(attrsResponse, attrsActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, attrsActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.FStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpFStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.FStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var attrsResponse = new SftpAttrsResponse(_protocolVersion); + + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); + + request.Complete(attrsResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, attrsActionInvocations.Count); + Assert.AreSame(attrsResponse, attrsActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, attrsAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, attrsActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpFStatRequest(_protocolVersion, _requestId, _handle, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.FStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs index 704c6982..4f039b1f 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpInitRequestTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpInitRequestTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpInitRequestTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs index 878b18a2..08313b05 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLStatRequestTest.cs @@ -1,115 +1,115 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpLStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _encoding = Encoding.Unicode; - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.LStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var attrsResponse = new SftpAttrsResponse(_protocolVersion); - - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(attrsResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, attrsActionInvocations.Count); - Assert.AreSame(attrsResponse, attrsActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, attrsActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Pah length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.LStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpLStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _encoding = Encoding.Unicode; + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.LStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var attrsResponse = new SftpAttrsResponse(_protocolVersion); + + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(attrsResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, attrsActionInvocations.Count); + Assert.AreSame(attrsResponse, attrsActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, attrsActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpLStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Pah length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.LStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs index 77b94645..eba2f249 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpLinkRequestTest.cs @@ -1,110 +1,110 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private string _newLinkPath; - private byte[] _newLinkPathBytes; - private string _existingPath; - private byte[] _existingPathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newLinkPathBytes = Encoding.UTF8.GetBytes(_newLinkPath); - _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); - _existingPathBytes = Encoding.UTF8.GetBytes(_existingPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); - - Assert.AreEqual(_existingPath, request.ExistingPath); - Assert.IsTrue(request.IsSymLink); - Assert.AreEqual(_newLinkPath, request.NewLinkPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Link, request.SftpMessageType); - - request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, false, null); - - Assert.IsFalse(request.IsSymLink); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // NewLinkPath length - expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath - expectedBytesLength += 4; // ExistingPath length - expectedBytesLength += _existingPathBytes.Length; // ExistingPath - expectedBytesLength += 1; // IsSymLink - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Link, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; - sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); - Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); - - Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); - var actualExistingPath = new byte[_existingPathBytes.Length]; - sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); - Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); - - Assert.AreEqual(1, sshDataStream.ReadByte()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpLinkRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private string _newLinkPath; + private byte[] _newLinkPathBytes; + private string _existingPath; + private byte[] _existingPathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newLinkPathBytes = Encoding.UTF8.GetBytes(_newLinkPath); + _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); + _existingPathBytes = Encoding.UTF8.GetBytes(_existingPath); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); + + Assert.AreEqual(_existingPath, request.ExistingPath); + Assert.IsTrue(request.IsSymLink); + Assert.AreEqual(_newLinkPath, request.NewLinkPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Link, request.SftpMessageType); + + request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, false, null); + + Assert.IsFalse(request.IsSymLink); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpLinkRequest(_protocolVersion, _requestId, _newLinkPath, _existingPath, true, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // NewLinkPath length + expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath + expectedBytesLength += 4; // ExistingPath length + expectedBytesLength += _existingPathBytes.Length; // ExistingPath + expectedBytesLength += 1; // IsSymLink + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Link, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); + var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; + sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); + Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); + + Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); + var actualExistingPath = new byte[_existingPathBytes.Length]; + sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); + Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); + + Assert.AreEqual(1, sshDataStream.ReadByte()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs index e3bed2fb..d8a3a9eb 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpMkDirRequestTest.cs @@ -1,102 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpMkDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.MkDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.MkDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpMkDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.MkDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpMkDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.MkDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenDirRequestTest.cs index 55fe352d..2ee19ad4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenDirRequestTest.cs @@ -1,115 +1,115 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpOpenDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.OpenDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpHandleResponse() - { - var statusActionInvocations = new List(); - var handleActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action handleAction = handleActionInvocations.Add; - var handleResponse = new SftpHandleResponse(_protocolVersion); - - var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, handleAction, statusAction); - - request.Complete(handleResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, handleActionInvocations.Count); - Assert.AreSame(handleResponse, handleActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var handleActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action handleAction = handleActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, handleAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, handleActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.OpenDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpOpenDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.OpenDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpHandleResponse() + { + var statusActionInvocations = new List(); + var handleActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action handleAction = handleActionInvocations.Add; + var handleResponse = new SftpHandleResponse(_protocolVersion); + + var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, handleAction, statusAction); + + request.Complete(handleResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, handleActionInvocations.Count); + Assert.AreSame(handleResponse, handleActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var handleActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action handleAction = handleActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, handleAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, handleActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpOpenDirRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.OpenDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs index 5a4a1c70..9a82ae8e 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpOpenRequestTest.cs @@ -1,143 +1,143 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpOpenRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _filename; - private byte[] _filenameBytes; - private Flags _flags; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _filename = random.Next().ToString(CultureInfo.InvariantCulture); - _filenameBytes = _encoding.GetBytes(_filename); - _flags = Flags.Read; - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_filename, request.Filename); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Open, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpHandleResponse() - { - var statusActionInvocations = new List(); - var handleActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action handleAction = handleActionInvocations.Add; - var handleResponse = new SftpHandleResponse(_protocolVersion); - - var request = new SftpOpenRequest( - _protocolVersion, - _requestId, - _filename, - _encoding, - _flags, - handleAction, - statusAction); - - request.Complete(handleResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, handleActionInvocations.Count); - Assert.AreSame(handleResponse, handleActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var handleActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action handleAction = handleActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpOpenRequest( - _protocolVersion, - _requestId, - _filename, - _encoding, - _flags, - handleAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, handleActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Filename length - expectedBytesLength += _filenameBytes.Length; // Filename - expectedBytesLength += 4; // Flags - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Open, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_filenameBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_filenameBytes.SequenceEqual(actualPath)); - - Assert.AreEqual((uint) _flags, sshDataStream.ReadUInt32()); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpOpenRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _filename; + private byte[] _filenameBytes; + private Flags _flags; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _filename = random.Next().ToString(CultureInfo.InvariantCulture); + _filenameBytes = _encoding.GetBytes(_filename); + _flags = Flags.Read; + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_filename, request.Filename); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Open, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpHandleResponse() + { + var statusActionInvocations = new List(); + var handleActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action handleAction = handleActionInvocations.Add; + var handleResponse = new SftpHandleResponse(_protocolVersion); + + var request = new SftpOpenRequest( + _protocolVersion, + _requestId, + _filename, + _encoding, + _flags, + handleAction, + statusAction); + + request.Complete(handleResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, handleActionInvocations.Count); + Assert.AreSame(handleResponse, handleActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var handleActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action handleAction = handleActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpOpenRequest( + _protocolVersion, + _requestId, + _filename, + _encoding, + _flags, + handleAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, handleActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpOpenRequest(_protocolVersion, _requestId, _filename, _encoding, _flags, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Filename length + expectedBytesLength += _filenameBytes.Length; // Filename + expectedBytesLength += 4; // Flags + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Open, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_filenameBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_filenameBytes.SequenceEqual(actualPath)); + + Assert.AreEqual((uint) _flags, sshDataStream.ReadUInt32()); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs index 020c4f7c..01b21ed1 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadDirRequestTest.cs @@ -1,110 +1,110 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.ReadDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); - - request.Complete(nameResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, nameActionInvocations.Count); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, nameActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.ReadDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpReadDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.ReadDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); + + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); + + request.Complete(nameResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, nameActionInvocations.Count); + Assert.AreSame(nameResponse, nameActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, nameAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, nameActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpReadDirRequest(_protocolVersion, _requestId, _handle, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.ReadDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs index 3f03f766..04dccf7b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadLinkRequestTest.cs @@ -1,128 +1,128 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadLinkRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.ReadLink, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpNameResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpReadLinkRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(nameResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, nameActionInvocations.Count); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadLinkRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, nameActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.ReadLink, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } - +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpReadLinkRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.ReadLink, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpNameResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); + + var request = new SftpReadLinkRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + request.Complete(nameResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, nameActionInvocations.Count); + Assert.AreSame(nameResponse, nameActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpReadLinkRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, nameActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpReadLinkRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.ReadLink, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } + } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs index 36e3ad6a..6d4dc882 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpReadRequestTest.cs @@ -1,134 +1,134 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpReadRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private uint _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _length = (uint) random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_offset, request.Offset); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Read, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpDataResponse() - { - var statusActionInvocations = new List(); - var dataActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action dataAction = dataActionInvocations.Add; - var dataResponse = new SftpDataResponse(_protocolVersion); - - var request = new SftpReadRequest( - _protocolVersion, - _requestId, - _handle, - _offset, - _length, - dataAction, - statusAction); - - request.Complete(dataResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, dataActionInvocations.Count); - Assert.AreSame(dataResponse, dataActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var dataActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action dataAction = dataActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpReadRequest( - _protocolVersion, - _requestId, - _handle, - _offset, - _length, - dataAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, dataActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 4; // Length - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Read, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt32()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpReadRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private uint _length; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _length = (uint) random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_length, request.Length); + Assert.AreEqual(_offset, request.Offset); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Read, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpDataResponse() + { + var statusActionInvocations = new List(); + var dataActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action dataAction = dataActionInvocations.Add; + var dataResponse = new SftpDataResponse(_protocolVersion); + + var request = new SftpReadRequest( + _protocolVersion, + _requestId, + _handle, + _offset, + _length, + dataAction, + statusAction); + + request.Complete(dataResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, dataActionInvocations.Count); + Assert.AreSame(dataResponse, dataActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var dataActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action dataAction = dataActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpReadRequest( + _protocolVersion, + _requestId, + _handle, + _offset, + _length, + dataAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, dataActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpReadRequest(_protocolVersion, _requestId, _handle, _offset, _length, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 4; // Length + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Read, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + Assert.AreEqual(_length, sshDataStream.ReadUInt32()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs index fc3cb13a..1ee8653c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRealPathRequestTest.cs @@ -1,143 +1,143 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRealPathRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - - var request = new SftpRealPathRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.RealPath, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpNameResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); - - var request = new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); - - request.Complete(nameResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, nameActionInvocations.Count); - Assert.AreSame(nameResponse, nameActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRealPathRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - Assert.AreEqual(0, nameActionInvocations.Count); - } - - [TestMethod] - public void GetBytes() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - Action nameAction = nameActionInvocations.Add; - var request = new SftpRealPathRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - nameAction, - statusAction); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.RealPath, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRealPathRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + + var request = new SftpRealPathRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.RealPath, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpNameResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var nameResponse = new SftpNameResponse(_protocolVersion, Encoding.Unicode); + + var request = new SftpRealPathRequest(_protocolVersion, _requestId, _path, _encoding, nameAction, statusAction); + + request.Complete(nameResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, nameActionInvocations.Count); + Assert.AreSame(nameResponse, nameActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRealPathRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + Assert.AreEqual(0, nameActionInvocations.Count); + } + + [TestMethod] + public void GetBytes() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + Action nameAction = nameActionInvocations.Add; + var request = new SftpRealPathRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + nameAction, + statusAction); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.RealPath, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs index 9db8db2b..b0910c56 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRemoveRequestTest.cs @@ -1,93 +1,93 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRemoveRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _filename; - private byte[] _filenameBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _filename = random.Next().ToString(CultureInfo.InvariantCulture); - _filenameBytes = _encoding.GetBytes(_filename); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_filename, request.Filename); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Remove, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Filename length - expectedBytesLength += _filenameBytes.Length; // Filename - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Remove, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); - var actualFilename = new byte[_filenameBytes.Length]; - sshDataStream.Read(actualFilename, 0, actualFilename.Length); - Assert.IsTrue(_filenameBytes.SequenceEqual(actualFilename)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRemoveRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _filename; + private byte[] _filenameBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _filename = random.Next().ToString(CultureInfo.InvariantCulture); + _filenameBytes = _encoding.GetBytes(_filename); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_filename, request.Filename); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Remove, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpRemoveRequest(_protocolVersion, _requestId, _filename, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Filename length + expectedBytesLength += _filenameBytes.Length; // Filename + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Remove, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _filenameBytes.Length, sshDataStream.ReadUInt32()); + var actualFilename = new byte[_filenameBytes.Length]; + sshDataStream.Read(actualFilename, 0, actualFilename.Length); + Assert.IsTrue(_filenameBytes.SequenceEqual(actualFilename)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs index ce4e235f..0225e505 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRenameRequestTest.cs @@ -1,105 +1,105 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRenameRequestTest : TestBase - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _oldPath; - private byte[] _oldPathBytes; - private string _newPath; - private byte[] _newPathBytes; - - protected override void OnInit() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); - _oldPathBytes = _encoding.GetBytes(_oldPath); - _newPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newPathBytes = _encoding.GetBytes(_newPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_newPath, request.NewPath); - Assert.AreEqual(_oldPath, request.OldPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Rename, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // OldPath length - expectedBytesLength += _oldPathBytes.Length; // OldPath - expectedBytesLength += 4; // NewPath length - expectedBytesLength += _newPathBytes.Length; // NewPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Rename, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); - var actualOldPath = new byte[_oldPathBytes.Length]; - sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); - Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); - - Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewPath = new byte[_newPathBytes.Length]; - sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); - Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRenameRequestTest : TestBase + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _oldPath; + private byte[] _oldPathBytes; + private string _newPath; + private byte[] _newPathBytes; + + protected override void OnInit() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _oldPath = random.Next().ToString(CultureInfo.InvariantCulture); + _oldPathBytes = _encoding.GetBytes(_oldPath); + _newPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newPathBytes = _encoding.GetBytes(_newPath); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_newPath, request.NewPath); + Assert.AreEqual(_oldPath, request.OldPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Rename, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpRenameRequest(_protocolVersion, _requestId, _oldPath, _newPath, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // OldPath length + expectedBytesLength += _oldPathBytes.Length; // OldPath + expectedBytesLength += 4; // NewPath length + expectedBytesLength += _newPathBytes.Length; // NewPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Rename, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _oldPathBytes.Length, sshDataStream.ReadUInt32()); + var actualOldPath = new byte[_oldPathBytes.Length]; + sshDataStream.Read(actualOldPath, 0, actualOldPath.Length); + Assert.IsTrue(_oldPathBytes.SequenceEqual(actualOldPath)); + + Assert.AreEqual((uint) _newPathBytes.Length, sshDataStream.ReadUInt32()); + var actualNewPath = new byte[_newPathBytes.Length]; + sshDataStream.Read(actualNewPath, 0, actualNewPath.Length); + Assert.IsTrue(_newPathBytes.SequenceEqual(actualNewPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs index 8cfbdda9..bd7f12c3 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpRmDirRequestTest.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpRmDirRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.RmDir, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var statusActionInvocations = new List(); - var nameActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.RmDir, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpRmDirRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.RmDir, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var statusActionInvocations = new List(); + var nameActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var request = new SftpRmDirRequest(_protocolVersion, _requestId, _path, _encoding, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.RmDir, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs index eb6694cf..7c1bb454 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSetStatRequestTest.cs @@ -1,107 +1,107 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpSetStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - private SftpFileAttributes _attributes; - private byte[] _attributesBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - _attributes = SftpFileAttributes.Empty; - _attributesBytes = _attributes.GetBytes(); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.SetStat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpSetStatRequest( - _protocolVersion, - _requestId, - _path, - _encoding, - _attributes, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - expectedBytesLength += _attributesBytes.Length; // Attributes - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.SetStat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - var actualAttributes = new byte[_attributesBytes.Length]; - sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); - Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpSetStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + private SftpFileAttributes _attributes; + private byte[] _attributesBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + _attributes = SftpFileAttributes.Empty; + _attributesBytes = _attributes.GetBytes(); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.SetStat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpSetStatRequest( + _protocolVersion, + _requestId, + _path, + _encoding, + _attributes, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpSetStatRequest(_protocolVersion, _requestId, _path, _encoding, _attributes, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + expectedBytesLength += _attributesBytes.Length; // Attributes + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.SetStat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + var actualAttributes = new byte[_attributesBytes.Length]; + sshDataStream.Read(actualAttributes, 0, actualAttributes.Length); + Assert.IsTrue(_attributesBytes.SequenceEqual(actualAttributes)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs index e0870493..8f6e9a31 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpStatRequestTest.cs @@ -1,113 +1,113 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpStatRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _path; - private byte[] _pathBytes; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _pathBytes = _encoding.GetBytes(_path); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_path, request.Path); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Stat, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpAttrsResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var attrsResponse = new SftpAttrsResponse(_protocolVersion); - - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(attrsResponse); - - Assert.AreEqual(0, statusActionInvocations.Count); - Assert.AreEqual(1, attrsActionInvocations.Count); - Assert.AreSame(attrsResponse, attrsActionInvocations[0]); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - var attrsActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - Action attrsAction = attrsActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreEqual(0, attrsActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Path length - expectedBytesLength += _pathBytes.Length; // Path - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Stat, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); - var actualPath = new byte[_pathBytes.Length]; - sshDataStream.Read(actualPath, 0, actualPath.Length); - Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpStatRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _path; + private byte[] _pathBytes; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _pathBytes = _encoding.GetBytes(_path); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_path, request.Path); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Stat, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpAttrsResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var attrsResponse = new SftpAttrsResponse(_protocolVersion); + + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(attrsResponse); + + Assert.AreEqual(0, statusActionInvocations.Count); + Assert.AreEqual(1, attrsActionInvocations.Count); + Assert.AreSame(attrsResponse, attrsActionInvocations[0]); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + var attrsActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + Action attrsAction = attrsActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, attrsAction, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreEqual(0, attrsActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpStatRequest(_protocolVersion, _requestId, _path, _encoding, null, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Path length + expectedBytesLength += _pathBytes.Length; // Path + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Stat, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _pathBytes.Length, sshDataStream.ReadUInt32()); + var actualPath = new byte[_pathBytes.Length]; + sshDataStream.Read(actualPath, 0, actualPath.Length); + Assert.IsTrue(_pathBytes.SequenceEqual(actualPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs index 8bc97087..8b9a6e6c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpSymLinkRequestTest.cs @@ -1,123 +1,123 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpSymLinkRequestTest : TestBase - { - private uint _protocolVersion; - private uint _requestId; - private Encoding _encoding; - private string _newLinkPath; - private byte[] _newLinkPathBytes; - private string _existingPath; - private byte[] _existingPathBytes; - - protected override void OnInit() - { - var random = new Random(); - - _protocolVersion = (uint) random.Next(0, int.MaxValue); - _requestId = (uint) random.Next(0, int.MaxValue); - _encoding = Encoding.Unicode; - _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); - _newLinkPathBytes = _encoding.GetBytes(_newLinkPath); - _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); - _existingPathBytes = _encoding.GetBytes(_existingPath); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpSymLinkRequest( - _protocolVersion, - _requestId, - _newLinkPath, - _existingPath, - _encoding, - null); - - Assert.AreSame(_encoding, request.Encoding); - Assert.AreEqual(_existingPath, request.ExistingPath); - Assert.AreEqual(_newLinkPath, request.NewLinkPath); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.SymLink, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpSymLinkRequest( - _protocolVersion, - _requestId, - _newLinkPath, - _existingPath, - _encoding, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpSymLinkRequest( - _protocolVersion, - _requestId, - _newLinkPath, - _existingPath, - _encoding, - null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // NewLinkPath length - expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath - expectedBytesLength += 4; // ExistingPath length - expectedBytesLength += _existingPathBytes.Length; // ExistingPath - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.SymLink, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); - var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; - sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); - Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); - - Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); - var actualExistingPath = new byte[_existingPathBytes.Length]; - sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); - Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpSymLinkRequestTest : TestBase + { + private uint _protocolVersion; + private uint _requestId; + private Encoding _encoding; + private string _newLinkPath; + private byte[] _newLinkPathBytes; + private string _existingPath; + private byte[] _existingPathBytes; + + protected override void OnInit() + { + var random = new Random(); + + _protocolVersion = (uint) random.Next(0, int.MaxValue); + _requestId = (uint) random.Next(0, int.MaxValue); + _encoding = Encoding.Unicode; + _newLinkPath = random.Next().ToString(CultureInfo.InvariantCulture); + _newLinkPathBytes = _encoding.GetBytes(_newLinkPath); + _existingPath = random.Next().ToString(CultureInfo.InvariantCulture); + _existingPathBytes = _encoding.GetBytes(_existingPath); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpSymLinkRequest( + _protocolVersion, + _requestId, + _newLinkPath, + _existingPath, + _encoding, + null); + + Assert.AreSame(_encoding, request.Encoding); + Assert.AreEqual(_existingPath, request.ExistingPath); + Assert.AreEqual(_newLinkPath, request.NewLinkPath); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.SymLink, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpSymLinkRequest( + _protocolVersion, + _requestId, + _newLinkPath, + _existingPath, + _encoding, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpSymLinkRequest( + _protocolVersion, + _requestId, + _newLinkPath, + _existingPath, + _encoding, + null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // NewLinkPath length + expectedBytesLength += _newLinkPathBytes.Length; // NewLinkPath + expectedBytesLength += 4; // ExistingPath length + expectedBytesLength += _existingPathBytes.Length; // ExistingPath + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.SymLink, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _newLinkPathBytes.Length, sshDataStream.ReadUInt32()); + var actualNewLinkPath = new byte[_newLinkPathBytes.Length]; + sshDataStream.Read(actualNewLinkPath, 0, actualNewLinkPath.Length); + Assert.IsTrue(_newLinkPathBytes.SequenceEqual(actualNewLinkPath)); + + Assert.AreEqual((uint) _existingPathBytes.Length, sshDataStream.ReadUInt32()); + var actualExistingPath = new byte[_existingPathBytes.Length]; + sshDataStream.Read(actualExistingPath, 0, actualExistingPath.Length); + Assert.IsTrue(_existingPathBytes.SequenceEqual(actualExistingPath)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs index 6cbe4aa6..40ea7c3d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpUnblockRequestTest.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpUnblockRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private ulong _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _length = (ulong) random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); - - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Unblock, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 8; // Length - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Unblock, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - Assert.AreEqual(_length, sshDataStream.ReadUInt64()); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpUnblockRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private ulong _length; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _length = (ulong) random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); + + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Unblock, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpUnblockRequest(_protocolVersion, _requestId, _handle, _offset, _length, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 8; // Length + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Unblock, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + Assert.AreEqual(_length, sshDataStream.ReadUInt64()); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs index 096355c0..68531c9b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Requests/SftpWriteRequestTest.cs @@ -1,112 +1,112 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Requests; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Requests -{ - [TestClass] - public class SftpWriteRequestTest - { - private uint _protocolVersion; - private uint _requestId; - private byte[] _handle; - private ulong _offset; - private byte[] _data; - private int _length; - - [TestInitialize] - public void Init() - { - var random = new Random(); - - _protocolVersion = (uint)random.Next(0, int.MaxValue); - _requestId = (uint)random.Next(0, int.MaxValue); - _handle = new byte[random.Next(1, 10)]; - random.NextBytes(_handle); - _offset = (ulong) random.Next(0, int.MaxValue); - _data = new byte[random.Next(5, 10)]; - random.NextBytes(_data); - _length = random.Next(1, 4); - } - - [TestMethod] - public void Constructor() - { - var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); - - Assert.AreSame(_data, request.Data); - Assert.AreSame(_handle, request.Handle); - Assert.AreEqual(_length, request.Length); - Assert.AreEqual(_protocolVersion, request.ProtocolVersion); - Assert.AreEqual(_requestId, request.RequestId); - Assert.AreEqual(SftpMessageTypes.Write, request.SftpMessageType); - } - - [TestMethod] - public void Complete_SftpStatusResponse() - { - var statusActionInvocations = new List(); - Action statusAction = statusActionInvocations.Add; - var statusResponse = new SftpStatusResponse(_protocolVersion); - - var request = new SftpWriteRequest( - _protocolVersion, - _requestId, - _handle, - _offset, - _data, - _length, - statusAction); - - request.Complete(statusResponse); - - Assert.AreEqual(1, statusActionInvocations.Count); - Assert.AreSame(statusResponse, statusActionInvocations[0]); - } - - [TestMethod] - public void GetBytes() - { - var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); - - var bytes = request.GetBytes(); - - var expectedBytesLength = 0; - expectedBytesLength += 4; // Length - expectedBytesLength += 1; // Type - expectedBytesLength += 4; // RequestId - expectedBytesLength += 4; // Handle length - expectedBytesLength += _handle.Length; // Handle - expectedBytesLength += 8; // Offset - expectedBytesLength += 4; // Data length - expectedBytesLength += _length; // Data - - Assert.AreEqual(expectedBytesLength, bytes.Length); - - var sshDataStream = new SshDataStream(bytes); - - Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); - Assert.AreEqual((byte) SftpMessageTypes.Write, sshDataStream.ReadByte()); - Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); - - Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); - var actualHandle = new byte[_handle.Length]; - sshDataStream.Read(actualHandle, 0, actualHandle.Length); - Assert.IsTrue(_handle.SequenceEqual(actualHandle)); - - Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); - - Assert.AreEqual((uint) _length, sshDataStream.ReadUInt32()); - var actualData = new byte[_length]; - sshDataStream.Read(actualData, 0, actualData.Length); - Assert.IsTrue(_data.Take(_length).SequenceEqual(actualData)); - - Assert.IsTrue(sshDataStream.IsEndOfData); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Requests; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Requests +{ + [TestClass] + public class SftpWriteRequestTest + { + private uint _protocolVersion; + private uint _requestId; + private byte[] _handle; + private ulong _offset; + private byte[] _data; + private int _length; + + [TestInitialize] + public void Init() + { + var random = new Random(); + + _protocolVersion = (uint)random.Next(0, int.MaxValue); + _requestId = (uint)random.Next(0, int.MaxValue); + _handle = new byte[random.Next(1, 10)]; + random.NextBytes(_handle); + _offset = (ulong) random.Next(0, int.MaxValue); + _data = new byte[random.Next(5, 10)]; + random.NextBytes(_data); + _length = random.Next(1, 4); + } + + [TestMethod] + public void Constructor() + { + var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); + + Assert.AreSame(_data, request.Data); + Assert.AreSame(_handle, request.Handle); + Assert.AreEqual(_length, request.Length); + Assert.AreEqual(_protocolVersion, request.ProtocolVersion); + Assert.AreEqual(_requestId, request.RequestId); + Assert.AreEqual(SftpMessageTypes.Write, request.SftpMessageType); + } + + [TestMethod] + public void Complete_SftpStatusResponse() + { + var statusActionInvocations = new List(); + Action statusAction = statusActionInvocations.Add; + var statusResponse = new SftpStatusResponse(_protocolVersion); + + var request = new SftpWriteRequest( + _protocolVersion, + _requestId, + _handle, + _offset, + _data, + _length, + statusAction); + + request.Complete(statusResponse); + + Assert.AreEqual(1, statusActionInvocations.Count); + Assert.AreSame(statusResponse, statusActionInvocations[0]); + } + + [TestMethod] + public void GetBytes() + { + var request = new SftpWriteRequest(_protocolVersion, _requestId, _handle, _offset, _data, _length, null); + + var bytes = request.GetBytes(); + + var expectedBytesLength = 0; + expectedBytesLength += 4; // Length + expectedBytesLength += 1; // Type + expectedBytesLength += 4; // RequestId + expectedBytesLength += 4; // Handle length + expectedBytesLength += _handle.Length; // Handle + expectedBytesLength += 8; // Offset + expectedBytesLength += 4; // Data length + expectedBytesLength += _length; // Data + + Assert.AreEqual(expectedBytesLength, bytes.Length); + + var sshDataStream = new SshDataStream(bytes); + + Assert.AreEqual((uint) bytes.Length - 4, sshDataStream.ReadUInt32()); + Assert.AreEqual((byte) SftpMessageTypes.Write, sshDataStream.ReadByte()); + Assert.AreEqual(_requestId, sshDataStream.ReadUInt32()); + + Assert.AreEqual((uint) _handle.Length, sshDataStream.ReadUInt32()); + var actualHandle = new byte[_handle.Length]; + sshDataStream.Read(actualHandle, 0, actualHandle.Length); + Assert.IsTrue(_handle.SequenceEqual(actualHandle)); + + Assert.AreEqual(_offset, sshDataStream.ReadUInt64()); + + Assert.AreEqual((uint) _length, sshDataStream.ReadUInt32()); + var actualData = new byte[_length]; + sshDataStream.Read(actualData, 0, actualData.Length); + Assert.IsTrue(_data.Take(_length).SequenceEqual(actualData)); + + Assert.IsTrue(sshDataStream.IsEndOfData); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs index 5788e683..14711feb 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/ExtendedReplies/StatVfsReplyInfoTest.cs @@ -1,90 +1,90 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class StatVfsReplyInfoTest - { - private Random _random; - private uint _responseId; - private ulong _bsize; - private ulong _frsize; - private ulong _blocks; - private ulong _bfree; - private ulong _bavail; - private ulong _files; - private ulong _ffree; - private ulong _favail; - private ulong _sid; - private ulong _namemax; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _responseId = (uint) _random.Next(0, int.MaxValue); - _bsize = (ulong) _random.Next(0, int.MaxValue); - _frsize = (ulong)_random.Next(0, int.MaxValue); - _blocks = (ulong)_random.Next(0, int.MaxValue); - _bfree = (ulong)_random.Next(0, int.MaxValue); - _bavail = (ulong)_random.Next(0, int.MaxValue); - _files = (ulong)_random.Next(0, int.MaxValue); - _ffree = (ulong)_random.Next(0, int.MaxValue); - _favail = (ulong)_random.Next(0, int.MaxValue); - _sid = (ulong)_random.Next(0, int.MaxValue); - _namemax = (ulong)_random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var target = new StatVfsReplyInfo(); - - Assert.IsNull(target.Information); - } - - [TestMethod] - public void Load() - { - var target = new StatVfsReplyInfo(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); - sshDataStream.Write((uint) (sshDataStream.Capacity - 4)); - sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); - sshDataStream.Write(_responseId); - sshDataStream.Write(_bsize); - sshDataStream.Write(_frsize); - sshDataStream.Write(_blocks); - sshDataStream.Write(_bfree); - sshDataStream.Write(_bavail); - sshDataStream.Write(_files); - sshDataStream.Write(_ffree); - sshDataStream.Write(_favail); - sshDataStream.Write(_sid); - sshDataStream.Write((ulong) 0x1); - sshDataStream.Write(_namemax); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Information); - - var information = target.Information; - Assert.AreEqual(_bavail, information.AvailableBlocks); - Assert.AreEqual(_favail, information.AvailableNodes); - Assert.AreEqual(_frsize, information.BlockSize); - Assert.AreEqual(_bsize, information.FileSystemBlockSize); - Assert.AreEqual(_bfree, information.FreeBlocks); - Assert.AreEqual(_ffree, information.FreeNodes); - Assert.IsTrue(information.IsReadOnly); - Assert.AreEqual(_namemax, information.MaxNameLenght); - Assert.AreEqual(_sid, information.Sid); - Assert.IsTrue(information.SupportsSetUid); - Assert.AreEqual(_blocks, information.TotalBlocks); - Assert.AreEqual(_files, information.TotalNodes); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class StatVfsReplyInfoTest + { + private Random _random; + private uint _responseId; + private ulong _bsize; + private ulong _frsize; + private ulong _blocks; + private ulong _bfree; + private ulong _bavail; + private ulong _files; + private ulong _ffree; + private ulong _favail; + private ulong _sid; + private ulong _namemax; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _responseId = (uint) _random.Next(0, int.MaxValue); + _bsize = (ulong) _random.Next(0, int.MaxValue); + _frsize = (ulong)_random.Next(0, int.MaxValue); + _blocks = (ulong)_random.Next(0, int.MaxValue); + _bfree = (ulong)_random.Next(0, int.MaxValue); + _bavail = (ulong)_random.Next(0, int.MaxValue); + _files = (ulong)_random.Next(0, int.MaxValue); + _ffree = (ulong)_random.Next(0, int.MaxValue); + _favail = (ulong)_random.Next(0, int.MaxValue); + _sid = (ulong)_random.Next(0, int.MaxValue); + _namemax = (ulong)_random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var target = new StatVfsReplyInfo(); + + Assert.IsNull(target.Information); + } + + [TestMethod] + public void Load() + { + var target = new StatVfsReplyInfo(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); + sshDataStream.Write((uint) (sshDataStream.Capacity - 4)); + sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); + sshDataStream.Write(_responseId); + sshDataStream.Write(_bsize); + sshDataStream.Write(_frsize); + sshDataStream.Write(_blocks); + sshDataStream.Write(_bfree); + sshDataStream.Write(_bavail); + sshDataStream.Write(_files); + sshDataStream.Write(_ffree); + sshDataStream.Write(_favail); + sshDataStream.Write(_sid); + sshDataStream.Write((ulong) 0x1); + sshDataStream.Write(_namemax); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Information); + + var information = target.Information; + Assert.AreEqual(_bavail, information.AvailableBlocks); + Assert.AreEqual(_favail, information.AvailableNodes); + Assert.AreEqual(_frsize, information.BlockSize); + Assert.AreEqual(_bsize, information.FileSystemBlockSize); + Assert.AreEqual(_bfree, information.FreeBlocks); + Assert.AreEqual(_ffree, information.FreeNodes); + Assert.IsTrue(information.IsReadOnly); + Assert.AreEqual(_namemax, information.MaxNameLenght); + Assert.AreEqual(_sid, information.Sid); + Assert.IsTrue(information.SupportsSetUid); + Assert.AreEqual(_blocks, information.TotalBlocks); + Assert.AreEqual(_files, information.TotalNodes); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs index 2ce13986..3e8840ef 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpAttrsResponseTest.cs @@ -1,73 +1,73 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpAttrsResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint)_random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpAttrsResponse(_protocolVersion); - - Assert.IsNull(target.Attributes); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpAttrsResponse(_protocolVersion); - var attributes = CreateSftpFileAttributes(); - var attributesBytes = attributes.GetBytes(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + attributesBytes.Length); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); - sshDataStream.Write(_responseId); - sshDataStream.Write(attributesBytes, 0, attributesBytes.Length); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Attributes); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); - - // check attributes in detail - Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId); - Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); - Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); - Assert.AreEqual(attributes.UserId, target.Attributes.UserId); - } - - private SftpFileAttributes CreateSftpFileAttributes() - { - var attributes = SftpFileAttributes.Empty; - attributes.GroupId = _random.Next(); - attributes.LastAccessTime = new DateTime(2014, 8, 23, 17, 43, 50, DateTimeKind.Local); - attributes.LastWriteTime = new DateTime(2013, 7, 22, 16, 40, 42, DateTimeKind.Local); - attributes.UserId = _random.Next(); - return attributes; - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpAttrsResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint)_random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpAttrsResponse(_protocolVersion); + + Assert.IsNull(target.Attributes); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpAttrsResponse(_protocolVersion); + var attributes = CreateSftpFileAttributes(); + var attributesBytes = attributes.GetBytes(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + attributesBytes.Length); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); + sshDataStream.Write(_responseId); + sshDataStream.Write(attributesBytes, 0, attributesBytes.Length); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Attributes); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Attrs, target.SftpMessageType); + + // check attributes in detail + Assert.AreEqual(attributes.GroupId, target.Attributes.GroupId); + Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); + Assert.AreEqual(attributes.LastWriteTime, target.Attributes.LastWriteTime); + Assert.AreEqual(attributes.UserId, target.Attributes.UserId); + } + + private SftpFileAttributes CreateSftpFileAttributes() + { + var attributes = SftpFileAttributes.Empty; + attributes.GroupId = _random.Next(); + attributes.LastAccessTime = new DateTime(2014, 8, 23, 17, 43, 50, DateTimeKind.Local); + attributes.LastWriteTime = new DateTime(2013, 7, 22, 16, 40, 42, DateTimeKind.Local); + attributes.UserId = _random.Next(); + return attributes; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs index 39bde628..33952f14 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpDataResponseTest.cs @@ -1,60 +1,60 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpDataResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - private byte[] _data; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint) _random.Next(0, int.MaxValue); - _data = new byte[_random.Next(10, 100)]; - _random.NextBytes(_data); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpDataResponse(_protocolVersion); - - Assert.IsNull(target.Data); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpDataResponse(_protocolVersion); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + _data.Length); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte)SftpMessageTypes.Attrs); - sshDataStream.Write(_responseId); - sshDataStream.Write((uint) _data.Length); - sshDataStream.Write(_data, 0, _data.Length); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Data); - Assert.IsTrue(target.Data.SequenceEqual(_data)); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpDataResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + private byte[] _data; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint) _random.Next(0, int.MaxValue); + _data = new byte[_random.Next(10, 100)]; + _random.NextBytes(_data); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpDataResponse(_protocolVersion); + + Assert.IsNull(target.Data); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpDataResponse(_protocolVersion); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + _data.Length); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte)SftpMessageTypes.Attrs); + sshDataStream.Write(_responseId); + sshDataStream.Write((uint) _data.Length); + sshDataStream.Write(_data, 0, _data.Length); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Data); + Assert.IsTrue(target.Data.SequenceEqual(_data)); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Data, target.SftpMessageType); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs index cb77f19d..751e4b13 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpExtendedReplyResponseTest.cs @@ -1,103 +1,103 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpExtendedReplyResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint) _random.Next(0, int.MaxValue); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpExtendedReplyResponse(_protocolVersion); - - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpExtendedReplyResponse(_protocolVersion); - - var sshDataStream = new SshDataStream(4 + 1 + 4); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); - sshDataStream.Write(_responseId); - - target.Load(sshDataStream.ToArray()); - - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); - } - - [TestMethod] - public void GetReply_StatVfsReplyInfo() - { - var bsize = (ulong) _random.Next(0, int.MaxValue); - var frsize = (ulong) _random.Next(0, int.MaxValue); - var blocks = (ulong) _random.Next(0, int.MaxValue); - var bfree = (ulong) _random.Next(0, int.MaxValue); - var bavail = (ulong) _random.Next(0, int.MaxValue); - var files = (ulong) _random.Next(0, int.MaxValue); - var ffree = (ulong) _random.Next(0, int.MaxValue); - var favail = (ulong) _random.Next(0, int.MaxValue); - var sid = (ulong) _random.Next(0, int.MaxValue); - var namemax = (ulong) _random.Next(0, int.MaxValue); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); - sshDataStream.Write(_responseId); - sshDataStream.Write(bsize); - sshDataStream.Write(frsize); - sshDataStream.Write(blocks); - sshDataStream.Write(bfree); - sshDataStream.Write(bavail); - sshDataStream.Write(files); - sshDataStream.Write(ffree); - sshDataStream.Write(favail); - sshDataStream.Write(sid); - sshDataStream.Write((ulong) 0x2); - sshDataStream.Write(namemax); - - var target = new SftpExtendedReplyResponse(_protocolVersion); - target.Load(sshDataStream.ToArray()); - - var reply = target.GetReply(); - Assert.IsNotNull(reply); - - var information = reply.Information; - Assert.IsNotNull(information); - Assert.AreEqual(bavail, information.AvailableBlocks); - Assert.AreEqual(favail, information.AvailableNodes); - Assert.AreEqual(frsize, information.BlockSize); - Assert.AreEqual(bsize, information.FileSystemBlockSize); - Assert.AreEqual(bfree, information.FreeBlocks); - Assert.AreEqual(ffree, information.FreeNodes); - Assert.IsFalse(information.IsReadOnly); - Assert.AreEqual(namemax, information.MaxNameLenght); - Assert.AreEqual(sid, information.Sid); - Assert.IsFalse(information.SupportsSetUid); - Assert.AreEqual(blocks, information.TotalBlocks); - Assert.AreEqual(files, information.TotalNodes); - } - } +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpExtendedReplyResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint) _random.Next(0, int.MaxValue); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpExtendedReplyResponse(_protocolVersion); + + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpExtendedReplyResponse(_protocolVersion); + + var sshDataStream = new SshDataStream(4 + 1 + 4); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); + sshDataStream.Write(_responseId); + + target.Load(sshDataStream.ToArray()); + + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.ExtendedReply, target.SftpMessageType); + } + + [TestMethod] + public void GetReply_StatVfsReplyInfo() + { + var bsize = (ulong) _random.Next(0, int.MaxValue); + var frsize = (ulong) _random.Next(0, int.MaxValue); + var blocks = (ulong) _random.Next(0, int.MaxValue); + var bfree = (ulong) _random.Next(0, int.MaxValue); + var bavail = (ulong) _random.Next(0, int.MaxValue); + var files = (ulong) _random.Next(0, int.MaxValue); + var ffree = (ulong) _random.Next(0, int.MaxValue); + var favail = (ulong) _random.Next(0, int.MaxValue); + var sid = (ulong) _random.Next(0, int.MaxValue); + var namemax = (ulong) _random.Next(0, int.MaxValue); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.Attrs); + sshDataStream.Write(_responseId); + sshDataStream.Write(bsize); + sshDataStream.Write(frsize); + sshDataStream.Write(blocks); + sshDataStream.Write(bfree); + sshDataStream.Write(bavail); + sshDataStream.Write(files); + sshDataStream.Write(ffree); + sshDataStream.Write(favail); + sshDataStream.Write(sid); + sshDataStream.Write((ulong) 0x2); + sshDataStream.Write(namemax); + + var target = new SftpExtendedReplyResponse(_protocolVersion); + target.Load(sshDataStream.ToArray()); + + var reply = target.GetReply(); + Assert.IsNotNull(reply); + + var information = reply.Information; + Assert.IsNotNull(information); + Assert.AreEqual(bavail, information.AvailableBlocks); + Assert.AreEqual(favail, information.AvailableNodes); + Assert.AreEqual(frsize, information.BlockSize); + Assert.AreEqual(bsize, information.FileSystemBlockSize); + Assert.AreEqual(bfree, information.FreeBlocks); + Assert.AreEqual(ffree, information.FreeNodes); + Assert.IsFalse(information.IsReadOnly); + Assert.AreEqual(namemax, information.MaxNameLenght); + Assert.AreEqual(sid, information.Sid); + Assert.IsFalse(information.SupportsSetUid); + Assert.AreEqual(blocks, information.TotalBlocks); + Assert.AreEqual(files, information.TotalNodes); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs index 36000ded..e7b509cb 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpHandleResponseTest.cs @@ -1,60 +1,60 @@ - using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpHandleResponseTest - { - private Random _random; - private uint _protocolVersion; - private uint _responseId; - private byte[] _handle; - - [TestInitialize] - public void Init() - { - _random = new Random(); - _protocolVersion = (uint) _random.Next(0, int.MaxValue); - _responseId = (uint) _random.Next(0, int.MaxValue); - _handle = new byte[_random.Next(1, 10)]; - _random.NextBytes(_handle); - } - - [TestMethod] - public void Constructor() - { - var target = new SftpHandleResponse(_protocolVersion); - - Assert.IsNull(target.Handle); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual((uint) 0, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); - } - - [TestMethod] - public void Load() - { - var target = new SftpHandleResponse(_protocolVersion); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + _handle.Length); - sshDataStream.Position = 4; // skip 4 bytes for SSH packet length - sshDataStream.WriteByte((byte) SftpMessageTypes.Handle); - sshDataStream.Write(_responseId); - sshDataStream.Write((uint) _handle.Length); - sshDataStream.Write(_handle, 0, _handle.Length); - - target.Load(sshDataStream.ToArray()); - - Assert.IsNotNull(target.Handle); - Assert.IsTrue(target.Handle.SequenceEqual(_handle)); - Assert.AreEqual(_protocolVersion, target.ProtocolVersion); - Assert.AreEqual(_responseId, target.ResponseId); - Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); - } - } -} + using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpHandleResponseTest + { + private Random _random; + private uint _protocolVersion; + private uint _responseId; + private byte[] _handle; + + [TestInitialize] + public void Init() + { + _random = new Random(); + _protocolVersion = (uint) _random.Next(0, int.MaxValue); + _responseId = (uint) _random.Next(0, int.MaxValue); + _handle = new byte[_random.Next(1, 10)]; + _random.NextBytes(_handle); + } + + [TestMethod] + public void Constructor() + { + var target = new SftpHandleResponse(_protocolVersion); + + Assert.IsNull(target.Handle); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual((uint) 0, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); + } + + [TestMethod] + public void Load() + { + var target = new SftpHandleResponse(_protocolVersion); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + _handle.Length); + sshDataStream.Position = 4; // skip 4 bytes for SSH packet length + sshDataStream.WriteByte((byte) SftpMessageTypes.Handle); + sshDataStream.Write(_responseId); + sshDataStream.Write((uint) _handle.Length); + sshDataStream.Write(_handle, 0, _handle.Length); + + target.Load(sshDataStream.ToArray()); + + Assert.IsNotNull(target.Handle); + Assert.IsTrue(target.Handle.SequenceEqual(_handle)); + Assert.AreEqual(_protocolVersion, target.ProtocolVersion); + Assert.AreEqual(_responseId, target.ResponseId); + Assert.AreEqual(SftpMessageTypes.Handle, target.SftpMessageType); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs index 164580f3..2265e3f5 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpNameResponseTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpNameResponseTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpNameResponseTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs index 8552e562..ca46720d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpStatusResponseTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpStatusResponseTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpStatusResponseTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs index 7e8150de..4cabe306 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/Responses/SftpVersionResponseTest.cs @@ -1,10 +1,10 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp.Responses -{ - [TestClass] - public class SftpVersionResponseTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp.Responses +{ + [TestClass] + public class SftpVersionResponseTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs index 76d27d25..eb978638 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpDownloadAsyncResultTest.cs @@ -1,27 +1,27 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpDownloadAsyncResultTest and is intended - ///to contain all SftpDownloadAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpDownloadAsyncResultTest : TestBase - { - /// - ///A test for SftpDownloadAsyncResult Constructor - /// - [TestMethod()] - public void SftpDownloadAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpDownloadAsyncResult target = new SftpDownloadAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpDownloadAsyncResultTest and is intended + ///to contain all SftpDownloadAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpDownloadAsyncResultTest : TestBase + { + /// + ///A test for SftpDownloadAsyncResult Constructor + /// + [TestMethod()] + public void SftpDownloadAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpDownloadAsyncResult target = new SftpDownloadAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs index 350b9243..5d2b7944 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileAttributesTest.cs @@ -1,237 +1,237 @@ -using Renci.SshNet.Sftp; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for SftpFileAttributesTest and is intended - ///to contain all SftpFileAttributesTest Unit Tests - /// - [TestClass()] - public class SftpFileAttributesTest : TestBase - { - /// - ///A test for SetPermissions - /// - [TestMethod()] - public void SetPermissionsTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - short mode = 0; // TODO: Initialize to an appropriate value - target.SetPermissions(mode); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GroupCanExecute - /// - [TestMethod()] - public void GroupCanExecuteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.GroupCanExecute = expected; - actual = target.GroupCanExecute; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GroupCanRead - /// - [TestMethod()] - public void GroupCanReadTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.GroupCanRead = expected; - actual = target.GroupCanRead; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GroupCanWrite - /// - [TestMethod()] - public void GroupCanWriteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.GroupCanWrite = expected; - actual = target.GroupCanWrite; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GroupId - /// - [TestMethod()] - public void GroupIdTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - target.GroupId = expected; - actual = target.GroupId; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for LastAccessTime - /// - [TestMethod()] - public void LastAccessTimeTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - target.LastAccessTime = expected; - actual = target.LastAccessTime; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for LastWriteTime - /// - [TestMethod()] - public void LastWriteTimeTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - target.LastWriteTime = expected; - actual = target.LastWriteTime; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OthersCanExecute - /// - [TestMethod()] - public void OthersCanExecuteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OthersCanExecute = expected; - actual = target.OthersCanExecute; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OthersCanRead - /// - [TestMethod()] - public void OthersCanReadTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OthersCanRead = expected; - actual = target.OthersCanRead; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OthersCanWrite - /// - [TestMethod()] - public void OthersCanWriteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OthersCanWrite = expected; - actual = target.OthersCanWrite; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OwnerCanExecute - /// - [TestMethod()] - public void OwnerCanExecuteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OwnerCanExecute = expected; - actual = target.OwnerCanExecute; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OwnerCanRead - /// - [TestMethod()] - public void OwnerCanReadTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OwnerCanRead = expected; - actual = target.OwnerCanRead; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OwnerCanWrite - /// - [TestMethod()] - public void OwnerCanWriteTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - target.OwnerCanWrite = expected; - actual = target.OwnerCanWrite; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Size - /// - [TestMethod()] - public void SizeTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - long expected = 0; // TODO: Initialize to an appropriate value - long actual; - target.Size = expected; - actual = target.Size; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for UserId - /// - [TestMethod()] - public void UserIdTest() - { - SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value - int expected = 0; // TODO: Initialize to an appropriate value - int actual; - target.UserId = expected; - actual = target.UserId; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Renci.SshNet.Sftp; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for SftpFileAttributesTest and is intended + ///to contain all SftpFileAttributesTest Unit Tests + /// + [TestClass()] + public class SftpFileAttributesTest : TestBase + { + /// + ///A test for SetPermissions + /// + [TestMethod()] + public void SetPermissionsTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + short mode = 0; // TODO: Initialize to an appropriate value + target.SetPermissions(mode); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GroupCanExecute + /// + [TestMethod()] + public void GroupCanExecuteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.GroupCanExecute = expected; + actual = target.GroupCanExecute; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GroupCanRead + /// + [TestMethod()] + public void GroupCanReadTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.GroupCanRead = expected; + actual = target.GroupCanRead; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GroupCanWrite + /// + [TestMethod()] + public void GroupCanWriteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.GroupCanWrite = expected; + actual = target.GroupCanWrite; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GroupId + /// + [TestMethod()] + public void GroupIdTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + target.GroupId = expected; + actual = target.GroupId; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for LastAccessTime + /// + [TestMethod()] + public void LastAccessTimeTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + target.LastAccessTime = expected; + actual = target.LastAccessTime; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for LastWriteTime + /// + [TestMethod()] + public void LastWriteTimeTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + target.LastWriteTime = expected; + actual = target.LastWriteTime; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OthersCanExecute + /// + [TestMethod()] + public void OthersCanExecuteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OthersCanExecute = expected; + actual = target.OthersCanExecute; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OthersCanRead + /// + [TestMethod()] + public void OthersCanReadTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OthersCanRead = expected; + actual = target.OthersCanRead; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OthersCanWrite + /// + [TestMethod()] + public void OthersCanWriteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OthersCanWrite = expected; + actual = target.OthersCanWrite; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OwnerCanExecute + /// + [TestMethod()] + public void OwnerCanExecuteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OwnerCanExecute = expected; + actual = target.OwnerCanExecute; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OwnerCanRead + /// + [TestMethod()] + public void OwnerCanReadTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OwnerCanRead = expected; + actual = target.OwnerCanRead; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OwnerCanWrite + /// + [TestMethod()] + public void OwnerCanWriteTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + target.OwnerCanWrite = expected; + actual = target.OwnerCanWrite; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Size + /// + [TestMethod()] + public void SizeTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + long expected = 0; // TODO: Initialize to an appropriate value + long actual; + target.Size = expected; + actual = target.Size; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for UserId + /// + [TestMethod()] + public void UserIdTest() + { + SftpFileAttributes target = SftpFileAttributes.Empty; // TODO: Initialize to an appropriate value + int expected = 0; // TODO: Initialize to an appropriate value + int actual; + target.UserId = expected; + actual = target.UserId; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs index 15342bd9..f11cd8f6 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Closed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(0, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Closed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(0, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs index 6310f333..296728d4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(0, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(0, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs index 5176fb8f..f988edff 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Closed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(0, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Closed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(0, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs index eb267701..5d69b468 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Disposed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Disposed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs index 44478b27..a6e8fe31 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs index f5d3e5ae..448b373b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_Disposed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_Disposed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs index 30c97c04..d1c0747d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs index c396b9a2..041a20bc 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs index ae17eab8..8fc229d4 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanRead; - } - - [TestMethod] - public void CanReadShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanRead_SessionOpen_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanRead; + } + + [TestMethod] + public void CanReadShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs index c46bfa76..424b2e4d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Closed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Closed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs index 4d6ce5de..9d94a222 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs index 1a6b1c72..9952030f 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Closed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Closed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs index cbb5a6a5..540dc1f2 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Disposed_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Disposed_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs index 95ebe14f..2554d22c 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs index 7141961a..d02389bc 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs @@ -1,74 +1,74 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs index 7dc8a8d0..c95b9280 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CaWriteShouldReturnFalse() - { - Assert.IsFalse(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessRead + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CaWriteShouldReturnFalse() + { + Assert.IsFalse(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs index be20911e..4501f40d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs index 48e5d2f0..4049d527 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite.cs @@ -1,73 +1,73 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private bool _actual; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(0, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - } - - protected void Act() - { - _actual = _sftpFileStream.CanWrite; - } - - [TestMethod] - public void CanWriteShouldReturnTrue() - { - Assert.IsTrue(_actual); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_CanWrite_SessionOpen_FileAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private bool _actual; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(0, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + } + + protected void Act() + { + _actual = _sftpFileStream.CanWrite; + } + + [TestMethod] + public void CanWriteShouldReturnTrue() + { + Assert.IsTrue(_actual); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs index 81d7c2d8..08949600 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_Closed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_Closed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs index b9d55b3c..0257b1ba 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_Disposed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_Disposed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs index 1bdcf1e5..97b590b1 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs @@ -1,76 +1,76 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_SessionNotOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(false); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_SessionNotOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(false); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs index 3836a0c1..fb220b58 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs @@ -1,78 +1,78 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Close_SessionOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - } - - protected void Act() - { - _sftpFileStream.Close(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Close_SessionOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + } + + protected void Act() + { + _sftpFileStream.Close(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs index dce77334..af2683e5 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_Closed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_Closed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs index 0ea2cba6..9fda20d8 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs @@ -1,79 +1,79 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_Disposed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_Disposed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs index 1d4371f6..0436f056 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs @@ -1,78 +1,78 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_SessionNotOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(false); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_SessionNotOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(false); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs index ff4fa576..1a08ffb9 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs @@ -1,78 +1,78 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Dispose_SessionOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - } - - protected void Act() - { - _sftpFileStream.Dispose(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Dispose_SessionOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + } + + protected void Act() + { + _sftpFileStream.Dispose(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs index 8a3718d5..32db6393 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs @@ -1,80 +1,80 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_Finalize_SessionOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); - _sftpFileStream = null; - } - - protected void Act() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - } - - [TestMethod] - public void IsOpenOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.IsOpen, Times.Never); - } - - [TestMethod] - public void RequestCloseOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_Finalize_SessionOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Read, (int) _bufferSize); + _sftpFileStream = null; + } + + protected void Act() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + [TestMethod] + public void IsOpenOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.IsOpen, Times.Never); + } + + [TestMethod] + public void RequestCloseOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs index 3889185a..fbd84b0b 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs @@ -1,90 +1,90 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_Closed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Close(); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(5); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual( - string.Format( - "Cannot access a disposed object.{0}Object name: '{1}'.", - Environment.NewLine, - _actualException.ObjectName), - _actualException.Message); - Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_Closed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Close(); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(5); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual( + string.Format( + "Cannot access a disposed object.{0}Object name: '{1}'.", + Environment.NewLine, + _actualException.ObjectName), + _actualException.Message); + Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs index 712147fa..ce521f71 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Disposed.cs @@ -1,90 +1,90 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_Disposed - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint)random.Next(1, 1000); - _readBufferSize = (uint)random.Next(0, 1000); - _writeBufferSize = (uint)random.Next(0, 1000); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(sequence) - .Setup(p => p.RequestClose(_handle)); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - _sftpFileStream.Dispose(); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(5); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual( - string.Format( - "Cannot access a disposed object.{0}Object name: '{1}'.", - Environment.NewLine, - _actualException.ObjectName), - _actualException.Message); - Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_Disposed + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint)random.Next(1, 1000); + _readBufferSize = (uint)random.Next(0, 1000); + _writeBufferSize = (uint)random.Next(0, 1000); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(sequence) + .Setup(p => p.RequestClose(_handle)); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + _sftpFileStream.Dispose(); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(5); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual( + string.Format( + "Cannot access a disposed object.{0}Object name: '{1}'.", + Environment.NewLine, + _actualException.ObjectName), + _actualException.Message); + Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs index 84f86844..bab89847 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionNotOpen.cs @@ -1,96 +1,96 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionNotOpen - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(false); - - _sftpFileStream = new SftpFileStream( - _sftpSessionMock.Object, - _path, - FileMode.Create, - FileAccess.Read, - (int)_bufferSize); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(_length); - Assert.Fail(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual( - string.Format( - "Cannot access a closed SFTP session.{0}Object name: '{1}'.", - Environment.NewLine, - _actualException.ObjectName), - _actualException.Message); - Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); - } - - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionNotOpen + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(false); + + _sftpFileStream = new SftpFileStream( + _sftpSessionMock.Object, + _path, + FileMode.Create, + FileAccess.Read, + (int)_bufferSize); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(_length); + Assert.Fail(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual( + string.Format( + "Cannot access a closed SFTP session.{0}Object name: '{1}'.", + Environment.NewLine, + _actualException.ObjectName), + _actualException.Message); + Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName); + } + + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs index bbb0acfa..f2fa6bcd 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessRead.cs @@ -1,89 +1,89 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccess - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private NotSupportedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(true); - - _sftpFileStream = new SftpFileStream( - _sftpSessionMock.Object, - _path, - FileMode.Create, - FileAccess.Read, - (int) _bufferSize); - } - - protected void Act() - { - try - { - _sftpFileStream.SetLength(_length); - Assert.Fail(); - } - catch (NotSupportedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SetLengthShouldHaveThrownNotSupportedException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("Write not supported.", _actualException.Message); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccess + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private NotSupportedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(true); + + _sftpFileStream = new SftpFileStream( + _sftpSessionMock.Object, + _path, + FileMode.Create, + FileAccess.Read, + (int) _bufferSize); + } + + protected void Act() + { + try + { + _sftpFileStream.SetLength(_length); + Assert.Fail(); + } + catch (NotSupportedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SetLengthShouldHaveThrownNotSupportedException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("Write not supported.", _actualException.Message); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs index 5ce4198a..dbfad31d 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite.cs @@ -1,99 +1,99 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private long _lengthPassedToRequestFSetStat; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) - .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.SetLength(_length); - } - - [TestMethod] - public void PositionShouldReturnOriginalPosition() - { - _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.AreEqual(0, _sftpFileStream.Position); - - _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() - { - Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() - { - Assert.AreEqual(_length, _fileAttributes.Size); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessReadWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private long _lengthPassedToRequestFSetStat; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) + .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.SetLength(_length); + } + + [TestMethod] + public void PositionShouldReturnOriginalPosition() + { + _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.AreEqual(0, _sftpFileStream.Position); + + _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() + { + Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() + { + Assert.AreEqual(_length, _fileAttributes.Size); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs index 3329f183..477ec749 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite.cs @@ -1,99 +1,99 @@ -using System; -using System.Globalization; -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite - { - private Mock _sftpSessionMock; - private string _path; - private SftpFileStream _sftpFileStream; - private byte[] _handle; - private SftpFileAttributes _fileAttributes; - private uint _bufferSize; - private uint _readBufferSize; - private uint _writeBufferSize; - private MockSequence _sequence; - private long _length; - private long _lengthPassedToRequestFSetStat; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _path = random.Next().ToString(CultureInfo.InvariantCulture); - _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - _fileAttributes = SftpFileAttributes.Empty; - _bufferSize = (uint) random.Next(1, 1000); - _readBufferSize = (uint) random.Next(0, 1000); - _writeBufferSize = (uint) random.Next(0, 1000); - _length = random.Next(); - - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) - .Returns(_handle); - _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) - .Returns(_readBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) - .Returns(_writeBufferSize); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.IsOpen) - .Returns(true); - _sftpSessionMock.InSequence(_sequence) - .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) - .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); - - _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); - } - - protected void Act() - { - _sftpFileStream.SetLength(_length); - } - - [TestMethod] - public void PositionShouldReturnOriginalPosition() - { - _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.AreEqual(0, _sftpFileStream.Position); - - _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() - { - Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); - } - - [TestMethod] - public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() - { - Assert.AreEqual(_length, _fileAttributes.Size); - } - } -} +using System; +using System.Globalization; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpFileStreamTest_SetLength_SessionOpen_FIleAccessWrite + { + private Mock _sftpSessionMock; + private string _path; + private SftpFileStream _sftpFileStream; + private byte[] _handle; + private SftpFileAttributes _fileAttributes; + private uint _bufferSize; + private uint _readBufferSize; + private uint _writeBufferSize; + private MockSequence _sequence; + private long _length; + private long _lengthPassedToRequestFSetStat; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _path = random.Next().ToString(CultureInfo.InvariantCulture); + _handle = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + _fileAttributes = SftpFileAttributes.Empty; + _bufferSize = (uint) random.Next(1, 1000); + _readBufferSize = (uint) random.Next(0, 1000); + _writeBufferSize = (uint) random.Next(0, 1000); + _length = random.Next(); + + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true)) + .Returns(_handle); + _sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalReadLength(_bufferSize)) + .Returns(_readBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle)) + .Returns(_writeBufferSize); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.IsOpen) + .Returns(true); + _sftpSessionMock.InSequence(_sequence) + .Setup(p => p.RequestFSetStat(_handle, _fileAttributes)) + .Callback((bytes, attributes) => _lengthPassedToRequestFSetStat = attributes.Size); + + _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize); + } + + protected void Act() + { + _sftpFileStream.SetLength(_length); + } + + [TestMethod] + public void PositionShouldReturnOriginalPosition() + { + _sftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.AreEqual(0, _sftpFileStream.Position); + + _sftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat() + { + Assert.AreEqual(_length, _lengthPassedToRequestFSetStat); + } + + [TestMethod] + public void SizeOfSftpFileAttributesShouldBeEqualToNewLength() + { + Assert.AreEqual(_length, _fileAttributes.Size); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs index 6c5342a1..778302fc 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpFileSystemInformationTest.cs @@ -1,60 +1,60 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpFileSytemInformationTest and is intended - ///to contain all SftpFileSytemInformationTest Unit Tests - /// - [TestClass()] - public class SftpFileSystemInformationTest : TestBase - { - /// - ///A test for IsReadOnly - /// - [TestMethod()] - public void IsReadOnlyTest() - { - ulong bsize = 0; // TODO: Initialize to an appropriate value - ulong frsize = 0; // TODO: Initialize to an appropriate value - ulong blocks = 0; // TODO: Initialize to an appropriate value - ulong bfree = 0; // TODO: Initialize to an appropriate value - ulong bavail = 0; // TODO: Initialize to an appropriate value - ulong files = 0; // TODO: Initialize to an appropriate value - ulong ffree = 0; // TODO: Initialize to an appropriate value - ulong favail = 0; // TODO: Initialize to an appropriate value - ulong sid = 0; // TODO: Initialize to an appropriate value - ulong flag = 0; // TODO: Initialize to an appropriate value - ulong namemax = 0; // TODO: Initialize to an appropriate value - SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value - bool actual; - actual = target.IsReadOnly; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for SupportsSetUid - /// - [TestMethod()] - public void SupportsSetUidTest() - { - ulong bsize = 0; // TODO: Initialize to an appropriate value - ulong frsize = 0; // TODO: Initialize to an appropriate value - ulong blocks = 0; // TODO: Initialize to an appropriate value - ulong bfree = 0; // TODO: Initialize to an appropriate value - ulong bavail = 0; // TODO: Initialize to an appropriate value - ulong files = 0; // TODO: Initialize to an appropriate value - ulong ffree = 0; // TODO: Initialize to an appropriate value - ulong favail = 0; // TODO: Initialize to an appropriate value - ulong sid = 0; // TODO: Initialize to an appropriate value - ulong flag = 0; // TODO: Initialize to an appropriate value - ulong namemax = 0; // TODO: Initialize to an appropriate value - SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value - bool actual; - actual = target.SupportsSetUid; - Assert.Inconclusive("Verify the correctness of this test method."); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpFileSytemInformationTest and is intended + ///to contain all SftpFileSytemInformationTest Unit Tests + /// + [TestClass()] + public class SftpFileSystemInformationTest : TestBase + { + /// + ///A test for IsReadOnly + /// + [TestMethod()] + public void IsReadOnlyTest() + { + ulong bsize = 0; // TODO: Initialize to an appropriate value + ulong frsize = 0; // TODO: Initialize to an appropriate value + ulong blocks = 0; // TODO: Initialize to an appropriate value + ulong bfree = 0; // TODO: Initialize to an appropriate value + ulong bavail = 0; // TODO: Initialize to an appropriate value + ulong files = 0; // TODO: Initialize to an appropriate value + ulong ffree = 0; // TODO: Initialize to an appropriate value + ulong favail = 0; // TODO: Initialize to an appropriate value + ulong sid = 0; // TODO: Initialize to an appropriate value + ulong flag = 0; // TODO: Initialize to an appropriate value + ulong namemax = 0; // TODO: Initialize to an appropriate value + SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value + bool actual; + actual = target.IsReadOnly; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for SupportsSetUid + /// + [TestMethod()] + public void SupportsSetUidTest() + { + ulong bsize = 0; // TODO: Initialize to an appropriate value + ulong frsize = 0; // TODO: Initialize to an appropriate value + ulong blocks = 0; // TODO: Initialize to an appropriate value + ulong bfree = 0; // TODO: Initialize to an appropriate value + ulong bavail = 0; // TODO: Initialize to an appropriate value + ulong files = 0; // TODO: Initialize to an appropriate value + ulong ffree = 0; // TODO: Initialize to an appropriate value + ulong favail = 0; // TODO: Initialize to an appropriate value + ulong sid = 0; // TODO: Initialize to an appropriate value + ulong flag = 0; // TODO: Initialize to an appropriate value + ulong namemax = 0; // TODO: Initialize to an appropriate value + SftpFileSytemInformation target = new SftpFileSytemInformation(bsize, frsize, blocks, bfree, bavail, files, ffree, favail, sid, flag, namemax); // TODO: Initialize to an appropriate value + bool actual; + actual = target.SupportsSetUid; + Assert.Inconclusive("Verify the correctness of this test method."); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs index 4718f88d..aa20db90 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpListDirectoryAsyncResultTest.cs @@ -1,27 +1,27 @@ -using Renci.SshNet.Sftp; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests -{ - /// - ///This is a test class for SftpListDirectoryAsyncResultTest and is intended - ///to contain all SftpListDirectoryAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpListDirectoryAsyncResultTest : TestBase - { - /// - ///A test for SftpListDirectoryAsyncResult Constructor - /// - [TestMethod()] - public void SftpListDirectoryAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpListDirectoryAsyncResult target = new SftpListDirectoryAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using Renci.SshNet.Sftp; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests +{ + /// + ///This is a test class for SftpListDirectoryAsyncResultTest and is intended + ///to contain all SftpListDirectoryAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpListDirectoryAsyncResultTest : TestBase + { + /// + ///A test for SftpListDirectoryAsyncResult Constructor + /// + [TestMethod()] + public void SftpListDirectoryAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpListDirectoryAsyncResult target = new SftpListDirectoryAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs index 7b500df6..57f1d586 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestRead.cs @@ -1,140 +1,140 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; -using Renci.SshNet.Sftp.Responses; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpSessionTest_Connected_RequestRead - { - private Mock _sessionMock; - private Mock _channelSessionMock; - private SftpSession _sftpSession; - private TimeSpan _operationTimeout; - private byte[] _actual; - private byte[] _expected; - private Encoding _encoding; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - - _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _expected = new byte[random.Next(30, 50)]; - _encoding = Encoding.UTF8; - random.NextBytes(_expected); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - // generate response for SftpInitRequest - var versionInfoResponse = SftpVersionResponseBuilder.Create(3) - .Build(); - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, versionInfoResponse)); - }); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpNameResponse)); - } - ); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var sftpDataResponse = CreateSftpDataResponse(2, _expected); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpDataResponse.Take(0, 20))); - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpDataResponse.Take(20, sftpDataResponse.Length - 20))); - } - ); - - _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); - _sftpSession.Connect(); - } - - protected void Act() - { - _actual = _sftpSession.RequestRead(new byte[0], 0, 200); - } - - [TestMethod] - public void ReturnedValueShouldBeDataOfSftpDataResponse() - { - Assert.IsNotNull(_actual); - Assert.IsTrue(_expected.SequenceEqual(_actual)); - } - - private static byte[] CreateSftpDataResponse(uint responseId, byte[] data) - { - var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + data.Length + 1); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.Data); - sshDataStream.Write(responseId); - sshDataStream.Write((uint) data.Length); - sshDataStream.Write(data, 0, data.Length); - sshDataStream.WriteByte(1); // EOF - return sshDataStream.ToArray(); - } - - private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) - { - var namesAndAttributes = new List(); - foreach (var name in names) - { - var nameBytes = encoding.GetBytes(name); - var attributesBytes = SftpFileAttributes.Empty.GetBytes(); - - namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length - namesAndAttributes.AddRange(nameBytes); // filename - namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length - namesAndAttributes.AddRange(attributesBytes); // attributes - } - - var namesAndAttributesBytes = namesAndAttributes.ToArray(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.Name); - sshDataStream.Write(responseId); - sshDataStream.Write((uint) names.Length); - sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); - return sshDataStream.ToArray(); - } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; +using Renci.SshNet.Sftp.Responses; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpSessionTest_Connected_RequestRead + { + private Mock _sessionMock; + private Mock _channelSessionMock; + private SftpSession _sftpSession; + private TimeSpan _operationTimeout; + private byte[] _actual; + private byte[] _expected; + private Encoding _encoding; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + + _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _expected = new byte[random.Next(30, 50)]; + _encoding = Encoding.UTF8; + random.NextBytes(_expected); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + // generate response for SftpInitRequest + var versionInfoResponse = SftpVersionResponseBuilder.Create(3) + .Build(); + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, versionInfoResponse)); + }); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpNameResponse)); + } + ); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var sftpDataResponse = CreateSftpDataResponse(2, _expected); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpDataResponse.Take(0, 20))); + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpDataResponse.Take(20, sftpDataResponse.Length - 20))); + } + ); + + _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); + _sftpSession.Connect(); + } + + protected void Act() + { + _actual = _sftpSession.RequestRead(new byte[0], 0, 200); + } + + [TestMethod] + public void ReturnedValueShouldBeDataOfSftpDataResponse() + { + Assert.IsNotNull(_actual); + Assert.IsTrue(_expected.SequenceEqual(_actual)); + } + + private static byte[] CreateSftpDataResponse(uint responseId, byte[] data) + { + var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + data.Length + 1); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.Data); + sshDataStream.Write(responseId); + sshDataStream.Write((uint) data.Length); + sshDataStream.Write(data, 0, data.Length); + sshDataStream.WriteByte(1); // EOF + return sshDataStream.ToArray(); + } + + private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) + { + var namesAndAttributes = new List(); + foreach (var name in names) + { + var nameBytes = encoding.GetBytes(name); + var attributesBytes = SftpFileAttributes.Empty.GetBytes(); + + namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length + namesAndAttributes.AddRange(nameBytes); // filename + namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length + namesAndAttributes.AddRange(attributesBytes); // attributes + } + + var namesAndAttributesBytes = namesAndAttributes.ToArray(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.Name); + sshDataStream.Write(responseId); + sshDataStream.Write((uint) names.Length); + sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); + return sshDataStream.ToArray(); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs index b3188d3b..1fbc2a45 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSessionTest_Connected_RequestStatVfs.cs @@ -1,257 +1,257 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - [TestClass] - public class SftpSessionTest_Connected_RequestStatVfs - { - private Mock _sessionMock; - private Mock _channelSessionMock; - private SftpSession _sftpSession; - private TimeSpan _operationTimeout; - private SftpFileSytemInformation _actual; - private Encoding _encoding; - - private ulong _bAvail; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - - _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); - _encoding = Encoding.UTF8; - - _bAvail = (ulong) random.Next(0, int.MaxValue); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelSessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - // generate response for SftpInitRequest - var versionInfoResponse = SftpVersionResponseBuilder.Create(3) - .AddExtension("statvfs@openssh.com", "") - .Build(); - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, versionInfoResponse)); - }); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, sftpNameResponse)); - } - ); - _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( - () => - { - var statVfsReplyBuilder = StatVfsReplyBuilder.Create(2); - statVfsReplyBuilder.WithBAvail(_bAvail); - var statVfsReply = statVfsReplyBuilder.Build(); - - _channelSessionMock.Raise( - c => c.DataReceived += null, - new ChannelDataEventArgs(0, statVfsReply)); - } - ); - - _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); - _sftpSession.Connect(); - } - - protected void Act() - { - _actual = _sftpSession.RequestStatVfs("path"); - } - - [TestMethod] - public void ReturnedValueShouldNotBeNull() - { - Assert.IsNotNull(_actual); - } - - [TestMethod] - public void AvailableBlocksInReturnedValueShouldMatchValueInSftpResponse() - { - Assert.AreEqual(_bAvail, _actual.AvailableBlocks); - } - - private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) - { - var namesAndAttributes = new List(); - foreach (var name in names) - { - var nameBytes = encoding.GetBytes(name); - var attributesBytes = SftpFileAttributes.Empty.GetBytes(); - - namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length - namesAndAttributes.AddRange(nameBytes); // filename - namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length - namesAndAttributes.AddRange(attributesBytes); // attributes - } - - var namesAndAttributesBytes = namesAndAttributes.ToArray(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.Name); - sshDataStream.Write(responseId); - sshDataStream.Write((uint) names.Length); - sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); - return sshDataStream.ToArray(); - } - - public class StatVfsReplyBuilder - { - private readonly uint _responseId; - private ulong _bsize; - private ulong _frsize; - private ulong _blocks; - private ulong _bfree; - private ulong _bavail; - private ulong _files; - private ulong _ffree; - private ulong _favail; - private ulong _sid; - private ulong _flag; - private ulong _namemax; - - private StatVfsReplyBuilder(uint responseId) - { - _responseId = responseId; - } - - public static StatVfsReplyBuilder Create(uint responseId) - { - return new StatVfsReplyBuilder(responseId); - } - - public StatVfsReplyBuilder WithBSize(ulong bsize) - { - _bsize = bsize; - return this; - } - - public StatVfsReplyBuilder WithFrSize(ulong frsize) - { - _frsize = frsize; - return this; - } - - public StatVfsReplyBuilder WithBlocks(ulong blocks) - { - _blocks = blocks; - return this; - } - - public StatVfsReplyBuilder WithBFree(ulong bfree) - { - _bfree = bfree; - return this; - } - - public StatVfsReplyBuilder WithBAvail(ulong bavail) - { - _bavail = bavail; - return this; - } - - public StatVfsReplyBuilder WithFiles(ulong files) - { - _files = files; - return this; - } - - public StatVfsReplyBuilder WithFFree(ulong ffree) - { - _ffree = ffree; - return this; - } - - public StatVfsReplyBuilder WithFAvail(ulong favail) - { - _favail = favail; - return this; - } - - public StatVfsReplyBuilder WithSid(ulong sid) - { - _sid = sid; - return this; - } - - public StatVfsReplyBuilder WithIsReadOnly(bool isReadOnly) - { - if (isReadOnly) - _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; - else - _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; - - return this; - } - - public StatVfsReplyBuilder WithSupportsSetUid(bool supportsSetUid) - { - if (supportsSetUid) - _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; - else - _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; - - return this; - } - - public StatVfsReplyBuilder WithNameMax(ulong nameMax) - { - _namemax = nameMax; - return this; - } - - public byte[] Build() - { - var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); - sshDataStream.Write((uint) sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); - sshDataStream.Write(_responseId); - sshDataStream.Write(_bsize); - sshDataStream.Write(_frsize); - sshDataStream.Write(_blocks); - sshDataStream.Write(_bfree); - sshDataStream.Write(_bavail); - sshDataStream.Write(_files); - sshDataStream.Write(_ffree); - sshDataStream.Write(_favail); - sshDataStream.Write(_sid); - sshDataStream.Write(_flag); - sshDataStream.Write(_namemax); - return sshDataStream.ToArray(); - } - } - } +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + [TestClass] + public class SftpSessionTest_Connected_RequestStatVfs + { + private Mock _sessionMock; + private Mock _channelSessionMock; + private SftpSession _sftpSession; + private TimeSpan _operationTimeout; + private SftpFileSytemInformation _actual; + private Encoding _encoding; + + private ulong _bAvail; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + + _operationTimeout = TimeSpan.FromMilliseconds(random.Next(100, 500)); + _encoding = Encoding.UTF8; + + _bAvail = (ulong) random.Next(0, int.MaxValue); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelSessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(sequence).Setup(p => p.Open()); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest("sftp")).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + // generate response for SftpInitRequest + var versionInfoResponse = SftpVersionResponseBuilder.Create(3) + .AddExtension("statvfs@openssh.com", "") + .Build(); + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, versionInfoResponse)); + }); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var sftpNameResponse = CreateSftpNameResponse(1, _encoding, "ABC"); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, sftpNameResponse)); + } + ); + _channelSessionMock.InSequence(sequence).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(sequence).Setup(p => p.SendData(It.IsAny())).Callback( + () => + { + var statVfsReplyBuilder = StatVfsReplyBuilder.Create(2); + statVfsReplyBuilder.WithBAvail(_bAvail); + var statVfsReply = statVfsReplyBuilder.Build(); + + _channelSessionMock.Raise( + c => c.DataReceived += null, + new ChannelDataEventArgs(0, statVfsReply)); + } + ); + + _sftpSession = new SftpSession(_sessionMock.Object, _operationTimeout, _encoding); + _sftpSession.Connect(); + } + + protected void Act() + { + _actual = _sftpSession.RequestStatVfs("path"); + } + + [TestMethod] + public void ReturnedValueShouldNotBeNull() + { + Assert.IsNotNull(_actual); + } + + [TestMethod] + public void AvailableBlocksInReturnedValueShouldMatchValueInSftpResponse() + { + Assert.AreEqual(_bAvail, _actual.AvailableBlocks); + } + + private static byte[] CreateSftpNameResponse(uint responseId, Encoding encoding, params string[] names) + { + var namesAndAttributes = new List(); + foreach (var name in names) + { + var nameBytes = encoding.GetBytes(name); + var attributesBytes = SftpFileAttributes.Empty.GetBytes(); + + namesAndAttributes.AddRange((((uint) nameBytes.Length).GetBytes())); // filename length + namesAndAttributes.AddRange(nameBytes); // filename + namesAndAttributes.AddRange(((uint) 0).GetBytes()); // longname length + namesAndAttributes.AddRange(attributesBytes); // attributes + } + + var namesAndAttributesBytes = namesAndAttributes.ToArray(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + 4 + namesAndAttributesBytes.Length); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.Name); + sshDataStream.Write(responseId); + sshDataStream.Write((uint) names.Length); + sshDataStream.Write(namesAndAttributesBytes, 0, namesAndAttributesBytes.Length); + return sshDataStream.ToArray(); + } + + public class StatVfsReplyBuilder + { + private readonly uint _responseId; + private ulong _bsize; + private ulong _frsize; + private ulong _blocks; + private ulong _bfree; + private ulong _bavail; + private ulong _files; + private ulong _ffree; + private ulong _favail; + private ulong _sid; + private ulong _flag; + private ulong _namemax; + + private StatVfsReplyBuilder(uint responseId) + { + _responseId = responseId; + } + + public static StatVfsReplyBuilder Create(uint responseId) + { + return new StatVfsReplyBuilder(responseId); + } + + public StatVfsReplyBuilder WithBSize(ulong bsize) + { + _bsize = bsize; + return this; + } + + public StatVfsReplyBuilder WithFrSize(ulong frsize) + { + _frsize = frsize; + return this; + } + + public StatVfsReplyBuilder WithBlocks(ulong blocks) + { + _blocks = blocks; + return this; + } + + public StatVfsReplyBuilder WithBFree(ulong bfree) + { + _bfree = bfree; + return this; + } + + public StatVfsReplyBuilder WithBAvail(ulong bavail) + { + _bavail = bavail; + return this; + } + + public StatVfsReplyBuilder WithFiles(ulong files) + { + _files = files; + return this; + } + + public StatVfsReplyBuilder WithFFree(ulong ffree) + { + _ffree = ffree; + return this; + } + + public StatVfsReplyBuilder WithFAvail(ulong favail) + { + _favail = favail; + return this; + } + + public StatVfsReplyBuilder WithSid(ulong sid) + { + _sid = sid; + return this; + } + + public StatVfsReplyBuilder WithIsReadOnly(bool isReadOnly) + { + if (isReadOnly) + _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; + else + _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_RDONLY; + + return this; + } + + public StatVfsReplyBuilder WithSupportsSetUid(bool supportsSetUid) + { + if (supportsSetUid) + _flag |= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; + else + _flag &= SftpFileSytemInformation.SSH_FXE_STATVFS_ST_NOSUID; + + return this; + } + + public StatVfsReplyBuilder WithNameMax(ulong nameMax) + { + _namemax = nameMax; + return this; + } + + public byte[] Build() + { + var sshDataStream = new SshDataStream(4 + 1 + 4 + 88); + sshDataStream.Write((uint) sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte) SftpMessageTypes.ExtendedReply); + sshDataStream.Write(_responseId); + sshDataStream.Write(_bsize); + sshDataStream.Write(_frsize); + sshDataStream.Write(_blocks); + sshDataStream.Write(_bfree); + sshDataStream.Write(_bavail); + sshDataStream.Write(_files); + sshDataStream.Write(_ffree); + sshDataStream.Write(_favail); + sshDataStream.Write(_sid); + sshDataStream.Write(_flag); + sshDataStream.Write(_namemax); + return sshDataStream.ToArray(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs index 3f84f706..2a98c973 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpSynchronizeDirectoriesAsyncResultTest.cs @@ -1,27 +1,27 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpSynchronizeDirectoriesAsyncResultTest and is intended - ///to contain all SftpSynchronizeDirectoriesAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpSynchronizeDirectoriesAsyncResultTest : TestBase - { - /// - ///A test for SftpSynchronizeDirectoriesAsyncResult Constructor - /// - [TestMethod()] - public void SftpSynchronizeDirectoriesAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpSynchronizeDirectoriesAsyncResult target = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpSynchronizeDirectoriesAsyncResultTest and is intended + ///to contain all SftpSynchronizeDirectoriesAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpSynchronizeDirectoriesAsyncResultTest : TestBase + { + /// + ///A test for SftpSynchronizeDirectoriesAsyncResult Constructor + /// + [TestMethod()] + public void SftpSynchronizeDirectoriesAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpSynchronizeDirectoriesAsyncResult target = new SftpSynchronizeDirectoriesAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs index 81244c45..0194bca8 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpUploadAsyncResultTest.cs @@ -1,27 +1,27 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - /// - ///This is a test class for SftpUploadAsyncResultTest and is intended - ///to contain all SftpUploadAsyncResultTest Unit Tests - /// - [TestClass()] - public class SftpUploadAsyncResultTest : TestBase - { - /// - ///A test for SftpUploadAsyncResult Constructor - /// - [TestMethod()] - public void SftpUploadAsyncResultConstructorTest() - { - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - SftpUploadAsyncResult target = new SftpUploadAsyncResult(asyncCallback, state); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + /// + ///This is a test class for SftpUploadAsyncResultTest and is intended + ///to contain all SftpUploadAsyncResultTest Unit Tests + /// + [TestClass()] + public class SftpUploadAsyncResultTest : TestBase + { + /// + ///A test for SftpUploadAsyncResult Constructor + /// + [TestMethod()] + public void SftpUploadAsyncResultConstructorTest() + { + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + SftpUploadAsyncResult target = new SftpUploadAsyncResult(asyncCallback, state); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs b/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs index a8ef51d3..e5e1f670 100644 --- a/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs +++ b/src/Renci.SshNet.Tests/Classes/Sftp/SftpVersionResponseBuilder.cs @@ -1,53 +1,53 @@ -using System.Collections.Generic; -using System.Text; -using Renci.SshNet.Common; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes.Sftp -{ - public class SftpVersionResponseBuilder - { - private readonly uint _version; - private readonly IDictionary _extensions; - - private SftpVersionResponseBuilder(uint version) - { - _version = version; - _extensions = new Dictionary(); - } - - public static SftpVersionResponseBuilder Create(uint version) - { - return new SftpVersionResponseBuilder(version); - } - - public SftpVersionResponseBuilder AddExtension(string name, string data) - { - _extensions.Add(name, data); - return this; - } - - public byte[] Build() - { - var extensions = BuildExtensions(); - - var sshDataStream = new SshDataStream(4 + 1 + 4 + extensions.Length); - sshDataStream.Write((uint)sshDataStream.Capacity - 4); - sshDataStream.WriteByte((byte)SftpMessageTypes.Version); - sshDataStream.Write(_version); - sshDataStream.Write(extensions, 0, extensions.Length); - return sshDataStream.ToArray(); - } - - private byte[] BuildExtensions() - { - var sshDataStream = new SshDataStream(0); - foreach (var extensionPair in _extensions) - { - sshDataStream.Write(extensionPair.Key, Encoding.ASCII); - sshDataStream.Write(extensionPair.Value, Encoding.ASCII); - } - return sshDataStream.ToArray(); - } - } -} +using System.Collections.Generic; +using System.Text; +using Renci.SshNet.Common; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes.Sftp +{ + public class SftpVersionResponseBuilder + { + private readonly uint _version; + private readonly IDictionary _extensions; + + private SftpVersionResponseBuilder(uint version) + { + _version = version; + _extensions = new Dictionary(); + } + + public static SftpVersionResponseBuilder Create(uint version) + { + return new SftpVersionResponseBuilder(version); + } + + public SftpVersionResponseBuilder AddExtension(string name, string data) + { + _extensions.Add(name, data); + return this; + } + + public byte[] Build() + { + var extensions = BuildExtensions(); + + var sshDataStream = new SshDataStream(4 + 1 + 4 + extensions.Length); + sshDataStream.Write((uint)sshDataStream.Capacity - 4); + sshDataStream.WriteByte((byte)SftpMessageTypes.Version); + sshDataStream.Write(_version); + sshDataStream.Write(extensions, 0, extensions.Length); + return sshDataStream.ToArray(); + } + + private byte[] BuildExtensions() + { + var sshDataStream = new SshDataStream(0); + foreach (var extensionPair in _extensions) + { + sshDataStream.Write(extensionPair.Key, Encoding.ASCII); + sshDataStream.Write(extensionPair.Value, Encoding.ASCII); + } + return sshDataStream.ToArray(); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs index 2187639b..9ae69f6e 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.Connect.cs @@ -1,45 +1,45 @@ -using System.Net.Sockets; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Connect - { - [TestMethod] - public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("invalid.", 40, "user", - new KeyboardInteractiveAuthenticationMethod("user")); - var sftpClient = new SftpClient(connectionInfo); - - try - { - sftpClient.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int) SocketError.HostNotFound); - } - } - - [TestMethod] - public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() - { - var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, - "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); - var sftpClient = new SftpClient(connectionInfo); - - try - { - sftpClient.Connect(); - Assert.Fail(); - } - catch (SocketException ex) - { - Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); - } - } - } -} +using System.Net.Sockets; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Connect + { + [TestMethod] + public void Connect_HostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("invalid.", 40, "user", + new KeyboardInteractiveAuthenticationMethod("user")); + var sftpClient = new SftpClient(connectionInfo); + + try + { + sftpClient.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int) SocketError.HostNotFound); + } + } + + [TestMethod] + public void Connect_ProxyHostNameInvalid_ShouldThrowSocketExceptionWithErrorCodeHostNotFound() + { + var connectionInfo = new ConnectionInfo("localhost", 40, "user", ProxyTypes.Http, "invalid.", 80, + "proxyUser", "proxyPwd", new KeyboardInteractiveAuthenticationMethod("user")); + var sftpClient = new SftpClient(connectionInfo); + + try + { + sftpClient.Connect(); + Assert.Fail(); + } + catch (SocketException ex) + { + Assert.AreEqual(ex.ErrorCode, (int)SocketError.HostNotFound); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs index 4714d705..5a9446f5 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.DeleteFile.cs @@ -1,25 +1,25 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. - /// - public partial class SftpClientTest : TestBase - { - [TestMethod] - [TestCategory("Sftp")] - [Description("Test passing null to DeleteFile.")] - [ExpectedException(typeof(ArgumentException))] - public void Test_Sftp_DeleteFile_Null() - { - using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - sftp.DeleteFile(null); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. + /// + public partial class SftpClientTest : TestBase + { + [TestMethod] + [TestCategory("Sftp")] + [Description("Test passing null to DeleteFile.")] + [ExpectedException(typeof(ArgumentException))] + public void Test_Sftp_DeleteFile_Null() + { + using (var sftp = new SftpClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + sftp.DeleteFile(null); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs index d779a5c6..6f4ec964 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest.cs @@ -1,1272 +1,1272 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Sftp; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Collections.Generic; -using System.IO; -using System.Security.Cryptography; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. - /// - [TestClass] - public partial class SftpClientTest : TestBase - { - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SftpClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SftpClientConstructorTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for ChangePermissions - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ChangePermissionsTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - short mode = 0; // TODO: Initialize to an appropriate value - target.ChangePermissions(path, mode); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for ChangeDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ChangeDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.ChangeDirectory(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for BeginUploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginUploadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginUploadFile(input, path, asyncCallback, state, uploadCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginUploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginUploadFileTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - bool canOverride = false; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginUploadFile(input, path, canOverride, asyncCallback, state, uploadCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginSynchronizeDirectories - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginSynchronizeDirectoriesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string sourcePath = string.Empty; // TODO: Initialize to an appropriate value - string destinationPath = string.Empty; // TODO: Initialize to an appropriate value - string searchPattern = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginSynchronizeDirectories(sourcePath, destinationPath, searchPattern, asyncCallback, state); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginListDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginListDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action listCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginListDirectory(path, asyncCallback, state, listCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for BeginDownloadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginDownloadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - Action downloadCallback = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginDownloadFile(path, output, asyncCallback, state, downloadCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AppendText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.AppendText(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AppendText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.AppendText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for AppendAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - target.AppendAllText(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AppendAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.AppendAllText(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AppendAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - target.AppendAllLines(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for AppendAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AppendAllLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.AppendAllLines(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for CreateText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.CreateText(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - StreamWriter expected = null; // TODO: Initialize to an appropriate value - StreamWriter actual; - actual = target.CreateText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.CreateDirectory(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Create - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Create(path, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Create - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Create(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndSynchronizeDirectories - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndSynchronizeDirectoriesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.EndSynchronizeDirectories(asyncResult); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndListDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndListDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.EndListDirectory(asyncResult); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndDownloadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndDownloadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - target.EndDownloadFile(asyncResult); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for DownloadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DownloadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Action downloadCallback = null; // TODO: Initialize to an appropriate value - target.DownloadFile(path, output, downloadCallback); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for DeleteFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DeleteFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.DeleteFile(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for DeleteDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DeleteDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.DeleteDirectory(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Delete - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void DeleteTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - target.Delete(path); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GetLastAccessTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastAccessTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastAccessTimeUtc(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetLastAccessTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastAccessTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastAccessTime(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetAttributes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetAttributesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileAttributes expected = null; // TODO: Initialize to an appropriate value - SftpFileAttributes actual; - actual = target.GetAttributes(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Get - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFile expected = null; // TODO: Initialize to an appropriate value - SftpFile actual; - actual = target.Get(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Exists - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ExistsTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - bool expected = false; // TODO: Initialize to an appropriate value - bool actual; - actual = target.Exists(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for EndUploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void EndUploadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value - target.EndUploadFile(asyncResult); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for GetLastWriteTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastWriteTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastWriteTimeUtc(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetLastWriteTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetLastWriteTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value - DateTime actual; - actual = target.GetLastWriteTime(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for GetStatus - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void GetStatusTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileSytemInformation expected = null; // TODO: Initialize to an appropriate value - SftpFileSytemInformation actual; - actual = target.GetStatus(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ListDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ListDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Action listCallback = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ListDirectory(path, listCallback); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Open - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Open(path, mode); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Open - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value - FileAccess access = new FileAccess(); // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.Open(path, mode, access); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OpenRead - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenReadTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.OpenRead(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OpenText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - StreamReader expected = null; // TODO: Initialize to an appropriate value - StreamReader actual; - actual = target.OpenText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OpenWrite - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OpenWriteTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileStream expected = null; // TODO: Initialize to an appropriate value - SftpFileStream actual; - actual = target.OpenWrite(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllBytes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllBytesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - byte[] expected = null; // TODO: Initialize to an appropriate value - byte[] actual; - actual = target.ReadAllBytes(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - actual = target.ReadAllLines(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string[] expected = null; // TODO: Initialize to an appropriate value - string[] actual; - actual = target.ReadAllLines(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.ReadAllText(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadAllTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.ReadAllText(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ReadLines(path); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ReadLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ReadLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ReadLines(path, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for RenameFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RenameFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string oldPath = string.Empty; // TODO: Initialize to an appropriate value - string newPath = string.Empty; // TODO: Initialize to an appropriate value - target.RenameFile(oldPath, newPath); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for RenameFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RenameFileTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string oldPath = string.Empty; // TODO: Initialize to an appropriate value - string newPath = string.Empty; // TODO: Initialize to an appropriate value - bool isPosix = false; // TODO: Initialize to an appropriate value - target.RenameFile(oldPath, newPath, isPosix); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetAttributes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetAttributesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - SftpFileAttributes fileAttributes = null; // TODO: Initialize to an appropriate value - target.SetAttributes(path, fileAttributes); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastAccessTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastAccessTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastAccessTime = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastAccessTime(path, lastAccessTime); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastAccessTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastAccessTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastAccessTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastAccessTimeUtc(path, lastAccessTimeUtc); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastWriteTime - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastWriteTimeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastWriteTime = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastWriteTime(path, lastWriteTime); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SetLastWriteTimeUtc - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SetLastWriteTimeUtcTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - DateTime lastWriteTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value - target.SetLastWriteTimeUtc(path, lastWriteTimeUtc); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SymbolicLink - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SymbolicLinkTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string linkPath = string.Empty; // TODO: Initialize to an appropriate value - target.SymbolicLink(path, linkPath); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SynchronizeDirectories - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SynchronizeDirectoriesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string sourcePath = string.Empty; // TODO: Initialize to an appropriate value - string destinationPath = string.Empty; // TODO: Initialize to an appropriate value - string searchPattern = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable expected = null; // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.SynchronizeDirectories(sourcePath, destinationPath, searchPattern); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for UploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void UploadFileTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - target.UploadFile(input, path, uploadCallback); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for UploadFile - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void UploadFileTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - bool canOverride = false; // TODO: Initialize to an appropriate value - Action uploadCallback = null; // TODO: Initialize to an appropriate value - target.UploadFile(input, path, canOverride, uploadCallback); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllBytes - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllBytesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - byte[] bytes = null; // TODO: Initialize to an appropriate value - target.WriteAllBytes(path, bytes); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string[] contents = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest2() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - IEnumerable contents = null; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllLines - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllLinesTest3() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string[] contents = null; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.WriteAllLines(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllTextTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - target.WriteAllText(path, contents); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for WriteAllText - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WriteAllTextTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string path = string.Empty; // TODO: Initialize to an appropriate value - string contents = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - target.WriteAllText(path, contents, encoding); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for BufferSize - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BufferSizeTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - uint expected = 0; // TODO: Initialize to an appropriate value - uint actual; - target.BufferSize = expected; - actual = target.BufferSize; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for OperationTimeout - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void OperationTimeoutTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value - TimeSpan actual; - target.OperationTimeout = expected; - actual = target.OperationTimeout; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for WorkingDirectory - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void WorkingDirectoryTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value - string actual; - actual = target.WorkingDirectory; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - protected static string CalculateMD5(string fileName) - { - using (FileStream file = new FileStream(fileName, FileMode.Open)) - { - MD5 md5 = new MD5CryptoServiceProvider(); - byte[] retVal = md5.ComputeHash(file); - file.Close(); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < retVal.Length; i++) - { - sb.Append(retVal[i].ToString("x2")); - } - return sb.ToString(); - } - } - - private static void RemoveAllFiles() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - client.RunCommand("rm -rf *"); - client.Disconnect(); - } - } - - /// - /// Helper class to help with upload and download testing - /// - private class TestInfo - { - public string RemoteFileName { get; set; } - - public string UploadedFileName { get; set; } - - public string DownloadedFileName { get; set; } - - //public ulong UploadedBytes { get; set; } - - //public ulong DownloadedBytes { get; set; } - - public FileStream UploadedFile { get; set; } - - public FileStream DownloadedFile { get; set; } - - public string UploadedHash { get; set; } - - public string DownloadedHash { get; set; } - - public SftpUploadAsyncResult UploadResult { get; set; } - - public SftpDownloadAsyncResult DownloadResult { get; set; } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Sftp; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Collections.Generic; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Implementation of the SSH File Transfer Protocol (SFTP) over SSH. + /// + [TestClass] + public partial class SftpClientTest : TestBase + { + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SftpClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SftpClientConstructorTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for ChangePermissions + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ChangePermissionsTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + short mode = 0; // TODO: Initialize to an appropriate value + target.ChangePermissions(path, mode); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for ChangeDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ChangeDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.ChangeDirectory(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for BeginUploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginUploadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginUploadFile(input, path, asyncCallback, state, uploadCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginUploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginUploadFileTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + bool canOverride = false; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginUploadFile(input, path, canOverride, asyncCallback, state, uploadCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginSynchronizeDirectories + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginSynchronizeDirectoriesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string sourcePath = string.Empty; // TODO: Initialize to an appropriate value + string destinationPath = string.Empty; // TODO: Initialize to an appropriate value + string searchPattern = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginSynchronizeDirectories(sourcePath, destinationPath, searchPattern, asyncCallback, state); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginListDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginListDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action listCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginListDirectory(path, asyncCallback, state, listCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for BeginDownloadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginDownloadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + AsyncCallback asyncCallback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + Action downloadCallback = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginDownloadFile(path, output, asyncCallback, state, downloadCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AppendText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.AppendText(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AppendText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.AppendText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for AppendAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + target.AppendAllText(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AppendAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.AppendAllText(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AppendAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + target.AppendAllLines(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for AppendAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AppendAllLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.AppendAllLines(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for CreateText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.CreateText(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + StreamWriter expected = null; // TODO: Initialize to an appropriate value + StreamWriter actual; + actual = target.CreateText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.CreateDirectory(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Create + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Create(path, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Create + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Create(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndSynchronizeDirectories + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndSynchronizeDirectoriesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.EndSynchronizeDirectories(asyncResult); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndListDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndListDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.EndListDirectory(asyncResult); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndDownloadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndDownloadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + target.EndDownloadFile(asyncResult); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for DownloadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DownloadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Action downloadCallback = null; // TODO: Initialize to an appropriate value + target.DownloadFile(path, output, downloadCallback); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for DeleteFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DeleteFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.DeleteFile(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for DeleteDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DeleteDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.DeleteDirectory(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Delete + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void DeleteTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + target.Delete(path); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GetLastAccessTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastAccessTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastAccessTimeUtc(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetLastAccessTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastAccessTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastAccessTime(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetAttributes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetAttributesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileAttributes expected = null; // TODO: Initialize to an appropriate value + SftpFileAttributes actual; + actual = target.GetAttributes(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Get + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFile expected = null; // TODO: Initialize to an appropriate value + SftpFile actual; + actual = target.Get(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Exists + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ExistsTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + bool expected = false; // TODO: Initialize to an appropriate value + bool actual; + actual = target.Exists(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for EndUploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void EndUploadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + IAsyncResult asyncResult = null; // TODO: Initialize to an appropriate value + target.EndUploadFile(asyncResult); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for GetLastWriteTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastWriteTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastWriteTimeUtc(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetLastWriteTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetLastWriteTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value + DateTime actual; + actual = target.GetLastWriteTime(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for GetStatus + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void GetStatusTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileSytemInformation expected = null; // TODO: Initialize to an appropriate value + SftpFileSytemInformation actual; + actual = target.GetStatus(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ListDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ListDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Action listCallback = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ListDirectory(path, listCallback); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Open + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Open(path, mode); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Open + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + FileMode mode = new FileMode(); // TODO: Initialize to an appropriate value + FileAccess access = new FileAccess(); // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.Open(path, mode, access); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OpenRead + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenReadTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.OpenRead(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OpenText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + StreamReader expected = null; // TODO: Initialize to an appropriate value + StreamReader actual; + actual = target.OpenText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OpenWrite + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OpenWriteTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileStream expected = null; // TODO: Initialize to an appropriate value + SftpFileStream actual; + actual = target.OpenWrite(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllBytes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllBytesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + byte[] expected = null; // TODO: Initialize to an appropriate value + byte[] actual; + actual = target.ReadAllBytes(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + actual = target.ReadAllLines(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string[] expected = null; // TODO: Initialize to an appropriate value + string[] actual; + actual = target.ReadAllLines(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.ReadAllText(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadAllTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.ReadAllText(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ReadLines(path); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ReadLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ReadLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ReadLines(path, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for RenameFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RenameFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string oldPath = string.Empty; // TODO: Initialize to an appropriate value + string newPath = string.Empty; // TODO: Initialize to an appropriate value + target.RenameFile(oldPath, newPath); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for RenameFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RenameFileTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string oldPath = string.Empty; // TODO: Initialize to an appropriate value + string newPath = string.Empty; // TODO: Initialize to an appropriate value + bool isPosix = false; // TODO: Initialize to an appropriate value + target.RenameFile(oldPath, newPath, isPosix); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetAttributes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetAttributesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + SftpFileAttributes fileAttributes = null; // TODO: Initialize to an appropriate value + target.SetAttributes(path, fileAttributes); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastAccessTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastAccessTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastAccessTime = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastAccessTime(path, lastAccessTime); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastAccessTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastAccessTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastAccessTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastAccessTimeUtc(path, lastAccessTimeUtc); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastWriteTime + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastWriteTimeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastWriteTime = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastWriteTime(path, lastWriteTime); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SetLastWriteTimeUtc + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SetLastWriteTimeUtcTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + DateTime lastWriteTimeUtc = new DateTime(); // TODO: Initialize to an appropriate value + target.SetLastWriteTimeUtc(path, lastWriteTimeUtc); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SymbolicLink + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SymbolicLinkTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string linkPath = string.Empty; // TODO: Initialize to an appropriate value + target.SymbolicLink(path, linkPath); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SynchronizeDirectories + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SynchronizeDirectoriesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string sourcePath = string.Empty; // TODO: Initialize to an appropriate value + string destinationPath = string.Empty; // TODO: Initialize to an appropriate value + string searchPattern = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable expected = null; // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.SynchronizeDirectories(sourcePath, destinationPath, searchPattern); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for UploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void UploadFileTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + target.UploadFile(input, path, uploadCallback); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for UploadFile + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void UploadFileTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + bool canOverride = false; // TODO: Initialize to an appropriate value + Action uploadCallback = null; // TODO: Initialize to an appropriate value + target.UploadFile(input, path, canOverride, uploadCallback); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllBytes + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllBytesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + byte[] bytes = null; // TODO: Initialize to an appropriate value + target.WriteAllBytes(path, bytes); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string[] contents = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest2() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + IEnumerable contents = null; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllLines + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllLinesTest3() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string[] contents = null; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.WriteAllLines(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllTextTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + target.WriteAllText(path, contents); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for WriteAllText + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WriteAllTextTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string path = string.Empty; // TODO: Initialize to an appropriate value + string contents = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + target.WriteAllText(path, contents, encoding); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for BufferSize + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BufferSizeTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + uint expected = 0; // TODO: Initialize to an appropriate value + uint actual; + target.BufferSize = expected; + actual = target.BufferSize; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for OperationTimeout + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void OperationTimeoutTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value + TimeSpan actual; + target.OperationTimeout = expected; + actual = target.OperationTimeout; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for WorkingDirectory + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void WorkingDirectoryTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SftpClient target = new SftpClient(connectionInfo); // TODO: Initialize to an appropriate value + string actual; + actual = target.WorkingDirectory; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + protected static string CalculateMD5(string fileName) + { + using (FileStream file = new FileStream(fileName, FileMode.Open)) + { + MD5 md5 = new MD5CryptoServiceProvider(); + byte[] retVal = md5.ComputeHash(file); + file.Close(); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < retVal.Length; i++) + { + sb.Append(retVal[i].ToString("x2")); + } + return sb.ToString(); + } + } + + private static void RemoveAllFiles() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + client.RunCommand("rm -rf *"); + client.Disconnect(); + } + } + + /// + /// Helper class to help with upload and download testing + /// + private class TestInfo + { + public string RemoteFileName { get; set; } + + public string UploadedFileName { get; set; } + + public string DownloadedFileName { get; set; } + + //public ulong UploadedBytes { get; set; } + + //public ulong DownloadedBytes { get; set; } + + public FileStream UploadedFile { get; set; } + + public FileStream DownloadedFile { get; set; } + + public string UploadedHash { get; set; } + + public string DownloadedHash { get; set; } + + public SftpUploadAsyncResult UploadResult { get; set; } + + public SftpDownloadAsyncResult DownloadResult { get; set; } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs index dae241e9..db06da60 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Connected.cs @@ -1,108 +1,108 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Dispose_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sftpClient.Connect(); - } - - protected void Act() - { - _sftpClient.Dispose(); - } - - [TestMethod] - public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify( - p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), - Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Dispose_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sftpClient.Connect(); + } + + protected void Act() + { + _sftpClient.Dispose(); + } + + [TestMethod] + public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify( + p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), + Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs index 9daf237d..d5e4f53c 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disconnected.cs @@ -1,109 +1,109 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Dispose_Disconnected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sftpClient.Connect(); - _sftpClient.Disconnect(); - } - - protected void Act() - { - _sftpClient.Dispose(); - } - - [TestMethod] - public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify( - p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), - Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Dispose_Disconnected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sftpClient.Connect(); + _sftpClient.Disconnect(); + } + + protected void Act() + { + _sftpClient.Dispose(); + } + + [TestMethod] + public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify( + p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), + Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs index 841d705c..4fccdc72 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Dispose_Disposed.cs @@ -1,109 +1,109 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Dispose_Disposed - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _serviceFactoryMock.InSequence(sequence) - .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sftpClient.Connect(); - _sftpClient.Dispose(); - } - - protected void Act() - { - _sftpClient.Dispose(); - } - - [TestMethod] - public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify( - p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), - Times.Once); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnNetConfSessionShouldBeInvokedOnce() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Dispose_Disposed + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _serviceFactoryMock.InSequence(sequence) + .Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sftpSessionMock.InSequence(sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sftpClient.Connect(); + _sftpClient.Dispose(); + } + + protected void Act() + { + _sftpClient.Dispose(); + } + + [TestMethod] + public void CreateSftpSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify( + p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding), + Times.Once); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnNetConfSessionShouldBeInvokedOnce() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs index 9c95daac..5263f6ef 100644 --- a/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SftpClientTest_Finalize_Connected.cs @@ -1,75 +1,75 @@ -using System; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Sftp; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SftpClientTest_Finalize_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SftpClient _sftpClient; - private ConnectionInfo _connectionInfo; - private Mock _sftpSessionMock; - private TimeSpan _operationTimeout; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - _serviceFactoryMock = new Mock(MockBehavior.Loose); - _sessionMock = new Mock(MockBehavior.Strict); - _sftpSessionMock = new Mock(MockBehavior.Strict); - - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); - _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sftpClient.OperationTimeout = _operationTimeout; - - _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo)) - .Returns(_sessionMock.Object); - _sessionMock.Setup(p => p.Connect()); - _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns(_sftpSessionMock.Object); - _sftpSessionMock.Setup(p => p.Connect()); - - _sftpClient.Connect(); - _sftpClient = null; - - _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) - .Returns((ISftpSession) null); - _serviceFactoryMock.ResetCalls(); - - // we need to dereference all other mocks as they might otherwise hold the target alive - _sessionMock = null; - _connectionInfo = null; - _serviceFactoryMock = null; - } - - protected void Act() - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - } - - [TestMethod] - public void DisconnectOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never); - } - - [TestMethod] - public void DisposeOnSftpSessionShouldNeverBeInvoked() - { - _sftpSessionMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Sftp; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SftpClientTest_Finalize_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SftpClient _sftpClient; + private ConnectionInfo _connectionInfo; + private Mock _sftpSessionMock; + private TimeSpan _operationTimeout; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + _serviceFactoryMock = new Mock(MockBehavior.Loose); + _sessionMock = new Mock(MockBehavior.Strict); + _sftpSessionMock = new Mock(MockBehavior.Strict); + + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + _operationTimeout = TimeSpan.FromSeconds(new Random().Next(1, 10)); + _sftpClient = new SftpClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sftpClient.OperationTimeout = _operationTimeout; + + _serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo)) + .Returns(_sessionMock.Object); + _sessionMock.Setup(p => p.Connect()); + _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns(_sftpSessionMock.Object); + _sftpSessionMock.Setup(p => p.Connect()); + + _sftpClient.Connect(); + _sftpClient = null; + + _serviceFactoryMock.Setup(p => p.CreateSftpSession(_sessionMock.Object, _operationTimeout, _connectionInfo.Encoding)) + .Returns((ISftpSession) null); + _serviceFactoryMock.ResetCalls(); + + // we need to dereference all other mocks as they might otherwise hold the target alive + _sessionMock = null; + _connectionInfo = null; + _serviceFactoryMock = null; + } + + protected void Act() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + [TestMethod] + public void DisconnectOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.Disconnect(), Times.Never); + } + + [TestMethod] + public void DisposeOnSftpSessionShouldNeverBeInvoked() + { + _sftpSessionMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/ShellStream.cs b/src/Renci.SshNet.Tests/Classes/ShellStream.cs index 8640fb8e..f5d401af 100644 --- a/src/Renci.SshNet.Tests/Classes/ShellStream.cs +++ b/src/Renci.SshNet.Tests/Classes/ShellStream.cs @@ -1,13 +1,13 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Contains operation for working with SSH Shell. - /// - [TestClass] - public class ShellStreamTest : TestBase - { - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Contains operation for working with SSH Shell. + /// + [TestClass] + public class ShellStreamTest : TestBase + { + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs b/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs index c3a944ec..df442ad2 100644 --- a/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ShellStreamTest.cs @@ -1,118 +1,118 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using System.Threading; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Contains operation for working with SSH Shell. - /// - [TestClass] - public class ShellStreamTest : TestBase - { - private Mock _sessionMock; - private Mock _connectionInfoMock; - private Encoding _encoding; - private string _terminalName; - private uint _widthColumns; - private uint _heightRows; - private uint _widthPixels; - private uint _heightPixels; - private Dictionary _terminalModes; - private Mock _channelSessionMock; - - protected override void OnInit() - { - base.OnInit(); - - var random = new Random(); - _terminalName = random.Next().ToString(CultureInfo.InvariantCulture); - _widthColumns = (uint) random.Next(); - _heightRows = (uint) random.Next(); - _widthPixels = (uint)random.Next(); - _heightPixels = (uint)random.Next(); - _terminalModes = new Dictionary(); - - _encoding = Encoding.UTF8; - _sessionMock = new Mock(MockBehavior.Strict); - _connectionInfoMock = new Mock(MockBehavior.Strict); - _channelSessionMock = new Mock(MockBehavior.Strict); - } - - [TestMethod] // issue #2190 - public void ReadLine_MultiByteCharacters() - { - // bash: /root/menu.sh: Отказан - const string data1 = "bash: /root/menu.sh: \u041e\u0442\u043a\u0430\u0437\u0430\u043d"; - // о в доступе - const string data2 = "\u043e \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435"; - // done - const string data3 = "done"; - - var shellStream = CreateShellStream(); - - var channelDataPublishThread = new Thread(() => - { - _channelSessionMock.Raise(p => p.DataReceived += null, - new ChannelDataEventArgs(5, _encoding.GetBytes(data1))); - Thread.Sleep(50); - _channelSessionMock.Raise(p => p.DataReceived += null, - new ChannelDataEventArgs(5, _encoding.GetBytes(data2 + "\r\n"))); - _channelSessionMock.Raise(p => p.DataReceived += null, - new ChannelDataEventArgs(5, _encoding.GetBytes(data3 + "\r\n"))); - }); - channelDataPublishThread.Start(); - - Assert.AreEqual(data1 + data2, shellStream.ReadLine()); - Assert.AreEqual(data3, shellStream.ReadLine()); - - channelDataPublishThread.Join(); - } - - [TestMethod] - public void Write_Text_ShouldWriteNothingWhenTextIsNull() - { - var shellStream = CreateShellStream(); - const string text = null; - - shellStream.Write(text); - - _channelSessionMock.Verify(p => p.SendData(It.IsAny()), Times.Never); - } - - [TestMethod] - public void WriteLine_Line_ShouldOnlyWriteLineTerminatorWhenLineIsNull() - { - var shellStream = CreateShellStream(); - const string line = null; - var lineTerminator = _encoding.GetBytes("\r"); - - _channelSessionMock.Setup(p => p.SendData(lineTerminator)); - - shellStream.WriteLine(line); - - _channelSessionMock.Verify(p => p.SendData(lineTerminator), Times.Once); - } - - private ShellStream CreateShellStream() - { - _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); - _connectionInfoMock.Setup(p => p.Encoding).Returns(_encoding); - _sessionMock.Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.Setup(p => p.Open()); - _channelSessionMock.Setup(p => p.SendPseudoTerminalRequest(_terminalName, _widthColumns, _heightRows, - _widthPixels, _heightPixels, _terminalModes)).Returns(true); - _channelSessionMock.Setup(p => p.SendShellRequest()).Returns(true); - - return new ShellStream(_sessionMock.Object, _terminalName, _widthColumns, _heightRows, - _widthPixels, _heightPixels, _terminalModes); - } - } +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Contains operation for working with SSH Shell. + /// + [TestClass] + public class ShellStreamTest : TestBase + { + private Mock _sessionMock; + private Mock _connectionInfoMock; + private Encoding _encoding; + private string _terminalName; + private uint _widthColumns; + private uint _heightRows; + private uint _widthPixels; + private uint _heightPixels; + private Dictionary _terminalModes; + private Mock _channelSessionMock; + + protected override void OnInit() + { + base.OnInit(); + + var random = new Random(); + _terminalName = random.Next().ToString(CultureInfo.InvariantCulture); + _widthColumns = (uint) random.Next(); + _heightRows = (uint) random.Next(); + _widthPixels = (uint)random.Next(); + _heightPixels = (uint)random.Next(); + _terminalModes = new Dictionary(); + + _encoding = Encoding.UTF8; + _sessionMock = new Mock(MockBehavior.Strict); + _connectionInfoMock = new Mock(MockBehavior.Strict); + _channelSessionMock = new Mock(MockBehavior.Strict); + } + + [TestMethod] // issue #2190 + public void ReadLine_MultiByteCharacters() + { + // bash: /root/menu.sh: Отказан + const string data1 = "bash: /root/menu.sh: \u041e\u0442\u043a\u0430\u0437\u0430\u043d"; + // о в доступе + const string data2 = "\u043e \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435"; + // done + const string data3 = "done"; + + var shellStream = CreateShellStream(); + + var channelDataPublishThread = new Thread(() => + { + _channelSessionMock.Raise(p => p.DataReceived += null, + new ChannelDataEventArgs(5, _encoding.GetBytes(data1))); + Thread.Sleep(50); + _channelSessionMock.Raise(p => p.DataReceived += null, + new ChannelDataEventArgs(5, _encoding.GetBytes(data2 + "\r\n"))); + _channelSessionMock.Raise(p => p.DataReceived += null, + new ChannelDataEventArgs(5, _encoding.GetBytes(data3 + "\r\n"))); + }); + channelDataPublishThread.Start(); + + Assert.AreEqual(data1 + data2, shellStream.ReadLine()); + Assert.AreEqual(data3, shellStream.ReadLine()); + + channelDataPublishThread.Join(); + } + + [TestMethod] + public void Write_Text_ShouldWriteNothingWhenTextIsNull() + { + var shellStream = CreateShellStream(); + const string text = null; + + shellStream.Write(text); + + _channelSessionMock.Verify(p => p.SendData(It.IsAny()), Times.Never); + } + + [TestMethod] + public void WriteLine_Line_ShouldOnlyWriteLineTerminatorWhenLineIsNull() + { + var shellStream = CreateShellStream(); + const string line = null; + var lineTerminator = _encoding.GetBytes("\r"); + + _channelSessionMock.Setup(p => p.SendData(lineTerminator)); + + shellStream.WriteLine(line); + + _channelSessionMock.Verify(p => p.SendData(lineTerminator), Times.Once); + } + + private ShellStream CreateShellStream() + { + _sessionMock.Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object); + _connectionInfoMock.Setup(p => p.Encoding).Returns(_encoding); + _sessionMock.Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.Setup(p => p.Open()); + _channelSessionMock.Setup(p => p.SendPseudoTerminalRequest(_terminalName, _widthColumns, _heightRows, + _widthPixels, _heightPixels, _terminalModes)).Returns(true); + _channelSessionMock.Setup(p => p.SendShellRequest()).Returns(true); + + return new ShellStream(_sessionMock.Object, _terminalName, _widthColumns, _heightRows, + _widthPixels, _heightPixels, _terminalModes); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs b/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs index 87246685..c7eceb1e 100644 --- a/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs +++ b/src/Renci.SshNet.Tests/Classes/ShellTestTest.cs @@ -1,82 +1,82 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using System.Collections.Generic; -using System.IO; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Represents instance of the SSH shell object - /// - [TestClass] - [Ignore] // class contains just for unit tests - public partial class ShellTestTest : TestBase - { - /// - ///A test for Dispose - /// - [TestMethod()] - public void DisposeTest() - { - Session session = null; // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value - target.Dispose(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Start - /// - [TestMethod()] - public void StartTest() - { - Session session = null; // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value - target.Start(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for Stop - /// - [TestMethod()] - public void StopTest() - { - Session session = null; // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value - target.Stop(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using System.Collections.Generic; +using System.IO; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Represents instance of the SSH shell object + /// + [TestClass] + [Ignore] // class contains just for unit tests + public partial class ShellTestTest : TestBase + { + /// + ///A test for Dispose + /// + [TestMethod()] + public void DisposeTest() + { + Session session = null; // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value + target.Dispose(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Start + /// + [TestMethod()] + public void StartTest() + { + Session session = null; // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value + target.Start(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for Stop + /// + [TestMethod()] + public void StopTest() + { + Session session = null; // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell target = new Shell(session, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); // TODO: Initialize to an appropriate value + target.Stop(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest.cs index f06b5ba3..d7e295f8 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest.cs @@ -1,945 +1,945 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Linq; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Provides client connection to SSH server. - /// - [TestClass] - public class SshClientTest : TestBase - { - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_Correct_Password() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example SshClient(host, username) Connect - using (var client = new SshClient(host, username, password)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Handle_HostKeyReceived() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - var hostKeyValidated = false; - - #region Example SshClient Connect HostKeyReceived - using (var client = new SshClient(host, username, password)) - { - client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e) - { - hostKeyValidated = true; - - if (e.FingerPrint.SequenceEqual(new byte[] { 0x00, 0x01, 0x02, 0x03 })) - { - e.CanTrust = true; - } - else - { - e.CanTrust = false; - } - }; - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - - Assert.IsTrue(hostKeyValidated); - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Timeout() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - #region Example SshClient Connect Timeout - var connectionInfo = new PasswordConnectionInfo(host, username, password); - - connectionInfo.Timeout = TimeSpan.FromSeconds(30); - - using (var client = new SshClient(connectionInfo)) - { - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - Assert.Inconclusive(); - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Handle_ErrorOccurred() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - var exceptionOccured = false; - - #region Example SshClient Connect ErrorOccurred - using (var client = new SshClient(host, username, password)) - { - client.ErrorOccurred += delegate(object sender, ExceptionEventArgs e) - { - Console.WriteLine("Error occured: " + e.Exception.ToString()); - exceptionOccured = true; - }; - - client.Connect(); - // Do something here - client.Disconnect(); - } - #endregion - Assert.IsTrue(exceptionOccured); - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - [ExpectedException(typeof(SshAuthenticationException))] - public void Test_Connect_Using_Invalid_Password() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_Rsa_Key_Without_PassPhrase() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); - - #region Example SshClient(host, username) Connect PrivateKeyFile - using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream))) - { - client.Connect(); - client.Disconnect(); - } - #endregion - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_RsaKey_With_PassPhrase() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var passphrase = Resources.PASSWORD; - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)); - - #region Example SshClient(host, username) Connect PrivateKeyFile PassPhrase - using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream, passphrase))) - { - client.Connect(); - client.Disconnect(); - } - #endregion - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - [ExpectedException(typeof(SshPassPhraseNullOrEmptyException))] - public void Test_Connect_Using_Key_With_Empty_PassPhrase() - { - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)); - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, null))) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_DsaKey_Without_PassPhrase() - { - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS)); - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream))) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_DsaKey_With_PassPhrase() - { - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)); - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD))) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - [ExpectedException(typeof(SshAuthenticationException))] - public void Test_Connect_Using_Invalid_PrivateKey() - { - MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY)); - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream))) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Using_Multiple_PrivateKeys() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, - new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY))), - new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)), Resources.PASSWORD), - new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)), Resources.PASSWORD), - new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS))), - new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS))) - )) - { - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("Authentication")] - [TestCategory("integration")] - public void Test_Connect_Then_Reconnect() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - client.Disconnect(); - client.Connect(); - client.Disconnect(); - } - } - - [TestMethod] - public void CreateShellStream1_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - const int bufferSize = 4096; - - try - { - client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShellStream2_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - const int bufferSize = 4096; - - try - { - client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModes); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for CreateShellStream - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellStreamTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModeValues = null; // TODO: Initialize to an appropriate value - ShellStream expected = null; // TODO: Initialize to an appropriate value - ShellStream actual; - actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShellStream - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellStreamTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - ShellStream expected = null; // TODO: Initialize to an appropriate value - ShellStream actual; - actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void CreateShell1_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var encoding = Encoding.UTF8; - const string input = "INPUT"; - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - - - try - { - client.CreateShell(encoding, input, output, extendedOutput); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell2_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var encoding = Encoding.UTF8; - const string input = "INPUT"; - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - - try - { - client.CreateShell( - encoding, - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell3_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var encoding = Encoding.UTF8; - const string input = "INPUT"; - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - const int bufferSize = 4096; - - try - { - - client.CreateShell( - encoding, - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes, - bufferSize); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell4_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var input = new MemoryStream(); - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - - try - { - - client.CreateShell(input, output, extendedOutput); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell5_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var input = new MemoryStream(); - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - - try - { - client.CreateShell( - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateShell6_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var input = new MemoryStream(); - var output = new MemoryStream(); - var extendedOutput = new MemoryStream(); - const string terminalName = "vt100"; - const uint columns = 80; - const uint rows = 25; - const uint width = 640; - const uint height = 480; - var terminalModes = new Dictionary(); - const int bufferSize = 4096; - - try - { - - client.CreateShell( - input, - output, - extendedOutput, - terminalName, - columns, - rows, - width, - height, - terminalModes, - bufferSize); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string input = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(encoding, input, output, extendedOutput); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string input = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest2() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - string input = string.Empty; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest3() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(input, output, extendedOutput); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateShell - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateShellTest5() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - Stream input = null; // TODO: Initialize to an appropriate value - Stream output = null; // TODO: Initialize to an appropriate value - Stream extendedOutput = null; // TODO: Initialize to an appropriate value - string terminalName = string.Empty; // TODO: Initialize to an appropriate value - uint columns = 0; // TODO: Initialize to an appropriate value - uint rows = 0; // TODO: Initialize to an appropriate value - uint width = 0; // TODO: Initialize to an appropriate value - uint height = 0; // TODO: Initialize to an appropriate value - IDictionary terminalModes = null; // TODO: Initialize to an appropriate value - int bufferSize = 0; // TODO: Initialize to an appropriate value - Shell expected = null; // TODO: Initialize to an appropriate value - Shell actual; - actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - [TestMethod] - public void CreateCommand_CommandText_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - try - { - client.CreateCommand("ls"); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - [TestMethod] - public void CreateCommand_CommandTextAndEncoding_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - try - { - client.CreateCommand("ls", Encoding.UTF8); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for CreateCommand - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateCommandTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - Encoding encoding = null; // TODO: Initialize to an appropriate value - SshCommand expected = null; // TODO: Initialize to an appropriate value - SshCommand actual; - actual = target.CreateCommand(commandText, encoding); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CreateCommand - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CreateCommandTest1() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - SshCommand expected = null; // TODO: Initialize to an appropriate value - SshCommand actual; - actual = target.CreateCommand(commandText); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - - [TestMethod] - public void AddForwardedPort_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - var port = new ForwardedPortLocal(50, "host", 8080); - - try - { - client.AddForwardedPort(port); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - - /// - ///A test for AddForwardedPort - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void AddForwardedPortTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - ForwardedPort port = null; // TODO: Initialize to an appropriate value - target.AddForwardedPort(port); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest1() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, port, username, keyFiles); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest2() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest3() - { - string host = string.Empty; // TODO: Initialize to an appropriate value - int port = 0; // TODO: Initialize to an appropriate value - string username = string.Empty; // TODO: Initialize to an appropriate value - string password = string.Empty; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(host, port, username, password); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for SshClient Constructor - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void SshClientConstructorTest4() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); - Assert.Inconclusive("TODO: Implement code to verify target"); - } - - /// - ///A test for RemoveForwardedPort - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RemoveForwardedPortTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - ForwardedPort port = null; // TODO: Initialize to an appropriate value - target.RemoveForwardedPort(port); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - [TestMethod] - public void RunCommand_CommandText_NeverConnected() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) - { - try - { - client.RunCommand("ls"); - Assert.Fail(); - } - catch (SshConnectionException ex) - { - Assert.IsNull(ex.InnerException); - Assert.AreEqual("Client not connected.", ex.Message); - } - } - } - - /// - ///A test for RunCommand - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void RunCommandTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - SshCommand expected = null; // TODO: Initialize to an appropriate value - SshCommand actual; - actual = target.RunCommand(commandText); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for ForwardedPorts - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ForwardedPortsTest() - { - ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value - SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value - IEnumerable actual; - actual = target.ForwardedPorts; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Linq; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Provides client connection to SSH server. + /// + [TestClass] + public class SshClientTest : TestBase + { + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_Correct_Password() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example SshClient(host, username) Connect + using (var client = new SshClient(host, username, password)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Handle_HostKeyReceived() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + var hostKeyValidated = false; + + #region Example SshClient Connect HostKeyReceived + using (var client = new SshClient(host, username, password)) + { + client.HostKeyReceived += delegate(object sender, HostKeyEventArgs e) + { + hostKeyValidated = true; + + if (e.FingerPrint.SequenceEqual(new byte[] { 0x00, 0x01, 0x02, 0x03 })) + { + e.CanTrust = true; + } + else + { + e.CanTrust = false; + } + }; + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + + Assert.IsTrue(hostKeyValidated); + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Timeout() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + #region Example SshClient Connect Timeout + var connectionInfo = new PasswordConnectionInfo(host, username, password); + + connectionInfo.Timeout = TimeSpan.FromSeconds(30); + + using (var client = new SshClient(connectionInfo)) + { + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + Assert.Inconclusive(); + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Handle_ErrorOccurred() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + var exceptionOccured = false; + + #region Example SshClient Connect ErrorOccurred + using (var client = new SshClient(host, username, password)) + { + client.ErrorOccurred += delegate(object sender, ExceptionEventArgs e) + { + Console.WriteLine("Error occured: " + e.Exception.ToString()); + exceptionOccured = true; + }; + + client.Connect(); + // Do something here + client.Disconnect(); + } + #endregion + Assert.IsTrue(exceptionOccured); + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + [ExpectedException(typeof(SshAuthenticationException))] + public void Test_Connect_Using_Invalid_Password() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_Rsa_Key_Without_PassPhrase() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS)); + + #region Example SshClient(host, username) Connect PrivateKeyFile + using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream))) + { + client.Connect(); + client.Disconnect(); + } + #endregion + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_RsaKey_With_PassPhrase() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var passphrase = Resources.PASSWORD; + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)); + + #region Example SshClient(host, username) Connect PrivateKeyFile PassPhrase + using (var client = new SshClient(host, username, new PrivateKeyFile(keyFileStream, passphrase))) + { + client.Connect(); + client.Disconnect(); + } + #endregion + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + [ExpectedException(typeof(SshPassPhraseNullOrEmptyException))] + public void Test_Connect_Using_Key_With_Empty_PassPhrase() + { + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)); + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, null))) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_DsaKey_Without_PassPhrase() + { + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS)); + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream))) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_DsaKey_With_PassPhrase() + { + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)); + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream, Resources.PASSWORD))) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + [ExpectedException(typeof(SshAuthenticationException))] + public void Test_Connect_Using_Invalid_PrivateKey() + { + MemoryStream keyFileStream = new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY)); + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, new PrivateKeyFile(keyFileStream))) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Using_Multiple_PrivateKeys() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, + new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.INVALID_KEY))), + new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITH_PASS)), Resources.PASSWORD), + new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITH_PASS)), Resources.PASSWORD), + new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.RSA_KEY_WITHOUT_PASS))), + new PrivateKeyFile(new MemoryStream(Encoding.ASCII.GetBytes(Resources.DSA_KEY_WITHOUT_PASS))) + )) + { + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("Authentication")] + [TestCategory("integration")] + public void Test_Connect_Then_Reconnect() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + client.Disconnect(); + client.Connect(); + client.Disconnect(); + } + } + + [TestMethod] + public void CreateShellStream1_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + const int bufferSize = 4096; + + try + { + client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShellStream2_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + const int bufferSize = 4096; + + try + { + client.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModes); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for CreateShellStream + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellStreamTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModeValues = null; // TODO: Initialize to an appropriate value + ShellStream expected = null; // TODO: Initialize to an appropriate value + ShellStream actual; + actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize, terminalModeValues); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShellStream + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellStreamTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + ShellStream expected = null; // TODO: Initialize to an appropriate value + ShellStream actual; + actual = target.CreateShellStream(terminalName, columns, rows, width, height, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void CreateShell1_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var encoding = Encoding.UTF8; + const string input = "INPUT"; + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + + + try + { + client.CreateShell(encoding, input, output, extendedOutput); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell2_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var encoding = Encoding.UTF8; + const string input = "INPUT"; + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + + try + { + client.CreateShell( + encoding, + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell3_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var encoding = Encoding.UTF8; + const string input = "INPUT"; + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + const int bufferSize = 4096; + + try + { + + client.CreateShell( + encoding, + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes, + bufferSize); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell4_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var input = new MemoryStream(); + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + + try + { + + client.CreateShell(input, output, extendedOutput); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell5_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var input = new MemoryStream(); + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + + try + { + client.CreateShell( + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateShell6_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var input = new MemoryStream(); + var output = new MemoryStream(); + var extendedOutput = new MemoryStream(); + const string terminalName = "vt100"; + const uint columns = 80; + const uint rows = 25; + const uint width = 640; + const uint height = 480; + var terminalModes = new Dictionary(); + const int bufferSize = 4096; + + try + { + + client.CreateShell( + input, + output, + extendedOutput, + terminalName, + columns, + rows, + width, + height, + terminalModes, + bufferSize); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string input = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(encoding, input, output, extendedOutput); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string input = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest2() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + string input = string.Empty; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(encoding, input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest3() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(input, output, extendedOutput); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateShell + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateShellTest5() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + Stream input = null; // TODO: Initialize to an appropriate value + Stream output = null; // TODO: Initialize to an appropriate value + Stream extendedOutput = null; // TODO: Initialize to an appropriate value + string terminalName = string.Empty; // TODO: Initialize to an appropriate value + uint columns = 0; // TODO: Initialize to an appropriate value + uint rows = 0; // TODO: Initialize to an appropriate value + uint width = 0; // TODO: Initialize to an appropriate value + uint height = 0; // TODO: Initialize to an appropriate value + IDictionary terminalModes = null; // TODO: Initialize to an appropriate value + int bufferSize = 0; // TODO: Initialize to an appropriate value + Shell expected = null; // TODO: Initialize to an appropriate value + Shell actual; + actual = target.CreateShell(input, output, extendedOutput, terminalName, columns, rows, width, height, terminalModes, bufferSize); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + [TestMethod] + public void CreateCommand_CommandText_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + try + { + client.CreateCommand("ls"); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + [TestMethod] + public void CreateCommand_CommandTextAndEncoding_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + try + { + client.CreateCommand("ls", Encoding.UTF8); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for CreateCommand + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateCommandTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + Encoding encoding = null; // TODO: Initialize to an appropriate value + SshCommand expected = null; // TODO: Initialize to an appropriate value + SshCommand actual; + actual = target.CreateCommand(commandText, encoding); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CreateCommand + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CreateCommandTest1() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + SshCommand expected = null; // TODO: Initialize to an appropriate value + SshCommand actual; + actual = target.CreateCommand(commandText); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + + [TestMethod] + public void AddForwardedPort_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + var port = new ForwardedPortLocal(50, "host", 8080); + + try + { + client.AddForwardedPort(port); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + + /// + ///A test for AddForwardedPort + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void AddForwardedPortTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + ForwardedPort port = null; // TODO: Initialize to an appropriate value + target.AddForwardedPort(port); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest1() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + PrivateKeyFile[] keyFiles = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, port, username, keyFiles); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest2() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest3() + { + string host = string.Empty; // TODO: Initialize to an appropriate value + int port = 0; // TODO: Initialize to an appropriate value + string username = string.Empty; // TODO: Initialize to an appropriate value + string password = string.Empty; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(host, port, username, password); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for SshClient Constructor + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void SshClientConstructorTest4() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); + Assert.Inconclusive("TODO: Implement code to verify target"); + } + + /// + ///A test for RemoveForwardedPort + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RemoveForwardedPortTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + ForwardedPort port = null; // TODO: Initialize to an appropriate value + target.RemoveForwardedPort(port); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + [TestMethod] + public void RunCommand_CommandText_NeverConnected() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password")) + { + try + { + client.RunCommand("ls"); + Assert.Fail(); + } + catch (SshConnectionException ex) + { + Assert.IsNull(ex.InnerException); + Assert.AreEqual("Client not connected.", ex.Message); + } + } + } + + /// + ///A test for RunCommand + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void RunCommandTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + SshCommand expected = null; // TODO: Initialize to an appropriate value + SshCommand actual; + actual = target.RunCommand(commandText); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for ForwardedPorts + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ForwardedPortsTest() + { + ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value + SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value + IEnumerable actual; + actual = target.ForwardedPorts; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs index 0bf21792..4fe4116d 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Disconnect_ForwardedPortStarted.cs @@ -1,82 +1,82 @@ -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Disconnect_ForwardedPortStarted - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private Mock _forwardedPortMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - var sequence = new MockSequence(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _forwardedPortMock = new Mock(MockBehavior.Strict); - - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.AddForwardedPort(_forwardedPortMock.Object); - - _forwardedPortMock.Object.Start(); - } - - protected void Act() - { - _sshClient.Disconnect(); - } - - [TestMethod] - public void ForwardedPortShouldBeStopped() - { - _forwardedPortMock.Verify(p => p.Stop(), Times.Once); - } - - [TestMethod] - public void ForwardedPortShouldBeRemovedFromSshClient() - { - Assert.IsFalse(_sshClient.ForwardedPorts.Any()); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Disconnect_ForwardedPortStarted + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private Mock _forwardedPortMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + var sequence = new MockSequence(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _forwardedPortMock = new Mock(MockBehavior.Strict); + + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.AddForwardedPort(_forwardedPortMock.Object); + + _forwardedPortMock.Object.Start(); + } + + protected void Act() + { + _sshClient.Disconnect(); + } + + [TestMethod] + public void ForwardedPortShouldBeStopped() + { + _forwardedPortMock.Verify(p => p.Stop(), Times.Once); + } + + [TestMethod] + public void ForwardedPortShouldBeRemovedFromSshClient() + { + Assert.IsFalse(_sshClient.ForwardedPorts.Any()); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs index 50e14468..584d0b5e 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Connected.cs @@ -1,73 +1,73 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_Connected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_Connected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs index 9c250e46..5590db59 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disconnected.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_Disconnected - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.Disconnect(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_Disconnected + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.Disconnect(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs index 35a713c6..4ac9cee3 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_Disposed.cs @@ -1,74 +1,74 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_Disposed - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.Dispose(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() - { - _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void OnDisconnectingOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_Disposed + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.Dispose(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void CreateSessionOnServiceFactoryShouldBeInvokedOnce() + { + _serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo), Times.Once); + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void OnDisconnectingOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.OnDisconnecting(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs index 4f45f580..193b1205 100644 --- a/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs +++ b/src/Renci.SshNet.Tests/Classes/SshClientTest_Dispose_ForwardedPortStarted.cs @@ -1,97 +1,97 @@ -using System; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshClientTest_Dispose_ForwardedPortStarted - { - private Mock _serviceFactoryMock; - private Mock _sessionMock; - private Mock _forwardedPortMock; - private SshClient _sshClient; - private ConnectionInfo _connectionInfo; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - [TestCleanup] - public void Cleanup() - { - } - - protected void Arrange() - { - _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); - - var sequence = new MockSequence(); - - _serviceFactoryMock = new Mock(MockBehavior.Strict); - _sessionMock = new Mock(MockBehavior.Strict); - _forwardedPortMock = new Mock(MockBehavior.Strict); - - _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); - _sessionMock.InSequence(sequence).Setup(p => p.Connect()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); - _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); - _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); - _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); - _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); - - _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); - _sshClient.Connect(); - _sshClient.AddForwardedPort(_forwardedPortMock.Object); - - _forwardedPortMock.Object.Start(); - } - - protected void Act() - { - _sshClient.Dispose(); - } - - [TestMethod] - public void ForwardedPortShouldBeStopped() - { - _forwardedPortMock.Verify(p => p.Stop(), Times.Once); - } - - [TestMethod] - public void ForwardedPortShouldBeRemovedFromSshClient() - { - Assert.IsFalse(_sshClient.ForwardedPorts.Any()); - } - - [TestMethod] - public void IsConnectedShouldThrowObjectDisposedException() - { - try - { - var connected = _sshClient.IsConnected; - Assert.Fail("IsConnected should have thrown {0} but returned {1}.", - typeof (ObjectDisposedException).FullName, connected); - } - catch (ObjectDisposedException) - { - } - } - - [TestMethod] - public void DisconnectOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - - [TestMethod] - public void DisposeOnSessionShouldBeInvokedOnce() - { - _sessionMock.Verify(p => p.Disconnect(), Times.Once); - } - } -} +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshClientTest_Dispose_ForwardedPortStarted + { + private Mock _serviceFactoryMock; + private Mock _sessionMock; + private Mock _forwardedPortMock; + private SshClient _sshClient; + private ConnectionInfo _connectionInfo; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + [TestCleanup] + public void Cleanup() + { + } + + protected void Arrange() + { + _connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth")); + + var sequence = new MockSequence(); + + _serviceFactoryMock = new Mock(MockBehavior.Strict); + _sessionMock = new Mock(MockBehavior.Strict); + _forwardedPortMock = new Mock(MockBehavior.Strict); + + _serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object); + _sessionMock.InSequence(sequence).Setup(p => p.Connect()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Start()); + _sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting()); + _forwardedPortMock.InSequence(sequence).Setup(p => p.Stop()); + _sessionMock.InSequence(sequence).Setup(p => p.Disconnect()); + _sessionMock.InSequence(sequence).Setup(p => p.Dispose()); + + _sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object); + _sshClient.Connect(); + _sshClient.AddForwardedPort(_forwardedPortMock.Object); + + _forwardedPortMock.Object.Start(); + } + + protected void Act() + { + _sshClient.Dispose(); + } + + [TestMethod] + public void ForwardedPortShouldBeStopped() + { + _forwardedPortMock.Verify(p => p.Stop(), Times.Once); + } + + [TestMethod] + public void ForwardedPortShouldBeRemovedFromSshClient() + { + Assert.IsFalse(_sshClient.ForwardedPorts.Any()); + } + + [TestMethod] + public void IsConnectedShouldThrowObjectDisposedException() + { + try + { + var connected = _sshClient.IsConnected; + Assert.Fail("IsConnected should have thrown {0} but returned {1}.", + typeof (ObjectDisposedException).FullName, connected); + } + catch (ObjectDisposedException) + { + } + } + + [TestMethod] + public void DisconnectOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + + [TestMethod] + public void DisposeOnSessionShouldBeInvokedOnce() + { + _sessionMock.Verify(p => p.Disconnect(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs index 6fd3b088..589c6881 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest.NET40.cs @@ -1,100 +1,100 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Tests.Properties; -using System; -using System.Diagnostics; -using System.Threading.Tasks; - -namespace Renci.SshNet.Tests.Classes -{ - public partial class SshCommandTest - { - - public void Test_MultipleThread_Example_MultipleConnections() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - try - { - #region Example SshCommand RunCommand Parallel - System.Threading.Tasks.Parallel.For(0, 10000, - () => - { - var client = new SshClient(host, username, password); - client.Connect(); - return client; - }, - (int counter, ParallelLoopState pls, SshClient client) => - { - var result = client.RunCommand("echo 123"); - Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); - return client; - }, - (SshClient client) => - { - client.Disconnect(); - client.Dispose(); - } - ); - #endregion - - } - catch (Exception exp) - { - Assert.Fail(exp.ToString()); - } - } - - //[TestMethod] - public void Test_MultipleThread_10000_MultipleConnections() - { - try - { - System.Threading.Tasks.Parallel.For(0, 10000, - () => - { - var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD); - client.Connect(); - return client; - }, - (int counter, ParallelLoopState pls, SshClient client) => - { - var result = ExecuteTestCommand(client); - Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); - Assert.IsTrue(result); - return client; - }, - (SshClient client) => - { - client.Disconnect(); - client.Dispose(); - } - ); - } - catch (Exception exp) - { - Assert.Fail(exp.ToString()); - } - } - - //[TestMethod] - public void Test_MultipleThread_10000_MultipleSessions() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - System.Threading.Tasks.Parallel.For(0, 10000, - (counter) => - { - var result = ExecuteTestCommand(client); - Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); - Assert.IsTrue(result); - } - ); - - client.Disconnect(); - } - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Tests.Properties; +using System; +using System.Diagnostics; +using System.Threading.Tasks; + +namespace Renci.SshNet.Tests.Classes +{ + public partial class SshCommandTest + { + + public void Test_MultipleThread_Example_MultipleConnections() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + try + { + #region Example SshCommand RunCommand Parallel + System.Threading.Tasks.Parallel.For(0, 10000, + () => + { + var client = new SshClient(host, username, password); + client.Connect(); + return client; + }, + (int counter, ParallelLoopState pls, SshClient client) => + { + var result = client.RunCommand("echo 123"); + Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); + return client; + }, + (SshClient client) => + { + client.Disconnect(); + client.Dispose(); + } + ); + #endregion + + } + catch (Exception exp) + { + Assert.Fail(exp.ToString()); + } + } + + //[TestMethod] + public void Test_MultipleThread_10000_MultipleConnections() + { + try + { + System.Threading.Tasks.Parallel.For(0, 10000, + () => + { + var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD); + client.Connect(); + return client; + }, + (int counter, ParallelLoopState pls, SshClient client) => + { + var result = ExecuteTestCommand(client); + Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); + Assert.IsTrue(result); + return client; + }, + (SshClient client) => + { + client.Disconnect(); + client.Dispose(); + } + ); + } + catch (Exception exp) + { + Assert.Fail(exp.ToString()); + } + } + + //[TestMethod] + public void Test_MultipleThread_10000_MultipleSessions() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + System.Threading.Tasks.Parallel.For(0, 10000, + (counter) => + { + var result = ExecuteTestCommand(client); + Debug.WriteLine(string.Format("TestMultipleThreadMultipleConnections #{0}", counter)); + Assert.IsTrue(result); + } + ); + + client.Disconnect(); + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs index fc4a3b0e..c1979ce3 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest.cs @@ -1,635 +1,635 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; -using Renci.SshNet.Tests.Properties; -using System; -using System.IO; -using System.Text; -using System.Threading; - -namespace Renci.SshNet.Tests.Classes -{ - /// - /// Represents SSH command that can be executed. - /// - [TestClass] - public partial class SshCommandTest : TestBase - { - [TestMethod] - [ExpectedException(typeof(SshConnectionException))] - public void Test_Execute_SingleCommand_Without_Connecting() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - var result = ExecuteTestCommand(client); - - Assert.IsTrue(result); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Run_SingleCommand() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand RunCommand Result - client.Connect(); - - var testValue = Guid.NewGuid().ToString(); - var command = client.RunCommand(string.Format("echo {0}", testValue)); - var result = command.Result; - result = result.Substring(0, result.Length - 1); // Remove \n character returned by command - - client.Disconnect(); - #endregion - - Assert.IsTrue(result.Equals(testValue)); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_SingleCommand() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand CreateCommand Execute - client.Connect(); - - var testValue = Guid.NewGuid().ToString(); - var command = string.Format("echo {0}", testValue); - var cmd = client.CreateCommand(command); - var result = cmd.Execute(); - result = result.Substring(0, result.Length - 1); // Remove \n character returned by command - - client.Disconnect(); - #endregion - - Assert.IsTrue(result.Equals(testValue)); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_OutputStream() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand CreateCommand Execute OutputStream - client.Connect(); - - var cmd = client.CreateCommand("ls -l"); // very long list - var asynch = cmd.BeginExecute(); - - var reader = new StreamReader(cmd.OutputStream); - - while (!asynch.IsCompleted) - { - var result = reader.ReadToEnd(); - if (string.IsNullOrEmpty(result)) - continue; - Console.Write(result); - } - cmd.EndExecute(asynch); - - client.Disconnect(); - #endregion - - Assert.Inconclusive(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_ExtendedOutputStream() - { - var host = Resources.HOST; - var username = Resources.USERNAME; - var password = Resources.PASSWORD; - - using (var client = new SshClient(host, username, password)) - { - #region Example SshCommand CreateCommand Execute ExtendedOutputStream - - client.Connect(); - var cmd = client.CreateCommand("echo 12345; echo 654321 >&2"); - var result = cmd.Execute(); - - Console.Write(result); - - var reader = new StreamReader(cmd.ExtendedOutputStream); - Console.WriteLine("DEBUG:"); - Console.Write(reader.ReadToEnd()); - - client.Disconnect(); - - #endregion - - Assert.Inconclusive(); - } - } - - [TestMethod] - [TestCategory("integration")] - [ExpectedException(typeof(SshOperationTimeoutException))] - public void Test_Execute_Timeout() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand CreateCommand Execute CommandTimeout - client.Connect(); - var cmd = client.CreateCommand("sleep 10s"); - cmd.CommandTimeout = TimeSpan.FromSeconds(5); - cmd.Execute(); - client.Disconnect(); - #endregion - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Infinite_Timeout() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand("sleep 10s"); - cmd.Execute(); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_InvalidCommand() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - - var cmd = client.CreateCommand(";"); - cmd.Execute(); - if (string.IsNullOrEmpty(cmd.Error)) - { - Assert.Fail("Operation should fail"); - } - Assert.IsTrue(cmd.ExitStatus > 0); - - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_InvalidCommand_Then_Execute_ValidCommand() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand(";"); - cmd.Execute(); - if (string.IsNullOrEmpty(cmd.Error)) - { - Assert.Fail("Operation should fail"); - } - Assert.IsTrue(cmd.ExitStatus > 0); - - var result = ExecuteTestCommand(client); - - client.Disconnect(); - - Assert.IsTrue(result); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_with_ExtendedOutput() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand("echo 12345; echo 654321 >&2"); - cmd.Execute(); - - //var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray()); - var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd(); - client.Disconnect(); - - Assert.AreEqual("12345\n", cmd.Result); - Assert.AreEqual("654321\n", extendedData); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_Reconnect_Execute_Command() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var result = ExecuteTestCommand(client); - Assert.IsTrue(result); - - client.Disconnect(); - client.Connect(); - result = ExecuteTestCommand(client); - Assert.IsTrue(result); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_ExitStatus() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand RunCommand ExitStatus - client.Connect(); - - var cmd = client.RunCommand("exit 128"); - - Console.WriteLine(cmd.ExitStatus); - - client.Disconnect(); - #endregion - - Assert.IsTrue(cmd.ExitStatus == 128); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_Asynchronously() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - - var cmd = client.CreateCommand("sleep 5s; echo 'test'"); - var asyncResult = cmd.BeginExecute(null, null); - while (!asyncResult.IsCompleted) - { - Thread.Sleep(100); - } - - cmd.EndExecute(asyncResult); - - Assert.IsTrue(cmd.Result == "test\n"); - - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_Asynchronously_With_Error() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - - var cmd = client.CreateCommand("sleep 5s; ;"); - var asyncResult = cmd.BeginExecute(null, null); - while (!asyncResult.IsCompleted) - { - Thread.Sleep(100); - } - - cmd.EndExecute(asyncResult); - - Assert.IsFalse(string.IsNullOrEmpty(cmd.Error)); - - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_Asynchronously_With_Callback() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - - var callbackCalled = false; - - var cmd = client.CreateCommand("sleep 5s; echo 'test'"); - var asyncResult = cmd.BeginExecute(new AsyncCallback((s) => - { - callbackCalled = true; - }), null); - while (!asyncResult.IsCompleted) - { - Thread.Sleep(100); - } - - cmd.EndExecute(asyncResult); - - Assert.IsTrue(callbackCalled); - - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_Asynchronously_With_Callback_On_Different_Thread() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - - var currentThreadId = Thread.CurrentThread.ManagedThreadId; - int callbackThreadId = 0; - - var cmd = client.CreateCommand("sleep 5s; echo 'test'"); - var asyncResult = cmd.BeginExecute(new AsyncCallback((s) => - { - callbackThreadId = Thread.CurrentThread.ManagedThreadId; - }), null); - while (!asyncResult.IsCompleted) - { - Thread.Sleep(100); - } - - cmd.EndExecute(asyncResult); - - Assert.AreNotEqual(currentThreadId, callbackThreadId); - - client.Disconnect(); - } - } - - /// - /// Tests for Issue 563. - /// - [WorkItem(563), TestMethod] - [TestCategory("integration")] - public void Test_Execute_Command_Same_Object_Different_Commands() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand("echo 12345"); - cmd.Execute(); - Assert.AreEqual("12345\n", cmd.Result); - cmd.Execute("echo 23456"); - Assert.AreEqual("23456\n", cmd.Result); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Get_Result_Without_Execution() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand("ls -l"); - - Assert.IsTrue(string.IsNullOrEmpty(cmd.Result)); - client.Disconnect(); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Get_Error_Without_Execution() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand("ls -l"); - - Assert.IsTrue(string.IsNullOrEmpty(cmd.Error)); - client.Disconnect(); - } - } - - [WorkItem(703), TestMethod] - [ExpectedException(typeof(ArgumentException))] - [TestCategory("integration")] - public void Test_EndExecute_Before_BeginExecute() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - client.Connect(); - var cmd = client.CreateCommand("ls -l"); - cmd.EndExecute(null); - client.Disconnect(); - } - } - - /// - ///A test for BeginExecute - /// - [TestMethod()] - [TestCategory("integration")] - public void BeginExecuteTest() - { - string expected = "123\n"; - string result; - - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand CreateCommand BeginExecute IsCompleted EndExecute - - client.Connect(); - - var cmd = client.CreateCommand("sleep 15s;echo 123"); // Perform long running task - - var asynch = cmd.BeginExecute(); - - while (!asynch.IsCompleted) - { - // Waiting for command to complete... - Thread.Sleep(2000); - } - result = cmd.EndExecute(asynch); - client.Disconnect(); - - #endregion - - Assert.IsNotNull(asynch); - Assert.AreEqual(expected, result); - } - } - - [TestMethod] - [TestCategory("integration")] - public void Test_Execute_Invalid_Command() - { - using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) - { - #region Example SshCommand CreateCommand Error - - client.Connect(); - - var cmd = client.CreateCommand(";"); - cmd.Execute(); - if (!string.IsNullOrEmpty(cmd.Error)) - { - Console.WriteLine(cmd.Error); - } - - client.Disconnect(); - - #endregion - - Assert.Inconclusive(); - } - } - - - /// - ///A test for BeginExecute - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void BeginExecuteTest1() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string commandText1 = string.Empty; // TODO: Initialize to an appropriate value - AsyncCallback callback = null; // TODO: Initialize to an appropriate value - object state = null; // TODO: Initialize to an appropriate value - IAsyncResult expected = null; // TODO: Initialize to an appropriate value - IAsyncResult actual; - actual = target.BeginExecute(commandText1, callback, state); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CancelAsync - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CancelAsyncTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - target.CancelAsync(); - Assert.Inconclusive("A method that does not return a value cannot be verified."); - } - - - /// - ///A test for Execute - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ExecuteTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.Execute(); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Execute - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ExecuteTest1() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string commandText1 = string.Empty; // TODO: Initialize to an appropriate value - string expected = string.Empty; // TODO: Initialize to an appropriate value - string actual; - actual = target.Execute(commandText1); - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for CommandTimeout - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void CommandTimeoutTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value - TimeSpan actual; - target.CommandTimeout = expected; - actual = target.CommandTimeout; - Assert.AreEqual(expected, actual); - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Error - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ErrorTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string actual; - actual = target.Error; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - /// - ///A test for Result - /// - [TestMethod] - [Ignore] // placeholder for actual test - public void ResultTest() - { - Session session = null; // TODO: Initialize to an appropriate value - string commandText = string.Empty; // TODO: Initialize to an appropriate value - var encoding = Encoding.UTF8; - SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value - string actual; - actual = target.Result; - Assert.Inconclusive("Verify the correctness of this test method."); - } - - private static bool ExecuteTestCommand(SshClient s) - { - var testValue = Guid.NewGuid().ToString(); - var command = string.Format("echo {0}", testValue); - var cmd = s.CreateCommand(command); - var result = cmd.Execute(); - result = result.Substring(0, result.Length - 1); // Remove \n character returned by command - return result.Equals(testValue); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; +using Renci.SshNet.Tests.Properties; +using System; +using System.IO; +using System.Text; +using System.Threading; + +namespace Renci.SshNet.Tests.Classes +{ + /// + /// Represents SSH command that can be executed. + /// + [TestClass] + public partial class SshCommandTest : TestBase + { + [TestMethod] + [ExpectedException(typeof(SshConnectionException))] + public void Test_Execute_SingleCommand_Without_Connecting() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + var result = ExecuteTestCommand(client); + + Assert.IsTrue(result); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Run_SingleCommand() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand RunCommand Result + client.Connect(); + + var testValue = Guid.NewGuid().ToString(); + var command = client.RunCommand(string.Format("echo {0}", testValue)); + var result = command.Result; + result = result.Substring(0, result.Length - 1); // Remove \n character returned by command + + client.Disconnect(); + #endregion + + Assert.IsTrue(result.Equals(testValue)); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_SingleCommand() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand CreateCommand Execute + client.Connect(); + + var testValue = Guid.NewGuid().ToString(); + var command = string.Format("echo {0}", testValue); + var cmd = client.CreateCommand(command); + var result = cmd.Execute(); + result = result.Substring(0, result.Length - 1); // Remove \n character returned by command + + client.Disconnect(); + #endregion + + Assert.IsTrue(result.Equals(testValue)); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_OutputStream() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand CreateCommand Execute OutputStream + client.Connect(); + + var cmd = client.CreateCommand("ls -l"); // very long list + var asynch = cmd.BeginExecute(); + + var reader = new StreamReader(cmd.OutputStream); + + while (!asynch.IsCompleted) + { + var result = reader.ReadToEnd(); + if (string.IsNullOrEmpty(result)) + continue; + Console.Write(result); + } + cmd.EndExecute(asynch); + + client.Disconnect(); + #endregion + + Assert.Inconclusive(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_ExtendedOutputStream() + { + var host = Resources.HOST; + var username = Resources.USERNAME; + var password = Resources.PASSWORD; + + using (var client = new SshClient(host, username, password)) + { + #region Example SshCommand CreateCommand Execute ExtendedOutputStream + + client.Connect(); + var cmd = client.CreateCommand("echo 12345; echo 654321 >&2"); + var result = cmd.Execute(); + + Console.Write(result); + + var reader = new StreamReader(cmd.ExtendedOutputStream); + Console.WriteLine("DEBUG:"); + Console.Write(reader.ReadToEnd()); + + client.Disconnect(); + + #endregion + + Assert.Inconclusive(); + } + } + + [TestMethod] + [TestCategory("integration")] + [ExpectedException(typeof(SshOperationTimeoutException))] + public void Test_Execute_Timeout() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand CreateCommand Execute CommandTimeout + client.Connect(); + var cmd = client.CreateCommand("sleep 10s"); + cmd.CommandTimeout = TimeSpan.FromSeconds(5); + cmd.Execute(); + client.Disconnect(); + #endregion + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Infinite_Timeout() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("sleep 10s"); + cmd.Execute(); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_InvalidCommand() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + + var cmd = client.CreateCommand(";"); + cmd.Execute(); + if (string.IsNullOrEmpty(cmd.Error)) + { + Assert.Fail("Operation should fail"); + } + Assert.IsTrue(cmd.ExitStatus > 0); + + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_InvalidCommand_Then_Execute_ValidCommand() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand(";"); + cmd.Execute(); + if (string.IsNullOrEmpty(cmd.Error)) + { + Assert.Fail("Operation should fail"); + } + Assert.IsTrue(cmd.ExitStatus > 0); + + var result = ExecuteTestCommand(client); + + client.Disconnect(); + + Assert.IsTrue(result); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_with_ExtendedOutput() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("echo 12345; echo 654321 >&2"); + cmd.Execute(); + + //var extendedData = Encoding.ASCII.GetString(cmd.ExtendedOutputStream.ToArray()); + var extendedData = new StreamReader(cmd.ExtendedOutputStream, Encoding.ASCII).ReadToEnd(); + client.Disconnect(); + + Assert.AreEqual("12345\n", cmd.Result); + Assert.AreEqual("654321\n", extendedData); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_Reconnect_Execute_Command() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var result = ExecuteTestCommand(client); + Assert.IsTrue(result); + + client.Disconnect(); + client.Connect(); + result = ExecuteTestCommand(client); + Assert.IsTrue(result); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_ExitStatus() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand RunCommand ExitStatus + client.Connect(); + + var cmd = client.RunCommand("exit 128"); + + Console.WriteLine(cmd.ExitStatus); + + client.Disconnect(); + #endregion + + Assert.IsTrue(cmd.ExitStatus == 128); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_Asynchronously() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + + var cmd = client.CreateCommand("sleep 5s; echo 'test'"); + var asyncResult = cmd.BeginExecute(null, null); + while (!asyncResult.IsCompleted) + { + Thread.Sleep(100); + } + + cmd.EndExecute(asyncResult); + + Assert.IsTrue(cmd.Result == "test\n"); + + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_Asynchronously_With_Error() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + + var cmd = client.CreateCommand("sleep 5s; ;"); + var asyncResult = cmd.BeginExecute(null, null); + while (!asyncResult.IsCompleted) + { + Thread.Sleep(100); + } + + cmd.EndExecute(asyncResult); + + Assert.IsFalse(string.IsNullOrEmpty(cmd.Error)); + + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_Asynchronously_With_Callback() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + + var callbackCalled = false; + + var cmd = client.CreateCommand("sleep 5s; echo 'test'"); + var asyncResult = cmd.BeginExecute(new AsyncCallback((s) => + { + callbackCalled = true; + }), null); + while (!asyncResult.IsCompleted) + { + Thread.Sleep(100); + } + + cmd.EndExecute(asyncResult); + + Assert.IsTrue(callbackCalled); + + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_Asynchronously_With_Callback_On_Different_Thread() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + + var currentThreadId = Thread.CurrentThread.ManagedThreadId; + int callbackThreadId = 0; + + var cmd = client.CreateCommand("sleep 5s; echo 'test'"); + var asyncResult = cmd.BeginExecute(new AsyncCallback((s) => + { + callbackThreadId = Thread.CurrentThread.ManagedThreadId; + }), null); + while (!asyncResult.IsCompleted) + { + Thread.Sleep(100); + } + + cmd.EndExecute(asyncResult); + + Assert.AreNotEqual(currentThreadId, callbackThreadId); + + client.Disconnect(); + } + } + + /// + /// Tests for Issue 563. + /// + [WorkItem(563), TestMethod] + [TestCategory("integration")] + public void Test_Execute_Command_Same_Object_Different_Commands() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("echo 12345"); + cmd.Execute(); + Assert.AreEqual("12345\n", cmd.Result); + cmd.Execute("echo 23456"); + Assert.AreEqual("23456\n", cmd.Result); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Get_Result_Without_Execution() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("ls -l"); + + Assert.IsTrue(string.IsNullOrEmpty(cmd.Result)); + client.Disconnect(); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Get_Error_Without_Execution() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("ls -l"); + + Assert.IsTrue(string.IsNullOrEmpty(cmd.Error)); + client.Disconnect(); + } + } + + [WorkItem(703), TestMethod] + [ExpectedException(typeof(ArgumentException))] + [TestCategory("integration")] + public void Test_EndExecute_Before_BeginExecute() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("ls -l"); + cmd.EndExecute(null); + client.Disconnect(); + } + } + + /// + ///A test for BeginExecute + /// + [TestMethod()] + [TestCategory("integration")] + public void BeginExecuteTest() + { + string expected = "123\n"; + string result; + + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand CreateCommand BeginExecute IsCompleted EndExecute + + client.Connect(); + + var cmd = client.CreateCommand("sleep 15s;echo 123"); // Perform long running task + + var asynch = cmd.BeginExecute(); + + while (!asynch.IsCompleted) + { + // Waiting for command to complete... + Thread.Sleep(2000); + } + result = cmd.EndExecute(asynch); + client.Disconnect(); + + #endregion + + Assert.IsNotNull(asynch); + Assert.AreEqual(expected, result); + } + } + + [TestMethod] + [TestCategory("integration")] + public void Test_Execute_Invalid_Command() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + #region Example SshCommand CreateCommand Error + + client.Connect(); + + var cmd = client.CreateCommand(";"); + cmd.Execute(); + if (!string.IsNullOrEmpty(cmd.Error)) + { + Console.WriteLine(cmd.Error); + } + + client.Disconnect(); + + #endregion + + Assert.Inconclusive(); + } + } + + + /// + ///A test for BeginExecute + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void BeginExecuteTest1() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string commandText1 = string.Empty; // TODO: Initialize to an appropriate value + AsyncCallback callback = null; // TODO: Initialize to an appropriate value + object state = null; // TODO: Initialize to an appropriate value + IAsyncResult expected = null; // TODO: Initialize to an appropriate value + IAsyncResult actual; + actual = target.BeginExecute(commandText1, callback, state); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CancelAsync + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CancelAsyncTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + target.CancelAsync(); + Assert.Inconclusive("A method that does not return a value cannot be verified."); + } + + + /// + ///A test for Execute + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ExecuteTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.Execute(); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Execute + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ExecuteTest1() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string commandText1 = string.Empty; // TODO: Initialize to an appropriate value + string expected = string.Empty; // TODO: Initialize to an appropriate value + string actual; + actual = target.Execute(commandText1); + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for CommandTimeout + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void CommandTimeoutTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + TimeSpan expected = new TimeSpan(); // TODO: Initialize to an appropriate value + TimeSpan actual; + target.CommandTimeout = expected; + actual = target.CommandTimeout; + Assert.AreEqual(expected, actual); + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Error + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ErrorTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string actual; + actual = target.Error; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + /// + ///A test for Result + /// + [TestMethod] + [Ignore] // placeholder for actual test + public void ResultTest() + { + Session session = null; // TODO: Initialize to an appropriate value + string commandText = string.Empty; // TODO: Initialize to an appropriate value + var encoding = Encoding.UTF8; + SshCommand target = new SshCommand(session, commandText, encoding); // TODO: Initialize to an appropriate value + string actual; + actual = target.Result; + Assert.Inconclusive("Verify the correctness of this test method."); + } + + private static bool ExecuteTestCommand(SshClient s) + { + var testValue = Guid.NewGuid().ToString(); + var command = string.Format("echo {0}", testValue); + var cmd = s.CreateCommand(command); + var result = cmd.Execute(); + result = result.Substring(0, result.Length - 1); // Remove \n character returned by command + return result.Equals(testValue); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs index e14d4938..8fbbeac7 100644 --- a/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs +++ b/src/Renci.SshNet.Tests/Classes/SshCommandTest_EndExecute.cs @@ -1,72 +1,72 @@ -using System; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; -using Renci.SshNet.Tests.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SshCommand_EndExecute : TestBase - { - private Mock _sessionMock; - private Mock _channelSessionMock; - private string _commandText; - private Encoding _encoding; - private SshCommand _sshCommand; - - protected override void OnInit() - { - base.OnInit(); - - _sessionMock = new Mock(MockBehavior.Strict); - _commandText = new Random().Next().ToString(CultureInfo.InvariantCulture); - _encoding = Encoding.UTF8; - _channelSessionMock = new Mock(MockBehavior.Strict); - - _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding); - } - - [TestMethod] - public void EndExecute_ChannelClosed_ShouldDisposeChannelSession() - { - var seq = new MockSequence(); - - _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(seq).Setup(p => p.Open()); - _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) - .Returns(true) - .Raises(c => c.Closed += null, new ChannelEventArgs(5)); - _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(false); - _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); - - var asyncResult = _sshCommand.BeginExecute(); - _sshCommand.EndExecute(asyncResult); - - _channelSessionMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void EndExecute_ChannelOpen_ShouldSendEofAndCloseAndDisposeChannelSession() - { - var seq = new MockSequence(); - - _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); - _channelSessionMock.InSequence(seq).Setup(p => p.Open()); - _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) - .Returns(true) - .Raises(c => c.Closed += null, new ChannelEventArgs(5)); - _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(true); - _channelSessionMock.InSequence(seq).Setup(p => p.Close()); - _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); - - var asyncResult = _sshCommand.BeginExecute(); - _sshCommand.EndExecute(asyncResult); - - _channelSessionMock.Verify(p => p.Close(), Times.Once); - } - } -} +using System; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; +using Renci.SshNet.Tests.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SshCommand_EndExecute : TestBase + { + private Mock _sessionMock; + private Mock _channelSessionMock; + private string _commandText; + private Encoding _encoding; + private SshCommand _sshCommand; + + protected override void OnInit() + { + base.OnInit(); + + _sessionMock = new Mock(MockBehavior.Strict); + _commandText = new Random().Next().ToString(CultureInfo.InvariantCulture); + _encoding = Encoding.UTF8; + _channelSessionMock = new Mock(MockBehavior.Strict); + + _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding); + } + + [TestMethod] + public void EndExecute_ChannelClosed_ShouldDisposeChannelSession() + { + var seq = new MockSequence(); + + _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(seq).Setup(p => p.Open()); + _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) + .Returns(true) + .Raises(c => c.Closed += null, new ChannelEventArgs(5)); + _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(false); + _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); + + var asyncResult = _sshCommand.BeginExecute(); + _sshCommand.EndExecute(asyncResult); + + _channelSessionMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void EndExecute_ChannelOpen_ShouldSendEofAndCloseAndDisposeChannelSession() + { + var seq = new MockSequence(); + + _sessionMock.InSequence(seq).Setup(p => p.CreateChannelSession()).Returns(_channelSessionMock.Object); + _channelSessionMock.InSequence(seq).Setup(p => p.Open()); + _channelSessionMock.InSequence(seq).Setup(p => p.SendExecRequest(_commandText)) + .Returns(true) + .Raises(c => c.Closed += null, new ChannelEventArgs(5)); + _channelSessionMock.InSequence(seq).Setup(p => p.IsOpen).Returns(true); + _channelSessionMock.InSequence(seq).Setup(p => p.Close()); + _channelSessionMock.InSequence(seq).Setup(p => p.Dispose()); + + var asyncResult = _sshCommand.BeginExecute(); + _sshCommand.EndExecute(asyncResult); + + _channelSessionMock.Verify(p => p.Close(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs index 844f9a33..9fb77797 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSessionStub.cs @@ -1,45 +1,45 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - internal class SubsystemSessionStub : SubsystemSession - { - private int _onChannelOpenInvocationCount; - - public SubsystemSessionStub(ISession session, string subsystemName, TimeSpan operationTimeout, Encoding encoding) : base(session, subsystemName, operationTimeout, encoding) - { - OnDataReceivedInvocations = new List(); - } - - public int OnChannelOpenInvocationCount - { - get { return _onChannelOpenInvocationCount; } - } - - public IList OnDataReceivedInvocations { get; private set; } - - public Exception OnChannelOpenException { get; set; } - - public Exception OnDataReceivedException { get; set; } - - protected override void OnChannelOpen() - { - Interlocked.Increment(ref _onChannelOpenInvocationCount); - - if (OnChannelOpenException != null) - throw OnChannelOpenException; - } - - protected override void OnDataReceived(byte[] data) - { - OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data)); - - if (OnDataReceivedException != null) - throw OnDataReceivedException; - } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + internal class SubsystemSessionStub : SubsystemSession + { + private int _onChannelOpenInvocationCount; + + public SubsystemSessionStub(ISession session, string subsystemName, TimeSpan operationTimeout, Encoding encoding) : base(session, subsystemName, operationTimeout, encoding) + { + OnDataReceivedInvocations = new List(); + } + + public int OnChannelOpenInvocationCount + { + get { return _onChannelOpenInvocationCount; } + } + + public IList OnDataReceivedInvocations { get; private set; } + + public Exception OnChannelOpenException { get; set; } + + public Exception OnDataReceivedException { get; set; } + + protected override void OnChannelOpen() + { + Interlocked.Increment(ref _onChannelOpenInvocationCount); + + if (OnChannelOpenException != null) + throw OnChannelOpenException; + } + + protected override void OnDataReceived(byte[] data) + { + OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data)); + + if (OnDataReceivedException != null) + throw OnDataReceivedException; + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs index d635829e..422b70d9 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Connected.cs @@ -1,127 +1,127 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Connect_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private InvalidOperationException _actualException; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - try - { - _subsystemSession.Connect(); - Assert.Fail(); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - - } - - [TestMethod] - public void ConnectShouldHaveThrownInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("The session is already connected.", _actualException.Message); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Connect_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private InvalidOperationException _actualException; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + try + { + _subsystemSession.Connect(); + Assert.Fail(); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + + } + + [TestMethod] + public void ConnectShouldHaveThrownInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("The session is already connected.", _actualException.Message); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs index e74c09a5..f5e9a5a1 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disconnected.cs @@ -1,128 +1,128 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Connect_Disconnected - { - private Mock _sessionMock; - private Mock _channelBeforeDisconnectMock; - private Mock _channelAfterDisconnectMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelBeforeDisconnectMock = new Mock(MockBehavior.Strict); - _channelAfterDisconnectMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelBeforeDisconnectMock.Object); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Close()); - _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Dispose()); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelAfterDisconnectMock.Object); - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Disconnect(); - } - - protected void Act() - { - _subsystemSession.Connect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void CloseOnChannelBeforeDisconnectShouldBeInvokedOnce() - { - _channelBeforeDisconnectMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void CloseOnChannelAfterDisconnectShouldNeverBeInvoked() - { - _channelAfterDisconnectMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelBeforeDisconnectShouldBeInvokedOnce() - { - _channelBeforeDisconnectMock.Verify(p => p.Dispose(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelAfterDisconnectShouldBeInvokedOnce() - { - _channelAfterDisconnectMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Connect_Disconnected + { + private Mock _sessionMock; + private Mock _channelBeforeDisconnectMock; + private Mock _channelAfterDisconnectMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelBeforeDisconnectMock = new Mock(MockBehavior.Strict); + _channelAfterDisconnectMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelBeforeDisconnectMock.Object); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Close()); + _channelBeforeDisconnectMock.InSequence(_sequence).Setup(p => p.Dispose()); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelAfterDisconnectMock.Object); + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.Open()); + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Disconnect(); + } + + protected void Act() + { + _subsystemSession.Connect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelAfterDisconnectMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelAfterDisconnectMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void CloseOnChannelBeforeDisconnectShouldBeInvokedOnce() + { + _channelBeforeDisconnectMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void CloseOnChannelAfterDisconnectShouldNeverBeInvoked() + { + _channelAfterDisconnectMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelBeforeDisconnectShouldBeInvokedOnce() + { + _channelBeforeDisconnectMock.Verify(p => p.Dispose(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelAfterDisconnectShouldBeInvokedOnce() + { + _channelAfterDisconnectMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs index 44e23f4a..9dad3325 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_Disposed.cs @@ -1,97 +1,97 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Connect_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Dispose(); - } - - protected void Act() - { - try - { - _subsystemSession.Connect(); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void ConnectShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName),_actualException.Message); - Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Connect_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Dispose(); + } + + protected void Act() + { + try + { + _subsystemSession.Connect(); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void ConnectShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName),_actualException.Message); + Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs index 5994099e..d784c7ae 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Connect_NeverConnected.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - class SubsystemSession_Connect_NeverConnected - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + class SubsystemSession_Connect_NeverConnected + { + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs index 8a2d9039..9a545f95 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Connected.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Disconnect_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.Close()); - _channelMock.InSequence(_sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _subsystemSession.Disconnect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Disconnect_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.Close()); + _channelMock.InSequence(_sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _subsystemSession.Disconnect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs index 8a5295d5..734d8c5d 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_Disposed.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Disconnect_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _subsystemSession.Disconnect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Disconnect_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _subsystemSession.Disconnect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs index 3aad8e66..ecdc46fc 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Disconnect_NeverConnected.cs @@ -1,72 +1,72 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Disconnect_NeverConnected - { - private Mock _sessionMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - } - - protected void Act() - { - _subsystemSession.Disconnect(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Disconnect_NeverConnected + { + private Mock _sessionMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + } + + protected void Act() + { + _subsystemSession.Disconnect(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs index a2268d1d..3f03e5d4 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Connected.cs @@ -1,95 +1,95 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs index d29a4429..6fc758e5 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disconnected.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_Disconnected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Disconnect(); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_Disconnected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Disconnect(); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs index 384e9929..1edec5bb 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_Disposed.cs @@ -1,96 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - - [TestMethod] - public void CloseOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Close(), Times.Once); - } - - [TestMethod] - public void DisposeOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.Dispose(), Times.Once); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + + [TestMethod] + public void CloseOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Close(), Times.Once); + } + + [TestMethod] + public void DisposeOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.Dispose(), Times.Once); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs index 7d3726d0..63c22ea1 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_Dispose_NeverConnected.cs @@ -1,73 +1,73 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_Dispose_NeverConnected - { - private Mock _sessionMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - } - - protected void Act() - { - _subsystemSession.Dispose(); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_Dispose_NeverConnected + { + private Mock _sessionMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + } + + protected void Act() + { + _subsystemSession.Dispose(); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs index 263a9037..5878f1a9 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Connected.cs @@ -1,121 +1,121 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelDataReceived_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ChannelDataEventArgs _channelDataEventArgs; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelDataEventArgs = new ChannelDataEventArgs( - (uint)random.Next(0, int.MaxValue), - new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void OnDataReceivedShouldBeInvokedOnce() - { - Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); - - var received = _subsystemSession.OnDataReceivedInvocations[0]; - Assert.AreEqual(_channelDataEventArgs.Data, received.Data); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenSessionIsNotConnected() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Once); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelDataReceived_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ChannelDataEventArgs _channelDataEventArgs; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelDataEventArgs = new ChannelDataEventArgs( + (uint)random.Next(0, int.MaxValue), + new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void OnDataReceivedShouldBeInvokedOnce() + { + Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); + + var received = _subsystemSession.OnDataReceivedInvocations[0]; + Assert.AreEqual(_channelDataEventArgs.Data, received.Data); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenSessionIsNotConnected() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Once); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs index 55b393e9..66178326 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_Disposed.cs @@ -1,94 +1,94 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelDataReceived_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ChannelDataEventArgs _channelDataEventArgs; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelDataEventArgs = new ChannelDataEventArgs( - (uint)random.Next(0, int.MaxValue), - new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void OnDataReceivedShouldNeverBeInvoked() - { - Assert.AreEqual(0, _subsystemSession.OnDataReceivedInvocations.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelDataReceived_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ChannelDataEventArgs _channelDataEventArgs; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelDataEventArgs = new ChannelDataEventArgs( + (uint)random.Next(0, int.MaxValue), + new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) }); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void OnDataReceivedShouldNeverBeInvoked() + { + Assert.AreEqual(0, _subsystemSession.OnDataReceivedInvocations.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs index 4f558eb9..b724e14d 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception.cs @@ -1,92 +1,92 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ChannelDataEventArgs _channelDataEventArgs; - private Exception _onDataReceivedException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelDataEventArgs = new ChannelDataEventArgs( - (uint) random.Next(0, int.MaxValue), - new [] {(byte) random.Next(byte.MinValue, byte.MaxValue)}); - _onDataReceivedException = new SystemException(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.OnDataReceivedException = _onDataReceivedException; - _subsystemSession.Connect(); - } - - protected void Act() - { - _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHaveFiredOnce() - { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_onDataReceivedException, _errorOccurredRegister[0].Exception); - } - - [TestMethod] - public void OnDataReceivedShouldBeInvokedOnce() - { - Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); - - var received = _subsystemSession.OnDataReceivedInvocations[0]; - Assert.AreEqual(_channelDataEventArgs.Data, received.Data); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelDataReceived_OnDataReceived_Exception + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ChannelDataEventArgs _channelDataEventArgs; + private Exception _onDataReceivedException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelDataEventArgs = new ChannelDataEventArgs( + (uint) random.Next(0, int.MaxValue), + new [] {(byte) random.Next(byte.MinValue, byte.MaxValue)}); + _onDataReceivedException = new SystemException(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.OnDataReceivedException = _onDataReceivedException; + _subsystemSession.Connect(); + } + + protected void Act() + { + _channelMock.Raise(s => s.DataReceived += null, _channelDataEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHaveFiredOnce() + { + Assert.AreEqual(1, _errorOccurredRegister.Count); + Assert.AreSame(_onDataReceivedException, _errorOccurredRegister[0].Exception); + } + + [TestMethod] + public void OnDataReceivedShouldBeInvokedOnce() + { + Assert.AreEqual(1, _subsystemSession.OnDataReceivedInvocations.Count); + + var received = _subsystemSession.OnDataReceivedInvocations[0]; + Assert.AreEqual(_channelDataEventArgs.Data, received.Data); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs index f601758b..887330e5 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Connected.cs @@ -1,111 +1,111 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelException_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _channelExceptionEventArgs; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasFiredOnce() - { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_channelExceptionEventArgs.Exception, _errorOccurredRegister[0].Exception); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelException_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _channelExceptionEventArgs; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasFiredOnce() + { + Assert.AreEqual(1, _errorOccurredRegister.Count); + Assert.AreSame(_channelExceptionEventArgs.Exception, _errorOccurredRegister[0].Exception); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs index 2bad6e46..6cb47486 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnChannelException_Disposed.cs @@ -1,89 +1,89 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnChannelException_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _channelExceptionEventArgs; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - - _disconnectedRegister.Clear(); - _errorOccurredRegister.Clear(); - } - - protected void Act() - { - _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnChannelException_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _channelExceptionEventArgs; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _channelExceptionEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + + _disconnectedRegister.Clear(); + _errorOccurredRegister.Clear(); + } + + protected void Act() + { + _channelMock.Raise(s => s.Exception += null, _channelExceptionEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs index 64a14670..318c64ae 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Connected.cs @@ -1,108 +1,108 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionDisconnected_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); - } - - [TestMethod] - public void DisconnectHasFiredOnce() - { - Assert.AreEqual(1, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionDisconnected_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); + } + + [TestMethod] + public void DisconnectHasFiredOnce() + { + Assert.AreEqual(1, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs index 5c2c13ab..df4f0f59 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionDisconnected_Disposed.cs @@ -1,84 +1,84 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionDisconnected_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionDisconnected_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs index 416fdf1e..aa2a135d 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Connected.cs @@ -1,111 +1,111 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionErrorOccurred_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _errorOccurredEventArgs; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasFiredOnce() - { - Assert.AreEqual(1, _errorOccurredRegister.Count); - Assert.AreSame(_errorOccurredEventArgs.Exception, _errorOccurredRegister[0].Exception); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); - } - - [TestMethod] - public void CloseOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Close(), Times.Never); - } - - [TestMethod] - public void DisposeOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.Dispose(), Times.Never); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionErrorOccurred_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _errorOccurredEventArgs; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasFiredOnce() + { + Assert.AreEqual(1, _errorOccurredRegister.Count); + Assert.AreSame(_errorOccurredEventArgs.Exception, _errorOccurredRegister[0].Exception); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(1)); + } + + [TestMethod] + public void CloseOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Close(), Times.Never); + } + + [TestMethod] + public void DisposeOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.Dispose(), Times.Never); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs index 9224fdd7..f59b0fcf 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_OnSessionErrorOccurred_Disposed.cs @@ -1,86 +1,86 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_OnSessionErrorOccurred_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ExceptionEventArgs _errorOccurredEventArgs; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_OnSessionErrorOccurred_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ExceptionEventArgs _errorOccurredEventArgs; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _errorOccurredEventArgs = new ExceptionEventArgs(new SystemException()); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + _sessionMock.Raise(s => s.ErrorOccured += null, _errorOccurredEventArgs); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs index a854da24..1d3e4090 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Connected.cs @@ -1,106 +1,106 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_SendData_Connected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private byte[] _data; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - _channelMock.InSequence(_sequence).Setup(p => p.SendData(_data)); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - } - - protected void Act() - { - _subsystemSession.SendData(_data); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void SendDataOnChannelShouldBeInvokedOnce() - { - _channelMock.Verify(p => p.SendData(_data), Times.Once); - } - - [TestMethod] - public void IsOpenShouldReturnTrueWhenChannelIsOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); - - Assert.IsTrue(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - - [TestMethod] - public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() - { - _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); - - Assert.IsFalse(_subsystemSession.IsOpen); - - _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_SendData_Connected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private byte[] _data; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + _channelMock.InSequence(_sequence).Setup(p => p.SendData(_data)); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + } + + protected void Act() + { + _subsystemSession.SendData(_data); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void SendDataOnChannelShouldBeInvokedOnce() + { + _channelMock.Verify(p => p.SendData(_data), Times.Once); + } + + [TestMethod] + public void IsOpenShouldReturnTrueWhenChannelIsOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true); + + Assert.IsTrue(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + + [TestMethod] + public void IsOpenShouldReturnFalseWhenChannelIsNotOpen() + { + _channelMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(false); + + Assert.IsFalse(_subsystemSession.IsOpen); + + _channelMock.Verify(p => p.IsOpen, Times.Exactly(2)); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs index 19afb1ec..6d60a61b 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disconnected.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Renci.SshNet.Tests.Classes -{ - class SubsystemSession_SendData_Disconnected - { - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Renci.SshNet.Tests.Classes +{ + class SubsystemSession_SendData_Disconnected + { + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs index 8477efa9..f8e5ef0c 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_Disposed.cs @@ -1,100 +1,100 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_SendData_Disposed - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private ObjectDisposedException _actualException; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - var sequence = new MockSequence(); - _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(sequence).Setup(p => p.Open()); - _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - _channelMock.InSequence(sequence).Setup(p => p.Close()); - _channelMock.InSequence(sequence).Setup(p => p.Dispose()); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - _subsystemSession.Connect(); - _subsystemSession.Dispose(); - } - - protected void Act() - { - try - { - _subsystemSession.SendData(new byte[0]); - } - catch (ObjectDisposedException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SendDataShouldThrowObjectDisposedException() - { - Assert.IsNotNull(_actualException); - Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName), _actualException.Message); - Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_SendData_Disposed + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private ObjectDisposedException _actualException; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + var sequence = new MockSequence(); + _sessionMock.InSequence(sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(sequence).Setup(p => p.Open()); + _channelMock.InSequence(sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + _channelMock.InSequence(sequence).Setup(p => p.Close()); + _channelMock.InSequence(sequence).Setup(p => p.Dispose()); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + _subsystemSession.Connect(); + _subsystemSession.Dispose(); + } + + protected void Act() + { + try + { + _subsystemSession.SendData(new byte[0]); + } + catch (ObjectDisposedException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SendDataShouldThrowObjectDisposedException() + { + Assert.IsNotNull(_actualException); + Assert.AreEqual(string.Format("Cannot access a disposed object.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName), _actualException.Message); + Assert.AreEqual(typeof(SubsystemSessionStub).FullName, _actualException.ObjectName); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs index ff58cc4f..0de12487 100644 --- a/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs +++ b/src/Renci.SshNet.Tests/Classes/SubsystemSession_SendData_NeverConnected.cs @@ -1,106 +1,106 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using Renci.SshNet.Channels; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Classes -{ - [TestClass] - public class SubsystemSession_SendData_NeverConnected - { - private Mock _sessionMock; - private Mock _channelMock; - private string _subsystemName; - private SubsystemSessionStub _subsystemSession; - private TimeSpan _operationTimeout; - private Encoding _encoding; - private IList _disconnectedRegister; - private IList _errorOccurredRegister; - private InvalidOperationException _actualException; - private byte[] _data; - private MockSequence _sequence; - - [TestInitialize] - public void Setup() - { - Arrange(); - Act(); - } - - protected void Arrange() - { - var random = new Random(); - _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); - _operationTimeout = TimeSpan.FromSeconds(30); - _encoding = Encoding.UTF8; - _disconnectedRegister = new List(); - _errorOccurredRegister = new List(); - _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; - - _sessionMock = new Mock(MockBehavior.Strict); - _channelMock = new Mock(MockBehavior.Strict); - - _sequence = new MockSequence(); - _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true); - _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); - _channelMock.InSequence(_sequence).Setup(p => p.Open()); - _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); - - _subsystemSession = new SubsystemSessionStub( - _sessionMock.Object, - _subsystemName, - _operationTimeout, - _encoding); - _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); - _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); - } - - protected void Act() - { - try - { - _subsystemSession.SendData(_data); - } - catch (InvalidOperationException ex) - { - _actualException = ex; - } - } - - [TestMethod] - public void SendDataShouldHaveThrownInvalidOperationException() - { - Assert.IsNotNull(_actualException); - Assert.IsNull(_actualException.InnerException); - Assert.AreEqual("The session is not open.", _actualException.Message); - } - - [TestMethod] - public void DisconnectHasNeverFired() - { - Assert.AreEqual(0, _disconnectedRegister.Count); - } - - [TestMethod] - public void ErrorOccurredHasNeverFired() - { - Assert.AreEqual(0, _errorOccurredRegister.Count); - } - - [TestMethod] - public void SendDataOnChannelShouldNeverBeInvoked() - { - _channelMock.Verify(p => p.SendData(_data), Times.Never); - } - - [TestMethod] - public void IsOpenShouldReturnFalse() - { - Assert.IsFalse(_subsystemSession.IsOpen); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Renci.SshNet.Channels; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Classes +{ + [TestClass] + public class SubsystemSession_SendData_NeverConnected + { + private Mock _sessionMock; + private Mock _channelMock; + private string _subsystemName; + private SubsystemSessionStub _subsystemSession; + private TimeSpan _operationTimeout; + private Encoding _encoding; + private IList _disconnectedRegister; + private IList _errorOccurredRegister; + private InvalidOperationException _actualException; + private byte[] _data; + private MockSequence _sequence; + + [TestInitialize] + public void Setup() + { + Arrange(); + Act(); + } + + protected void Arrange() + { + var random = new Random(); + _subsystemName = random.Next().ToString(CultureInfo.InvariantCulture); + _operationTimeout = TimeSpan.FromSeconds(30); + _encoding = Encoding.UTF8; + _disconnectedRegister = new List(); + _errorOccurredRegister = new List(); + _data = new[] {(byte) random.Next(byte.MinValue, byte.MaxValue)}; + + _sessionMock = new Mock(MockBehavior.Strict); + _channelMock = new Mock(MockBehavior.Strict); + + _sequence = new MockSequence(); + _sessionMock.InSequence(_sequence).Setup(p => p.IsConnected).Returns(true); + _sessionMock.InSequence(_sequence).Setup(p => p.CreateChannelSession()).Returns(_channelMock.Object); + _channelMock.InSequence(_sequence).Setup(p => p.Open()); + _channelMock.InSequence(_sequence).Setup(p => p.SendSubsystemRequest(_subsystemName)).Returns(true); + + _subsystemSession = new SubsystemSessionStub( + _sessionMock.Object, + _subsystemName, + _operationTimeout, + _encoding); + _subsystemSession.Disconnected += (sender, args) => _disconnectedRegister.Add(args); + _subsystemSession.ErrorOccurred += (sender, args) => _errorOccurredRegister.Add(args); + } + + protected void Act() + { + try + { + _subsystemSession.SendData(_data); + } + catch (InvalidOperationException ex) + { + _actualException = ex; + } + } + + [TestMethod] + public void SendDataShouldHaveThrownInvalidOperationException() + { + Assert.IsNotNull(_actualException); + Assert.IsNull(_actualException.InnerException); + Assert.AreEqual("The session is not open.", _actualException.Message); + } + + [TestMethod] + public void DisconnectHasNeverFired() + { + Assert.AreEqual(0, _disconnectedRegister.Count); + } + + [TestMethod] + public void ErrorOccurredHasNeverFired() + { + Assert.AreEqual(0, _errorOccurredRegister.Count); + } + + [TestMethod] + public void SendDataOnChannelShouldNeverBeInvoked() + { + _channelMock.Verify(p => p.SendData(_data), Times.Never); + } + + [TestMethod] + public void IsOpenShouldReturnFalse() + { + Assert.IsFalse(_subsystemSession.IsOpen); + } + } +} diff --git a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs index 6cd5c3a8..86b38c94 100644 --- a/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs +++ b/src/Renci.SshNet.Tests/Common/AsyncSocketListener.cs @@ -1,161 +1,161 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Tests.Common -{ - public class AsyncSocketListener : IDisposable - { - private readonly IPEndPoint _endPoint; - private readonly ManualResetEvent _acceptCallbackDone; - private Socket _listener; - private Thread _receiveThread; - private bool _started; - - public delegate void BytesReceivedHandler(byte[] bytesReceived, Socket socket); - public delegate void ConnectedHandler(Socket socket); - - public event BytesReceivedHandler BytesReceived; - public event ConnectedHandler Connected; - public event ConnectedHandler Disconnected; - - public AsyncSocketListener(IPEndPoint endPoint) - { - _endPoint = endPoint; - _acceptCallbackDone = new ManualResetEvent(false); - } - - public void Start() - { - _listener = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - _listener.Bind(_endPoint); - _listener.Listen(1); - - _started = true; - - _receiveThread = new Thread(StartListener); - _receiveThread.Start(_listener); - } - - public void Stop() - { - _started = false; - if (_listener != null) - { - _listener.Dispose(); - _listener = null; - } - if (_receiveThread != null) - { - _receiveThread.Join(); - _receiveThread = null; - } - } - - public void Dispose() - { - Stop(); - GC.SuppressFinalize(this); - } - - private void StartListener(object state) - { - var listener = (Socket)state; - while (_started) - { - _acceptCallbackDone.Reset(); - listener.BeginAccept(AcceptCallback, listener); - _acceptCallbackDone.WaitOne(); - } - } - - private void AcceptCallback(IAsyncResult ar) - { - // Signal the main thread to continue. - _acceptCallbackDone.Set(); - - // Get the socket that handles the client request. - var listener = (Socket)ar.AsyncState; - try - { - var handler = listener.EndAccept(ar); - SignalConnected(handler); - var state = new SocketStateObject(handler); - handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); - } - catch (ObjectDisposedException) - { - // when the socket is closed, an ObjectDisposedException is thrown - // by Socket.EndAccept(IAsyncResult) - } - } - - private void ReadCallback(IAsyncResult ar) - { - // Retrieve the state object and the handler socket - // from the asynchronous state object. - var state = (SocketStateObject)ar.AsyncState; - var handler = state.Socket; - - // Read data from the client socket. - var bytesRead = handler.EndReceive(ar); - - if (bytesRead > 0) - { - var bytesReceived = new byte[bytesRead]; - Array.Copy(state.Buffer, bytesReceived, bytesRead); - SignalBytesReceived(bytesReceived, handler); - - // prepare to receive more bytes - try - { - handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); - } - catch (ObjectDisposedException) - { - // when the socket is closed, an ObjectDisposedException is thrown - } - } - else - { - SignalDisconnected(handler); - handler.Shutdown(SocketShutdown.Send); - } - } - - private void SignalBytesReceived(byte[] bytesReceived, Socket client) - { - var subscribers = BytesReceived; - if (subscribers != null) - subscribers(bytesReceived, client); - } - - private void SignalConnected(Socket client) - { - var subscribers = Connected; - if (subscribers != null) - subscribers(client); - } - - private void SignalDisconnected(Socket client) - { - var subscribers = Disconnected; - if (subscribers != null) - subscribers(client); - } - - private class SocketStateObject - { - public Socket Socket { get; private set; } - - public readonly byte[] Buffer = new byte[1024]; - - public SocketStateObject(Socket handler) - { - Socket = handler; - } - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Tests.Common +{ + public class AsyncSocketListener : IDisposable + { + private readonly IPEndPoint _endPoint; + private readonly ManualResetEvent _acceptCallbackDone; + private Socket _listener; + private Thread _receiveThread; + private bool _started; + + public delegate void BytesReceivedHandler(byte[] bytesReceived, Socket socket); + public delegate void ConnectedHandler(Socket socket); + + public event BytesReceivedHandler BytesReceived; + public event ConnectedHandler Connected; + public event ConnectedHandler Disconnected; + + public AsyncSocketListener(IPEndPoint endPoint) + { + _endPoint = endPoint; + _acceptCallbackDone = new ManualResetEvent(false); + } + + public void Start() + { + _listener = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + _listener.Bind(_endPoint); + _listener.Listen(1); + + _started = true; + + _receiveThread = new Thread(StartListener); + _receiveThread.Start(_listener); + } + + public void Stop() + { + _started = false; + if (_listener != null) + { + _listener.Dispose(); + _listener = null; + } + if (_receiveThread != null) + { + _receiveThread.Join(); + _receiveThread = null; + } + } + + public void Dispose() + { + Stop(); + GC.SuppressFinalize(this); + } + + private void StartListener(object state) + { + var listener = (Socket)state; + while (_started) + { + _acceptCallbackDone.Reset(); + listener.BeginAccept(AcceptCallback, listener); + _acceptCallbackDone.WaitOne(); + } + } + + private void AcceptCallback(IAsyncResult ar) + { + // Signal the main thread to continue. + _acceptCallbackDone.Set(); + + // Get the socket that handles the client request. + var listener = (Socket)ar.AsyncState; + try + { + var handler = listener.EndAccept(ar); + SignalConnected(handler); + var state = new SocketStateObject(handler); + handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); + } + catch (ObjectDisposedException) + { + // when the socket is closed, an ObjectDisposedException is thrown + // by Socket.EndAccept(IAsyncResult) + } + } + + private void ReadCallback(IAsyncResult ar) + { + // Retrieve the state object and the handler socket + // from the asynchronous state object. + var state = (SocketStateObject)ar.AsyncState; + var handler = state.Socket; + + // Read data from the client socket. + var bytesRead = handler.EndReceive(ar); + + if (bytesRead > 0) + { + var bytesReceived = new byte[bytesRead]; + Array.Copy(state.Buffer, bytesReceived, bytesRead); + SignalBytesReceived(bytesReceived, handler); + + // prepare to receive more bytes + try + { + handler.BeginReceive(state.Buffer, 0, state.Buffer.Length, 0, ReadCallback, state); + } + catch (ObjectDisposedException) + { + // when the socket is closed, an ObjectDisposedException is thrown + } + } + else + { + SignalDisconnected(handler); + handler.Shutdown(SocketShutdown.Send); + } + } + + private void SignalBytesReceived(byte[] bytesReceived, Socket client) + { + var subscribers = BytesReceived; + if (subscribers != null) + subscribers(bytesReceived, client); + } + + private void SignalConnected(Socket client) + { + var subscribers = Connected; + if (subscribers != null) + subscribers(client); + } + + private void SignalDisconnected(Socket client) + { + var subscribers = Disconnected; + if (subscribers != null) + subscribers(client); + } + + private class SocketStateObject + { + public Socket Socket { get; private set; } + + public readonly byte[] Buffer = new byte[1024]; + + public SocketStateObject(Socket handler) + { + Socket = handler; + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs b/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs index f0358d00..d7bdba50 100644 --- a/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs +++ b/src/Renci.SshNet.Tests/Common/HttpProxyStub.cs @@ -1,169 +1,169 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Net.Sockets; -using System.Text; - -namespace Renci.SshNet.Tests.Common -{ - public class HttpProxyStub : IDisposable - { - private readonly IPEndPoint _endPoint; - private AsyncSocketListener _listener; - private HttpRequestParser _httpRequestParser; - private readonly IList _responses; - - public HttpProxyStub(IPEndPoint endPoint) - { - _endPoint = endPoint; - _responses = new List(); - } - - public HttpRequest HttpRequest - { - get - { - if (_httpRequestParser == null) - throw new InvalidOperationException("The proxy is not started."); - return _httpRequestParser.HttpRequest; - } - } - - public IList Responses - { - get { return _responses; } - } - - public void Start() - { - _httpRequestParser = new HttpRequestParser(); - - _listener = new AsyncSocketListener(_endPoint); - _listener.BytesReceived += OnBytesReceived; - _listener.Start(); - } - - public void Stop() - { - if (_listener != null) - _listener.Stop(); - } - - public void Dispose() - { - Stop(); - GC.SuppressFinalize(this); - } - - private void OnBytesReceived(byte[] bytesReceived, Socket socket) - { - _httpRequestParser.ProcessData(bytesReceived); - - if (_httpRequestParser.CurrentState == HttpRequestParser.State.Content) - { - foreach (var response in Responses) - socket.Send(response); - socket.Shutdown(SocketShutdown.Send); - } - } - - private class HttpRequestParser - { - private readonly List _buffer; - private readonly HttpRequest _httpRequest; - - public enum State - { - RequestLine, - Headers, - Content - } - - public HttpRequestParser() - { - CurrentState = State.RequestLine; - _buffer = new List(); - _httpRequest = new HttpRequest(); - } - - public HttpRequest HttpRequest - { - get { return _httpRequest; } - } - - public State CurrentState { get; private set; } - - public void ProcessData(byte[] data) - { - var position = 0; - - while (position != data.Length) - { - if (CurrentState == State.RequestLine) - { - var requestLine = ReadLine(data, ref position); - if (requestLine != null) - { - _httpRequest.RequestLine = requestLine; - CurrentState = State.Headers; - } - } - - if (CurrentState == State.Headers) - { - var line = ReadLine(data, ref position); - if (line != null) - { - if (line.Length == 0) - { - CurrentState = State.Content; - } - else - { - _httpRequest.Headers.Add(line); - } - } - } - - if (CurrentState == State.Content) - { - if (position < data.Length) - { - var currentContent = _httpRequest.MessageBody; - var newBufferSize = currentContent.Length + (data.Length - position); - var copyBuffer = new byte[newBufferSize]; - Array.Copy(currentContent, copyBuffer, currentContent.Length); - Array.Copy(data, position, copyBuffer, currentContent.Length, data.Length - position); - _httpRequest.MessageBody = copyBuffer; - break; - } - } - } - } - - private string ReadLine(byte[] data, ref int position) - { - for (; position < data.Length; position++) - { - var b = data[position]; - if (b == '\n') - { - var buffer = _buffer.ToArray(); - var bytesInLine = buffer.Length; - // when the previous byte was a CR, then do not include it in line - if (buffer.Length > 0 && buffer[buffer.Length - 1] == '\r') - bytesInLine -= 1; - // clear the buffer - _buffer.Clear(); - // move position up one position as we've processed the current byte - position++; - return Encoding.ASCII.GetString(buffer, 0, bytesInLine); - } - _buffer.Add(b); - } - - return null; - } - } - } +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Text; + +namespace Renci.SshNet.Tests.Common +{ + public class HttpProxyStub : IDisposable + { + private readonly IPEndPoint _endPoint; + private AsyncSocketListener _listener; + private HttpRequestParser _httpRequestParser; + private readonly IList _responses; + + public HttpProxyStub(IPEndPoint endPoint) + { + _endPoint = endPoint; + _responses = new List(); + } + + public HttpRequest HttpRequest + { + get + { + if (_httpRequestParser == null) + throw new InvalidOperationException("The proxy is not started."); + return _httpRequestParser.HttpRequest; + } + } + + public IList Responses + { + get { return _responses; } + } + + public void Start() + { + _httpRequestParser = new HttpRequestParser(); + + _listener = new AsyncSocketListener(_endPoint); + _listener.BytesReceived += OnBytesReceived; + _listener.Start(); + } + + public void Stop() + { + if (_listener != null) + _listener.Stop(); + } + + public void Dispose() + { + Stop(); + GC.SuppressFinalize(this); + } + + private void OnBytesReceived(byte[] bytesReceived, Socket socket) + { + _httpRequestParser.ProcessData(bytesReceived); + + if (_httpRequestParser.CurrentState == HttpRequestParser.State.Content) + { + foreach (var response in Responses) + socket.Send(response); + socket.Shutdown(SocketShutdown.Send); + } + } + + private class HttpRequestParser + { + private readonly List _buffer; + private readonly HttpRequest _httpRequest; + + public enum State + { + RequestLine, + Headers, + Content + } + + public HttpRequestParser() + { + CurrentState = State.RequestLine; + _buffer = new List(); + _httpRequest = new HttpRequest(); + } + + public HttpRequest HttpRequest + { + get { return _httpRequest; } + } + + public State CurrentState { get; private set; } + + public void ProcessData(byte[] data) + { + var position = 0; + + while (position != data.Length) + { + if (CurrentState == State.RequestLine) + { + var requestLine = ReadLine(data, ref position); + if (requestLine != null) + { + _httpRequest.RequestLine = requestLine; + CurrentState = State.Headers; + } + } + + if (CurrentState == State.Headers) + { + var line = ReadLine(data, ref position); + if (line != null) + { + if (line.Length == 0) + { + CurrentState = State.Content; + } + else + { + _httpRequest.Headers.Add(line); + } + } + } + + if (CurrentState == State.Content) + { + if (position < data.Length) + { + var currentContent = _httpRequest.MessageBody; + var newBufferSize = currentContent.Length + (data.Length - position); + var copyBuffer = new byte[newBufferSize]; + Array.Copy(currentContent, copyBuffer, currentContent.Length); + Array.Copy(data, position, copyBuffer, currentContent.Length, data.Length - position); + _httpRequest.MessageBody = copyBuffer; + break; + } + } + } + } + + private string ReadLine(byte[] data, ref int position) + { + for (; position < data.Length; position++) + { + var b = data[position]; + if (b == '\n') + { + var buffer = _buffer.ToArray(); + var bytesInLine = buffer.Length; + // when the previous byte was a CR, then do not include it in line + if (buffer.Length > 0 && buffer[buffer.Length - 1] == '\r') + bytesInLine -= 1; + // clear the buffer + _buffer.Clear(); + // move position up one position as we've processed the current byte + position++; + return Encoding.ASCII.GetString(buffer, 0, bytesInLine); + } + _buffer.Add(b); + } + + return null; + } + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Common/HttpRequest.cs b/src/Renci.SshNet.Tests/Common/HttpRequest.cs index 87797d20..56185fdd 100644 --- a/src/Renci.SshNet.Tests/Common/HttpRequest.cs +++ b/src/Renci.SshNet.Tests/Common/HttpRequest.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; - -namespace Renci.SshNet.Tests.Common -{ - public class HttpRequest - { - public HttpRequest() - { - Headers = new List(); - MessageBody = new byte[0]; - } - - public string RequestLine { get; set; } - public IList Headers { get; set; } - public byte[] MessageBody { get; set; } - } -} +using System.Collections.Generic; + +namespace Renci.SshNet.Tests.Common +{ + public class HttpRequest + { + public HttpRequest() + { + Headers = new List(); + MessageBody = new byte[0]; + } + + public string RequestLine { get; set; } + public IList Headers { get; set; } + public byte[] MessageBody { get; set; } + } +} diff --git a/src/Renci.SshNet.Tests/Common/TestBase.cs b/src/Renci.SshNet.Tests/Common/TestBase.cs index cda7e002..345fd1bd 100644 --- a/src/Renci.SshNet.Tests/Common/TestBase.cs +++ b/src/Renci.SshNet.Tests/Common/TestBase.cs @@ -1,56 +1,56 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.IO; -using System.Reflection; - -namespace Renci.SshNet.Tests.Common -{ - [TestClass] - public abstract class TestBase - { - private static Assembly _executingAssembly = Assembly.GetExecutingAssembly(); - [TestInitialize()] - public void Init() - { - this.OnInit(); - } - - [TestCleanup()] - public void Cleanup() - { - this.OnCleanup(); - } - - protected virtual void OnInit() - { - } - - protected virtual void OnCleanup() - { - } - - /// - /// Creates the test file. - /// - /// Name of the file. - /// Size in megabytes. - protected void CreateTestFile(string fileName, int size) - { - using (var testFile = File.Create(fileName)) - { - var random = new Random(); - for (int i = 0; i < 1024 * size; i++) - { - var buffer = new byte[1024]; - random.NextBytes(buffer); - testFile.Write(buffer, 0, buffer.Length); - } - } - } - - protected Stream GetData(string name) - { - return _executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", name)); - } - } +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.IO; +using System.Reflection; + +namespace Renci.SshNet.Tests.Common +{ + [TestClass] + public abstract class TestBase + { + private static Assembly _executingAssembly = Assembly.GetExecutingAssembly(); + [TestInitialize()] + public void Init() + { + this.OnInit(); + } + + [TestCleanup()] + public void Cleanup() + { + this.OnCleanup(); + } + + protected virtual void OnInit() + { + } + + protected virtual void OnCleanup() + { + } + + /// + /// Creates the test file. + /// + /// Name of the file. + /// Size in megabytes. + protected void CreateTestFile(string fileName, int size) + { + using (var testFile = File.Create(fileName)) + { + var random = new Random(); + for (int i = 0; i < 1024 * size; i++) + { + var buffer = new byte[1024]; + random.NextBytes(buffer); + testFile.Write(buffer, 0, buffer.Length); + } + } + } + + protected Stream GetData(string name) + { + return _executingAssembly.GetManifestResourceStream(string.Format("Renci.SshNet.Tests.Data.{0}", name)); + } + } } \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt index 1c8303f3..cc017a90 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.128.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: AES-128-CBC,AD7A2024C208E41F91C191B89AB9515A - -TFSgpmvpdkk1noN8C3hhiVMIW6aQ9sLhTbw/vrOh6Atp3/DgmgNOjXrClWXrZi6C -dyEV/ohLL12FCSkhEz5yl88IeSG0SA970zPoBrCi0OAyc40kQe/oQOHPg948BYcp -MIhJRYdbc6yZJC7umyteIaDg4BT2u9C1512JI/7CV1JzzfdYxFNpRVqW06wOdz/2 -IdtbusQsHRU0faGP6F3VMRLuCkS/l96K7orXQofpLw78f8siyNFqOvTrZNsIjErl -OXnY3k77SEtcfJ+Gji7BZBNHmDPG4mFacFGotypYb422C3ENCIrjFa5JsU5IGVe+ -3YDaZySq7JkgsFF3owwQvJycO0IDO8WgyYhDTFkWLL5bLU+R1bqvWxVq0WtLJO0n -B4katSG+kxhFFE85k2hmEOQjsWNvQD7EbPwQBXQUr80/sPFhfzm228z8aeLa/9nb -WCNg9ilEx7QAjc7i3RfqcJ9O4svZy5JUV5K1oe5CsTmTGfQiG93R8RNA/coRcv36 -iw3jldW+otB22hHxktrQIhPz3cRocVvr3xSe+2RsWrOOuCaJrrduPnlFTUHt3gRD -yBWoA6AD+Bt+0yW7TFpbR77rz2svcgoJ64wrA2sG0OtUlMzG52IX69pWA6tRKbdJ -rGj/j/9fIQi83bAUXpWG/gA4hL18+QiNAfyk3fmMtOvp58fyoWYguLAc794ar0jJ -HAseTc1RzBzRp2Ic/LwIQyxOwNBM0KXuVoyJjkFg6qNudVrIv0PSIPuu84Ro4dbn -HN+a7O/SQXk3NOSN4N/XSbBpu8tZVq94w3mPoNXcsnObeN/Br4cr0pGlm8sJJNbh -HZSAz+MxqXmpwPr7UUd3jmtnYmOgE89H7k2nayj06J2a7EgbzaXCeeXUg+IJN1xi -o1TMU4uQgX0XgChnRZ1Uo8ksAqWAEvgFypexFulNxHPCnLrjWOIA8nyt9Ue8T/SO -eEVsSLNhUuQsn+TiKgP4f4JaXMl2tchzSth2Gv2QEReMb1ftzIH41VZndhJlxmAE -o1AButj+5+d6oBuJo8rueRUz6invlv9FUXQWaDEjpFXACmXC+KtZ5rBa8oP9yak5 -Hh1GxVYHCs0WGyWdIRgW44oVWIfEBGLer2G9krhnZNF4lbyG8SuGhju+LYRe726Y -/Un1r/6+nykMNsAgR0vjnYkwx1Qd2mm8L8eLkz/Q7BsZLpChLqHv5HnXNuXqTsFB -orWBELQQsvLU69j70h3KK549gGPO4KBX8VrMaj0tIss7PYQub7lbyhNFXlfHy+xN -4EZntnj3gf0eqxsqduq6rP18vhaE3onIJ2I6twR+ivTulacNHxSH0/ieh+QCB9Bw -3gggWZ9Trf7QvyGEqzewfYMZ0RjagascnFFVjyTtPLn6jfaIoxSxMy7kcyIYHxPu -3qgLtO+AW6bY4VuT3cJroNrdrnGTXiGzim5TWDw2EcuLUpA8p3G+0RnSgM/EyjVQ -dZo8roiKvKSpdVS6cWsScyAvecq+fXTGzd95DDj15/feWP/4vk4WjTeSEr95k2cq -TGwZ2mF2ZKxS3eXVHOKysreLIQQOeMi+rlHAMAfzu5PTQhaYhhFZ2oPBmPsYYrJD +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-128-CBC,AD7A2024C208E41F91C191B89AB9515A + +TFSgpmvpdkk1noN8C3hhiVMIW6aQ9sLhTbw/vrOh6Atp3/DgmgNOjXrClWXrZi6C +dyEV/ohLL12FCSkhEz5yl88IeSG0SA970zPoBrCi0OAyc40kQe/oQOHPg948BYcp +MIhJRYdbc6yZJC7umyteIaDg4BT2u9C1512JI/7CV1JzzfdYxFNpRVqW06wOdz/2 +IdtbusQsHRU0faGP6F3VMRLuCkS/l96K7orXQofpLw78f8siyNFqOvTrZNsIjErl +OXnY3k77SEtcfJ+Gji7BZBNHmDPG4mFacFGotypYb422C3ENCIrjFa5JsU5IGVe+ +3YDaZySq7JkgsFF3owwQvJycO0IDO8WgyYhDTFkWLL5bLU+R1bqvWxVq0WtLJO0n +B4katSG+kxhFFE85k2hmEOQjsWNvQD7EbPwQBXQUr80/sPFhfzm228z8aeLa/9nb +WCNg9ilEx7QAjc7i3RfqcJ9O4svZy5JUV5K1oe5CsTmTGfQiG93R8RNA/coRcv36 +iw3jldW+otB22hHxktrQIhPz3cRocVvr3xSe+2RsWrOOuCaJrrduPnlFTUHt3gRD +yBWoA6AD+Bt+0yW7TFpbR77rz2svcgoJ64wrA2sG0OtUlMzG52IX69pWA6tRKbdJ +rGj/j/9fIQi83bAUXpWG/gA4hL18+QiNAfyk3fmMtOvp58fyoWYguLAc794ar0jJ +HAseTc1RzBzRp2Ic/LwIQyxOwNBM0KXuVoyJjkFg6qNudVrIv0PSIPuu84Ro4dbn +HN+a7O/SQXk3NOSN4N/XSbBpu8tZVq94w3mPoNXcsnObeN/Br4cr0pGlm8sJJNbh +HZSAz+MxqXmpwPr7UUd3jmtnYmOgE89H7k2nayj06J2a7EgbzaXCeeXUg+IJN1xi +o1TMU4uQgX0XgChnRZ1Uo8ksAqWAEvgFypexFulNxHPCnLrjWOIA8nyt9Ue8T/SO +eEVsSLNhUuQsn+TiKgP4f4JaXMl2tchzSth2Gv2QEReMb1ftzIH41VZndhJlxmAE +o1AButj+5+d6oBuJo8rueRUz6invlv9FUXQWaDEjpFXACmXC+KtZ5rBa8oP9yak5 +Hh1GxVYHCs0WGyWdIRgW44oVWIfEBGLer2G9krhnZNF4lbyG8SuGhju+LYRe726Y +/Un1r/6+nykMNsAgR0vjnYkwx1Qd2mm8L8eLkz/Q7BsZLpChLqHv5HnXNuXqTsFB +orWBELQQsvLU69j70h3KK549gGPO4KBX8VrMaj0tIss7PYQub7lbyhNFXlfHy+xN +4EZntnj3gf0eqxsqduq6rP18vhaE3onIJ2I6twR+ivTulacNHxSH0/ieh+QCB9Bw +3gggWZ9Trf7QvyGEqzewfYMZ0RjagascnFFVjyTtPLn6jfaIoxSxMy7kcyIYHxPu +3qgLtO+AW6bY4VuT3cJroNrdrnGTXiGzim5TWDw2EcuLUpA8p3G+0RnSgM/EyjVQ +dZo8roiKvKSpdVS6cWsScyAvecq+fXTGzd95DDj15/feWP/4vk4WjTeSEr95k2cq +TGwZ2mF2ZKxS3eXVHOKysreLIQQOeMi+rlHAMAfzu5PTQhaYhhFZ2oPBmPsYYrJD -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt index ef6ddde8..51e90210 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.192.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: AES-192-CBC,0E34605476FC4C57886CE6350CD6F61E - -yOzUZ81fSG2jBfhe7h/f2Uy7K86+VZFXVG3Y3qdQe6HD6kvQgQJLN+g8OVHan7vA -CYnKImqS5fiTIwvsMxzVWtCeY2kJ9BMNeNIoLXebD5RV93lKPBgl0IldrkfJrg0w -VNPkCHLFHWIOUA/bxYiXEeLRHuvndSkYH/JCzESiquf51chU4CIEmrbuvtvLXKta -YPO9eCw0PP1QKO/fJVrUHfp6Bsvai/J0+PG19XzkKCMsewG0MkAqpkzQrAjaCJyj -IwiqxxV72FIQDITgIQf5sY2yPzya/TjnBpu4m9D7TzQhCw9J2EDx61qvvKt3BDyq -DahaY6/T/wgcYvdoJ3RzOiWmSLvXNc1PNVY9OfQXG2EtJa/xi2BHyeHgo/Kib7Wr -nfaKgM7V998bLjiUnLK9CoD2WG3oSIrkAieNYbaD+RvU/mR/TNp5xMLMVJYduZo+ -EeyooM1a29WjOU8LPZ/AwNS4/DHnzEG1UBsUbKtyzQHiKU3JoW+5BkZ2tAs+VEWo -b5Jx9XCKfL9JepP0Ti2adAlPYU9jH6YzTpZZfu+sd2+X/N8obYssUP6bFSB0KWL0 -s/nx7DKzbXo4P+Lm04FpmeqmP3h4lhsInoozr0tP3JJKTb99kGV480eVdqDuV+Af -WJ4HLKlWxu8aHNnYb8/ATWEvh0Li0Qmx/ok8Ixa4XmHv2W0hjk7yhNewLpIwQ35X -qJgQph96gGzMGZQ3r/TjNd7YiAfPishOC/TnitIZzC/Es+zZ7QsGgBP4j1hPLAjs -OTrOvwkLuGUOoI9jJwm6343ZeGBFuWXJu0CSk4OF1EUMNziMUz9Rfw6xHSAnzff/ -YuQwDx+EtZLyyxFsfdhLjwcR38R6WoFqeDPpb3i6B5dYhHG6w60Yq5X1J4EnJgLL -4zYqVLoC6rvUuslFX2EFGrTTZP/7qRi5H3ZhNzMf/KDVbTyhzzHx27LR/8vbScA0 -IFp5NhmbmBbH7PmEF3UoVwSn/u+5iF8dmuhuOqNidImAULLCf5qCSbJNvagk9sSf -c6SdbX+EOkF6nTZYfSA0lT2u7rSfFw7khn6f+/ySRlQra7v3MBeeIuqrHEamlc73 -4hPKnl8eGcT3XvrpMnuiYADjJ4qOYzwx3YiKGqvdGzqd+ML6f2Tk31N7E53UDvSR -96gYz7IiBEkbaQSV1iZ95iiv/0m2J8B7VR5FfwvLltrmD10Alq97Gpj7HUH/Yy+8 -Wu4ADp6wdSWXMki2+QUxucIqWJ4nViE6K4FJy3SbPwtJWxiLkLQibGxdZl0jHDOl -F/FuWxjizKtOwn9rzQ+viVvYaQW1QTv5kS0d0L7FV2J8lQbsr8T86jUAJRASt5Cf -/+Z628xFSwDZjITOjhHT2GJqho/eW4h/naWgMRoThFI2l+o8Ko+kBFZ+fvmnY+MU -VcueeowDqsPawOj2YaaifvOzzsoP4C6Uu7K8UwAXE7gnKRWjIB4EJZLEaTXBpIUM -BcBcYCqd1X+JFQxp7fID+EGxlMfTjdZM4c51y67EHzMquZSiLEGBQgE8KiJclsIN -/PjY3hlwcZpyTEnqTYLnhL5SG/1fskUWPLaJ66u+aGoo9bcfOq9AE0yzPsl6MCes +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-192-CBC,0E34605476FC4C57886CE6350CD6F61E + +yOzUZ81fSG2jBfhe7h/f2Uy7K86+VZFXVG3Y3qdQe6HD6kvQgQJLN+g8OVHan7vA +CYnKImqS5fiTIwvsMxzVWtCeY2kJ9BMNeNIoLXebD5RV93lKPBgl0IldrkfJrg0w +VNPkCHLFHWIOUA/bxYiXEeLRHuvndSkYH/JCzESiquf51chU4CIEmrbuvtvLXKta +YPO9eCw0PP1QKO/fJVrUHfp6Bsvai/J0+PG19XzkKCMsewG0MkAqpkzQrAjaCJyj +IwiqxxV72FIQDITgIQf5sY2yPzya/TjnBpu4m9D7TzQhCw9J2EDx61qvvKt3BDyq +DahaY6/T/wgcYvdoJ3RzOiWmSLvXNc1PNVY9OfQXG2EtJa/xi2BHyeHgo/Kib7Wr +nfaKgM7V998bLjiUnLK9CoD2WG3oSIrkAieNYbaD+RvU/mR/TNp5xMLMVJYduZo+ +EeyooM1a29WjOU8LPZ/AwNS4/DHnzEG1UBsUbKtyzQHiKU3JoW+5BkZ2tAs+VEWo +b5Jx9XCKfL9JepP0Ti2adAlPYU9jH6YzTpZZfu+sd2+X/N8obYssUP6bFSB0KWL0 +s/nx7DKzbXo4P+Lm04FpmeqmP3h4lhsInoozr0tP3JJKTb99kGV480eVdqDuV+Af +WJ4HLKlWxu8aHNnYb8/ATWEvh0Li0Qmx/ok8Ixa4XmHv2W0hjk7yhNewLpIwQ35X +qJgQph96gGzMGZQ3r/TjNd7YiAfPishOC/TnitIZzC/Es+zZ7QsGgBP4j1hPLAjs +OTrOvwkLuGUOoI9jJwm6343ZeGBFuWXJu0CSk4OF1EUMNziMUz9Rfw6xHSAnzff/ +YuQwDx+EtZLyyxFsfdhLjwcR38R6WoFqeDPpb3i6B5dYhHG6w60Yq5X1J4EnJgLL +4zYqVLoC6rvUuslFX2EFGrTTZP/7qRi5H3ZhNzMf/KDVbTyhzzHx27LR/8vbScA0 +IFp5NhmbmBbH7PmEF3UoVwSn/u+5iF8dmuhuOqNidImAULLCf5qCSbJNvagk9sSf +c6SdbX+EOkF6nTZYfSA0lT2u7rSfFw7khn6f+/ySRlQra7v3MBeeIuqrHEamlc73 +4hPKnl8eGcT3XvrpMnuiYADjJ4qOYzwx3YiKGqvdGzqd+ML6f2Tk31N7E53UDvSR +96gYz7IiBEkbaQSV1iZ95iiv/0m2J8B7VR5FfwvLltrmD10Alq97Gpj7HUH/Yy+8 +Wu4ADp6wdSWXMki2+QUxucIqWJ4nViE6K4FJy3SbPwtJWxiLkLQibGxdZl0jHDOl +F/FuWxjizKtOwn9rzQ+viVvYaQW1QTv5kS0d0L7FV2J8lQbsr8T86jUAJRASt5Cf +/+Z628xFSwDZjITOjhHT2GJqho/eW4h/naWgMRoThFI2l+o8Ko+kBFZ+fvmnY+MU +VcueeowDqsPawOj2YaaifvOzzsoP4C6Uu7K8UwAXE7gnKRWjIB4EJZLEaTXBpIUM +BcBcYCqd1X+JFQxp7fID+EGxlMfTjdZM4c51y67EHzMquZSiLEGBQgE8KiJclsIN +/PjY3hlwcZpyTEnqTYLnhL5SG/1fskUWPLaJ66u+aGoo9bcfOq9AE0yzPsl6MCes -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt index 98243dc9..cb31e913 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Aes.256.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: AES-256-CBC,063DE67AE11456C89BCE9D4A21BE3DFB - -6mS1GhCjAg5mEwMFcKRJwg1uxCeY3ekJNCQewIN9NSI5A8prBOQ+JSyWAsn6c3Gw -OeRyur+5dxMFdt5Hz1CBi9EePvhVyMry7U5U86BWB0HgtDAD02b324sfc6Wk+kj5 -PZvuKyXDiqdwy0rsbBUT+bLtXjCI4Ws1k/KbbF0OqGhFJJvErNU5x8zMD9mqp92R -D8ZZ/F8Sks3V/JeUisAF86sgMfVCELJobn5Zq/IaUyzQwC6IEL+Sy5fSBB5NHiex -NDIJg2RW79uLbufCpuoMPS/GKydf4dq0L5MwvKeqtUgf9Wddc+ZAE4+q1Xz/T8iN -3IMqsQfVbYjVK7uTaVGKH+Ew77Qryj01Vg+zyzdf4UwOV3XXQKLVCjNxpMCVtoq7 -S45M3Ad7598vb7ooa/BFCIcEM8TkuzPnuttLqjzXEzUcA5kqm3kV14IKtlexBfNT -tarbidlZcOinvJaoIT3baP4rVnEWDKcxpc+UzNU5RRty6l0zpRmw/9RQ5+FKreh8 -eXDHD8TT8ArdaREFM8J2OGpkmIK5sLhhYi9gnTopmKIHn8OAXusmQosEOzS6kGxk -aFtZezXSCBGgXp5RsrBGGx3oXWHGuWbEFXAq+M7PKXMQe5rLRv6sQdfTFSB5hgNK -82P8UzV1wWtAX4JYAhRh2zA8agY2arbNvbjRyjSbp9HNVBgSbVQ60JInesOqLxEg -XURuCYp4F8AeHzyO805MTNpcX7PZT2kOxp9sKKABJ9BJ0RoSWa0LJqXzGCHvrExE -g7XY/ZfDFZlPLbQnrOgVlYh7pzyfyKB74/oXHkonAisRfsgnQ87yT2DmcHNP6Cek -eae2nrpx2yn9Bf8rYdpmJgNxduO8IZvpn84xEyPqK+FbQsdOefBvsg5TgfzETkh/ -SJjzbqCTDa3XHEUCInixo/wT7FxT8KR9vk43FGPNVRUvPB2GNxe9ZwLYIir64hcQ -CpdA3ipVx4/jVzWQH8KXG9UP9TDAKXEvbndLnr2taPnUdAnznwHN2EkfzS/PrFG4 -/j3l1+VY2AyRybbCTI2iuwJPnKdxOR5oWW6I2Ksfq93Oy+NQz/zasjyNpCZBZWds -5gBmwiNk2Xzq7ikEVtVk3osOQRw/u9GbretfaT9jtClALL3DFbOzL4WxA+0NJqpd -NB2MohOJa1BJjdfh6x6EVhugH85Y9uYyz/MQj7piljAJY96190n3Q86b/7phfwuD -A/ixS42nqpyOPO+EjiWFerFVTJ3iBj7GXXOZGwCrZfpTbqE7OdTDnE3Vr4MO/Etq -kSDmJ/+4SFFh80YwYVERDNFdDxCYxx5AnxaBFwbqjzatTV/btgGVabIf6zm2L6aY -BJ5wnBZnRnsRaIMehDQmTjioMcyHBSMqId+LYQp+KFpBXqXQTEjJPnq+t4o2FF/N -8yoKR8BX6HXSO5qUndI8emwec1JeveiRai6SDnEz1EFfetYXImR290mlqt0aRjQk -t/HXRv+fmDQk5hJbCPICydcVSRyrbzxKkppVceEf9NwkBT1MBsOZIFJ3s3A9I72n -XPIab5czlgSLYA/U9nEg2XU21hKD2kRH1OF0WSlpNhN2SJFViVqlC3v36MgHoWNh +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-256-CBC,063DE67AE11456C89BCE9D4A21BE3DFB + +6mS1GhCjAg5mEwMFcKRJwg1uxCeY3ekJNCQewIN9NSI5A8prBOQ+JSyWAsn6c3Gw +OeRyur+5dxMFdt5Hz1CBi9EePvhVyMry7U5U86BWB0HgtDAD02b324sfc6Wk+kj5 +PZvuKyXDiqdwy0rsbBUT+bLtXjCI4Ws1k/KbbF0OqGhFJJvErNU5x8zMD9mqp92R +D8ZZ/F8Sks3V/JeUisAF86sgMfVCELJobn5Zq/IaUyzQwC6IEL+Sy5fSBB5NHiex +NDIJg2RW79uLbufCpuoMPS/GKydf4dq0L5MwvKeqtUgf9Wddc+ZAE4+q1Xz/T8iN +3IMqsQfVbYjVK7uTaVGKH+Ew77Qryj01Vg+zyzdf4UwOV3XXQKLVCjNxpMCVtoq7 +S45M3Ad7598vb7ooa/BFCIcEM8TkuzPnuttLqjzXEzUcA5kqm3kV14IKtlexBfNT +tarbidlZcOinvJaoIT3baP4rVnEWDKcxpc+UzNU5RRty6l0zpRmw/9RQ5+FKreh8 +eXDHD8TT8ArdaREFM8J2OGpkmIK5sLhhYi9gnTopmKIHn8OAXusmQosEOzS6kGxk +aFtZezXSCBGgXp5RsrBGGx3oXWHGuWbEFXAq+M7PKXMQe5rLRv6sQdfTFSB5hgNK +82P8UzV1wWtAX4JYAhRh2zA8agY2arbNvbjRyjSbp9HNVBgSbVQ60JInesOqLxEg +XURuCYp4F8AeHzyO805MTNpcX7PZT2kOxp9sKKABJ9BJ0RoSWa0LJqXzGCHvrExE +g7XY/ZfDFZlPLbQnrOgVlYh7pzyfyKB74/oXHkonAisRfsgnQ87yT2DmcHNP6Cek +eae2nrpx2yn9Bf8rYdpmJgNxduO8IZvpn84xEyPqK+FbQsdOefBvsg5TgfzETkh/ +SJjzbqCTDa3XHEUCInixo/wT7FxT8KR9vk43FGPNVRUvPB2GNxe9ZwLYIir64hcQ +CpdA3ipVx4/jVzWQH8KXG9UP9TDAKXEvbndLnr2taPnUdAnznwHN2EkfzS/PrFG4 +/j3l1+VY2AyRybbCTI2iuwJPnKdxOR5oWW6I2Ksfq93Oy+NQz/zasjyNpCZBZWds +5gBmwiNk2Xzq7ikEVtVk3osOQRw/u9GbretfaT9jtClALL3DFbOzL4WxA+0NJqpd +NB2MohOJa1BJjdfh6x6EVhugH85Y9uYyz/MQj7piljAJY96190n3Q86b/7phfwuD +A/ixS42nqpyOPO+EjiWFerFVTJ3iBj7GXXOZGwCrZfpTbqE7OdTDnE3Vr4MO/Etq +kSDmJ/+4SFFh80YwYVERDNFdDxCYxx5AnxaBFwbqjzatTV/btgGVabIf6zm2L6aY +BJ5wnBZnRnsRaIMehDQmTjioMcyHBSMqId+LYQp+KFpBXqXQTEjJPnq+t4o2FF/N +8yoKR8BX6HXSO5qUndI8emwec1JeveiRai6SDnEz1EFfetYXImR290mlqt0aRjQk +t/HXRv+fmDQk5hJbCPICydcVSRyrbzxKkppVceEf9NwkBT1MBsOZIFJ3s3A9I72n +XPIab5czlgSLYA/U9nEg2XU21hKD2kRH1OF0WSlpNhN2SJFViVqlC3v36MgHoWNh -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt index 5ae4cc17..32734a07 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-CBC,BD35E157CDD07CAD - -VU1aEcNJaFe1bhZ+sEzv70KQB94Pu2H+VoemLXtyIVzEQJV9+cymnRYjkgzykJ5d -s4J0vJMdiGtMH5lYRYEPQRNroOzJMwLngNyPiV8yLZARMR7tINdQyM7JBUFL4GfA -+0Jl/e7cZaCRJKAKQZu5L5DGuP6488tG7bKY9Rhzys21hPF+ck/8Gzfp1vC91AxF -zuy71e8ihEERF55DB5Ai1/lvEN15GUvkx14s0Oonfarxueu3dp/ch4P4PhzkY9Ci -7/ONnlpfrBR7bLajcXUq2XAO21ftDZejk5m6y0Z0bl0L+HpbJk2zFJGtwM+B+T3h -WkZqEK+RyTER67KUeecoKl297sh2YQtbxbdoTseUxktCb2/BSkpOHV5cgS64c3Ys -zGbk4dUmKv4HFs4VJ7HD3Ix6qAhMJyGQXOqze1c7ky9NoU2e05HdfgI/9We0EZQJ -PbequZZ4GOKnj4f70EbIEFyJldsJgijNCLKCafRYtygIs8zZkj/oE/S92iYZtesn -q2wxBAat3ZYn6tpkXx+4u9bSZ+U9OfYijxBv2x+BnAf0nQ1zNqmTOolEAIEMLS60 -5WFWKVaOeqAP0Q185TEqpUFqcaTCycV2w1hN/XXuAiYqXaSYwg4ZtCmWmxbn20QH -SMvRuY6MZSNNncgoLbm+ySq1yP1Z46kRsU1ufAyN3Jue+6DVd8wFrEOXfLJnCbFk -Eykpd7vxzczHXWgrlakl2sPFy4ltcALc8ZhsmGO+goWNqwp4QPX4LMHeUsA9n86Q -ABNV+KkCyIzp6FsFVqeHCxD8EoE/MuiuMHy/n0oEGj7zp9Moq5DHrgQDmdKnhrAG -B2HqYlCH54LDKd3wlgT76/HJ8yviFZECY2q6Z1BnMzm2ikKLCyPBMKln2eaNUqss -YNt/16DUgxpThoXfS1T8zbYHGCO0niPGMy6LYWFu0XBVgKrFcl+D1mz9vGC2CBto -VA9YhIhjtlUWwmIaJAmlTXbHCXKWLjaK9/DbsnJOlUYG5XwTC+ntW24jZnDGkHzn -Vj87JDijGzziM6qte/JM4WrUKxd6Zrvl6AaTqGH3aPxZWdFsKETfJhfbBX3vjw5+ -j6ltm4ZA+YXE2j8DLUQ8XMQlo66FUpiOj559aOXxfEb4HhJNrwo7VLsKuK56LdYb -keQmeQr+4HkDGjD0T8+0sAOx82B0TkgWYaCFU1wmzIsny+wiQmMoKJIR3T3Mzb07 -9d5ncndS7DqcdAKMuG/F9w46QWW8G0veaJlV8ws7Ags1iBOxgTKrNsQNedB7B+zw -cTqikGnDgxVfiXOBRzHq7F3ZH9HcT4SSxuM6y2YN91C2DmPbtZAwlJX5nkORANy7 -05kCAW/Md35jfVkZJsLsDDLNfRqukcWadkcKp3XvDB7/4WWFu8BrR9CHBY9j8hEt -FC4FTxZnnoDnnVg5sC8rYB6avD/MiomOUGOlHgM3MMk/Ta7fmioauCUBR5oXa/We -uhSoNyRY0/VZgE+fJ7P0Y5hzgnBDncVH5j57G0q4KTiTBDfuHBTLw+h5Htd5VBGS -5PwhKfrAvIwetRWMyRhfjixPDtcWZ2jx20fWCVxpPp+3MxBtuMgn7A== ------END RSA PRIVATE KEY----- +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-CBC,BD35E157CDD07CAD + +VU1aEcNJaFe1bhZ+sEzv70KQB94Pu2H+VoemLXtyIVzEQJV9+cymnRYjkgzykJ5d +s4J0vJMdiGtMH5lYRYEPQRNroOzJMwLngNyPiV8yLZARMR7tINdQyM7JBUFL4GfA ++0Jl/e7cZaCRJKAKQZu5L5DGuP6488tG7bKY9Rhzys21hPF+ck/8Gzfp1vC91AxF +zuy71e8ihEERF55DB5Ai1/lvEN15GUvkx14s0Oonfarxueu3dp/ch4P4PhzkY9Ci +7/ONnlpfrBR7bLajcXUq2XAO21ftDZejk5m6y0Z0bl0L+HpbJk2zFJGtwM+B+T3h +WkZqEK+RyTER67KUeecoKl297sh2YQtbxbdoTseUxktCb2/BSkpOHV5cgS64c3Ys +zGbk4dUmKv4HFs4VJ7HD3Ix6qAhMJyGQXOqze1c7ky9NoU2e05HdfgI/9We0EZQJ +PbequZZ4GOKnj4f70EbIEFyJldsJgijNCLKCafRYtygIs8zZkj/oE/S92iYZtesn +q2wxBAat3ZYn6tpkXx+4u9bSZ+U9OfYijxBv2x+BnAf0nQ1zNqmTOolEAIEMLS60 +5WFWKVaOeqAP0Q185TEqpUFqcaTCycV2w1hN/XXuAiYqXaSYwg4ZtCmWmxbn20QH +SMvRuY6MZSNNncgoLbm+ySq1yP1Z46kRsU1ufAyN3Jue+6DVd8wFrEOXfLJnCbFk +Eykpd7vxzczHXWgrlakl2sPFy4ltcALc8ZhsmGO+goWNqwp4QPX4LMHeUsA9n86Q +ABNV+KkCyIzp6FsFVqeHCxD8EoE/MuiuMHy/n0oEGj7zp9Moq5DHrgQDmdKnhrAG +B2HqYlCH54LDKd3wlgT76/HJ8yviFZECY2q6Z1BnMzm2ikKLCyPBMKln2eaNUqss +YNt/16DUgxpThoXfS1T8zbYHGCO0niPGMy6LYWFu0XBVgKrFcl+D1mz9vGC2CBto +VA9YhIhjtlUWwmIaJAmlTXbHCXKWLjaK9/DbsnJOlUYG5XwTC+ntW24jZnDGkHzn +Vj87JDijGzziM6qte/JM4WrUKxd6Zrvl6AaTqGH3aPxZWdFsKETfJhfbBX3vjw5+ +j6ltm4ZA+YXE2j8DLUQ8XMQlo66FUpiOj559aOXxfEb4HhJNrwo7VLsKuK56LdYb +keQmeQr+4HkDGjD0T8+0sAOx82B0TkgWYaCFU1wmzIsny+wiQmMoKJIR3T3Mzb07 +9d5ncndS7DqcdAKMuG/F9w46QWW8G0veaJlV8ws7Ags1iBOxgTKrNsQNedB7B+zw +cTqikGnDgxVfiXOBRzHq7F3ZH9HcT4SSxuM6y2YN91C2DmPbtZAwlJX5nkORANy7 +05kCAW/Md35jfVkZJsLsDDLNfRqukcWadkcKp3XvDB7/4WWFu8BrR9CHBY9j8hEt +FC4FTxZnnoDnnVg5sC8rYB6avD/MiomOUGOlHgM3MMk/Ta7fmioauCUBR5oXa/We +uhSoNyRY0/VZgE+fJ7P0Y5hzgnBDncVH5j57G0q4KTiTBDfuHBTLw+h5Htd5VBGS +5PwhKfrAvIwetRWMyRhfjixPDtcWZ2jx20fWCVxpPp+3MxBtuMgn7A== +-----END RSA PRIVATE KEY----- diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt index ac61e0d8..aa9250a6 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CBC.12345.txt @@ -1,30 +1,30 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,AF373EFF708479DF - -iiuyZiL4qEI7nrJQL4gQZFyYYfji0GaNntX5rPrBlBLbwQySYq5d7ExLbv3tpB++ -V1sQBHV9vcxNdq+uYqFofOuKHBXebIJLwluS+qVHC4sZoaYJxFIizl0Cf2RQzPPH -4XtAet8lrherbVm48YGAIcop9on87ILcOinNPf+0mT+wNLwFmymMkHmSByEMXU1m -7CF0GWY31rtFgfEZGw8KUjrolA0/JKUn7taLEHKHrmsXJKH2O/c7DvxMgL7ldBFk -mPVNQxsJfNGWsuU1/OzJjXWc5YYbziO2zKnJsCDpYOhATl92WABA7dPhI5jAJhWT -N1xo2JStdgy/wnyrye4WWzRZdPL47hO1bbQnpcG+VAHMsTSNngJuy1Y0pezsb7OW -2vmRM/I4QY2sPLhMOm9nbVfImJXIBukPbwpO5AtT3m+JwiyElnJcihDIaSkFTGOk -89i2tKPxWrl3obdo9CYy8ukrFMDHiOP4EGRAYFbxHLI20QDuyBEw5TR90ClCFE7P -ltM2NZRU/wCtF/4XEZ3P1KNVYu33d3hjr2J/fkba1xQ0xkCEfTXA8EgCA5ioQLie -WzdJndxuWMDZkHHeFbrLDmUBBtcv2ubC9eL6ULyeTk/v9F3gbnh46Oye3KUG64Ur -7H+NugCIDYyKdvcLl9O8JfspcNpg7ooLUliRMFCjIZI8G8V5fXqP1c4OTMaU0bGt -kBiVZeULxpKhPe8Inx4E33C1TAaHGwYezxzr9QP162ib9iWQ6hAWHizkzOYC8vRx -v0TKYR//1joVw7Wh27KOogoZEGy/gR3FZ5RxHai8inW22wlV9DobLJcib2dPkhMU -6ACAhGNwmjr1oHnCmINmKaTCxGsiqs7R13k+3qbTF5SfofOIdNzgP0rlo1X4ckuU -uA0jcNMk/R2qAn7xWDS1bdlBwj+85DlqWkKsrYuc9Jrll11HYCPoyIiY/kTahVLL -VJ+FDIjRaHEK0knjfVMtB+E3aZhaHpvLBRFNsU1POoLkqer7CyUAxD4UJSC87kIc -x8gX7kLR+ZTPuZ8Dx39jEpH+501bvoVxgDRstQkH0JTnOYJmLu/zobwAaX/+Xgdx -ALu2YJZJ8ikkFU7vbqUdzvCYKiM4srbMa+E/5wqIr6G4SSk8FupWIJWsAkczbEkH -PEfbVmWR0Lgh2i/RZU3kNqmUgV6DRfaML64z6dA13UIYIhVyg7ix6KYsJFJVKC5P -YY8No7y29htDbPqjWDZ1Y95/9foKAKhv+iNOTLfIa7H7iWYFTLYXMLt3Vsux6V9V -15+eUCe82yg7/MqcdL3IkX41AgQ6yijBWk761mbYJQ0TFNfPdtHxwKd9Rvj7nU+R -g0XhLT/b9gBNNvJeo02Hgs0axNo1WtMvd/HqYFpEx7SJf/ClniJd+kBBpn29zbLA -vaZAkxmIZc4rVeZEV8N14i9HfzmfjLM69wiMjfpO3H9nwzHHLhZCnzp483yTGKbc -EGa4dkBt3eYQDPkiK68vTt6fUfAWtiqhjmHCpOi+bZF/EfbTmz1zGIRNscFOl1Ln -bIk+F6YypdWnYjwQMr0e/RBZDVvsFH0XgHESq8hLEFXa6kWzQPIaVw== +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,AF373EFF708479DF + +iiuyZiL4qEI7nrJQL4gQZFyYYfji0GaNntX5rPrBlBLbwQySYq5d7ExLbv3tpB++ +V1sQBHV9vcxNdq+uYqFofOuKHBXebIJLwluS+qVHC4sZoaYJxFIizl0Cf2RQzPPH +4XtAet8lrherbVm48YGAIcop9on87ILcOinNPf+0mT+wNLwFmymMkHmSByEMXU1m +7CF0GWY31rtFgfEZGw8KUjrolA0/JKUn7taLEHKHrmsXJKH2O/c7DvxMgL7ldBFk +mPVNQxsJfNGWsuU1/OzJjXWc5YYbziO2zKnJsCDpYOhATl92WABA7dPhI5jAJhWT +N1xo2JStdgy/wnyrye4WWzRZdPL47hO1bbQnpcG+VAHMsTSNngJuy1Y0pezsb7OW +2vmRM/I4QY2sPLhMOm9nbVfImJXIBukPbwpO5AtT3m+JwiyElnJcihDIaSkFTGOk +89i2tKPxWrl3obdo9CYy8ukrFMDHiOP4EGRAYFbxHLI20QDuyBEw5TR90ClCFE7P +ltM2NZRU/wCtF/4XEZ3P1KNVYu33d3hjr2J/fkba1xQ0xkCEfTXA8EgCA5ioQLie +WzdJndxuWMDZkHHeFbrLDmUBBtcv2ubC9eL6ULyeTk/v9F3gbnh46Oye3KUG64Ur +7H+NugCIDYyKdvcLl9O8JfspcNpg7ooLUliRMFCjIZI8G8V5fXqP1c4OTMaU0bGt +kBiVZeULxpKhPe8Inx4E33C1TAaHGwYezxzr9QP162ib9iWQ6hAWHizkzOYC8vRx +v0TKYR//1joVw7Wh27KOogoZEGy/gR3FZ5RxHai8inW22wlV9DobLJcib2dPkhMU +6ACAhGNwmjr1oHnCmINmKaTCxGsiqs7R13k+3qbTF5SfofOIdNzgP0rlo1X4ckuU +uA0jcNMk/R2qAn7xWDS1bdlBwj+85DlqWkKsrYuc9Jrll11HYCPoyIiY/kTahVLL +VJ+FDIjRaHEK0knjfVMtB+E3aZhaHpvLBRFNsU1POoLkqer7CyUAxD4UJSC87kIc +x8gX7kLR+ZTPuZ8Dx39jEpH+501bvoVxgDRstQkH0JTnOYJmLu/zobwAaX/+Xgdx +ALu2YJZJ8ikkFU7vbqUdzvCYKiM4srbMa+E/5wqIr6G4SSk8FupWIJWsAkczbEkH +PEfbVmWR0Lgh2i/RZU3kNqmUgV6DRfaML64z6dA13UIYIhVyg7ix6KYsJFJVKC5P +YY8No7y29htDbPqjWDZ1Y95/9foKAKhv+iNOTLfIa7H7iWYFTLYXMLt3Vsux6V9V +15+eUCe82yg7/MqcdL3IkX41AgQ6yijBWk761mbYJQ0TFNfPdtHxwKd9Rvj7nU+R +g0XhLT/b9gBNNvJeo02Hgs0axNo1WtMvd/HqYFpEx7SJf/ClniJd+kBBpn29zbLA +vaZAkxmIZc4rVeZEV8N14i9HfzmfjLM69wiMjfpO3H9nwzHHLhZCnzp483yTGKbc +EGa4dkBt3eYQDPkiK68vTt6fUfAWtiqhjmHCpOi+bZF/EfbTmz1zGIRNscFOl1Ln +bIk+F6YypdWnYjwQMr0e/RBZDVvsFH0XgHESq8hLEFXa6kWzQPIaVw== -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt index 91cf550d..066d39fb 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.Encrypted.Des.Ede3.CFB.1234567890.txt @@ -1,18 +1,18 @@ ------BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CFB,81C75CC63A21DFFB - -7BCpj4mM2LTaWGP2f/IK8+Zd7XssLHtagETCURfg+x+IYhOOsW/qORNBeOL4lT8G -s8ymGJIMjNC0aGwJb214Kp19ajMlRN8IaHtw1QD3BYIxFSx35DSWd6WrECcdaJCm -FZ5y+rXf0NMUOUKg9xXF+Xnbucau3QN4NiLBB50oJyRIRco6Wy/9AB1yKrZsll4N -3+1XnnXZuanvIugi8TybUgzyrGE1dqwyGjHtN+bf8hWu8jrnx3AkjmzXJ+yiGbd4 -w/JYfCzyVsEZuEzkn62johwNpwcuXFYEXxSSU444/TZf2BuuvvpkbCltkfvhOC3z -fp1DOtToaZadwHsH8laB+HPktisfetoPaQdqi/fGgqiERzDq9Xy7wY9JXdT65WeU -mh+USBy7mF6I57UgRM6AAZLvrJmG+hE8GYezThT9ZEnFyumrQgt8sTdWWFStYJcW -jlohuNO8c4IXwvXfVgafaIIAcFUcAKk/XgSLjMcn7YyBlaR6qIdwLLfRNEspv9mR -IF0M2ua4vZRLJfn+NOcs0n10v0jUFgMXoIqDr86OB3pW3ud/lET6bz6QYO3rNHW4 -NtAmD2wwl66nuq2d9uLUSSkQj5spVDbFzfvnZCN3yl4hdyWlmzRJqybyr5xTIbT7 -x5JF/eg3xq8weaZrFqq7r5uIhDYI7/sexxL9M/8nyV8COUYkDxxISbNpoDuCKbv8 -fyIX92mGQtM8D7YftvCbEr8kw1fga9XhkDdOEuBzKZyIAD50xE39rFFMNNq8l8/Y -Gxo8zq0rW/IsrwvhWLLGtvmy68Be+WAi/mDHf6x4 +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CFB,81C75CC63A21DFFB + +7BCpj4mM2LTaWGP2f/IK8+Zd7XssLHtagETCURfg+x+IYhOOsW/qORNBeOL4lT8G +s8ymGJIMjNC0aGwJb214Kp19ajMlRN8IaHtw1QD3BYIxFSx35DSWd6WrECcdaJCm +FZ5y+rXf0NMUOUKg9xXF+Xnbucau3QN4NiLBB50oJyRIRco6Wy/9AB1yKrZsll4N +3+1XnnXZuanvIugi8TybUgzyrGE1dqwyGjHtN+bf8hWu8jrnx3AkjmzXJ+yiGbd4 +w/JYfCzyVsEZuEzkn62johwNpwcuXFYEXxSSU444/TZf2BuuvvpkbCltkfvhOC3z +fp1DOtToaZadwHsH8laB+HPktisfetoPaQdqi/fGgqiERzDq9Xy7wY9JXdT65WeU +mh+USBy7mF6I57UgRM6AAZLvrJmG+hE8GYezThT9ZEnFyumrQgt8sTdWWFStYJcW +jlohuNO8c4IXwvXfVgafaIIAcFUcAKk/XgSLjMcn7YyBlaR6qIdwLLfRNEspv9mR +IF0M2ua4vZRLJfn+NOcs0n10v0jUFgMXoIqDr86OB3pW3ud/lET6bz6QYO3rNHW4 +NtAmD2wwl66nuq2d9uLUSSkQj5spVDbFzfvnZCN3yl4hdyWlmzRJqybyr5xTIbT7 +x5JF/eg3xq8weaZrFqq7r5uIhDYI7/sexxL9M/8nyV8COUYkDxxISbNpoDuCKbv8 +fyIX92mGQtM8D7YftvCbEr8kw1fga9XhkDdOEuBzKZyIAD50xE39rFFMNNq8l8/Y +Gxo8zq0rW/IsrwvhWLLGtvmy68Be+WAi/mDHf6x4 -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Data/Key.RSA.txt b/src/Renci.SshNet.Tests/Data/Key.RSA.txt index bdd30e06..cf2cc979 100644 --- a/src/Renci.SshNet.Tests/Data/Key.RSA.txt +++ b/src/Renci.SshNet.Tests/Data/Key.RSA.txt @@ -1,27 +1,27 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEoQIBAAKCAQEAuTtXn+BatX1oJuvhqfJZw5jc/pcIxJUPmuoFCH3+bXfKBJ/9 -4ixNETzZBasyvT/ozboAbCG3qcJOYxf2BEeTAIXe1jLAoTd1GKCwMvZOyjnsPN95 -/lChwfdnBbMzpZYTGfoUylXme/mzjjLu/J0qXgR5lyk9HFT+x5YEtRl8VSHiDkLK -TZ37dwhsqgcs+PkfvYMUK+C8evnfE0tgWgKZk0Eatl87nLWyVXB4LzhSDtGKLCPA -OgrX7fYfplDwJ2WK1N6nG0FnxW1HhDeSK7e2TbAa2vZQgvFXMWnO4O/NZKp4COpO -ReyliWhdtKAjr/+cD4yDfPjhjjKOYfxbvdRG4QIBIwKCAQAqVrTxV9o4HKoXhl93 -TVZYl/f/rX5Y0Z0quSW4zFdpendRg6e+qwpNFTjrWlS9ivNiOSSrAGR+ktAWpmQe -PD7bjFAw9ahfXSIUQfxja3+5Mc+Y4p+KlhZYOIyTlqy4Ik2CR8o84G8yR7QDPteK -Mo1XUXrguPgGedPV2SWlvK60XyAXqsewDhi7SeImZomKzbh33SXjVxakzHfa8BEU -eIIeR9oFlQMuYdo4GrHhFO2T+g/gqw/kVd1zkeEwt06fZVDErVwp+twewxxvwrk4 -CKUCzavfhDfi5sJ5YdzhDBRgkyBgJI+f15dKyqqOiAparV9+uzrD6vIuNnlVoqQA -iugLAoGBAPBliy32e83nshBknBn5HOK2rO3a1zHxvYr/NzITXtdZOjatNyfXtkwi -Ll/el5tZhJvKe9nItSI/4w7mvlvXZfW8h3MR0qb8at4jWa8ya2hwEerqaJonqjjb -+eBhg27ltZIQRk8Bv6ApXTAWkc+dFGhEIysokDQX7V72Bdrizup1AoGBAMVBLHK0 -5IFb8x7danlAmDX6bqCObId4Pce2OeONFIj1jIowvCXaE0t9zU4X5SdN5ujqu4Dq -XgzUdNeKcJxWpFO74MDRxT3CbMz36fikJnvxWl/+q0HalYuCY8gm14VYcThUBAro -3c941INueybGNLIA9jc7RMnsFtyVTvNYpaU9AoGAFJr9TRUgjf3qsPKuS15+0Zqh -G7OsC5hgtCSBEuu3rA72XHU/Pe3rDdcLSgvD2h2dpvQZPo2L3l0/WQx2t2o78H3f -uWftfAcB2Iav6nIJNNZn75BvXaug4E1ej5NUaJdYtL+Q/3UtrqR1s6opwVabWWTt -ElPvGmhzboodwk30en8CgYAyuPzNCfGdm00lMZ8JPH7pTwaBDq4xdrDM9FgHUCna -E0FlXP0uTgT2J6nSQKijtPI75JadfhgvL1E+vTLmX2wViBU45XvcrlZ92Vlr0nBL -wbgnUB1otIzauyD49AuIsFegxSWcZ8QCJmKIMlouir0X1FyR3Apfzv6Qfio+kyNH -vwKBgQCtwxojkzUSfV3zDt6bYSLBzgXgo/Zr9lS+gSggP72DzINmW2gbA0fkM2Zu -JltcfakKv4gVX/1zooz+7t+4bj6dqt+bl7hYz0VnTSDZGuo5LKDif/4gSGrdblC2 -QLTuX2HjWCZdsue7mRwL7cXR4zlIoE99+Ryhdxvc5wHSfYr/JA== +-----BEGIN RSA PRIVATE KEY----- +MIIEoQIBAAKCAQEAuTtXn+BatX1oJuvhqfJZw5jc/pcIxJUPmuoFCH3+bXfKBJ/9 +4ixNETzZBasyvT/ozboAbCG3qcJOYxf2BEeTAIXe1jLAoTd1GKCwMvZOyjnsPN95 +/lChwfdnBbMzpZYTGfoUylXme/mzjjLu/J0qXgR5lyk9HFT+x5YEtRl8VSHiDkLK +TZ37dwhsqgcs+PkfvYMUK+C8evnfE0tgWgKZk0Eatl87nLWyVXB4LzhSDtGKLCPA +OgrX7fYfplDwJ2WK1N6nG0FnxW1HhDeSK7e2TbAa2vZQgvFXMWnO4O/NZKp4COpO +ReyliWhdtKAjr/+cD4yDfPjhjjKOYfxbvdRG4QIBIwKCAQAqVrTxV9o4HKoXhl93 +TVZYl/f/rX5Y0Z0quSW4zFdpendRg6e+qwpNFTjrWlS9ivNiOSSrAGR+ktAWpmQe +PD7bjFAw9ahfXSIUQfxja3+5Mc+Y4p+KlhZYOIyTlqy4Ik2CR8o84G8yR7QDPteK +Mo1XUXrguPgGedPV2SWlvK60XyAXqsewDhi7SeImZomKzbh33SXjVxakzHfa8BEU +eIIeR9oFlQMuYdo4GrHhFO2T+g/gqw/kVd1zkeEwt06fZVDErVwp+twewxxvwrk4 +CKUCzavfhDfi5sJ5YdzhDBRgkyBgJI+f15dKyqqOiAparV9+uzrD6vIuNnlVoqQA +iugLAoGBAPBliy32e83nshBknBn5HOK2rO3a1zHxvYr/NzITXtdZOjatNyfXtkwi +Ll/el5tZhJvKe9nItSI/4w7mvlvXZfW8h3MR0qb8at4jWa8ya2hwEerqaJonqjjb ++eBhg27ltZIQRk8Bv6ApXTAWkc+dFGhEIysokDQX7V72Bdrizup1AoGBAMVBLHK0 +5IFb8x7danlAmDX6bqCObId4Pce2OeONFIj1jIowvCXaE0t9zU4X5SdN5ujqu4Dq +XgzUdNeKcJxWpFO74MDRxT3CbMz36fikJnvxWl/+q0HalYuCY8gm14VYcThUBAro +3c941INueybGNLIA9jc7RMnsFtyVTvNYpaU9AoGAFJr9TRUgjf3qsPKuS15+0Zqh +G7OsC5hgtCSBEuu3rA72XHU/Pe3rDdcLSgvD2h2dpvQZPo2L3l0/WQx2t2o78H3f +uWftfAcB2Iav6nIJNNZn75BvXaug4E1ej5NUaJdYtL+Q/3UtrqR1s6opwVabWWTt +ElPvGmhzboodwk30en8CgYAyuPzNCfGdm00lMZ8JPH7pTwaBDq4xdrDM9FgHUCna +E0FlXP0uTgT2J6nSQKijtPI75JadfhgvL1E+vTLmX2wViBU45XvcrlZ92Vlr0nBL +wbgnUB1otIzauyD49AuIsFegxSWcZ8QCJmKIMlouir0X1FyR3Apfzv6Qfio+kyNH +vwKBgQCtwxojkzUSfV3zDt6bYSLBzgXgo/Zr9lS+gSggP72DzINmW2gbA0fkM2Zu +JltcfakKv4gVX/1zooz+7t+4bj6dqt+bl7hYz0VnTSDZGuo5LKDif/4gSGrdblC2 +QLTuX2HjWCZdsue7mRwL7cXR4zlIoE99+Ryhdxvc5wHSfYr/JA== -----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs b/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs index f68e8b94..443203d0 100644 --- a/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.Tests/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Tests .NET 4.0")] -[assembly: Guid("defb66b2-a4b9-40ca-b205-2183d84b7323")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Tests .NET 4.0")] +[assembly: Guid("defb66b2-a4b9-40ca-b205-2183d84b7323")] diff --git a/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs b/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs index 51f0afb9..cfec397f 100644 --- a/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs +++ b/src/Renci.SshNet.Tests/Properties/Resources.Designer.cs @@ -1,206 +1,206 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.18033 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Renci.SshNet.Tests.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Renci.SshNet.Tests.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///Proc-Type: 4,ENCRYPTED - ///DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 - /// - ///nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva - ///swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI - ///qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 - ///2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP - ///iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd - ///nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm - ///P+lkxKf2RWnh406F [rest of string was truncated]";. - /// - internal static string DSA_KEY_WITH_PASS { - get { - return ResourceManager.GetString("DSA_KEY_WITH_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw - ///fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe - ///bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 - ///UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr - ///u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB - ///xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM - ///HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH - ///4UOFA/UFdQ0TYXXW0 [rest of string was truncated]";. - /// - internal static string DSA_KEY_WITHOUT_PASS { - get { - return ResourceManager.GetString("DSA_KEY_WITHOUT_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 192.168.10.192. - /// - internal static string HOST { - get { - return ResourceManager.GetString("HOST", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- - ///MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO - ///h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P - ///12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT - ///1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO - ///eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy - ///wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq - ///JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi - ///YTV9H2SWRF6UF+GiR [rest of string was truncated]";. - /// - internal static string INVALID_KEY { - get { - return ResourceManager.GetString("INVALID_KEY", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to tester. - /// - internal static string PASSWORD { - get { - return ResourceManager.GetString("PASSWORD", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 22. - /// - internal static string PORT { - get { - return ResourceManager.GetString("PORT", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org. - /// - internal static string PROXY_HOST { - get { - return ResourceManager.GetString("PROXY_HOST", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to 8123. - /// - internal static string PROXY_PORT { - get { - return ResourceManager.GetString("PROXY_PORT", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- - ///Proc-Type: 4,ENCRYPTED - ///DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 - /// - ///Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr - ///uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG - ///FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ - ///OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB - ///nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ - ///bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 - ///SMP7QVfPf5aJIaa8 [rest of string was truncated]";. - /// - internal static string RSA_KEY_WITH_PASS { - get { - return ResourceManager.GetString("RSA_KEY_WITH_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- - ///MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D - ///9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl - ///9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba - ///orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb - ///d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q - ///mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz - ///9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA - ///RW493jlECIBWjd+1a [rest of string was truncated]";. - /// - internal static string RSA_KEY_WITHOUT_PASS { - get { - return ResourceManager.GetString("RSA_KEY_WITHOUT_PASS", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to tester. - /// - internal static string USERNAME { - get { - return ResourceManager.GetString("USERNAME", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.18033 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Renci.SshNet.Tests.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Renci.SshNet.Tests.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///Proc-Type: 4,ENCRYPTED + ///DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 + /// + ///nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva + ///swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI + ///qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 + ///2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP + ///iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd + ///nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm + ///P+lkxKf2RWnh406F [rest of string was truncated]";. + /// + internal static string DSA_KEY_WITH_PASS { + get { + return ResourceManager.GetString("DSA_KEY_WITH_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw + ///fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe + ///bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 + ///UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr + ///u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB + ///xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM + ///HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH + ///4UOFA/UFdQ0TYXXW0 [rest of string was truncated]";. + /// + internal static string DSA_KEY_WITHOUT_PASS { + get { + return ResourceManager.GetString("DSA_KEY_WITHOUT_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 192.168.10.192. + /// + internal static string HOST { + get { + return ResourceManager.GetString("HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN DSA PRIVATE KEY----- + ///MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO + ///h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P + ///12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT + ///1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO + ///eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy + ///wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq + ///JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi + ///YTV9H2SWRF6UF+GiR [rest of string was truncated]";. + /// + internal static string INVALID_KEY { + get { + return ResourceManager.GetString("INVALID_KEY", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tester. + /// + internal static string PASSWORD { + get { + return ResourceManager.GetString("PASSWORD", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 22. + /// + internal static string PORT { + get { + return ResourceManager.GetString("PORT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to proxy.oleg-centos.edc.renci.org. + /// + internal static string PROXY_HOST { + get { + return ResourceManager.GetString("PROXY_HOST", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 8123. + /// + internal static string PROXY_PORT { + get { + return ResourceManager.GetString("PROXY_PORT", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- + ///Proc-Type: 4,ENCRYPTED + ///DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 + /// + ///Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr + ///uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG + ///FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ + ///OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB + ///nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ + ///bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 + ///SMP7QVfPf5aJIaa8 [rest of string was truncated]";. + /// + internal static string RSA_KEY_WITH_PASS { + get { + return ResourceManager.GetString("RSA_KEY_WITH_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to -----BEGIN RSA PRIVATE KEY----- + ///MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D + ///9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl + ///9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba + ///orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb + ///d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q + ///mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz + ///9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA + ///RW493jlECIBWjd+1a [rest of string was truncated]";. + /// + internal static string RSA_KEY_WITHOUT_PASS { + get { + return ResourceManager.GetString("RSA_KEY_WITHOUT_PASS", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to tester. + /// + internal static string USERNAME { + get { + return ResourceManager.GetString("USERNAME", resourceCulture); + } + } + } +} diff --git a/src/Renci.SshNet.Tests/Properties/Resources.resx b/src/Renci.SshNet.Tests/Properties/Resources.resx index 60fb7011..c392eb5c 100644 --- a/src/Renci.SshNet.Tests/Properties/Resources.resx +++ b/src/Renci.SshNet.Tests/Properties/Resources.resx @@ -1,244 +1,244 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - -----BEGIN DSA PRIVATE KEY----- -MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw -fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe -bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 -UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr -u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB -xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM -HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH -4UOFA/UFdQ0TYXXW0wRX/amynT4iTEXAx0FjxUNK5ryxloeoXiXEH4FK7D8RtJO1 -1UsaRrN+nqWiSTVAehl6tzoMCPargGcWeFlAZZnPGN76OD9J1GiKZj8CFQCl8SkF -GWfS+mH8xhLsxh1nI7rfJw== ------END DSA PRIVATE KEY----- - - - -----BEGIN DSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 - -nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva -swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI -qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 -2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP -iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd -nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm -P+lkxKf2RWnh406FxBvBZzwB3rQeeM7QTg2IcFqGnlf005FIikp6SlyhZ/3M/Nl3 -FW235vuO37jLCL8qosGt4NOWAstXaxDujfIb/Q+IYxUpWZrdiH5tM/mUXARK0Sjf -D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM -7jB0kNVZrz3qUKnoJHIozA== ------END DSA PRIVATE KEY----- - - - 192.168.10.192 - - - -----BEGIN DSA PRIVATE KEY----- -MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO -h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P -12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT -1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO -eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy -wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq -JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi -YTV9H2SWRF6UF+GiR5SajChveS106T9O+tepip+7V5YgFfW+ALOxwar+6V8VoUF4 -xNvNTWtaw+wK8xsgxhhYDaWVhVLVhR40QmeQhx/BQm+EYkSSa9kkCQIURGd0R+Zj -tM7dZpB+reWl9L5e2L8= ------END DSA PRIVATE KEY----- - - - tester - - - 22 - - - proxy.oleg-centos.edc.renci.org - - - 8123 - - - -----BEGIN RSA PRIVATE KEY----- -MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D -9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl -9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba -orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb -d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q -mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz -9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA -RW493jlECIBWjd+1aZWPM2vGKJtTp2q802u6DOX9cbgFUcVB899ugFqDjREVxLqU -dBqhtjDJQ0sTPBVy2CBkrsrvLy7AZd4LlaqxpdTdpkD/auUxg4zdThHT/XeQ0V0G -3BS5vGehfqgkDOQpQSm7HexM+9GDJnnzMdNXjmWBPxZU49QAlxujZeZ1M2IgKwMq -eNkWAOnZJidfsfwYluSCi8OHPN2i1s/b7pgn6ffb50S/k2mmhTHxNChDdGTlW91G -6CFLAoGBAPlGA4qzZCG4SLBQicGhhXZlwaKKfTvWNi4xNPZeoJezC0G+yZZT7IIV -zCj83t3dteaRRw15e+7NuIXZx3zl2hANfEpBZwnS4sOekvbS9/S7cEVzOEk53jRU -TOtHRsvNxS2xK3RywqoaqzcPaK2Df917yzbqvEajMRudRPrsTvYdAoGBAPggB/kJ -+VxZf13JqV2KgrFoVvykJpRlw2F5+lkH69ON9gdl976J3TNJDqAmHeWFxBUL+6Lt -9TSpMq3fYueJXg9xaTkSYg177sPRGCmRLO5aneA4nJkIB6KHRXsR71C9D4fJK8Fi -YB5n5dnBUTBhkvaI6KsxcxDzEg2zAJEcn4WNAoGBAOsHf66pI+VHWnpakINdxvqa -dL3TCFz9K8UnFK3G7y/x9Kuz4qOuNsPLaLjua7s+wXL+ASn2MwW6pqoWekKPkxZz -HWqVb8dvEFIKipDyzIepadsU3UxbIfbTI/PG3FnCAw3S7nUbvtrl8eN07arpsxKn -63zr81iLPO4mkX7ezhs/AoGADi23UA8y0hO+Ip3PKeqoYei0g3cYJbysFDLbGwfE -VTtP4ypl7aF6WrO3sWFDiXVbqW5mJpFBNjWN3gzD0rdkdek5NnYUO0jpEoD6EQD7 -QNH6ZJWFSpK+m5Kzg2AcTcGpHbO5W4H23SqCKbNGd8sPtlD3Wj1XCEhnbn9B3GgJ -HZMCgYEAjn9BH4fcobMaM15AV0s6sCEyr/vzn3QBfoIBqqqlipMqOtPDv8oyvGO4 -5tSpMrTKf4e3YAMPA4TXRAiVLjeRYlhdj3He0LkAuZZabrHeRmWqjDruMWd1TcKZ -3o8DLgYbSH7eGXUJ+euM4spKr5OLkBEkmH7Of6Qxss2njvjVNTE= ------END RSA PRIVATE KEY----- - - - -----BEGIN RSA PRIVATE KEY----- -Proc-Type: 4,ENCRYPTED -DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 - -Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr -uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG -FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ -OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB -nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ -bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 -SMP7QVfPf5aJIaa8t+SlpvtIFTIkEhTViOCl+udT04670DGwmJUgrJAV0r+/Ytf7 -Mi+m3DagN7gGmCvYo+7r7EBl1G6e3hCSYm0rFxGOBesmCWriRoeRpxirWnkrns57 -D57pEC1hg90IdycCGpiwqubGDKFljuMLiVd2w0onVhudShPszP+nJAaq18wUB+rE -mtBv+GlpqCITREB4lG2noP4r9P9lgrOTqmKvWjvUTQjfS3u0XO/1aQllKlwe97C7 -mfOxcZQWy5F7+9CiWpDpomW7Eso89ja6uyupw4Q4gsm7EUacqOOaVxHrm3MVhYjE -Bfk9I5agKFqeHdjBUUP0DQ6X7JUEtb/Ri8ZrFnyT8sBG7JYnMTXfjPQqdR493cp2 -hWI5reZLi4CCUqt4Pcmhm2vtwJz5HXChARPYq2C3DhdJHcdhxUr97rfTGE1w8mPY -JcwSFnNN47UBcDg6nvSfY3SJKV0gmmqz9fEw1pBoCrudJKw9U0vQrNoCEJOpEETG -4XojbAMsTr0Ps5fI2X1VbVYWtU1uyZxqF8KaTCTN1Paapmqaq4N+qIFrrXA+PTH+ -dyaMLmYJ263Gy5eNkCZMeWLDFZ9WHX/Zx2ERMXfI6fyGImXkb6E0Dia+bB087BZP -9C5gHAvZIjv+FosZrViFqDfrV5hDXL6bO3+V3zieemRxRCTvMtk+RXUJDd50qIOW -gKNcSbevLPOyQH7eQbR+fU4KtJDUigbTFunSn2MZkDl2GDDlKI35wUAVr5yGsJbE -yiIQe5DgLGZcMiEpqbhuqSfuOw0cUlFVyKeNZ/Hr701HWngLt677IY8ExyuNbBfT -PRaes+hcjJ1QmJoRHZx9rQ3w0IpezCpRkRLRKJzzuQZOuwd95whKFXroFsdeaHxO -hS4PqlLbuSMLiSIaPSZM6Huc4kb5lqCaxg/SBlXTCX17Z/8TFoqV/wCJz17XnkH6 -9WtKAC2TwKxiLZ2Qzwr2XV48lASugIOZkSW2qxM9ui+b1T9ICFKRGLn/UB//pOiG -270hNJDLB/BKRExjS+RXeOpdAIJB5XsAEp8h56ub9emhhf9tCEXOn7PN7HbMCnQh -7k8EpAG0h5StLUhY1HHvynVz2/qyMvZa/bIaaudL2565Z6nDU+iBxed7O1qrbRAH -Vakr7Sa3K5niCyH5kxdyO1t29l1ksBqpDUrj+vViFuLkd3XIiui8IA== ------END RSA PRIVATE KEY----- - - - tester - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + -----BEGIN DSA PRIVATE KEY----- +MIIBvAIBAAKBgQDdQrrwGvknwD+pb9Gpv/vDxj8yqFUg0cUuC/tkjm3u+lQj86Rw +fA8RJOV+OP4Gtvs9zOSsxiuginoB/uEiT+6jbHvyvJeJp2fsDWLx/tVRXxpi8Nwe +bfb455R0wVVZdqnFKsAZLrQAT589EUtLgyVAFQbUP5Fz6px8H8AG0qlybQIVALn7 +UOxnbFR7fDfZkq2Pc7ZCVegpAoGBANRKf9vezuz1aGUnUGWILHO09SibHK255fkr +u4//zvCbdawWSZOoU+vMnplLUhNaVMoSyYE/TYOZvvbG9UtPvr8wZGdNPipvIXIB +xlpr+FH0mnSx0qlaRy3PEoDRAmw6msRCzVYV3vZ8ZTEUdt+phuru+pn0W9EugzCM +HikVVhJMAoGASHB5nNlWhpqvungn+otYyGKoVoATkRdRfSiUo3fb0mJLTmxrEhEH +4UOFA/UFdQ0TYXXW0wRX/amynT4iTEXAx0FjxUNK5ryxloeoXiXEH4FK7D8RtJO1 +1UsaRrN+nqWiSTVAehl6tzoMCPargGcWeFlAZZnPGN76OD9J1GiKZj8CFQCl8SkF +GWfS+mH8xhLsxh1nI7rfJw== +-----END DSA PRIVATE KEY----- + + + -----BEGIN DSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,053105DCFC6132E7 + +nVjIhJr3Eeqk0aBfyYK38B6cF0g35U2acgq5t3zG8fCM5JLSnFcmkkYvohbmCLva +swNHMfmwumoX8Ga94cxGu6vW1qf+IMvgEU4U53DtJqRoeICMwIre1yUq2cCrV+gI +qQ6MAVMDgfMs7HrPs5999m+KoDh7oYsA1l5q+axU/rqM4g3lySr/1oT6oAQx5Qp2 +2DYkZEwnX5+NTw6aoMXl2qgIHBVxa7wZRMp9L0yAlEFk8T7fMuPrLSAEUBghcIaP +iBY1OY+M9MgDTTU56ZjLl+DfT3XfKzsZ3fmn1+bLqTRreiuS4/WF6xIa/DQu1sQd +nnjYgnKYcTWSvWWK9AcIVSpoiW2y6FcPkMAIw54ABrzBp4Rz0//Ykwv2Ga7AZxxm +P+lkxKf2RWnh406FxBvBZzwB3rQeeM7QTg2IcFqGnlf005FIikp6SlyhZ/3M/Nl3 +FW235vuO37jLCL8qosGt4NOWAstXaxDujfIb/Q+IYxUpWZrdiH5tM/mUXARK0Sjf +D8DHbFwAT2mUv1QxRXYJO1y4pENboEzT6LUqxJgE+ae/F/29g2RD9DhtwqKqWjhM +7jB0kNVZrz3qUKnoJHIozA== +-----END DSA PRIVATE KEY----- + + + 192.168.10.192 + + + -----BEGIN DSA PRIVATE KEY----- +MIIBugIBAAKBgQCG3ij/JvdNp+1VUsK2zmLM5QWNN4MRRm/FCOHDknDJrWdSKheO +h6BbCgyFOw+k5qYtwXQnt3DpQfxPi7PIjr3tQJ9gB8LzqH2DwT2hMXm9VV2ImX2P +12aj8hZVM99WOp/ma6+ivLSFHnwET19eaqS9SRb0ftIqZXpWGE3ddW07qQIVAOfT +1OPSsvAnOsSrYc5HG5K3xIWlAoGAAzhTmi29+v0YTIsW2W1FihsexeAnpPPjYgRO +eT6HreyTvh20UASxDP+IJ2Ba+41G6MU0isuAijp8Z4CCC4RpoS46Ksc3JtPsZiRy +wAjwlb7JKGRBoY8V3aT47Xyx+iTSclZfzTmv0Z0bb56NZ6KEU8WRnks2d7tsb0fq +JTAgLkkCgYBvt5EoxhlCwEUgm8j3nD4TLSRYt1lt6LVulBYA9qlV4F68b2cJUuOi +YTV9H2SWRF6UF+GiR5SajChveS106T9O+tepip+7V5YgFfW+ALOxwar+6V8VoUF4 +xNvNTWtaw+wK8xsgxhhYDaWVhVLVhR40QmeQhx/BQm+EYkSSa9kkCQIURGd0R+Zj +tM7dZpB+reWl9L5e2L8= +-----END DSA PRIVATE KEY----- + + + tester + + + 22 + + + proxy.oleg-centos.edc.renci.org + + + 8123 + + + -----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEA8ZsD8jgH7ySXnd4dprEFFkJ+zs1ne81E8febjR8hekiKrc+D +9GjeEykchy0PsrsBrf2F8J3GtLNISVerkl+EnVh1E0pi9Vllc1vcpQHvBeNPG/jl +9Dnum/DcaaMKLot+ARXjBuMX/xJVfnlgkvfpBvoq4QzQ6E27rOMbcPlvrN7KeYba +orsTpDMUraHX5u99P1evvw7sOuNl3lc9YpIgmjHT6dWUGTqBx9T2SEKXBRVk2NNb +d2UctQkr5BJn1gGehA+1KYS30FMiCSN8F8ZOlpYj1+K6xzs0srq1z30LailIyy7Q +mYp739BJlOF3cVywdcFXGre35H2cJylcNV2e+QIBIwKCAQAbnK/+bM207j02nQqz +9vlEX17zECkVdouJXiBn5kz4CEpdAcXwC/wfcmmpDHbSmQeBmVEi0DP3ZPJRhlzA +RW493jlECIBWjd+1aZWPM2vGKJtTp2q802u6DOX9cbgFUcVB899ugFqDjREVxLqU +dBqhtjDJQ0sTPBVy2CBkrsrvLy7AZd4LlaqxpdTdpkD/auUxg4zdThHT/XeQ0V0G +3BS5vGehfqgkDOQpQSm7HexM+9GDJnnzMdNXjmWBPxZU49QAlxujZeZ1M2IgKwMq +eNkWAOnZJidfsfwYluSCi8OHPN2i1s/b7pgn6ffb50S/k2mmhTHxNChDdGTlW91G +6CFLAoGBAPlGA4qzZCG4SLBQicGhhXZlwaKKfTvWNi4xNPZeoJezC0G+yZZT7IIV +zCj83t3dteaRRw15e+7NuIXZx3zl2hANfEpBZwnS4sOekvbS9/S7cEVzOEk53jRU +TOtHRsvNxS2xK3RywqoaqzcPaK2Df917yzbqvEajMRudRPrsTvYdAoGBAPggB/kJ ++VxZf13JqV2KgrFoVvykJpRlw2F5+lkH69ON9gdl976J3TNJDqAmHeWFxBUL+6Lt +9TSpMq3fYueJXg9xaTkSYg177sPRGCmRLO5aneA4nJkIB6KHRXsR71C9D4fJK8Fi +YB5n5dnBUTBhkvaI6KsxcxDzEg2zAJEcn4WNAoGBAOsHf66pI+VHWnpakINdxvqa +dL3TCFz9K8UnFK3G7y/x9Kuz4qOuNsPLaLjua7s+wXL+ASn2MwW6pqoWekKPkxZz +HWqVb8dvEFIKipDyzIepadsU3UxbIfbTI/PG3FnCAw3S7nUbvtrl8eN07arpsxKn +63zr81iLPO4mkX7ezhs/AoGADi23UA8y0hO+Ip3PKeqoYei0g3cYJbysFDLbGwfE +VTtP4ypl7aF6WrO3sWFDiXVbqW5mJpFBNjWN3gzD0rdkdek5NnYUO0jpEoD6EQD7 +QNH6ZJWFSpK+m5Kzg2AcTcGpHbO5W4H23SqCKbNGd8sPtlD3Wj1XCEhnbn9B3GgJ +HZMCgYEAjn9BH4fcobMaM15AV0s6sCEyr/vzn3QBfoIBqqqlipMqOtPDv8oyvGO4 +5tSpMrTKf4e3YAMPA4TXRAiVLjeRYlhdj3He0LkAuZZabrHeRmWqjDruMWd1TcKZ +3o8DLgYbSH7eGXUJ+euM4spKr5OLkBEkmH7Of6Qxss2njvjVNTE= +-----END RSA PRIVATE KEY----- + + + -----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,B3475536EDD1B442 + +Xa6Y7FYTfz19CMzPcVbCpBHEh8x3tnA9PutKEDNMwKbR+NVUvBx5fN1QjrLpltCr +uX7yD3vLCeyihg4oaK3nTBZBcsB/1TZx+MlLgpvMfV1JKmbKCmebBZ3lUpsypHlG +FpCY41miFwdHmBe6tuwL9XA3vz26eJwSgJGMkVN9EBvNbiOHinEPhSW0whzBfbv+ +OfseG73gvHc4jZS6Sw8h5VDBAmlldJEfkP/s/1/iTbCXFQ22xRb4Z6NilEyKiWpB +nQviXmaucTWCEuNF5QDA7oV7Ugwm5cAXuBqFIs9ZGaKV4/XpfX1tClOLfB3Lguh+ +bbkwjPb0ztlhKa4gkwXiMs0S/lhoueXBae4QStM0qJBXHtFhhRYIn4JeIZ8CJ0k6 +SMP7QVfPf5aJIaa8t+SlpvtIFTIkEhTViOCl+udT04670DGwmJUgrJAV0r+/Ytf7 +Mi+m3DagN7gGmCvYo+7r7EBl1G6e3hCSYm0rFxGOBesmCWriRoeRpxirWnkrns57 +D57pEC1hg90IdycCGpiwqubGDKFljuMLiVd2w0onVhudShPszP+nJAaq18wUB+rE +mtBv+GlpqCITREB4lG2noP4r9P9lgrOTqmKvWjvUTQjfS3u0XO/1aQllKlwe97C7 +mfOxcZQWy5F7+9CiWpDpomW7Eso89ja6uyupw4Q4gsm7EUacqOOaVxHrm3MVhYjE +Bfk9I5agKFqeHdjBUUP0DQ6X7JUEtb/Ri8ZrFnyT8sBG7JYnMTXfjPQqdR493cp2 +hWI5reZLi4CCUqt4Pcmhm2vtwJz5HXChARPYq2C3DhdJHcdhxUr97rfTGE1w8mPY +JcwSFnNN47UBcDg6nvSfY3SJKV0gmmqz9fEw1pBoCrudJKw9U0vQrNoCEJOpEETG +4XojbAMsTr0Ps5fI2X1VbVYWtU1uyZxqF8KaTCTN1Paapmqaq4N+qIFrrXA+PTH+ +dyaMLmYJ263Gy5eNkCZMeWLDFZ9WHX/Zx2ERMXfI6fyGImXkb6E0Dia+bB087BZP +9C5gHAvZIjv+FosZrViFqDfrV5hDXL6bO3+V3zieemRxRCTvMtk+RXUJDd50qIOW +gKNcSbevLPOyQH7eQbR+fU4KtJDUigbTFunSn2MZkDl2GDDlKI35wUAVr5yGsJbE +yiIQe5DgLGZcMiEpqbhuqSfuOw0cUlFVyKeNZ/Hr701HWngLt677IY8ExyuNbBfT +PRaes+hcjJ1QmJoRHZx9rQ3w0IpezCpRkRLRKJzzuQZOuwd95whKFXroFsdeaHxO +hS4PqlLbuSMLiSIaPSZM6Huc4kb5lqCaxg/SBlXTCX17Z/8TFoqV/wCJz17XnkH6 +9WtKAC2TwKxiLZ2Qzwr2XV48lASugIOZkSW2qxM9ui+b1T9ICFKRGLn/UB//pOiG +270hNJDLB/BKRExjS+RXeOpdAIJB5XsAEp8h56ub9emhhf9tCEXOn7PN7HbMCnQh +7k8EpAG0h5StLUhY1HHvynVz2/qyMvZa/bIaaudL2565Z6nDU+iBxed7O1qrbRAH +Vakr7Sa3K5niCyH5kxdyO1t29l1ksBqpDUrj+vViFuLkd3XIiui8IA== +-----END RSA PRIVATE KEY----- + + + tester + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj index 9aac0d87..e4b8f4d0 100644 --- a/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj +++ b/src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj @@ -1,566 +1,566 @@ - - - - Debug - AnyCPU - 2.0 - {C45379B9-17B1-4E89-BC2E-6D41726413E8} - Library - Properties - Renci.SshNet.Tests - Renci.SshNet.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - TRACE;DEBUG;FEATURE_ENCODING_ASCII - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 0 - - - - - - - true - - - ..\Renci.SshNet.snk - - - - - - ..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll - - - - 3.5 - - - - - - - - - False - - - - - Classes\Abstractions\CryptoAbstraction_GenerateRandom.cs - - - Classes\Abstractions\DnsAbstraction_GetHostAddresses.cs - - - Classes\Abstractions\ThreadAbstraction_ExecuteThread.cs - - - Classes\SshMessageFactoryTest.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Resources.resx - True - True - - - - Properties\CommonAssemblyInfo.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {2F5F8C90-0BD1-424F-997C-7BC6280919D1} - Renci.SshNet - - - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - - - - - - - - - - - - - - - Renci.SshNet.snk - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 2.0 + {C45379B9-17B1-4E89-BC2E-6D41726413E8} + Library + Properties + Renci.SshNet.Tests + Renci.SshNet.Tests + v4.0 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + true + full + false + bin\Debug\ + TRACE;DEBUG;FEATURE_ENCODING_ASCII + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 0 + + + + + + + true + + + ..\Renci.SshNet.snk + + + + + + ..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll + + + + 3.5 + + + + + + + + + False + + + + + Classes\Abstractions\CryptoAbstraction_GenerateRandom.cs + + + Classes\Abstractions\DnsAbstraction_GetHostAddresses.cs + + + Classes\Abstractions\ThreadAbstraction_ExecuteThread.cs + + + Classes\SshMessageFactoryTest.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Resources.resx + True + True + + + + Properties\CommonAssemblyInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {2F5F8C90-0BD1-424F-997C-7BC6280919D1} + Renci.SshNet + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + + + + + + + + + + + + + + + Renci.SshNet.snk + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet.Tests/packages.config b/src/Renci.SshNet.Tests/packages.config index 1ebfe799..f6c56582 100644 --- a/src/Renci.SshNet.Tests/packages.config +++ b/src/Renci.SshNet.Tests/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs b/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs index 6025b9f7..f61fb134 100644 --- a/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.WindowsPhone/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Windows Phone 7.1")] -[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Windows Phone 7.1")] +[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] diff --git a/src/Renci.SshNet.WindowsPhone/Session.WP.cs b/src/Renci.SshNet.WindowsPhone/Session.WP.cs index e6ba0f3e..ed9b07f3 100644 --- a/src/Renci.SshNet.WindowsPhone/Session.WP.cs +++ b/src/Renci.SshNet.WindowsPhone/Session.WP.cs @@ -1,77 +1,77 @@ -using System; -using Renci.SshNet.Messages.Transport; -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Authentication; -using Renci.SshNet.Messages.Connection; -using System.Diagnostics; - -namespace Renci.SshNet -{ - public partial class Session - { - partial void HandleMessageCore(Message message) - { - if (message == null) - throw new ArgumentNullException("message"); - else if (message is DisconnectMessage) - this.HandleMessage((DisconnectMessage)message); - else if (message is IgnoreMessage) - this.HandleMessage((IgnoreMessage)message); - else if (message is UnimplementedMessage) - this.HandleMessage((UnimplementedMessage)message); - else if (message is DebugMessage) - this.HandleMessage((DebugMessage)message); - else if (message is ServiceRequestMessage) - this.HandleMessage((ServiceRequestMessage)message); - else if (message is ServiceAcceptMessage) - this.HandleMessage((ServiceAcceptMessage)message); - else if (message is KeyExchangeInitMessage) - this.HandleMessage((KeyExchangeInitMessage)message); - else if (message is NewKeysMessage) - this.HandleMessage((NewKeysMessage)message); - else if (message is RequestMessage) - this.HandleMessage((RequestMessage)message); - else if (message is FailureMessage) - this.HandleMessage((FailureMessage)message); - else if (message is SuccessMessage) - this.HandleMessage((SuccessMessage)message); - else if (message is BannerMessage) - this.HandleMessage((BannerMessage)message); - else if (message is GlobalRequestMessage) - this.HandleMessage((GlobalRequestMessage)message); - else if (message is RequestSuccessMessage) - this.HandleMessage((RequestSuccessMessage)message); - else if (message is RequestFailureMessage) - this.HandleMessage((RequestFailureMessage)message); - else if (message is ChannelOpenMessage) - this.HandleMessage((ChannelOpenMessage)message); - else if (message is ChannelOpenConfirmationMessage) - this.HandleMessage((ChannelOpenConfirmationMessage)message); - else if (message is ChannelOpenFailureMessage) - this.HandleMessage((ChannelOpenFailureMessage)message); - else if (message is ChannelWindowAdjustMessage) - this.HandleMessage((ChannelWindowAdjustMessage)message); - else if (message is ChannelDataMessage) - this.HandleMessage((ChannelDataMessage)message); - else if (message is ChannelExtendedDataMessage) - this.HandleMessage((ChannelExtendedDataMessage)message); - else if (message is ChannelEofMessage) - this.HandleMessage((ChannelEofMessage)message); - else if (message is ChannelCloseMessage) - this.HandleMessage((ChannelCloseMessage)message); - else if (message is ChannelRequestMessage) - this.HandleMessage((ChannelRequestMessage)message); - else if (message is ChannelSuccessMessage) - this.HandleMessage((ChannelSuccessMessage)message); - else if (message is ChannelFailureMessage) - this.HandleMessage((ChannelFailureMessage)message); - else - { - Debug.WriteLine("SSH.NET WARNING: unknown message type {0} - may need to add new type to Session.WP.cs, HandleMessageCore method", - message.GetType().FullName); - - this.HandleMessage(message); - } - } - } -} +using System; +using Renci.SshNet.Messages.Transport; +using Renci.SshNet.Messages; +using Renci.SshNet.Messages.Authentication; +using Renci.SshNet.Messages.Connection; +using System.Diagnostics; + +namespace Renci.SshNet +{ + public partial class Session + { + partial void HandleMessageCore(Message message) + { + if (message == null) + throw new ArgumentNullException("message"); + else if (message is DisconnectMessage) + this.HandleMessage((DisconnectMessage)message); + else if (message is IgnoreMessage) + this.HandleMessage((IgnoreMessage)message); + else if (message is UnimplementedMessage) + this.HandleMessage((UnimplementedMessage)message); + else if (message is DebugMessage) + this.HandleMessage((DebugMessage)message); + else if (message is ServiceRequestMessage) + this.HandleMessage((ServiceRequestMessage)message); + else if (message is ServiceAcceptMessage) + this.HandleMessage((ServiceAcceptMessage)message); + else if (message is KeyExchangeInitMessage) + this.HandleMessage((KeyExchangeInitMessage)message); + else if (message is NewKeysMessage) + this.HandleMessage((NewKeysMessage)message); + else if (message is RequestMessage) + this.HandleMessage((RequestMessage)message); + else if (message is FailureMessage) + this.HandleMessage((FailureMessage)message); + else if (message is SuccessMessage) + this.HandleMessage((SuccessMessage)message); + else if (message is BannerMessage) + this.HandleMessage((BannerMessage)message); + else if (message is GlobalRequestMessage) + this.HandleMessage((GlobalRequestMessage)message); + else if (message is RequestSuccessMessage) + this.HandleMessage((RequestSuccessMessage)message); + else if (message is RequestFailureMessage) + this.HandleMessage((RequestFailureMessage)message); + else if (message is ChannelOpenMessage) + this.HandleMessage((ChannelOpenMessage)message); + else if (message is ChannelOpenConfirmationMessage) + this.HandleMessage((ChannelOpenConfirmationMessage)message); + else if (message is ChannelOpenFailureMessage) + this.HandleMessage((ChannelOpenFailureMessage)message); + else if (message is ChannelWindowAdjustMessage) + this.HandleMessage((ChannelWindowAdjustMessage)message); + else if (message is ChannelDataMessage) + this.HandleMessage((ChannelDataMessage)message); + else if (message is ChannelExtendedDataMessage) + this.HandleMessage((ChannelExtendedDataMessage)message); + else if (message is ChannelEofMessage) + this.HandleMessage((ChannelEofMessage)message); + else if (message is ChannelCloseMessage) + this.HandleMessage((ChannelCloseMessage)message); + else if (message is ChannelRequestMessage) + this.HandleMessage((ChannelRequestMessage)message); + else if (message is ChannelSuccessMessage) + this.HandleMessage((ChannelSuccessMessage)message); + else if (message is ChannelFailureMessage) + this.HandleMessage((ChannelFailureMessage)message); + else + { + Debug.WriteLine("SSH.NET WARNING: unknown message type {0} - may need to add new type to Session.WP.cs, HandleMessageCore method", + message.GetType().FullName); + + this.HandleMessage(message); + } + } + } +} diff --git a/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs b/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs index ca080563..3db5746c 100644 --- a/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs +++ b/src/Renci.SshNet.WindowsPhone8/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SSH.NET Windows Phone 8.0")] -[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] - +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("SSH.NET Windows Phone 8.0")] +[assembly: Guid("b044a9d9-fe40-4d7e-b198-c142ab9721f0")] + [assembly: InternalsVisibleTo("Renci.SshNet.Tests")] \ No newline at end of file diff --git a/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj b/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj index 714d15da..5d5391f6 100644 --- a/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj +++ b/src/Renci.SshNet.WindowsPhone8/Renci.SshNet.WindowsPhone8.csproj @@ -1,948 +1,948 @@ - - - - Debug - AnyCPU - 10.0.20506 - 2.0 - {4A6CA785-1C8A-47FE-98C0-30C675A9328B} - {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - Renci.SshNet - Renci.SshNet - v8.0 - WindowsPhone - false - true - true - 11.0 - - - true - full - false - Bin\Debug - TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - prompt - 4 - false - Bin\Debug\Renci.SshNet.xml - true - - - none - true - Bin\Release - TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - prompt - 4 - false - Bin\Release\Renci.SshNet.xml - - - true - - - true - Bin\x86\Debug - TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - full - - - prompt - MinimumRecommendedRules.ruleset - false - - - Bin\x86\Release - TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - pdbonly - - - prompt - MinimumRecommendedRules.ruleset - - - true - Bin\ARM\Debug - TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - full - - - prompt - MinimumRecommendedRules.ruleset - false - - - Bin\ARM\Release - TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 - true - true - pdbonly - - - prompt - MinimumRecommendedRules.ruleset - - - - Session.WP.cs - - - Abstractions\CryptoAbstraction.cs - - - Abstractions\DiagnosticAbstraction.cs - - - Abstractions\DnsAbstraction.cs - - - Abstractions\ReflectionAbstraction.cs - - - Abstractions\SocketAbstraction.cs - - - Abstractions\ThreadAbstraction.cs - - - AuthenticationMethod.cs - - - AuthenticationResult.cs - - - BaseClient.cs - - - Channels\Channel.cs - - - Channels\ChannelDirectTcpip.cs - - - Channels\ChannelForwardedTcpip.cs - - - Channels\ChannelSession.cs - - - Channels\ChannelTypes.cs - - - Channels\ClientChannel.cs - - - Channels\IChannel.cs - - - Channels\IChannelDirectTcpip.cs - - - Channels\IChannelForwardedTcpip.cs - - - Channels\IChannelSession.cs - - - Channels\ServerChannel.cs - - - CipherInfo.cs - - - ClientAuthentication.cs - - - CommandAsyncResult.cs - - - Common\Array.cs - - - Common\ASCIIEncoding.cs - - - Common\AsyncResult.cs - - - Common\AuthenticationBannerEventArgs.cs - - - Common\AuthenticationEventArgs.cs - - - Common\AuthenticationPasswordChangeEventArgs.cs - - - Common\AuthenticationPrompt.cs - - - Common\AuthenticationPromptEventArgs.cs - - - Common\BigInteger.cs - - - Common\ChannelDataEventArgs.cs - - - Common\ChannelEventArgs.cs - - - Common\ChannelExtendedDataEventArgs.cs - - - Common\ChannelOpenConfirmedEventArgs.cs - - - Common\ChannelOpenFailedEventArgs.cs - - - Common\ChannelRequestEventArgs.cs - - - Common\DerData.cs - - - Common\ExceptionEventArgs.cs - - - Common\Extensions.cs - - - Common\Extensions.cs - - - Common\HostKeyEventArgs.cs - - - Common\ObjectIdentifier.cs - - - Common\PipeStream.cs - - - Common\PortForwardEventArgs.cs - - - Common\ProxyException.cs - - - Common\ScpDownloadEventArgs.cs - - - Common\ScpException.cs - - - Common\ScpUploadEventArgs.cs - - - Common\SemaphoreLight.cs - - - Common\SftpPathNotFoundException.cs - - - Common\SftpPermissionDeniedException.cs - - - Common\ShellDataEventArgs.cs - - - Common\SshAuthenticationException.cs - - - Common\SshConnectionException.cs - - - Common\SshData.cs - - - Common\SshDataStream.cs - - - Common\SshException.cs - - - Common\SshOperationTimeoutException.cs - - - Common\SshPassPhraseNullOrEmptyException.cs - - - Common\TerminalModes.cs - - - Compression\CompressionMode.cs - - - Compression\Compressor.cs - - - Compression\Zlib.cs - - - Compression\ZlibOpenSsh.cs - - - Compression\ZlibStream.cs - - - ConnectionInfo.cs - - - ExpectAction.cs - - - ExpectAsyncResult.cs - - - ForwardedPort.cs - - - ForwardedPortDynamic.cs - - - ForwardedPortLocal.cs - - - ForwardedPortRemote.cs - - - HashInfo.cs - - - IAuthenticationMethod.cs - - - IClientAuthentication.cs - - - IConnectionInfo.cs - - - IForwardedPort.cs - - - IServiceFactory.cs - - - ISession.cs - - - ISubsystemSession.cs - - - KeyboardInteractiveAuthenticationMethod.cs - - - KeyboardInteractiveConnectionInfo.cs - - - MessageEventArgs.cs - - - Messages\Authentication\BannerMessage.cs - - - Messages\Authentication\FailureMessage.cs - - - Messages\Authentication\InformationRequestMessage.cs - - - Messages\Authentication\InformationResponseMessage.cs - - - Messages\Authentication\PasswordChangeRequiredMessage.cs - - - Messages\Authentication\PublicKeyMessage.cs - - - Messages\Authentication\RequestMessage.cs - - - Messages\Authentication\RequestMessageHost.cs - - - Messages\Authentication\RequestMessageKeyboardInteractive.cs - - - Messages\Authentication\RequestMessageNone.cs - - - Messages\Authentication\RequestMessagePassword.cs - - - Messages\Authentication\RequestMessagePublicKey.cs - - - Messages\Authentication\SuccessMessage.cs - - - Messages\Connection\ChannelCloseMessage.cs - - - Messages\Connection\ChannelDataMessage.cs - - - Messages\Connection\ChannelEofMessage.cs - - - Messages\Connection\ChannelExtendedDataMessage.cs - - - Messages\Connection\ChannelFailureMessage.cs - - - Messages\Connection\ChannelMessage.cs - - - Messages\Connection\ChannelOpenConfirmationMessage.cs - - - Messages\Connection\ChannelOpenFailureMessage.cs - - - Messages\Connection\ChannelOpenFailureReasons.cs - - - Messages\Connection\ChannelOpen\ChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\ChannelOpenMessage.cs - - - Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs - - - Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs - - - Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs - - - Messages\Connection\ChannelRequest\BreakRequestInfo.cs - - - Messages\Connection\ChannelRequest\ChannelRequestMessage.cs - - - Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs - - - Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExecRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs - - - Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs - - - Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs - - - Messages\Connection\ChannelRequest\RequestInfo.cs - - - Messages\Connection\ChannelRequest\ShellRequestInfo.cs - - - Messages\Connection\ChannelRequest\SignalRequestInfo.cs - - - Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs - - - Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs - - - Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs - - - Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs - - - Messages\Connection\ChannelSuccessMessage.cs - - - Messages\Connection\ChannelWindowAdjustMessage.cs - - - Messages\Connection\GlobalRequestMessage.cs - - - Messages\Connection\GlobalRequestName.cs - - - Messages\Connection\RequestFailureMessage.cs - - - Messages\Connection\RequestSuccessMessage.cs - - - Messages\Message.cs - - - Messages\MessageAttribute.cs - - - Messages\ServiceName.cs - - - Messages\Transport\DebugMessage.cs - - - Messages\Transport\DisconnectMessage.cs - - - Messages\Transport\DisconnectReason.cs - - - Messages\Transport\IgnoreMessage.cs - - - Messages\Transport\IKeyExchangedAllowed.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeInit.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeReply.cs - - - Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs - - - Messages\Transport\KeyExchangeDhInitMessage.cs - - - Messages\Transport\KeyExchangeDhReplyMessage.cs - - - Messages\Transport\KeyExchangeEcdhInitMessage.cs - - - Messages\Transport\KeyExchangeEcdhReplyMessage.cs - - - Messages\Transport\KeyExchangeInitMessage.cs - - - Messages\Transport\NewKeysMessage.cs - - - Messages\Transport\ServiceAcceptMessage.cs - - - Messages\Transport\ServiceRequestMessage.cs - - - Messages\Transport\UnimplementedMessage.cs - - - NoneAuthenticationMethod.cs - - - PasswordAuthenticationMethod.cs - - - PasswordConnectionInfo.cs - - - PrivateKeyAuthenticationMethod.cs - - - PrivateKeyConnectionInfo.cs - - - PrivateKeyFile.cs - - - ProxyTypes.cs - - - ScpClient.cs - - - Security\Algorithm.cs - - - Security\CertificateHostAlgorithm.cs - - - Security\Cryptography\AsymmetricCipher.cs - - - Security\Cryptography\BlockCipher.cs - - - Security\Cryptography\Cipher.cs - - - Security\Cryptography\CipherDigitalSignature.cs - - - Security\Cryptography\Ciphers\AesCipher.cs - - - Security\Cryptography\Ciphers\Arc4Cipher.cs - - - Security\Cryptography\Ciphers\BlowfishCipher.cs - - - Security\Cryptography\Ciphers\CastCipher.cs - - - Security\Cryptography\Ciphers\CipherMode.cs - - - Security\Cryptography\Ciphers\CipherPadding.cs - - - Security\Cryptography\Ciphers\DesCipher.cs - - - Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs - - - Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs - - - Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs - - - Security\Cryptography\Ciphers\RsaCipher.cs - - - Security\Cryptography\Ciphers\SerpentCipher.cs - - - Security\Cryptography\Ciphers\TripleDesCipher.cs - - - Security\Cryptography\Ciphers\TwofishCipher.cs - - - Security\Cryptography\DigitalSignature.cs - - - Security\Cryptography\DsaDigitalSignature.cs - - - Security\Cryptography\DsaKey.cs - - - Security\Cryptography\HMACMD5.cs - - - Security\Cryptography\HMACSHA1.cs - - - Security\Cryptography\HMACSHA256.cs - - - Security\Cryptography\HMACSHA384.cs - - - Security\Cryptography\HMACSHA512.cs - - - Security\Cryptography\Key.cs - - - Security\Cryptography\RsaDigitalSignature.cs - - - Security\Cryptography\RsaKey.cs - - - Security\Cryptography\StreamCipher.cs - - - Security\Cryptography\SymmetricCipher.cs - - - Security\GroupExchangeHashData.cs - - - Security\HostAlgorithm.cs - - - Security\IKeyExchange.cs - - - Security\KeyExchange.cs - - - Security\KeyExchangeDiffieHellman.cs - - - Security\KeyExchangeDiffieHellmanGroup14Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroup1Sha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs - - - Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs - - - Security\KeyExchangeDiffieHellmanGroupSha1.cs - - - Security\KeyHostAlgorithm.cs - - - ServiceFactory.cs - - - Session.cs - - - Session.cs - - - SftpClient.cs - - - Sftp\Flags.cs - - - Sftp\ISftpSession.cs - - - Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs - - - Sftp\Requests\ExtendedRequests\HardLinkRequest.cs - - - Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs - - - Sftp\Requests\ExtendedRequests\StatVfsRequest.cs - - - Sftp\Requests\SftpBlockRequest.cs - - - Sftp\Requests\SftpCloseRequest.cs - - - Sftp\Requests\SftpExtendedRequest.cs - - - Sftp\Requests\SftpFSetStatRequest.cs - - - Sftp\Requests\SftpFStatRequest.cs - - - Sftp\Requests\SftpInitRequest.cs - - - Sftp\Requests\SftpLinkRequest.cs - - - Sftp\Requests\SftpLStatRequest.cs - - - Sftp\Requests\SftpMkDirRequest.cs - - - Sftp\Requests\SftpOpenDirRequest.cs - - - Sftp\Requests\SftpOpenRequest.cs - - - Sftp\Requests\SftpReadDirRequest.cs - - - Sftp\Requests\SftpReadLinkRequest.cs - - - Sftp\Requests\SftpReadRequest.cs - - - Sftp\Requests\SftpRealPathRequest.cs - - - Sftp\Requests\SftpRemoveRequest.cs - - - Sftp\Requests\SftpRenameRequest.cs - - - Sftp\Requests\SftpRequest.cs - - - Sftp\Requests\SftpRmDirRequest.cs - - - Sftp\Requests\SftpSetStatRequest.cs - - - Sftp\Requests\SftpStatRequest.cs - - - Sftp\Requests\SftpSymLinkRequest.cs - - - Sftp\Requests\SftpUnblockRequest.cs - - - Sftp\Requests\SftpWriteRequest.cs - - - Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs - - - Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs - - - Sftp\Responses\SftpAttrsResponse.cs - - - Sftp\Responses\SftpDataResponse.cs - - - Sftp\Responses\SftpExtendedReplyResponse.cs - - - Sftp\Responses\SftpHandleResponse.cs - - - Sftp\Responses\SftpNameResponse.cs - - - Sftp\Responses\SftpResponse.cs - - - Sftp\Responses\SftpStatusResponse.cs - - - Sftp\Responses\SftpVersionResponse.cs - - - Sftp\SftpDownloadAsyncResult.cs - - - Sftp\SftpFile.cs - - - Sftp\SftpFileAttributes.cs - - - Sftp\SftpFileStream.cs - - - Sftp\SftpFileSystemInformation.cs - - - Sftp\SftpListDirectoryAsyncResult.cs - - - Sftp\SftpMessage.cs - - - Sftp\SftpMessageTypes.cs - - - Sftp\SftpSession.cs - - - Sftp\SftpSynchronizeDirectoriesAsyncResult.cs - - - Sftp\SftpUploadAsyncResult.cs - - - Sftp\StatusCodes.cs - - - Shell.cs - - - ShellStream.cs - - - SshClient.cs - - - SshCommand.cs - - - SshMessageFactory.cs - - - SubsystemSession.cs - - - - Properties\CommonAssemblyInfo.cs - - - - - False - ..\..\packages\SshNet.Security.Cryptography.1.0.0\lib\wp8\SshNet.Security.Cryptography.dll - True - - - - - - - - - - - - - + + + + Debug + AnyCPU + 10.0.20506 + 2.0 + {4A6CA785-1C8A-47FE-98C0-30C675A9328B} + {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Renci.SshNet + Renci.SshNet + v8.0 + WindowsPhone + false + true + true + 11.0 + + + true + full + false + Bin\Debug + TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + prompt + 4 + false + Bin\Debug\Renci.SshNet.xml + true + + + none + true + Bin\Release + TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + prompt + 4 + false + Bin\Release\Renci.SshNet.xml + + + true + + + true + Bin\x86\Debug + TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + full + + + prompt + MinimumRecommendedRules.ruleset + false + + + Bin\x86\Release + TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + pdbonly + + + prompt + MinimumRecommendedRules.ruleset + + + true + Bin\ARM\Debug + TRACE;DEBUG;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + full + + + prompt + MinimumRecommendedRules.ruleset + false + + + Bin\ARM\Release + TRACE;WINDOWS_PHONE;FEATURE_RNG_CSP;FEATURE_SOCKET_EAP;FEATURE_STREAM_APM;FEATURE_DEVICEINFORMATION_APM;FEATURE_THREAD_THREADPOOL;FEATURE_THREAD_SLEEP;FEATURE_MEMORYSTREAM_GETBUFFER;FEATURE_HASH_SHA1;FEATURE_HASH_SHA256;FEATURE_HMAC_SHA1;FEATURE_HMAC_SHA256 + true + true + pdbonly + + + prompt + MinimumRecommendedRules.ruleset + + + + Session.WP.cs + + + Abstractions\CryptoAbstraction.cs + + + Abstractions\DiagnosticAbstraction.cs + + + Abstractions\DnsAbstraction.cs + + + Abstractions\ReflectionAbstraction.cs + + + Abstractions\SocketAbstraction.cs + + + Abstractions\ThreadAbstraction.cs + + + AuthenticationMethod.cs + + + AuthenticationResult.cs + + + BaseClient.cs + + + Channels\Channel.cs + + + Channels\ChannelDirectTcpip.cs + + + Channels\ChannelForwardedTcpip.cs + + + Channels\ChannelSession.cs + + + Channels\ChannelTypes.cs + + + Channels\ClientChannel.cs + + + Channels\IChannel.cs + + + Channels\IChannelDirectTcpip.cs + + + Channels\IChannelForwardedTcpip.cs + + + Channels\IChannelSession.cs + + + Channels\ServerChannel.cs + + + CipherInfo.cs + + + ClientAuthentication.cs + + + CommandAsyncResult.cs + + + Common\Array.cs + + + Common\ASCIIEncoding.cs + + + Common\AsyncResult.cs + + + Common\AuthenticationBannerEventArgs.cs + + + Common\AuthenticationEventArgs.cs + + + Common\AuthenticationPasswordChangeEventArgs.cs + + + Common\AuthenticationPrompt.cs + + + Common\AuthenticationPromptEventArgs.cs + + + Common\BigInteger.cs + + + Common\ChannelDataEventArgs.cs + + + Common\ChannelEventArgs.cs + + + Common\ChannelExtendedDataEventArgs.cs + + + Common\ChannelOpenConfirmedEventArgs.cs + + + Common\ChannelOpenFailedEventArgs.cs + + + Common\ChannelRequestEventArgs.cs + + + Common\DerData.cs + + + Common\ExceptionEventArgs.cs + + + Common\Extensions.cs + + + Common\Extensions.cs + + + Common\HostKeyEventArgs.cs + + + Common\ObjectIdentifier.cs + + + Common\PipeStream.cs + + + Common\PortForwardEventArgs.cs + + + Common\ProxyException.cs + + + Common\ScpDownloadEventArgs.cs + + + Common\ScpException.cs + + + Common\ScpUploadEventArgs.cs + + + Common\SemaphoreLight.cs + + + Common\SftpPathNotFoundException.cs + + + Common\SftpPermissionDeniedException.cs + + + Common\ShellDataEventArgs.cs + + + Common\SshAuthenticationException.cs + + + Common\SshConnectionException.cs + + + Common\SshData.cs + + + Common\SshDataStream.cs + + + Common\SshException.cs + + + Common\SshOperationTimeoutException.cs + + + Common\SshPassPhraseNullOrEmptyException.cs + + + Common\TerminalModes.cs + + + Compression\CompressionMode.cs + + + Compression\Compressor.cs + + + Compression\Zlib.cs + + + Compression\ZlibOpenSsh.cs + + + Compression\ZlibStream.cs + + + ConnectionInfo.cs + + + ExpectAction.cs + + + ExpectAsyncResult.cs + + + ForwardedPort.cs + + + ForwardedPortDynamic.cs + + + ForwardedPortLocal.cs + + + ForwardedPortRemote.cs + + + HashInfo.cs + + + IAuthenticationMethod.cs + + + IClientAuthentication.cs + + + IConnectionInfo.cs + + + IForwardedPort.cs + + + IServiceFactory.cs + + + ISession.cs + + + ISubsystemSession.cs + + + KeyboardInteractiveAuthenticationMethod.cs + + + KeyboardInteractiveConnectionInfo.cs + + + MessageEventArgs.cs + + + Messages\Authentication\BannerMessage.cs + + + Messages\Authentication\FailureMessage.cs + + + Messages\Authentication\InformationRequestMessage.cs + + + Messages\Authentication\InformationResponseMessage.cs + + + Messages\Authentication\PasswordChangeRequiredMessage.cs + + + Messages\Authentication\PublicKeyMessage.cs + + + Messages\Authentication\RequestMessage.cs + + + Messages\Authentication\RequestMessageHost.cs + + + Messages\Authentication\RequestMessageKeyboardInteractive.cs + + + Messages\Authentication\RequestMessageNone.cs + + + Messages\Authentication\RequestMessagePassword.cs + + + Messages\Authentication\RequestMessagePublicKey.cs + + + Messages\Authentication\SuccessMessage.cs + + + Messages\Connection\ChannelCloseMessage.cs + + + Messages\Connection\ChannelDataMessage.cs + + + Messages\Connection\ChannelEofMessage.cs + + + Messages\Connection\ChannelExtendedDataMessage.cs + + + Messages\Connection\ChannelFailureMessage.cs + + + Messages\Connection\ChannelMessage.cs + + + Messages\Connection\ChannelOpenConfirmationMessage.cs + + + Messages\Connection\ChannelOpenFailureMessage.cs + + + Messages\Connection\ChannelOpenFailureReasons.cs + + + Messages\Connection\ChannelOpen\ChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\ChannelOpenMessage.cs + + + Messages\Connection\ChannelOpen\DirectTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\ForwardedTcpipChannelInfo.cs + + + Messages\Connection\ChannelOpen\SessionChannelOpenInfo.cs + + + Messages\Connection\ChannelOpen\X11ChannelOpenInfo.cs + + + Messages\Connection\ChannelRequest\BreakRequestInfo.cs + + + Messages\Connection\ChannelRequest\ChannelRequestMessage.cs + + + Messages\Connection\ChannelRequest\EndOfWriteRequestInfo.cs + + + Messages\Connection\ChannelRequest\EnvironmentVariableRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExecRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitSignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\ExitStatusRequestInfo.cs + + + Messages\Connection\ChannelRequest\KeepAliveRequestInfo.cs + + + Messages\Connection\ChannelRequest\PseudoTerminalInfo.cs + + + Messages\Connection\ChannelRequest\RequestInfo.cs + + + Messages\Connection\ChannelRequest\ShellRequestInfo.cs + + + Messages\Connection\ChannelRequest\SignalRequestInfo.cs + + + Messages\Connection\ChannelRequest\SubsystemRequestInfo.cs + + + Messages\Connection\ChannelRequest\WindowChangeRequestInfo.cs + + + Messages\Connection\ChannelRequest\X11ForwardingRequestInfo.cs + + + Messages\Connection\ChannelRequest\XonXoffRequestInfo.cs + + + Messages\Connection\ChannelSuccessMessage.cs + + + Messages\Connection\ChannelWindowAdjustMessage.cs + + + Messages\Connection\GlobalRequestMessage.cs + + + Messages\Connection\GlobalRequestName.cs + + + Messages\Connection\RequestFailureMessage.cs + + + Messages\Connection\RequestSuccessMessage.cs + + + Messages\Message.cs + + + Messages\MessageAttribute.cs + + + Messages\ServiceName.cs + + + Messages\Transport\DebugMessage.cs + + + Messages\Transport\DisconnectMessage.cs + + + Messages\Transport\DisconnectReason.cs + + + Messages\Transport\IgnoreMessage.cs + + + Messages\Transport\IKeyExchangedAllowed.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeGroup.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeInit.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeReply.cs + + + Messages\Transport\KeyExchangeDhGroupExchangeRequest.cs + + + Messages\Transport\KeyExchangeDhInitMessage.cs + + + Messages\Transport\KeyExchangeDhReplyMessage.cs + + + Messages\Transport\KeyExchangeEcdhInitMessage.cs + + + Messages\Transport\KeyExchangeEcdhReplyMessage.cs + + + Messages\Transport\KeyExchangeInitMessage.cs + + + Messages\Transport\NewKeysMessage.cs + + + Messages\Transport\ServiceAcceptMessage.cs + + + Messages\Transport\ServiceRequestMessage.cs + + + Messages\Transport\UnimplementedMessage.cs + + + NoneAuthenticationMethod.cs + + + PasswordAuthenticationMethod.cs + + + PasswordConnectionInfo.cs + + + PrivateKeyAuthenticationMethod.cs + + + PrivateKeyConnectionInfo.cs + + + PrivateKeyFile.cs + + + ProxyTypes.cs + + + ScpClient.cs + + + Security\Algorithm.cs + + + Security\CertificateHostAlgorithm.cs + + + Security\Cryptography\AsymmetricCipher.cs + + + Security\Cryptography\BlockCipher.cs + + + Security\Cryptography\Cipher.cs + + + Security\Cryptography\CipherDigitalSignature.cs + + + Security\Cryptography\Ciphers\AesCipher.cs + + + Security\Cryptography\Ciphers\Arc4Cipher.cs + + + Security\Cryptography\Ciphers\BlowfishCipher.cs + + + Security\Cryptography\Ciphers\CastCipher.cs + + + Security\Cryptography\Ciphers\CipherMode.cs + + + Security\Cryptography\Ciphers\CipherPadding.cs + + + Security\Cryptography\Ciphers\DesCipher.cs + + + Security\Cryptography\Ciphers\Modes\CbcCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CfbCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs + + + Security\Cryptography\Ciphers\Modes\OfbCipherMode.cs + + + Security\Cryptography\Ciphers\Paddings\PKCS7Padding.cs + + + Security\Cryptography\Ciphers\RsaCipher.cs + + + Security\Cryptography\Ciphers\SerpentCipher.cs + + + Security\Cryptography\Ciphers\TripleDesCipher.cs + + + Security\Cryptography\Ciphers\TwofishCipher.cs + + + Security\Cryptography\DigitalSignature.cs + + + Security\Cryptography\DsaDigitalSignature.cs + + + Security\Cryptography\DsaKey.cs + + + Security\Cryptography\HMACMD5.cs + + + Security\Cryptography\HMACSHA1.cs + + + Security\Cryptography\HMACSHA256.cs + + + Security\Cryptography\HMACSHA384.cs + + + Security\Cryptography\HMACSHA512.cs + + + Security\Cryptography\Key.cs + + + Security\Cryptography\RsaDigitalSignature.cs + + + Security\Cryptography\RsaKey.cs + + + Security\Cryptography\StreamCipher.cs + + + Security\Cryptography\SymmetricCipher.cs + + + Security\GroupExchangeHashData.cs + + + Security\HostAlgorithm.cs + + + Security\IKeyExchange.cs + + + Security\KeyExchange.cs + + + Security\KeyExchangeDiffieHellman.cs + + + Security\KeyExchangeDiffieHellmanGroup14Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroup1Sha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha1.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeSha256.cs + + + Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs + + + Security\KeyExchangeDiffieHellmanGroupSha1.cs + + + Security\KeyHostAlgorithm.cs + + + ServiceFactory.cs + + + Session.cs + + + Session.cs + + + SftpClient.cs + + + Sftp\Flags.cs + + + Sftp\ISftpSession.cs + + + Sftp\Requests\ExtendedRequests\FStatVfsRequest.cs + + + Sftp\Requests\ExtendedRequests\HardLinkRequest.cs + + + Sftp\Requests\ExtendedRequests\PosixRenameRequest.cs + + + Sftp\Requests\ExtendedRequests\StatVfsRequest.cs + + + Sftp\Requests\SftpBlockRequest.cs + + + Sftp\Requests\SftpCloseRequest.cs + + + Sftp\Requests\SftpExtendedRequest.cs + + + Sftp\Requests\SftpFSetStatRequest.cs + + + Sftp\Requests\SftpFStatRequest.cs + + + Sftp\Requests\SftpInitRequest.cs + + + Sftp\Requests\SftpLinkRequest.cs + + + Sftp\Requests\SftpLStatRequest.cs + + + Sftp\Requests\SftpMkDirRequest.cs + + + Sftp\Requests\SftpOpenDirRequest.cs + + + Sftp\Requests\SftpOpenRequest.cs + + + Sftp\Requests\SftpReadDirRequest.cs + + + Sftp\Requests\SftpReadLinkRequest.cs + + + Sftp\Requests\SftpReadRequest.cs + + + Sftp\Requests\SftpRealPathRequest.cs + + + Sftp\Requests\SftpRemoveRequest.cs + + + Sftp\Requests\SftpRenameRequest.cs + + + Sftp\Requests\SftpRequest.cs + + + Sftp\Requests\SftpRmDirRequest.cs + + + Sftp\Requests\SftpSetStatRequest.cs + + + Sftp\Requests\SftpStatRequest.cs + + + Sftp\Requests\SftpSymLinkRequest.cs + + + Sftp\Requests\SftpUnblockRequest.cs + + + Sftp\Requests\SftpWriteRequest.cs + + + Sftp\Responses\ExtendedReplies\ExtendedReplyInfo.cs + + + Sftp\Responses\ExtendedReplies\StatVfsReplyInfo.cs + + + Sftp\Responses\SftpAttrsResponse.cs + + + Sftp\Responses\SftpDataResponse.cs + + + Sftp\Responses\SftpExtendedReplyResponse.cs + + + Sftp\Responses\SftpHandleResponse.cs + + + Sftp\Responses\SftpNameResponse.cs + + + Sftp\Responses\SftpResponse.cs + + + Sftp\Responses\SftpStatusResponse.cs + + + Sftp\Responses\SftpVersionResponse.cs + + + Sftp\SftpDownloadAsyncResult.cs + + + Sftp\SftpFile.cs + + + Sftp\SftpFileAttributes.cs + + + Sftp\SftpFileStream.cs + + + Sftp\SftpFileSystemInformation.cs + + + Sftp\SftpListDirectoryAsyncResult.cs + + + Sftp\SftpMessage.cs + + + Sftp\SftpMessageTypes.cs + + + Sftp\SftpSession.cs + + + Sftp\SftpSynchronizeDirectoriesAsyncResult.cs + + + Sftp\SftpUploadAsyncResult.cs + + + Sftp\StatusCodes.cs + + + Shell.cs + + + ShellStream.cs + + + SshClient.cs + + + SshCommand.cs + + + SshMessageFactory.cs + + + SubsystemSession.cs + + + + Properties\CommonAssemblyInfo.cs + + + + + False + ..\..\packages\SshNet.Security.Cryptography.1.0.0\lib\wp8\SshNet.Security.Cryptography.dll + True + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Renci.SshNet/AuthenticationMethod.cs b/src/Renci.SshNet/AuthenticationMethod.cs index 2a7534d2..2b7302ca 100644 --- a/src/Renci.SshNet/AuthenticationMethod.cs +++ b/src/Renci.SshNet/AuthenticationMethod.cs @@ -1,63 +1,63 @@ -using System; -using System.Collections.Generic; - -namespace Renci.SshNet -{ - /// - /// Base class for all supported authentication methods - /// - public abstract class AuthenticationMethod : IAuthenticationMethod - { - /// - /// Gets the name of the authentication method. - /// - /// - /// The name of the authentication method. - /// - public abstract string Name { get; } - - /// - /// Gets connection username. - /// - public string Username { get; private set; } - - /// - /// Gets list of allowed authentications. - /// - public IList AllowedAuthentications { get; protected set; } - - /// - /// Initializes a new instance of the class. - /// - /// The username. - /// is whitespace or null. - protected AuthenticationMethod(string username) - { - if (username.IsNullOrWhiteSpace()) - throw new ArgumentException("username"); - - Username = username; - } - - /// - /// Authenticates the specified session. - /// - /// The session to authenticate. - /// - /// The result of the authentication process. - /// - public abstract AuthenticationResult Authenticate(Session session); - - /// - /// Authenticates the specified session. - /// - /// The session to authenticate. - /// - /// The result of the authentication process. - /// - AuthenticationResult IAuthenticationMethod.Authenticate(ISession session) - { - return Authenticate((Session) session); - } - } -} +using System; +using System.Collections.Generic; + +namespace Renci.SshNet +{ + /// + /// Base class for all supported authentication methods + /// + public abstract class AuthenticationMethod : IAuthenticationMethod + { + /// + /// Gets the name of the authentication method. + /// + /// + /// The name of the authentication method. + /// + public abstract string Name { get; } + + /// + /// Gets connection username. + /// + public string Username { get; private set; } + + /// + /// Gets list of allowed authentications. + /// + public IList AllowedAuthentications { get; protected set; } + + /// + /// Initializes a new instance of the class. + /// + /// The username. + /// is whitespace or null. + protected AuthenticationMethod(string username) + { + if (username.IsNullOrWhiteSpace()) + throw new ArgumentException("username"); + + Username = username; + } + + /// + /// Authenticates the specified session. + /// + /// The session to authenticate. + /// + /// The result of the authentication process. + /// + public abstract AuthenticationResult Authenticate(Session session); + + /// + /// Authenticates the specified session. + /// + /// The session to authenticate. + /// + /// The result of the authentication process. + /// + AuthenticationResult IAuthenticationMethod.Authenticate(ISession session) + { + return Authenticate((Session) session); + } + } +} diff --git a/src/Renci.SshNet/AuthenticationResult.cs b/src/Renci.SshNet/AuthenticationResult.cs index bfc1b019..71414966 100644 --- a/src/Renci.SshNet/AuthenticationResult.cs +++ b/src/Renci.SshNet/AuthenticationResult.cs @@ -1,21 +1,21 @@ -namespace Renci.SshNet -{ - /// - /// Represents possible authentication methods results - /// - public enum AuthenticationResult - { - /// - /// Authentication was successful. - /// - Success, - /// - /// Authentication completed with partial success. - /// - PartialSuccess, - /// - /// Authentication failed. - /// - Failure - } -} +namespace Renci.SshNet +{ + /// + /// Represents possible authentication methods results + /// + public enum AuthenticationResult + { + /// + /// Authentication was successful. + /// + Success, + /// + /// Authentication completed with partial success. + /// + PartialSuccess, + /// + /// Authentication failed. + /// + Failure + } +} diff --git a/src/Renci.SshNet/Channels/Channel.cs b/src/Renci.SshNet/Channels/Channel.cs index bd306eaf..f9e57ced 100644 --- a/src/Renci.SshNet/Channels/Channel.cs +++ b/src/Renci.SshNet/Channels/Channel.cs @@ -1,915 +1,915 @@ -using System; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Common; -using Renci.SshNet.Messages; -using Renci.SshNet.Messages.Connection; -using System.Globalization; - -namespace Renci.SshNet.Channels -{ - /// - /// Represents base class for SSH channel implementations. - /// - internal abstract class Channel : IChannel - { - private const int Initial = 0; - private const int Considered = 1; - private const int Sent = 2; - - private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(false); - private EventWaitHandle _channelServerWindowAdjustWaitHandle = new ManualResetEvent(false); - private EventWaitHandle _errorOccuredWaitHandle = new ManualResetEvent(false); - private readonly object _serverWindowSizeLock = new object(); - private readonly uint _initialWindowSize; - private uint? _remoteWindowSize; - private uint? _remoteChannelNumber; - private uint? _remotePacketSize; - private ISession _session; - - /// - /// Holds a value indicating whether the SSH_MSG_CHANNEL_CLOSE has been sent to the remote party. - /// - /// - /// 0 when the SSH_MSG_CHANNEL_CLOSE message has not been sent or considered - /// 1 when sending a SSH_MSG_CHANNEL_CLOSE message to the remote party is under consideration - /// 2 when this message has been sent to the remote party - /// - private int _closeMessageSent; - - /// - /// Holds a value indicating whether a SSH_MSG_CHANNEL_CLOSE has been received from the other - /// party. - /// - /// - /// true when a SSH_MSG_CHANNEL_CLOSE message has been received from the other party; - /// otherwise, false. - /// - private bool _closeMessageReceived; - - /// - /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been received from the other party. - /// - /// - /// true when a SSH_MSG_CHANNEL_EOF message has been received from the other party; - /// otherwise, false. - /// - private bool _eofMessageReceived; - - /// - /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been sent to the remote party. - /// - /// - /// 0 when the SSH_MSG_CHANNEL_EOF message has not been sent or considered - /// 1 when sending a SSH_MSG_CHANNEL_EOF message to the remote party is under consideration - /// 2 when this message has been sent to the remote party - /// - private int _eofMessageSent; - - /// - /// Occurs when an exception is thrown when processing channel messages. - /// - public event EventHandler Exception; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - protected Channel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - { - _session = session; - _initialWindowSize = localWindowSize; - LocalChannelNumber = localChannelNumber; - LocalPacketSize = localPacketSize; - LocalWindowSize = localWindowSize; - - _session.ChannelWindowAdjustReceived += OnChannelWindowAdjust; - _session.ChannelDataReceived += OnChannelData; - _session.ChannelExtendedDataReceived += OnChannelExtendedData; - _session.ChannelEofReceived += OnChannelEof; - _session.ChannelCloseReceived += OnChannelClose; - _session.ChannelRequestReceived += OnChannelRequest; - _session.ChannelSuccessReceived += OnChannelSuccess; - _session.ChannelFailureReceived += OnChannelFailure; - _session.ErrorOccured += Session_ErrorOccured; - _session.Disconnected += Session_Disconnected; - } - - /// - /// Gets the session. - /// - /// - /// Thhe session. - /// - protected ISession Session - { - get { return _session; } - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public abstract ChannelTypes ChannelType { get; } - - /// - /// Gets the local channel number. - /// - /// - /// The local channel number. - /// - public uint LocalChannelNumber { get; private set; } - - /// - /// Gets the maximum size of a packet. - /// - /// - /// The maximum size of a packet. - /// - public uint LocalPacketSize { get; private set; } - - /// - /// Gets the size of the local window. - /// - /// - /// The size of the local window. - /// - public uint LocalWindowSize { get; private set; } - - /// - /// Gets the remote channel number. - /// - /// - /// The remote channel number. - /// - public uint RemoteChannelNumber - { - get - { - if (!_remoteChannelNumber.HasValue) - throw CreateRemoteChannelInfoNotAvailableException(); - return _remoteChannelNumber.Value; - } - private set - { - _remoteChannelNumber = value; - } - } - - /// - /// Gets the maximum size of a data packet that we can send using the channel. - /// - /// - /// The maximum size of data that can be sent using a - /// on the current channel. - /// - /// The channel has not been opened, or the open has not yet been confirmed. - public uint RemotePacketSize - { - get - { - if (!_remotePacketSize.HasValue) - throw CreateRemoteChannelInfoNotAvailableException(); - return _remotePacketSize.Value; - } - private set - { - _remotePacketSize = value; - } - } - - /// - /// Gets the window size of the remote server. - /// - /// - /// The size of the server window. - /// - public uint RemoteWindowSize - { - get - { - if (!_remoteWindowSize.HasValue) - throw CreateRemoteChannelInfoNotAvailableException(); - return _remoteWindowSize.Value; - } - private set - { - _remoteWindowSize = value; - } - } - - /// - /// Gets a value indicating whether this channel is open. - /// - /// - /// true if this channel is open; otherwise, false. - /// - public bool IsOpen { get; protected set; } - - #region Message events - - /// - /// Occurs when message received - /// - public event EventHandler DataReceived; - - /// - /// Occurs when message received - /// - public event EventHandler ExtendedDataReceived; - - /// - /// Occurs when message received - /// - public event EventHandler EndOfData; - - /// - /// Occurs when message received - /// - public event EventHandler Closed; - - /// - /// Occurs when message received - /// - public event EventHandler RequestReceived; - - /// - /// Occurs when message received - /// - public event EventHandler RequestSucceeded; - - /// - /// Occurs when message received - /// - public event EventHandler RequestFailed; - - #endregion - - /// - /// Gets a value indicating whether the session is connected. - /// - /// - /// true if the session is connected; otherwise, false. - /// - protected bool IsConnected - { - get { return _session.IsConnected; } - } - - /// - /// Gets the connection info. - /// - /// The connection info. - protected IConnectionInfo ConnectionInfo - { - get { return _session.ConnectionInfo; } - } - - /// - /// Gets the session semaphore to control number of session channels - /// - /// The session semaphore. - protected SemaphoreLight SessionSemaphore - { - get { return _session.SessionSemaphore; } - } - - protected void InitializeRemoteInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - { - RemoteChannelNumber = remoteChannelNumber; - RemoteWindowSize = remoteWindowSize; - RemotePacketSize = remotePacketSize; - } - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// The payload to send. - public void SendData(byte[] data) - { - SendData(data, 0, data.Length); - } - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// An array of containing the payload to send. - /// The zero-based offset in at which to begin taking data from. - /// The number of bytes of to send. - /// - /// - /// When the size of the data to send exceeds the maximum packet size or the remote window - /// size does not allow the full data to be sent, then this method will send the data in - /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. - /// - /// - /// This is done to support SSH servers will a small window size that do not agressively - /// increase their window size. We need to take into account that there may be SSH servers - /// that only increase their window size when it has reached zero. - /// - /// - public void SendData(byte[] data, int offset, int size) - { - // send channel messages only while channel is open - if (!IsOpen) - return; - - var totalBytesToSend = size; - while (totalBytesToSend > 0) - { - var sizeOfCurrentMessage = GetDataLengthThatCanBeSentInMessage(totalBytesToSend); - - var channelDataMessage = new ChannelDataMessage( - RemoteChannelNumber, - data, - offset, - sizeOfCurrentMessage); - _session.SendMessage(channelDataMessage); - - totalBytesToSend -= sizeOfCurrentMessage; - offset += sizeOfCurrentMessage; - } - } - - /// - /// Closes the channel. - /// - public void Close() - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Close"); -#endif // DEBUG_GERT - Close(true); - } - - #region Channel virtual methods - - /// - /// Called when channel window need to be adjust. - /// - /// The bytes to add. - protected virtual void OnWindowAdjust(uint bytesToAdd) - { - lock (_serverWindowSizeLock) - { - RemoteWindowSize += bytesToAdd; - } - _channelServerWindowAdjustWaitHandle.Set(); - } - - /// - /// Called when channel data is received. - /// - /// The data. - protected virtual void OnData(byte[] data) - { - AdjustDataWindow(data); - - var dataReceived = DataReceived; - if (dataReceived != null) - dataReceived(this, new ChannelDataEventArgs(LocalChannelNumber, data)); - } - - /// - /// Called when channel extended data is received. - /// - /// The data. - /// The data type code. - protected virtual void OnExtendedData(byte[] data, uint dataTypeCode) - { - AdjustDataWindow(data); - - var extendedDataReceived = ExtendedDataReceived; - if (extendedDataReceived != null) - extendedDataReceived(this, new ChannelExtendedDataEventArgs(LocalChannelNumber, data, dataTypeCode)); - } - - /// - /// Called when channel has no more data to receive. - /// - protected virtual void OnEof() - { - _eofMessageReceived = true; - - var endOfData = EndOfData; - if (endOfData != null) - endOfData(this, new ChannelEventArgs(LocalChannelNumber)); - } - - /// - /// Called when channel is closed by the server. - /// - protected virtual void OnClose() - { - _closeMessageReceived = true; - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.OnClose()"); -#endif // DEBUG_GERT - - // close the channel - Close(false); - - var closed = Closed; - if (closed != null) - closed(this, new ChannelEventArgs(LocalChannelNumber)); - } - - /// - /// Called when channel request received. - /// - /// Channel request information. - protected virtual void OnRequest(RequestInfo info) - { - var requestReceived = RequestReceived; - if (requestReceived != null) - requestReceived(this, new ChannelRequestEventArgs(info)); - } - - /// - /// Called when channel request was successful - /// - protected virtual void OnSuccess() - { - var requestSuccessed = RequestSucceeded; - if (requestSuccessed != null) - requestSuccessed(this, new ChannelEventArgs(LocalChannelNumber)); - } - - /// - /// Called when channel request failed. - /// - protected virtual void OnFailure() - { - var requestFailed = RequestFailed; - if (requestFailed != null) - requestFailed(this, new ChannelEventArgs(LocalChannelNumber)); - } - - #endregion // Channel virtual methods - - /// - /// Raises event. - /// - /// The exception. - protected void RaiseExceptionEvent(Exception exception) - { - var handlers = Exception; - if (handlers != null) - { - handlers(this, new ExceptionEventArgs(exception)); - } - } - - /// - /// Sends a message to the server. - /// - /// The message to send. - /// - /// true if the message was sent to the server; otherwise, false. - /// - /// The size of the packet exceeds the maximum size defined by the protocol. - /// - /// This methods returns false when the attempt to send the message results in a - /// or a . - /// - private bool TrySendMessage(Message message) - { - return _session.TrySendMessage(message); - } - - /// - /// Sends SSH message to the server. - /// - /// The message. - protected void SendMessage(Message message) - { - // send channel messages only while channel is open - if (!IsOpen) - return; - - _session.SendMessage(message); - } - - /// - /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. - /// - /// The channel is closed. - public void SendEof() - { - if (!IsOpen) - throw CreateChannelClosedException(); - - _session.SendMessage(new ChannelEofMessage(RemoteChannelNumber)); - _eofMessageSent = Sent; - } - - /// - /// Waits for the handle to be signaled or for an error to occurs. - /// - /// The wait handle. - protected void WaitOnHandle(WaitHandle waitHandle) - { - _session.WaitOnHandle(waitHandle); - } - - /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. - /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected virtual void Close(bool wait) - { - // send EOF message first when channel need to be closed, and the remote party has not already sent - // a SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message - // - // note that we might have had a race condition here when the remote party sends a SSH_MSG_CHANNEL_CLOSE - // immediately after it has sent a SSH_MSG_CHANNEL_EOF message - // - // in that case, we would risk sending a SSH_MSG_CHANNEL_EOF message after the remote party has - // closed its end of the channel - // - // as a solution for this issue we only send a SSH_MSG_CHANNEL_EOF message if we haven't received a - // SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message from the remote party - if (Interlocked.CompareExchange(ref _eofMessageSent, Considered, Initial) == Initial) - { - if (!_closeMessageReceived && !_eofMessageReceived && IsOpen && IsConnected) - { - if (TrySendMessage(new ChannelEofMessage(RemoteChannelNumber))) - _eofMessageSent = Sent; - } - } - - // send message to close the channel on the server - if (Interlocked.CompareExchange(ref _closeMessageSent, Considered, Initial) == Initial) - { - // ignore sending close message when client is not connected or the channel is closed - if (IsOpen && IsConnected) - { - if (TrySendMessage(new ChannelCloseMessage(RemoteChannelNumber))) - _closeMessageSent = Sent; - } - } - - // mark the channel closed - IsOpen = false; - - // wait for channel to be closed if we actually sent a close message (either to initiate closing - // the channel, or as response to a SSH_MSG_CHANNEL_CLOSE message sent by the server - if (wait && _closeMessageSent == Sent) - { - try - { - WaitOnHandle(_channelClosedWaitHandle); - } - catch (SshConnectionException) - { - // ignore connection failures as we're closing the channel anyway - } - } - - // reset indicators in case we want to reopen the channel; these are safe to reset - // since the channel is marked closed by now - _eofMessageSent = Initial; - _eofMessageReceived = false; - _closeMessageReceived = false; - _closeMessageSent = Initial; - } - - protected virtual void OnDisconnected() - { - } - - protected virtual void OnErrorOccured(Exception exp) - { - } - - private void Session_Disconnected(object sender, EventArgs e) - { - IsOpen = false; - - try - { - OnDisconnected(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - - /// - /// Called when an occurs while processing a channel message. - /// - /// The . - /// - /// This method will in turn invoke , and - /// raise the event. - /// - protected void OnChannelException(Exception ex) - { - OnErrorOccured(ex); - RaiseExceptionEvent(ex); - } - - private void Session_ErrorOccured(object sender, ExceptionEventArgs e) - { - try - { - OnErrorOccured(e.Exception); - - var errorOccuredWaitHandle = _errorOccuredWaitHandle; - if (errorOccuredWaitHandle != null) - errorOccuredWaitHandle.Set(); - } - catch (Exception ex) - { - RaiseExceptionEvent(ex); - } - } - - #region Channel message event handlers - - private void OnChannelWindowAdjust(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnWindowAdjust(e.Message.BytesToAdd); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelData(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnData(e.Message.Data); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelExtendedData(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnExtendedData(e.Message.Data, e.Message.DataTypeCode); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelEof(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnEof(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelClose(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnClose(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - - var channelClosedWaitHandle = _channelClosedWaitHandle; - if (channelClosedWaitHandle != null) - channelClosedWaitHandle.Set(); - } - } - - private void OnChannelRequest(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - if (_session.ConnectionInfo.ChannelRequests.ContainsKey(e.Message.RequestName)) - { - // Get request specific class - var requestInfo = _session.ConnectionInfo.ChannelRequests[e.Message.RequestName]; - - // Load request specific data - requestInfo.Load(e.Message.RequestData); - - // Raise request specific event - OnRequest(requestInfo); - } - else - { - // TODO: we should also send a SSH_MSG_CHANNEL_FAILURE message - throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Request '{0}' is not supported.", e.Message.RequestName)); - } - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelSuccess(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnSuccess(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelFailure(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnFailure(); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - #endregion // Channel message event handlers - - private void AdjustDataWindow(byte[] messageData) - { - LocalWindowSize -= (uint)messageData.Length; - - // Adjust window if window size is too low - if (LocalWindowSize < LocalPacketSize) - { - SendMessage(new ChannelWindowAdjustMessage(RemoteChannelNumber, _initialWindowSize - LocalWindowSize)); - LocalWindowSize = _initialWindowSize; - } - } - - /// - /// Determines the length of data that currently can be sent in a single message. - /// - /// The length of the message that must be sent. - /// - /// The actual data length that currently can be sent. - /// - private int GetDataLengthThatCanBeSentInMessage(int messageLength) - { - do - { - lock (_serverWindowSizeLock) - { - var serverWindowSize = RemoteWindowSize; - if (serverWindowSize == 0) - { - // allow us to be signal when remote window size is adjusted - _channelServerWindowAdjustWaitHandle.Reset(); - } - else - { - var bytesThatCanBeSent = Math.Min(Math.Min(RemotePacketSize, (uint) messageLength), - serverWindowSize); - RemoteWindowSize -= bytesThatCanBeSent; - return (int) bytesThatCanBeSent; - } - } - // wait for remote window size to change - WaitOnHandle(_channelServerWindowAdjustWaitHandle); - } while (true); - } - - private InvalidOperationException CreateRemoteChannelInfoNotAvailableException() - { - throw new InvalidOperationException("The channel has not been opened, or the open has not yet been confirmed."); - } - - private InvalidOperationException CreateChannelClosedException() - { - throw new InvalidOperationException("The channel is closed."); - } - - #region IDisposable Members - - private bool _isDisposed; - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool disposing) - { - if (_isDisposed) - return; - - if (disposing) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Dipose(bool)"); -#endif // DEBUG_GERT - - Close(false); - - var session = _session; - if (session != null) - { - session.ChannelWindowAdjustReceived -= OnChannelWindowAdjust; - session.ChannelDataReceived -= OnChannelData; - session.ChannelExtendedDataReceived -= OnChannelExtendedData; - session.ChannelEofReceived -= OnChannelEof; - session.ChannelCloseReceived -= OnChannelClose; - session.ChannelRequestReceived -= OnChannelRequest; - session.ChannelSuccessReceived -= OnChannelSuccess; - session.ChannelFailureReceived -= OnChannelFailure; - session.ErrorOccured -= Session_ErrorOccured; - session.Disconnected -= Session_Disconnected; - _session = null; - } - - var channelClosedWaitHandle = _channelClosedWaitHandle; - if (channelClosedWaitHandle != null) - { - channelClosedWaitHandle.Dispose(); - _channelClosedWaitHandle = null; - } - - var channelServerWindowAdjustWaitHandle = _channelServerWindowAdjustWaitHandle; - if (channelServerWindowAdjustWaitHandle != null) - { - channelServerWindowAdjustWaitHandle.Dispose(); - _channelServerWindowAdjustWaitHandle = null; - } - - var errorOccuredWaitHandle = _errorOccuredWaitHandle; - if (errorOccuredWaitHandle != null) - { - errorOccuredWaitHandle.Dispose(); - _errorOccuredWaitHandle = null; - } - - _isDisposed = true; - } - } - - /// - /// Releases unmanaged resources and performs other cleanup operations before the - /// is reclaimed by garbage collection. - /// - ~Channel() - { - Dispose(false); - } - - #endregion // IDisposable Members - } -} +using System; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Common; +using Renci.SshNet.Messages; +using Renci.SshNet.Messages.Connection; +using System.Globalization; + +namespace Renci.SshNet.Channels +{ + /// + /// Represents base class for SSH channel implementations. + /// + internal abstract class Channel : IChannel + { + private const int Initial = 0; + private const int Considered = 1; + private const int Sent = 2; + + private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(false); + private EventWaitHandle _channelServerWindowAdjustWaitHandle = new ManualResetEvent(false); + private EventWaitHandle _errorOccuredWaitHandle = new ManualResetEvent(false); + private readonly object _serverWindowSizeLock = new object(); + private readonly uint _initialWindowSize; + private uint? _remoteWindowSize; + private uint? _remoteChannelNumber; + private uint? _remotePacketSize; + private ISession _session; + + /// + /// Holds a value indicating whether the SSH_MSG_CHANNEL_CLOSE has been sent to the remote party. + /// + /// + /// 0 when the SSH_MSG_CHANNEL_CLOSE message has not been sent or considered + /// 1 when sending a SSH_MSG_CHANNEL_CLOSE message to the remote party is under consideration + /// 2 when this message has been sent to the remote party + /// + private int _closeMessageSent; + + /// + /// Holds a value indicating whether a SSH_MSG_CHANNEL_CLOSE has been received from the other + /// party. + /// + /// + /// true when a SSH_MSG_CHANNEL_CLOSE message has been received from the other party; + /// otherwise, false. + /// + private bool _closeMessageReceived; + + /// + /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been received from the other party. + /// + /// + /// true when a SSH_MSG_CHANNEL_EOF message has been received from the other party; + /// otherwise, false. + /// + private bool _eofMessageReceived; + + /// + /// Holds a value indicating whether the SSH_MSG_CHANNEL_EOF has been sent to the remote party. + /// + /// + /// 0 when the SSH_MSG_CHANNEL_EOF message has not been sent or considered + /// 1 when sending a SSH_MSG_CHANNEL_EOF message to the remote party is under consideration + /// 2 when this message has been sent to the remote party + /// + private int _eofMessageSent; + + /// + /// Occurs when an exception is thrown when processing channel messages. + /// + public event EventHandler Exception; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + protected Channel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + { + _session = session; + _initialWindowSize = localWindowSize; + LocalChannelNumber = localChannelNumber; + LocalPacketSize = localPacketSize; + LocalWindowSize = localWindowSize; + + _session.ChannelWindowAdjustReceived += OnChannelWindowAdjust; + _session.ChannelDataReceived += OnChannelData; + _session.ChannelExtendedDataReceived += OnChannelExtendedData; + _session.ChannelEofReceived += OnChannelEof; + _session.ChannelCloseReceived += OnChannelClose; + _session.ChannelRequestReceived += OnChannelRequest; + _session.ChannelSuccessReceived += OnChannelSuccess; + _session.ChannelFailureReceived += OnChannelFailure; + _session.ErrorOccured += Session_ErrorOccured; + _session.Disconnected += Session_Disconnected; + } + + /// + /// Gets the session. + /// + /// + /// Thhe session. + /// + protected ISession Session + { + get { return _session; } + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public abstract ChannelTypes ChannelType { get; } + + /// + /// Gets the local channel number. + /// + /// + /// The local channel number. + /// + public uint LocalChannelNumber { get; private set; } + + /// + /// Gets the maximum size of a packet. + /// + /// + /// The maximum size of a packet. + /// + public uint LocalPacketSize { get; private set; } + + /// + /// Gets the size of the local window. + /// + /// + /// The size of the local window. + /// + public uint LocalWindowSize { get; private set; } + + /// + /// Gets the remote channel number. + /// + /// + /// The remote channel number. + /// + public uint RemoteChannelNumber + { + get + { + if (!_remoteChannelNumber.HasValue) + throw CreateRemoteChannelInfoNotAvailableException(); + return _remoteChannelNumber.Value; + } + private set + { + _remoteChannelNumber = value; + } + } + + /// + /// Gets the maximum size of a data packet that we can send using the channel. + /// + /// + /// The maximum size of data that can be sent using a + /// on the current channel. + /// + /// The channel has not been opened, or the open has not yet been confirmed. + public uint RemotePacketSize + { + get + { + if (!_remotePacketSize.HasValue) + throw CreateRemoteChannelInfoNotAvailableException(); + return _remotePacketSize.Value; + } + private set + { + _remotePacketSize = value; + } + } + + /// + /// Gets the window size of the remote server. + /// + /// + /// The size of the server window. + /// + public uint RemoteWindowSize + { + get + { + if (!_remoteWindowSize.HasValue) + throw CreateRemoteChannelInfoNotAvailableException(); + return _remoteWindowSize.Value; + } + private set + { + _remoteWindowSize = value; + } + } + + /// + /// Gets a value indicating whether this channel is open. + /// + /// + /// true if this channel is open; otherwise, false. + /// + public bool IsOpen { get; protected set; } + + #region Message events + + /// + /// Occurs when message received + /// + public event EventHandler DataReceived; + + /// + /// Occurs when message received + /// + public event EventHandler ExtendedDataReceived; + + /// + /// Occurs when message received + /// + public event EventHandler EndOfData; + + /// + /// Occurs when message received + /// + public event EventHandler Closed; + + /// + /// Occurs when message received + /// + public event EventHandler RequestReceived; + + /// + /// Occurs when message received + /// + public event EventHandler RequestSucceeded; + + /// + /// Occurs when message received + /// + public event EventHandler RequestFailed; + + #endregion + + /// + /// Gets a value indicating whether the session is connected. + /// + /// + /// true if the session is connected; otherwise, false. + /// + protected bool IsConnected + { + get { return _session.IsConnected; } + } + + /// + /// Gets the connection info. + /// + /// The connection info. + protected IConnectionInfo ConnectionInfo + { + get { return _session.ConnectionInfo; } + } + + /// + /// Gets the session semaphore to control number of session channels + /// + /// The session semaphore. + protected SemaphoreLight SessionSemaphore + { + get { return _session.SessionSemaphore; } + } + + protected void InitializeRemoteInfo(uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + { + RemoteChannelNumber = remoteChannelNumber; + RemoteWindowSize = remoteWindowSize; + RemotePacketSize = remotePacketSize; + } + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// The payload to send. + public void SendData(byte[] data) + { + SendData(data, 0, data.Length); + } + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// An array of containing the payload to send. + /// The zero-based offset in at which to begin taking data from. + /// The number of bytes of to send. + /// + /// + /// When the size of the data to send exceeds the maximum packet size or the remote window + /// size does not allow the full data to be sent, then this method will send the data in + /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. + /// + /// + /// This is done to support SSH servers will a small window size that do not agressively + /// increase their window size. We need to take into account that there may be SSH servers + /// that only increase their window size when it has reached zero. + /// + /// + public void SendData(byte[] data, int offset, int size) + { + // send channel messages only while channel is open + if (!IsOpen) + return; + + var totalBytesToSend = size; + while (totalBytesToSend > 0) + { + var sizeOfCurrentMessage = GetDataLengthThatCanBeSentInMessage(totalBytesToSend); + + var channelDataMessage = new ChannelDataMessage( + RemoteChannelNumber, + data, + offset, + sizeOfCurrentMessage); + _session.SendMessage(channelDataMessage); + + totalBytesToSend -= sizeOfCurrentMessage; + offset += sizeOfCurrentMessage; + } + } + + /// + /// Closes the channel. + /// + public void Close() + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Close"); +#endif // DEBUG_GERT + Close(true); + } + + #region Channel virtual methods + + /// + /// Called when channel window need to be adjust. + /// + /// The bytes to add. + protected virtual void OnWindowAdjust(uint bytesToAdd) + { + lock (_serverWindowSizeLock) + { + RemoteWindowSize += bytesToAdd; + } + _channelServerWindowAdjustWaitHandle.Set(); + } + + /// + /// Called when channel data is received. + /// + /// The data. + protected virtual void OnData(byte[] data) + { + AdjustDataWindow(data); + + var dataReceived = DataReceived; + if (dataReceived != null) + dataReceived(this, new ChannelDataEventArgs(LocalChannelNumber, data)); + } + + /// + /// Called when channel extended data is received. + /// + /// The data. + /// The data type code. + protected virtual void OnExtendedData(byte[] data, uint dataTypeCode) + { + AdjustDataWindow(data); + + var extendedDataReceived = ExtendedDataReceived; + if (extendedDataReceived != null) + extendedDataReceived(this, new ChannelExtendedDataEventArgs(LocalChannelNumber, data, dataTypeCode)); + } + + /// + /// Called when channel has no more data to receive. + /// + protected virtual void OnEof() + { + _eofMessageReceived = true; + + var endOfData = EndOfData; + if (endOfData != null) + endOfData(this, new ChannelEventArgs(LocalChannelNumber)); + } + + /// + /// Called when channel is closed by the server. + /// + protected virtual void OnClose() + { + _closeMessageReceived = true; + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.OnClose()"); +#endif // DEBUG_GERT + + // close the channel + Close(false); + + var closed = Closed; + if (closed != null) + closed(this, new ChannelEventArgs(LocalChannelNumber)); + } + + /// + /// Called when channel request received. + /// + /// Channel request information. + protected virtual void OnRequest(RequestInfo info) + { + var requestReceived = RequestReceived; + if (requestReceived != null) + requestReceived(this, new ChannelRequestEventArgs(info)); + } + + /// + /// Called when channel request was successful + /// + protected virtual void OnSuccess() + { + var requestSuccessed = RequestSucceeded; + if (requestSuccessed != null) + requestSuccessed(this, new ChannelEventArgs(LocalChannelNumber)); + } + + /// + /// Called when channel request failed. + /// + protected virtual void OnFailure() + { + var requestFailed = RequestFailed; + if (requestFailed != null) + requestFailed(this, new ChannelEventArgs(LocalChannelNumber)); + } + + #endregion // Channel virtual methods + + /// + /// Raises event. + /// + /// The exception. + protected void RaiseExceptionEvent(Exception exception) + { + var handlers = Exception; + if (handlers != null) + { + handlers(this, new ExceptionEventArgs(exception)); + } + } + + /// + /// Sends a message to the server. + /// + /// The message to send. + /// + /// true if the message was sent to the server; otherwise, false. + /// + /// The size of the packet exceeds the maximum size defined by the protocol. + /// + /// This methods returns false when the attempt to send the message results in a + /// or a . + /// + private bool TrySendMessage(Message message) + { + return _session.TrySendMessage(message); + } + + /// + /// Sends SSH message to the server. + /// + /// The message. + protected void SendMessage(Message message) + { + // send channel messages only while channel is open + if (!IsOpen) + return; + + _session.SendMessage(message); + } + + /// + /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. + /// + /// The channel is closed. + public void SendEof() + { + if (!IsOpen) + throw CreateChannelClosedException(); + + _session.SendMessage(new ChannelEofMessage(RemoteChannelNumber)); + _eofMessageSent = Sent; + } + + /// + /// Waits for the handle to be signaled or for an error to occurs. + /// + /// The wait handle. + protected void WaitOnHandle(WaitHandle waitHandle) + { + _session.WaitOnHandle(waitHandle); + } + + /// + /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to + /// be received from the server. + /// + /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. + protected virtual void Close(bool wait) + { + // send EOF message first when channel need to be closed, and the remote party has not already sent + // a SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message + // + // note that we might have had a race condition here when the remote party sends a SSH_MSG_CHANNEL_CLOSE + // immediately after it has sent a SSH_MSG_CHANNEL_EOF message + // + // in that case, we would risk sending a SSH_MSG_CHANNEL_EOF message after the remote party has + // closed its end of the channel + // + // as a solution for this issue we only send a SSH_MSG_CHANNEL_EOF message if we haven't received a + // SSH_MSG_CHANNEL_EOF or SSH_MSG_CHANNEL_CLOSE message from the remote party + if (Interlocked.CompareExchange(ref _eofMessageSent, Considered, Initial) == Initial) + { + if (!_closeMessageReceived && !_eofMessageReceived && IsOpen && IsConnected) + { + if (TrySendMessage(new ChannelEofMessage(RemoteChannelNumber))) + _eofMessageSent = Sent; + } + } + + // send message to close the channel on the server + if (Interlocked.CompareExchange(ref _closeMessageSent, Considered, Initial) == Initial) + { + // ignore sending close message when client is not connected or the channel is closed + if (IsOpen && IsConnected) + { + if (TrySendMessage(new ChannelCloseMessage(RemoteChannelNumber))) + _closeMessageSent = Sent; + } + } + + // mark the channel closed + IsOpen = false; + + // wait for channel to be closed if we actually sent a close message (either to initiate closing + // the channel, or as response to a SSH_MSG_CHANNEL_CLOSE message sent by the server + if (wait && _closeMessageSent == Sent) + { + try + { + WaitOnHandle(_channelClosedWaitHandle); + } + catch (SshConnectionException) + { + // ignore connection failures as we're closing the channel anyway + } + } + + // reset indicators in case we want to reopen the channel; these are safe to reset + // since the channel is marked closed by now + _eofMessageSent = Initial; + _eofMessageReceived = false; + _closeMessageReceived = false; + _closeMessageSent = Initial; + } + + protected virtual void OnDisconnected() + { + } + + protected virtual void OnErrorOccured(Exception exp) + { + } + + private void Session_Disconnected(object sender, EventArgs e) + { + IsOpen = false; + + try + { + OnDisconnected(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + + /// + /// Called when an occurs while processing a channel message. + /// + /// The . + /// + /// This method will in turn invoke , and + /// raise the event. + /// + protected void OnChannelException(Exception ex) + { + OnErrorOccured(ex); + RaiseExceptionEvent(ex); + } + + private void Session_ErrorOccured(object sender, ExceptionEventArgs e) + { + try + { + OnErrorOccured(e.Exception); + + var errorOccuredWaitHandle = _errorOccuredWaitHandle; + if (errorOccuredWaitHandle != null) + errorOccuredWaitHandle.Set(); + } + catch (Exception ex) + { + RaiseExceptionEvent(ex); + } + } + + #region Channel message event handlers + + private void OnChannelWindowAdjust(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnWindowAdjust(e.Message.BytesToAdd); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelData(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnData(e.Message.Data); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelExtendedData(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnExtendedData(e.Message.Data, e.Message.DataTypeCode); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelEof(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnEof(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelClose(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnClose(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + + var channelClosedWaitHandle = _channelClosedWaitHandle; + if (channelClosedWaitHandle != null) + channelClosedWaitHandle.Set(); + } + } + + private void OnChannelRequest(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + if (_session.ConnectionInfo.ChannelRequests.ContainsKey(e.Message.RequestName)) + { + // Get request specific class + var requestInfo = _session.ConnectionInfo.ChannelRequests[e.Message.RequestName]; + + // Load request specific data + requestInfo.Load(e.Message.RequestData); + + // Raise request specific event + OnRequest(requestInfo); + } + else + { + // TODO: we should also send a SSH_MSG_CHANNEL_FAILURE message + throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Request '{0}' is not supported.", e.Message.RequestName)); + } + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelSuccess(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnSuccess(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelFailure(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnFailure(); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + #endregion // Channel message event handlers + + private void AdjustDataWindow(byte[] messageData) + { + LocalWindowSize -= (uint)messageData.Length; + + // Adjust window if window size is too low + if (LocalWindowSize < LocalPacketSize) + { + SendMessage(new ChannelWindowAdjustMessage(RemoteChannelNumber, _initialWindowSize - LocalWindowSize)); + LocalWindowSize = _initialWindowSize; + } + } + + /// + /// Determines the length of data that currently can be sent in a single message. + /// + /// The length of the message that must be sent. + /// + /// The actual data length that currently can be sent. + /// + private int GetDataLengthThatCanBeSentInMessage(int messageLength) + { + do + { + lock (_serverWindowSizeLock) + { + var serverWindowSize = RemoteWindowSize; + if (serverWindowSize == 0) + { + // allow us to be signal when remote window size is adjusted + _channelServerWindowAdjustWaitHandle.Reset(); + } + else + { + var bytesThatCanBeSent = Math.Min(Math.Min(RemotePacketSize, (uint) messageLength), + serverWindowSize); + RemoteWindowSize -= bytesThatCanBeSent; + return (int) bytesThatCanBeSent; + } + } + // wait for remote window size to change + WaitOnHandle(_channelServerWindowAdjustWaitHandle); + } while (true); + } + + private InvalidOperationException CreateRemoteChannelInfoNotAvailableException() + { + throw new InvalidOperationException("The channel has not been opened, or the open has not yet been confirmed."); + } + + private InvalidOperationException CreateChannelClosedException() + { + throw new InvalidOperationException("The channel is closed."); + } + + #region IDisposable Members + + private bool _isDisposed; + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases unmanaged and - optionally - managed resources + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + if (_isDisposed) + return; + + if (disposing) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Channel.Dipose(bool)"); +#endif // DEBUG_GERT + + Close(false); + + var session = _session; + if (session != null) + { + session.ChannelWindowAdjustReceived -= OnChannelWindowAdjust; + session.ChannelDataReceived -= OnChannelData; + session.ChannelExtendedDataReceived -= OnChannelExtendedData; + session.ChannelEofReceived -= OnChannelEof; + session.ChannelCloseReceived -= OnChannelClose; + session.ChannelRequestReceived -= OnChannelRequest; + session.ChannelSuccessReceived -= OnChannelSuccess; + session.ChannelFailureReceived -= OnChannelFailure; + session.ErrorOccured -= Session_ErrorOccured; + session.Disconnected -= Session_Disconnected; + _session = null; + } + + var channelClosedWaitHandle = _channelClosedWaitHandle; + if (channelClosedWaitHandle != null) + { + channelClosedWaitHandle.Dispose(); + _channelClosedWaitHandle = null; + } + + var channelServerWindowAdjustWaitHandle = _channelServerWindowAdjustWaitHandle; + if (channelServerWindowAdjustWaitHandle != null) + { + channelServerWindowAdjustWaitHandle.Dispose(); + _channelServerWindowAdjustWaitHandle = null; + } + + var errorOccuredWaitHandle = _errorOccuredWaitHandle; + if (errorOccuredWaitHandle != null) + { + errorOccuredWaitHandle.Dispose(); + _errorOccuredWaitHandle = null; + } + + _isDisposed = true; + } + } + + /// + /// Releases unmanaged resources and performs other cleanup operations before the + /// is reclaimed by garbage collection. + /// + ~Channel() + { + Dispose(false); + } + + #endregion // IDisposable Members + } +} diff --git a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs index 98a245ee..b5eae832 100644 --- a/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelDirectTcpip.cs @@ -1,345 +1,345 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Abstractions; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Implements "direct-tcpip" SSH channel. - /// - internal class ChannelDirectTcpip : ClientChannel, IChannelDirectTcpip - { - private readonly object _socketLock = new object(); - - private EventWaitHandle _channelOpen = new AutoResetEvent(false); - private EventWaitHandle _channelData = new AutoResetEvent(false); - private IForwardedPort _forwardedPort; - private Socket _socket; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - public ChannelDirectTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public override ChannelTypes ChannelType - { - get { return ChannelTypes.DirectTcpip; } - } - - public void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket) - { - if (IsOpen) - throw new SshException("Channel is already open."); - if (!IsConnected) - throw new SshException("Session is not connected."); - - _socket = socket; - _forwardedPort = forwardedPort; - _forwardedPort.Closing += ForwardedPort_Closing; - - var ep = (IPEndPoint) socket.RemoteEndPoint; - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage send '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // open channel - SendMessage(new ChannelOpenMessage(LocalChannelNumber, LocalWindowSize, LocalPacketSize, - new DirectTcpipChannelInfo(remoteHost, port, ep.Address.ToString(), (uint) ep.Port))); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage sent '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // Wait for channel to open - WaitOnHandle(_channelOpen); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage flagged '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - } - - /// - /// Occurs as the forwarded port is being stopped. - /// - private void ForwardedPort_Closing(object sender, EventArgs eventArgs) - { - // signal to the client that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the client sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Binds channel to remote host. - /// - public void Bind() - { - // Cannot bind if channel is not open - if (!IsOpen) - return; - - var buffer = new byte[RemotePacketSize]; - - SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Bind (after) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // even though the client has disconnected, we still want to properly close the - // channel - // - // we'll do this in in Close(bool) that way we have a single place from which we - // send an SSH_MSG_CHANNEL_EOF message and wait for the SSH_MSG_CHANNEL_CLOSE - // message - } - - /// - /// Closes the socket, hereby interrupting the blocking receive in . - /// - private void CloseSocket() - { - if (_socket == null) - return; - - lock (_socketLock) - { - if (_socket == null) - return; - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.CloseSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - // closing a socket actually disposes the socket, so we can safely dereference - // the field to avoid entering the lock again later - _socket.Dispose(); - _socket = null; - } - } - - /// - /// Shuts down the socket. - /// - /// One of the values that specifies the operation that will no longer be allowed. - private void ShutdownSocket(SocketShutdown how) - { - if (_socket == null) - return; - - lock (_socketLock) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.ShutdownSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - if (_socket == null || !_socket.Connected) - return; - - _socket.Shutdown(how); - } - } - - /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. - /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected override void Close(bool wait) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Close(bool) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - - var forwardedPort = _forwardedPort; - if (forwardedPort != null) - { - forwardedPort.Closing -= ForwardedPort_Closing; - _forwardedPort = null; - } - - // signal to the client that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the client sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed - ShutdownSocket(SocketShutdown.Send); - - // close the SSH channel, and mark the channel closed - base.Close(wait); - - // close the socket - CloseSocket(); - } - - /// - /// Called when channel data is received. - /// - /// The data. - protected override void OnData(byte[] data) - { - base.OnData(data); - - if (_socket != null && _socket.Connected) - { - lock (_socketLock) - { - if (_socket != null && _socket.Connected) - { - SocketAbstraction.Send(_socket, data, 0, data.Length); - } - } - } - } - - /// - /// Called when channel is opened by the server. - /// - /// The remote channel number. - /// Initial size of the window. - /// Maximum size of the packet. - protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); - - _channelOpen.Set(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage confirmed '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - } - - protected override void OnOpenFailure(uint reasonCode, string description, string language) - { - base.OnOpenFailure(reasonCode, description, language); - - _channelOpen.Set(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage failure '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); -#endif // DEBUG_GERT - } - - /// - /// Called when channel has no more data to receive. - /// - protected override void OnEof() - { - base.OnEof(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnEof '" + LocalChannelNumber + "' | " + - DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - // the channel will send no more data, and hence it does not make sense to receive - // any more data from the client to send to the remote party (and we surely won't - // send anything anymore) - // - // this will also interrupt the blocking receive in Bind() - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Called whenever an unhandled occurs in causing - /// the message loop to be interrupted, or when an exception occurred processing a channel message. - /// - protected override void OnErrorOccured(Exception exp) - { - base.OnErrorOccured(exp); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnErrorOccured '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - // signal to the client that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the client sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Called when the server wants to terminate the connection immmediately. - /// - /// - /// The sender MUST NOT send or receive any data after this message, and - /// the recipient MUST NOT accept any data after receiving this message. - /// - protected override void OnDisconnected() - { - base.OnDisconnected(); - -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnDisconnected '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - // the channel will accept or send no more data, and hence it does not make sense - // to accept any more data from the client (and we surely won't send anything - // anymore) - // - // - // so lets signal to the client that we will not send or receive anything anymore - // this will also interrupt the blocking receive in Bind() - ShutdownSocket(SocketShutdown.Both); - } - - protected override void Dispose(bool disposing) - { - // make sure we've unsubscribed from all session events and closed the channel - // before we starting disposing - base.Dispose(disposing); - - if (disposing) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Dispose '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); -#endif // DEBUG_GERT - - if (_socket != null) - { - lock (_socketLock) - { - if (_socket != null) - { - _socket.Dispose(); - _socket = null; - } - } - } - - var channelOpen = _channelOpen; - if (channelOpen != null) - { - channelOpen.Dispose(); - _channelOpen = null; - } - - var channelData = _channelData; - if (channelData != null) - { - channelData.Dispose(); - _channelData = null; - } - } - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Abstractions; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Implements "direct-tcpip" SSH channel. + /// + internal class ChannelDirectTcpip : ClientChannel, IChannelDirectTcpip + { + private readonly object _socketLock = new object(); + + private EventWaitHandle _channelOpen = new AutoResetEvent(false); + private EventWaitHandle _channelData = new AutoResetEvent(false); + private IForwardedPort _forwardedPort; + private Socket _socket; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + public ChannelDirectTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public override ChannelTypes ChannelType + { + get { return ChannelTypes.DirectTcpip; } + } + + public void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket) + { + if (IsOpen) + throw new SshException("Channel is already open."); + if (!IsConnected) + throw new SshException("Session is not connected."); + + _socket = socket; + _forwardedPort = forwardedPort; + _forwardedPort.Closing += ForwardedPort_Closing; + + var ep = (IPEndPoint) socket.RemoteEndPoint; + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage send '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // open channel + SendMessage(new ChannelOpenMessage(LocalChannelNumber, LocalWindowSize, LocalPacketSize, + new DirectTcpipChannelInfo(remoteHost, port, ep.Address.ToString(), (uint) ep.Port))); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage sent '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // Wait for channel to open + WaitOnHandle(_channelOpen); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage flagged '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + } + + /// + /// Occurs as the forwarded port is being stopped. + /// + private void ForwardedPort_Closing(object sender, EventArgs eventArgs) + { + // signal to the client that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the client sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Binds channel to remote host. + /// + public void Bind() + { + // Cannot bind if channel is not open + if (!IsOpen) + return; + + var buffer = new byte[RemotePacketSize]; + + SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Bind (after) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // even though the client has disconnected, we still want to properly close the + // channel + // + // we'll do this in in Close(bool) that way we have a single place from which we + // send an SSH_MSG_CHANNEL_EOF message and wait for the SSH_MSG_CHANNEL_CLOSE + // message + } + + /// + /// Closes the socket, hereby interrupting the blocking receive in . + /// + private void CloseSocket() + { + if (_socket == null) + return; + + lock (_socketLock) + { + if (_socket == null) + return; + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.CloseSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + // closing a socket actually disposes the socket, so we can safely dereference + // the field to avoid entering the lock again later + _socket.Dispose(); + _socket = null; + } + } + + /// + /// Shuts down the socket. + /// + /// One of the values that specifies the operation that will no longer be allowed. + private void ShutdownSocket(SocketShutdown how) + { + if (_socket == null) + return; + + lock (_socketLock) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.ShutdownSocket '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + if (_socket == null || !_socket.Connected) + return; + + _socket.Shutdown(how); + } + } + + /// + /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to + /// be received from the server. + /// + /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. + protected override void Close(bool wait) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.Close(bool) '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + + var forwardedPort = _forwardedPort; + if (forwardedPort != null) + { + forwardedPort.Closing -= ForwardedPort_Closing; + _forwardedPort = null; + } + + // signal to the client that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the client sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed + ShutdownSocket(SocketShutdown.Send); + + // close the SSH channel, and mark the channel closed + base.Close(wait); + + // close the socket + CloseSocket(); + } + + /// + /// Called when channel data is received. + /// + /// The data. + protected override void OnData(byte[] data) + { + base.OnData(data); + + if (_socket != null && _socket.Connected) + { + lock (_socketLock) + { + if (_socket != null && _socket.Connected) + { + SocketAbstraction.Send(_socket, data, 0, data.Length); + } + } + } + } + + /// + /// Called when channel is opened by the server. + /// + /// The remote channel number. + /// Initial size of the window. + /// Maximum size of the packet. + protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); + + _channelOpen.Set(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage confirmed '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + } + + protected override void OnOpenFailure(uint reasonCode, string description, string language) + { + base.OnOpenFailure(reasonCode, description, language); + + _channelOpen.Set(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelOpenMessage failure '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss.fff")); +#endif // DEBUG_GERT + } + + /// + /// Called when channel has no more data to receive. + /// + protected override void OnEof() + { + base.OnEof(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnEof '" + LocalChannelNumber + "' | " + + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + // the channel will send no more data, and hence it does not make sense to receive + // any more data from the client to send to the remote party (and we surely won't + // send anything anymore) + // + // this will also interrupt the blocking receive in Bind() + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Called whenever an unhandled occurs in causing + /// the message loop to be interrupted, or when an exception occurred processing a channel message. + /// + protected override void OnErrorOccured(Exception exp) + { + base.OnErrorOccured(exp); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnErrorOccured '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + // signal to the client that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the client sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Called when the server wants to terminate the connection immmediately. + /// + /// + /// The sender MUST NOT send or receive any data after this message, and + /// the recipient MUST NOT accept any data after receiving this message. + /// + protected override void OnDisconnected() + { + base.OnDisconnected(); + +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelDirectTcpip.OnDisconnected '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + // the channel will accept or send no more data, and hence it does not make sense + // to accept any more data from the client (and we surely won't send anything + // anymore) + // + // + // so lets signal to the client that we will not send or receive anything anymore + // this will also interrupt the blocking receive in Bind() + ShutdownSocket(SocketShutdown.Both); + } + + protected override void Dispose(bool disposing) + { + // make sure we've unsubscribed from all session events and closed the channel + // before we starting disposing + base.Dispose(disposing); + + if (disposing) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | Dispose '" + LocalChannelNumber + "' | " + DateTime.Now.ToString("hh:mm:ss")); +#endif // DEBUG_GERT + + if (_socket != null) + { + lock (_socketLock) + { + if (_socket != null) + { + _socket.Dispose(); + _socket = null; + } + } + } + + var channelOpen = _channelOpen; + if (channelOpen != null) + { + channelOpen.Dispose(); + _channelOpen = null; + } + + var channelData = _channelData; + if (channelData != null) + { + channelData.Dispose(); + _channelData = null; + } + } + } + } +} diff --git a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs index fac2a90d..ff76166e 100644 --- a/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs @@ -1,212 +1,212 @@ -using System; -using System.Net; -using System.Net.Sockets; -using System.Threading; -using Renci.SshNet.Abstractions; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Implements "forwarded-tcpip" SSH channel. - /// - internal class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip - { - private readonly object _socketShutdownAndCloseLock = new object(); - private Socket _socket; - private IForwardedPort _forwardedPort; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - /// The remote channel number. - /// The window size of the remote party. - /// The maximum size of a data packet that we can send to the remote party. - internal ChannelForwardedTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize, remoteChannelNumber, remoteWindowSize, remotePacketSize) - { - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public override ChannelTypes ChannelType - { - get { return ChannelTypes.ForwardedTcpip; } - } - - /// - /// Binds the channel to the specified endpoint. - /// - /// The endpoint to connect to. - /// The forwarded port for which the channel is opened. - public void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort) - { - if (!IsConnected) - { - throw new SshException("Session is not connected."); - } - - _forwardedPort = forwardedPort; - _forwardedPort.Closing += ForwardedPort_Closing; - - // Try to connect to the socket - try - { - _socket = SocketAbstraction.Connect(remoteEndpoint, ConnectionInfo.Timeout); - - // send channel open confirmation message - SendMessage(new ChannelOpenConfirmationMessage(RemoteChannelNumber, LocalWindowSize, LocalPacketSize, LocalChannelNumber)); - } - catch (Exception exp) - { - // send channel open failure message - SendMessage(new ChannelOpenFailureMessage(RemoteChannelNumber, exp.ToString(), ChannelOpenFailureMessage.ConnectFailed, "en")); - - throw; - } - - var buffer = new byte[RemotePacketSize]; - - SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); - } - - protected override void OnErrorOccured(Exception exp) - { - base.OnErrorOccured(exp); - - // signal to the server that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the server sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Occurs as the forwarded port is being stopped. - /// - private void ForwardedPort_Closing(object sender, EventArgs eventArgs) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ForwardedPort_Closing"); -#endif // DEBUG_GERT - - // signal to the server that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the server sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) - ShutdownSocket(SocketShutdown.Send); - } - - /// - /// Shuts down the socket. - /// - /// One of the values that specifies the operation that will no longer be allowed. - private void ShutdownSocket(SocketShutdown how) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ShutdownSocket"); -#endif // DEBUG_GERT - - if (_socket == null || !_socket.Connected) - return; - - lock (_socketShutdownAndCloseLock) - { - var socket = _socket; - if (socket == null || !socket.Connected) - return; - - socket.Shutdown(how); - } - } - - /// - /// Closes the socket, hereby interrupting the blocking receive in . - /// - private void CloseSocket() - { - if (_socket == null) - return; - - lock (_socketShutdownAndCloseLock) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.CloseSocket"); -#endif // DEBUG_GERT - - var socket = _socket; - if (socket != null) - { - // closing a socket actually disposes the socket, so we can safely dereference - // the field to avoid entering the lock again later - socket.Dispose(); - _socket = null; - } - } - } - - /// - /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to - /// be received from the server. - /// - /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. - protected override void Close(bool wait) - { -#if DEBUG_GERT - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.Close"); -#endif // DEBUG_GERT - - var forwardedPort = _forwardedPort; - if (forwardedPort != null) - { - forwardedPort.Closing -= ForwardedPort_Closing; - _forwardedPort = null; - } - - // signal to the server that we will not send anything anymore; this will also interrupt the - // blocking receive in Bind if the server sends FIN/ACK in time - // - // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed - ShutdownSocket(SocketShutdown.Send); - - // close the SSH channel, and mark the channel closed - base.Close(wait); - - // close the socket - CloseSocket(); - } - -#if DEBUG_GERT - protected override void OnClose() - { - base.OnClose(); - - Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | OnClose"); - } -#endif // DEBUG_GERT - - /// - /// Called when channel data is received. - /// - /// The data. - protected override void OnData(byte[] data) - { - base.OnData(data); - - var socket = _socket; - if (socket != null && socket.Connected) - { - SocketAbstraction.Send(socket, data, 0, data.Length); - } - } - } -} +using System; +using System.Net; +using System.Net.Sockets; +using System.Threading; +using Renci.SshNet.Abstractions; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Implements "forwarded-tcpip" SSH channel. + /// + internal class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip + { + private readonly object _socketShutdownAndCloseLock = new object(); + private Socket _socket; + private IForwardedPort _forwardedPort; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + /// The remote channel number. + /// The window size of the remote party. + /// The maximum size of a data packet that we can send to the remote party. + internal ChannelForwardedTcpip(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize, remoteChannelNumber, remoteWindowSize, remotePacketSize) + { + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public override ChannelTypes ChannelType + { + get { return ChannelTypes.ForwardedTcpip; } + } + + /// + /// Binds the channel to the specified endpoint. + /// + /// The endpoint to connect to. + /// The forwarded port for which the channel is opened. + public void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort) + { + if (!IsConnected) + { + throw new SshException("Session is not connected."); + } + + _forwardedPort = forwardedPort; + _forwardedPort.Closing += ForwardedPort_Closing; + + // Try to connect to the socket + try + { + _socket = SocketAbstraction.Connect(remoteEndpoint, ConnectionInfo.Timeout); + + // send channel open confirmation message + SendMessage(new ChannelOpenConfirmationMessage(RemoteChannelNumber, LocalWindowSize, LocalPacketSize, LocalChannelNumber)); + } + catch (Exception exp) + { + // send channel open failure message + SendMessage(new ChannelOpenFailureMessage(RemoteChannelNumber, exp.ToString(), ChannelOpenFailureMessage.ConnectFailed, "en")); + + throw; + } + + var buffer = new byte[RemotePacketSize]; + + SocketAbstraction.ReadContinuous(_socket, buffer, 0, buffer.Length, SendData); + } + + protected override void OnErrorOccured(Exception exp) + { + base.OnErrorOccured(exp); + + // signal to the server that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the server sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Occurs as the forwarded port is being stopped. + /// + private void ForwardedPort_Closing(object sender, EventArgs eventArgs) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ForwardedPort_Closing"); +#endif // DEBUG_GERT + + // signal to the server that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the server sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed in Close(bool) + ShutdownSocket(SocketShutdown.Send); + } + + /// + /// Shuts down the socket. + /// + /// One of the values that specifies the operation that will no longer be allowed. + private void ShutdownSocket(SocketShutdown how) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.ShutdownSocket"); +#endif // DEBUG_GERT + + if (_socket == null || !_socket.Connected) + return; + + lock (_socketShutdownAndCloseLock) + { + var socket = _socket; + if (socket == null || !socket.Connected) + return; + + socket.Shutdown(how); + } + } + + /// + /// Closes the socket, hereby interrupting the blocking receive in . + /// + private void CloseSocket() + { + if (_socket == null) + return; + + lock (_socketShutdownAndCloseLock) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.CloseSocket"); +#endif // DEBUG_GERT + + var socket = _socket; + if (socket != null) + { + // closing a socket actually disposes the socket, so we can safely dereference + // the field to avoid entering the lock again later + socket.Dispose(); + _socket = null; + } + } + } + + /// + /// Closes the channel, optionally waiting for the SSH_MSG_CHANNEL_CLOSE message to + /// be received from the server. + /// + /// true to wait for the SSH_MSG_CHANNEL_CLOSE message to be received from the server; otherwise, false. + protected override void Close(bool wait) + { +#if DEBUG_GERT + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | ChannelForwardedTcpip.Close"); +#endif // DEBUG_GERT + + var forwardedPort = _forwardedPort; + if (forwardedPort != null) + { + forwardedPort.Closing -= ForwardedPort_Closing; + _forwardedPort = null; + } + + // signal to the server that we will not send anything anymore; this will also interrupt the + // blocking receive in Bind if the server sends FIN/ACK in time + // + // if the FIN/ACK is not sent in time, the socket will be closed after the channel is closed + ShutdownSocket(SocketShutdown.Send); + + // close the SSH channel, and mark the channel closed + base.Close(wait); + + // close the socket + CloseSocket(); + } + +#if DEBUG_GERT + protected override void OnClose() + { + base.OnClose(); + + Console.WriteLine("ID: " + Thread.CurrentThread.ManagedThreadId + " | OnClose"); + } +#endif // DEBUG_GERT + + /// + /// Called when channel data is received. + /// + /// The data. + protected override void OnData(byte[] data) + { + base.OnData(data); + + var socket = _socket; + if (socket != null && socket.Connected) + { + SocketAbstraction.Send(socket, data, 0, data.Length); + } + } + } +} diff --git a/src/Renci.SshNet/Channels/ChannelSession.cs b/src/Renci.SshNet/Channels/ChannelSession.cs index c268c2ad..580cbb4d 100644 --- a/src/Renci.SshNet/Channels/ChannelSession.cs +++ b/src/Renci.SshNet/Channels/ChannelSession.cs @@ -1,429 +1,429 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Threading; -using Renci.SshNet.Abstractions; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Implements Session SSH channel. - /// - internal class ChannelSession : ClientChannel, IChannelSession - { - /// - /// Counts failed channel open attempts - /// - private int _failedOpenAttempts; - - /// - /// Holds a value indicating whether the session semaphore has been obtained by the current - /// channel. - /// - /// - /// 0 when the session semaphore has not been obtained or has already been released, - /// and 1 when the session has been obtained and still needs to be released. - /// - private int _sessionSemaphoreObtained; - - /// - /// Wait handle to signal when response was received to open the channel - /// - private EventWaitHandle _channelOpenResponseWaitHandle = new AutoResetEvent(false); - - private EventWaitHandle _channelRequestResponse = new ManualResetEvent(false); - - private bool _channelRequestSucces; - - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - public ChannelSession(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - } - - /// - /// Gets the type of the channel. - /// - /// - /// The type of the channel. - /// - public override ChannelTypes ChannelType - { - get { return ChannelTypes.Session; } - } - - /// - /// Opens the channel. - /// - public virtual void Open() - { - if (!IsOpen) - { - // Try to open channel several times - while (!IsOpen && _failedOpenAttempts < ConnectionInfo.RetryAttempts) - { - SendChannelOpenMessage(); - try - { - WaitOnHandle(_channelOpenResponseWaitHandle); - } - catch (Exception) - { - // avoid leaking session semaphore - ReleaseSemaphore(); - throw; - } - } - - if (!IsOpen) - throw new SshException(string.Format(CultureInfo.CurrentCulture, "Failed to open a channel after {0} attempts.", _failedOpenAttempts)); - } - } - - /// - /// Called when channel is opened by the server. - /// - /// The remote channel number. - /// Initial size of the window. - /// Maximum size of the packet. - protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); - _channelOpenResponseWaitHandle.Set(); - } - - /// - /// Called when channel failed to open. - /// - /// The reason code. - /// The description. - /// The language. - protected override void OnOpenFailure(uint reasonCode, string description, string language) - { - _failedOpenAttempts++; - ReleaseSemaphore(); - _channelOpenResponseWaitHandle.Set(); - } - - /// - /// Called when channel is closed by the server. - /// - protected override void OnClose() - { - base.OnClose(); - - // This timeout needed since when channel is closed it does not immediately becomes available - // but it takes time for the server to clean up resource and allow new channels to be created. - ThreadAbstraction.Sleep(100); - } - - protected override void Close(bool wait) - { - base.Close(wait); - - ReleaseSemaphore(); - } - - /// - /// Sends the pseudo terminal request. - /// - /// The environment variable. - /// The columns. - /// The rows. - /// The width. - /// The height. - /// The terminal mode values. - /// - /// true if request was successful; otherwise false. - /// - public bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, IDictionary terminalModeValues) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new PseudoTerminalRequestInfo(environmentVariable, columns, rows, width, height, terminalModeValues))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the X11 forwarding request. - /// - /// if set to true the it is single connection. - /// The protocol. - /// The cookie. - /// The screen number. - /// - /// true if request was successful; otherwise false. - /// - public bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new X11ForwardingRequestInfo(isSingleConnection, protocol, cookie, screenNumber))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the environment variable request. - /// - /// Name of the variable. - /// The variable value. - /// - /// true if request was successful; otherwise false. - /// - public bool SendEnvironmentVariableRequest(string variableName, string variableValue) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EnvironmentVariableRequestInfo(variableName, variableValue))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the shell request. - /// - /// - /// true if request was successful; otherwise false. - /// - public bool SendShellRequest() - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ShellRequestInfo())); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the exec request. - /// - /// The command. - /// - /// true if request was successful; otherwise false. - /// - public bool SendExecRequest(string command) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExecRequestInfo(command, ConnectionInfo.Encoding))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the exec request. - /// - /// Length of the break. - /// - /// true if request was successful; otherwise false. - /// - public bool SendBreakRequest(uint breakLength) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new BreakRequestInfo(breakLength))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the subsystem request. - /// - /// The subsystem. - /// - /// true if request was successful; otherwise false. - /// - public bool SendSubsystemRequest(string subsystem) - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SubsystemRequestInfo(subsystem))); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends the window change request. - /// - /// The columns. - /// The rows. - /// The width. - /// The height. - /// - /// true if request was successful; otherwise false. - /// - public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new WindowChangeRequestInfo(columns, rows, width, height))); - return true; - } - - /// - /// Sends the local flow request. - /// - /// if set to true [client can do]. - /// - /// true if request was successful; otherwise false. - /// - public bool SendLocalFlowRequest(bool clientCanDo) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new XonXoffRequestInfo(clientCanDo))); - return true; - } - - /// - /// Sends the signal request. - /// - /// Name of the signal. - /// - /// true if request was successful; otherwise false. - /// - public bool SendSignalRequest(string signalName) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SignalRequestInfo(signalName))); - return true; - } - - /// - /// Sends the exit status request. - /// - /// The exit status. - /// - /// true if request was successful; otherwise false. - /// - public bool SendExitStatusRequest(uint exitStatus) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitStatusRequestInfo(exitStatus))); - return true; - } - - /// - /// Sends the exit signal request. - /// - /// Name of the signal. - /// if set to true [core dumped]. - /// The error message. - /// The language. - /// - /// true if request was successful; otherwise false. - /// - public bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language) - { - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitSignalRequestInfo(signalName, coreDumped, errorMessage, language))); - return true; - } - - /// - /// Sends eow@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - public bool SendEndOfWriteRequest() - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EndOfWriteRequestInfo())); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Sends keepalive@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - public bool SendKeepAliveRequest() - { - _channelRequestResponse.Reset(); - SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new KeepAliveRequestInfo())); - WaitOnHandle(_channelRequestResponse); - return _channelRequestSucces; - } - - /// - /// Called when channel request was successful - /// - protected override void OnSuccess() - { - base.OnSuccess(); - _channelRequestSucces = true; - - var channelRequestResponse = _channelRequestResponse; - if (channelRequestResponse != null) - channelRequestResponse.Set(); - } - - /// - /// Called when channel request failed. - /// - protected override void OnFailure() - { - base.OnFailure(); - _channelRequestSucces = false; - - var channelRequestResponse = _channelRequestResponse; - if (channelRequestResponse != null) - channelRequestResponse.Set(); - } - - /// - /// Sends the channel open message. - /// - protected void SendChannelOpenMessage() - { - // do not allow open to be ChannelOpenMessage to be sent again until we've - // had a response on the previous attempt for the current channel - if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 1, 0) == 0) - { - SessionSemaphore.Wait(); - SendMessage( - new ChannelOpenMessage( - LocalChannelNumber, - LocalWindowSize, - LocalPacketSize, - new SessionChannelOpenInfo())); - } - } - - /// - /// Releases unmanaged and - optionally - managed resources - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - if (disposing) - { - if (_channelOpenResponseWaitHandle != null) - { - _channelOpenResponseWaitHandle.Dispose(); - _channelOpenResponseWaitHandle = null; - } - - if (_channelRequestResponse != null) - { - _channelRequestResponse.Dispose(); - _channelRequestResponse = null; - } - } - } - - /// - /// Releases the session semaphore. - /// - /// - /// When the session semaphore has already been released, or was never obtained by - /// this instance, then this method does nothing. - /// - private void ReleaseSemaphore() - { - if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 0, 1) == 1) - SessionSemaphore.Release(); - } - } -} +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Threading; +using Renci.SshNet.Abstractions; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Implements Session SSH channel. + /// + internal class ChannelSession : ClientChannel, IChannelSession + { + /// + /// Counts failed channel open attempts + /// + private int _failedOpenAttempts; + + /// + /// Holds a value indicating whether the session semaphore has been obtained by the current + /// channel. + /// + /// + /// 0 when the session semaphore has not been obtained or has already been released, + /// and 1 when the session has been obtained and still needs to be released. + /// + private int _sessionSemaphoreObtained; + + /// + /// Wait handle to signal when response was received to open the channel + /// + private EventWaitHandle _channelOpenResponseWaitHandle = new AutoResetEvent(false); + + private EventWaitHandle _channelRequestResponse = new ManualResetEvent(false); + + private bool _channelRequestSucces; + + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + public ChannelSession(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + } + + /// + /// Gets the type of the channel. + /// + /// + /// The type of the channel. + /// + public override ChannelTypes ChannelType + { + get { return ChannelTypes.Session; } + } + + /// + /// Opens the channel. + /// + public virtual void Open() + { + if (!IsOpen) + { + // Try to open channel several times + while (!IsOpen && _failedOpenAttempts < ConnectionInfo.RetryAttempts) + { + SendChannelOpenMessage(); + try + { + WaitOnHandle(_channelOpenResponseWaitHandle); + } + catch (Exception) + { + // avoid leaking session semaphore + ReleaseSemaphore(); + throw; + } + } + + if (!IsOpen) + throw new SshException(string.Format(CultureInfo.CurrentCulture, "Failed to open a channel after {0} attempts.", _failedOpenAttempts)); + } + } + + /// + /// Called when channel is opened by the server. + /// + /// The remote channel number. + /// Initial size of the window. + /// Maximum size of the packet. + protected override void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + base.OnOpenConfirmation(remoteChannelNumber, initialWindowSize, maximumPacketSize); + _channelOpenResponseWaitHandle.Set(); + } + + /// + /// Called when channel failed to open. + /// + /// The reason code. + /// The description. + /// The language. + protected override void OnOpenFailure(uint reasonCode, string description, string language) + { + _failedOpenAttempts++; + ReleaseSemaphore(); + _channelOpenResponseWaitHandle.Set(); + } + + /// + /// Called when channel is closed by the server. + /// + protected override void OnClose() + { + base.OnClose(); + + // This timeout needed since when channel is closed it does not immediately becomes available + // but it takes time for the server to clean up resource and allow new channels to be created. + ThreadAbstraction.Sleep(100); + } + + protected override void Close(bool wait) + { + base.Close(wait); + + ReleaseSemaphore(); + } + + /// + /// Sends the pseudo terminal request. + /// + /// The environment variable. + /// The columns. + /// The rows. + /// The width. + /// The height. + /// The terminal mode values. + /// + /// true if request was successful; otherwise false. + /// + public bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, IDictionary terminalModeValues) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new PseudoTerminalRequestInfo(environmentVariable, columns, rows, width, height, terminalModeValues))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the X11 forwarding request. + /// + /// if set to true the it is single connection. + /// The protocol. + /// The cookie. + /// The screen number. + /// + /// true if request was successful; otherwise false. + /// + public bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new X11ForwardingRequestInfo(isSingleConnection, protocol, cookie, screenNumber))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the environment variable request. + /// + /// Name of the variable. + /// The variable value. + /// + /// true if request was successful; otherwise false. + /// + public bool SendEnvironmentVariableRequest(string variableName, string variableValue) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EnvironmentVariableRequestInfo(variableName, variableValue))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the shell request. + /// + /// + /// true if request was successful; otherwise false. + /// + public bool SendShellRequest() + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ShellRequestInfo())); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the exec request. + /// + /// The command. + /// + /// true if request was successful; otherwise false. + /// + public bool SendExecRequest(string command) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExecRequestInfo(command, ConnectionInfo.Encoding))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the exec request. + /// + /// Length of the break. + /// + /// true if request was successful; otherwise false. + /// + public bool SendBreakRequest(uint breakLength) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new BreakRequestInfo(breakLength))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the subsystem request. + /// + /// The subsystem. + /// + /// true if request was successful; otherwise false. + /// + public bool SendSubsystemRequest(string subsystem) + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SubsystemRequestInfo(subsystem))); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends the window change request. + /// + /// The columns. + /// The rows. + /// The width. + /// The height. + /// + /// true if request was successful; otherwise false. + /// + public bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new WindowChangeRequestInfo(columns, rows, width, height))); + return true; + } + + /// + /// Sends the local flow request. + /// + /// if set to true [client can do]. + /// + /// true if request was successful; otherwise false. + /// + public bool SendLocalFlowRequest(bool clientCanDo) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new XonXoffRequestInfo(clientCanDo))); + return true; + } + + /// + /// Sends the signal request. + /// + /// Name of the signal. + /// + /// true if request was successful; otherwise false. + /// + public bool SendSignalRequest(string signalName) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new SignalRequestInfo(signalName))); + return true; + } + + /// + /// Sends the exit status request. + /// + /// The exit status. + /// + /// true if request was successful; otherwise false. + /// + public bool SendExitStatusRequest(uint exitStatus) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitStatusRequestInfo(exitStatus))); + return true; + } + + /// + /// Sends the exit signal request. + /// + /// Name of the signal. + /// if set to true [core dumped]. + /// The error message. + /// The language. + /// + /// true if request was successful; otherwise false. + /// + public bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language) + { + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new ExitSignalRequestInfo(signalName, coreDumped, errorMessage, language))); + return true; + } + + /// + /// Sends eow@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + public bool SendEndOfWriteRequest() + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new EndOfWriteRequestInfo())); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Sends keepalive@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + public bool SendKeepAliveRequest() + { + _channelRequestResponse.Reset(); + SendMessage(new ChannelRequestMessage(RemoteChannelNumber, new KeepAliveRequestInfo())); + WaitOnHandle(_channelRequestResponse); + return _channelRequestSucces; + } + + /// + /// Called when channel request was successful + /// + protected override void OnSuccess() + { + base.OnSuccess(); + _channelRequestSucces = true; + + var channelRequestResponse = _channelRequestResponse; + if (channelRequestResponse != null) + channelRequestResponse.Set(); + } + + /// + /// Called when channel request failed. + /// + protected override void OnFailure() + { + base.OnFailure(); + _channelRequestSucces = false; + + var channelRequestResponse = _channelRequestResponse; + if (channelRequestResponse != null) + channelRequestResponse.Set(); + } + + /// + /// Sends the channel open message. + /// + protected void SendChannelOpenMessage() + { + // do not allow open to be ChannelOpenMessage to be sent again until we've + // had a response on the previous attempt for the current channel + if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 1, 0) == 0) + { + SessionSemaphore.Wait(); + SendMessage( + new ChannelOpenMessage( + LocalChannelNumber, + LocalWindowSize, + LocalPacketSize, + new SessionChannelOpenInfo())); + } + } + + /// + /// Releases unmanaged and - optionally - managed resources + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + if (_channelOpenResponseWaitHandle != null) + { + _channelOpenResponseWaitHandle.Dispose(); + _channelOpenResponseWaitHandle = null; + } + + if (_channelRequestResponse != null) + { + _channelRequestResponse.Dispose(); + _channelRequestResponse = null; + } + } + } + + /// + /// Releases the session semaphore. + /// + /// + /// When the session semaphore has already been released, or was never obtained by + /// this instance, then this method does nothing. + /// + private void ReleaseSemaphore() + { + if (Interlocked.CompareExchange(ref _sessionSemaphoreObtained, 0, 1) == 1) + SessionSemaphore.Release(); + } + } +} diff --git a/src/Renci.SshNet/Channels/ChannelTypes.cs b/src/Renci.SshNet/Channels/ChannelTypes.cs index 7b257675..23042023 100644 --- a/src/Renci.SshNet/Channels/ChannelTypes.cs +++ b/src/Renci.SshNet/Channels/ChannelTypes.cs @@ -1,26 +1,26 @@ - -namespace Renci.SshNet.Channels -{ - /// - /// Lists channel types as defined by the protocol. - /// - internal enum ChannelTypes - { - /// - /// session - /// - Session, - /// - /// x11 - /// - X11, - /// - /// forwarded-tcpip - /// - ForwardedTcpip, - /// - /// direct-tcpip - /// - DirectTcpip - } -} + +namespace Renci.SshNet.Channels +{ + /// + /// Lists channel types as defined by the protocol. + /// + internal enum ChannelTypes + { + /// + /// session + /// + Session, + /// + /// x11 + /// + X11, + /// + /// forwarded-tcpip + /// + ForwardedTcpip, + /// + /// direct-tcpip + /// + DirectTcpip + } +} diff --git a/src/Renci.SshNet/Channels/ClientChannel.cs b/src/Renci.SshNet/Channels/ClientChannel.cs index d84c3e98..0d1704ea 100644 --- a/src/Renci.SshNet/Channels/ClientChannel.cs +++ b/src/Renci.SshNet/Channels/ClientChannel.cs @@ -1,127 +1,127 @@ -using System; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - internal abstract class ClientChannel : Channel - { - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - protected ClientChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - session.ChannelOpenConfirmationReceived += OnChannelOpenConfirmation; - session.ChannelOpenFailureReceived += OnChannelOpenFailure; - } - - /// - /// Occurs when message is received. - /// - public event EventHandler OpenConfirmed; - - /// - /// Occurs when message is received. - /// - public event EventHandler OpenFailed; - - /// - /// Called when channel is opened by the server. - /// - /// The remote channel number. - /// Initial size of the window. - /// Maximum size of the packet. - protected virtual void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) - { - InitializeRemoteInfo(remoteChannelNumber, initialWindowSize, maximumPacketSize); - - // Channel is consider to be open when confirmation message was received - IsOpen = true; - - var openConfirmed = OpenConfirmed; - if (openConfirmed != null) - openConfirmed(this, new ChannelOpenConfirmedEventArgs(remoteChannelNumber, initialWindowSize, maximumPacketSize)); - } - - /// - /// Send message to open a channel. - /// - /// Message to send - protected void SendMessage(ChannelOpenMessage message) - { - Session.SendMessage(message); - } - - /// - /// Called when channel failed to open. - /// - /// The reason code. - /// The description. - /// The language. - protected virtual void OnOpenFailure(uint reasonCode, string description, string language) - { - var openFailed = OpenFailed; - if (openFailed != null) - openFailed(this, new ChannelOpenFailedEventArgs(LocalChannelNumber, reasonCode, description, language)); - } - - private void OnChannelOpenConfirmation(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnOpenConfirmation(e.Message.RemoteChannelNumber, e.Message.InitialWindowSize, - e.Message.MaximumPacketSize); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - private void OnChannelOpenFailure(object sender, MessageEventArgs e) - { - if (e.Message.LocalChannelNumber == LocalChannelNumber) - { - try - { - OnOpenFailure(e.Message.ReasonCode, e.Message.Description, e.Message.Language); - } - catch (Exception ex) - { - OnChannelException(ex); - } - } - } - - protected override void Dispose(bool disposing) - { - UnsubscribeFromSessionEvents(Session); - - base.Dispose(disposing); - } - - /// - /// Unsubscribes the current from session events. - /// - /// The session. - /// - /// Does nothing when is null. - /// - private void UnsubscribeFromSessionEvents(ISession session) - { - if (session == null) - return; - - session.ChannelOpenConfirmationReceived -= OnChannelOpenConfirmation; - session.ChannelOpenFailureReceived -= OnChannelOpenFailure; - } - } -} +using System; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + internal abstract class ClientChannel : Channel + { + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + protected ClientChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + session.ChannelOpenConfirmationReceived += OnChannelOpenConfirmation; + session.ChannelOpenFailureReceived += OnChannelOpenFailure; + } + + /// + /// Occurs when message is received. + /// + public event EventHandler OpenConfirmed; + + /// + /// Occurs when message is received. + /// + public event EventHandler OpenFailed; + + /// + /// Called when channel is opened by the server. + /// + /// The remote channel number. + /// Initial size of the window. + /// Maximum size of the packet. + protected virtual void OnOpenConfirmation(uint remoteChannelNumber, uint initialWindowSize, uint maximumPacketSize) + { + InitializeRemoteInfo(remoteChannelNumber, initialWindowSize, maximumPacketSize); + + // Channel is consider to be open when confirmation message was received + IsOpen = true; + + var openConfirmed = OpenConfirmed; + if (openConfirmed != null) + openConfirmed(this, new ChannelOpenConfirmedEventArgs(remoteChannelNumber, initialWindowSize, maximumPacketSize)); + } + + /// + /// Send message to open a channel. + /// + /// Message to send + protected void SendMessage(ChannelOpenMessage message) + { + Session.SendMessage(message); + } + + /// + /// Called when channel failed to open. + /// + /// The reason code. + /// The description. + /// The language. + protected virtual void OnOpenFailure(uint reasonCode, string description, string language) + { + var openFailed = OpenFailed; + if (openFailed != null) + openFailed(this, new ChannelOpenFailedEventArgs(LocalChannelNumber, reasonCode, description, language)); + } + + private void OnChannelOpenConfirmation(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnOpenConfirmation(e.Message.RemoteChannelNumber, e.Message.InitialWindowSize, + e.Message.MaximumPacketSize); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + private void OnChannelOpenFailure(object sender, MessageEventArgs e) + { + if (e.Message.LocalChannelNumber == LocalChannelNumber) + { + try + { + OnOpenFailure(e.Message.ReasonCode, e.Message.Description, e.Message.Language); + } + catch (Exception ex) + { + OnChannelException(ex); + } + } + } + + protected override void Dispose(bool disposing) + { + UnsubscribeFromSessionEvents(Session); + + base.Dispose(disposing); + } + + /// + /// Unsubscribes the current from session events. + /// + /// The session. + /// + /// Does nothing when is null. + /// + private void UnsubscribeFromSessionEvents(ISession session) + { + if (session == null) + return; + + session.ChannelOpenConfirmationReceived -= OnChannelOpenConfirmation; + session.ChannelOpenFailureReceived -= OnChannelOpenFailure; + } + } +} diff --git a/src/Renci.SshNet/Channels/IChannel.cs b/src/Renci.SshNet/Channels/IChannel.cs index 49a237a4..0a89066d 100644 --- a/src/Renci.SshNet/Channels/IChannel.cs +++ b/src/Renci.SshNet/Channels/IChannel.cs @@ -1,108 +1,108 @@ -using System; -using Renci.SshNet.Common; -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - /// - /// Represents SSH channel. - /// - internal interface IChannel : IDisposable - { - /// - /// Occurs when message received - /// - event EventHandler DataReceived; - - /// - /// Occurs when an exception is thrown when processing channel messages. - /// - event EventHandler Exception; - - /// - /// Occurs when message received - /// - event EventHandler ExtendedDataReceived; - - /// - /// Occurs when message received - /// - event EventHandler RequestReceived; - - /// - /// Occurs when message received - /// - event EventHandler Closed; - - /// - /// Gets the local channel number. - /// - /// - /// The local channel number. - /// - uint LocalChannelNumber { get; } - - /// - /// Gets the maximum size of a packet. - /// - /// - /// The maximum size of a packet. - /// - uint LocalPacketSize { get; } - - /// - /// Gets the maximum size of a data packet that can be sent using the channel. - /// - /// - /// The maximum size of data that can be sent using a - /// on the current channel. - /// - /// The channel has not been opened, or the open has not yet been confirmed. - uint RemotePacketSize { get; } - - /// - /// Closes the channel. - /// - void Close(); - - /// - /// Gets a value indicating whether this channel is open. - /// - /// - /// true if this channel is open; otherwise, false. - /// - bool IsOpen { get; } - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// The payload to send. - void SendData(byte[] data); - - /// - /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. - /// - /// An array of containing the payload to send. - /// The zero-based offset in at which to begin taking data from. - /// The number of bytes of to send. - /// - /// - /// When the size of the data to send exceeds the maximum packet size or the remote window - /// size does not allow the full data to be sent, then this method will send the data in - /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. - /// - /// - /// This is done to support SSH servers will a small window size that do not agressively - /// increase their window size. We need to take into account that there may be SSH servers - /// that only increase their window size when it has reached zero. - /// - /// - void SendData(byte[] data, int offset, int size); - - /// - /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. - /// - /// The channel is closed. - void SendEof(); - } -} +using System; +using Renci.SshNet.Common; +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + /// + /// Represents SSH channel. + /// + internal interface IChannel : IDisposable + { + /// + /// Occurs when message received + /// + event EventHandler DataReceived; + + /// + /// Occurs when an exception is thrown when processing channel messages. + /// + event EventHandler Exception; + + /// + /// Occurs when message received + /// + event EventHandler ExtendedDataReceived; + + /// + /// Occurs when message received + /// + event EventHandler RequestReceived; + + /// + /// Occurs when message received + /// + event EventHandler Closed; + + /// + /// Gets the local channel number. + /// + /// + /// The local channel number. + /// + uint LocalChannelNumber { get; } + + /// + /// Gets the maximum size of a packet. + /// + /// + /// The maximum size of a packet. + /// + uint LocalPacketSize { get; } + + /// + /// Gets the maximum size of a data packet that can be sent using the channel. + /// + /// + /// The maximum size of data that can be sent using a + /// on the current channel. + /// + /// The channel has not been opened, or the open has not yet been confirmed. + uint RemotePacketSize { get; } + + /// + /// Closes the channel. + /// + void Close(); + + /// + /// Gets a value indicating whether this channel is open. + /// + /// + /// true if this channel is open; otherwise, false. + /// + bool IsOpen { get; } + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// The payload to send. + void SendData(byte[] data); + + /// + /// Sends a SSH_MSG_CHANNEL_DATA message with the specified payload. + /// + /// An array of containing the payload to send. + /// The zero-based offset in at which to begin taking data from. + /// The number of bytes of to send. + /// + /// + /// When the size of the data to send exceeds the maximum packet size or the remote window + /// size does not allow the full data to be sent, then this method will send the data in + /// multiple chunks and will wait for the remote window size to be adjusted when it's zero. + /// + /// + /// This is done to support SSH servers will a small window size that do not agressively + /// increase their window size. We need to take into account that there may be SSH servers + /// that only increase their window size when it has reached zero. + /// + /// + void SendData(byte[] data, int offset, int size); + + /// + /// Sends a SSH_MSG_CHANNEL_EOF message to the remote server. + /// + /// The channel is closed. + void SendEof(); + } +} diff --git a/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs b/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs index 9aff0db6..051fc77c 100644 --- a/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs +++ b/src/Renci.SshNet/Channels/IChannelDirectTcpip.cs @@ -1,52 +1,52 @@ -using System; -using System.Net.Sockets; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Channels -{ - /// - /// A "direct-tcpip" SSH channel. - /// - internal interface IChannelDirectTcpip : IDisposable - { - /// - /// Occurs when an exception is thrown while processing channel messages. - /// - event EventHandler Exception; - - /// - /// Gets a value indicating whether this channel is open. - /// - /// - /// true if this channel is open; otherwise, false. - /// - bool IsOpen { get; } - - /// - /// Gets the local channel number. - /// - /// - /// The local channel number. - /// - uint LocalChannelNumber { get; } - - /// - /// Opens a channel for a locally forwarded TCP/IP port. - /// - /// The name of the remote host to forward to. - /// The port of the remote hosts to forward to. - /// The forwarded port for which the channel is opened. - /// The socket to receive requests from, and send responses from the remote host to. - void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket); - - /// - /// Binds the channel to the remote host. - /// - void Bind(); - - /// - /// Closes the channel. - /// - void Close(); - } -} +using System; +using System.Net.Sockets; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Channels +{ + /// + /// A "direct-tcpip" SSH channel. + /// + internal interface IChannelDirectTcpip : IDisposable + { + /// + /// Occurs when an exception is thrown while processing channel messages. + /// + event EventHandler Exception; + + /// + /// Gets a value indicating whether this channel is open. + /// + /// + /// true if this channel is open; otherwise, false. + /// + bool IsOpen { get; } + + /// + /// Gets the local channel number. + /// + /// + /// The local channel number. + /// + uint LocalChannelNumber { get; } + + /// + /// Opens a channel for a locally forwarded TCP/IP port. + /// + /// The name of the remote host to forward to. + /// The port of the remote hosts to forward to. + /// The forwarded port for which the channel is opened. + /// The socket to receive requests from, and send responses from the remote host to. + void Open(string remoteHost, uint port, IForwardedPort forwardedPort, Socket socket); + + /// + /// Binds the channel to the remote host. + /// + void Bind(); + + /// + /// Closes the channel. + /// + void Close(); + } +} diff --git a/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs b/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs index 8ebc5b4e..f97fd1a4 100644 --- a/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs +++ b/src/Renci.SshNet/Channels/IChannelForwardedTcpip.cs @@ -1,29 +1,29 @@ -using System; -using System.Net; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Channels -{ - /// - /// A "forwarded-tcpip" SSH channel. - /// - internal interface IChannelForwardedTcpip : IDisposable - { - /// - /// Occurs when an exception is thrown while processing channel messages. - /// - event EventHandler Exception; - - /// - /// Binds the channel to the specified endpoint. - /// - /// The endpoint to connect to. - /// The forwarded port for which the channel is opened. - void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort); - - /// - /// Closes the channel. - /// - void Close(); - } -} +using System; +using System.Net; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Channels +{ + /// + /// A "forwarded-tcpip" SSH channel. + /// + internal interface IChannelForwardedTcpip : IDisposable + { + /// + /// Occurs when an exception is thrown while processing channel messages. + /// + event EventHandler Exception; + + /// + /// Binds the channel to the specified endpoint. + /// + /// The endpoint to connect to. + /// The forwarded port for which the channel is opened. + void Bind(IPEndPoint remoteEndpoint, IForwardedPort forwardedPort); + + /// + /// Closes the channel. + /// + void Close(); + } +} diff --git a/src/Renci.SshNet/Channels/IChannelSession.cs b/src/Renci.SshNet/Channels/IChannelSession.cs index 2b4d7c76..1599ce22 100644 --- a/src/Renci.SshNet/Channels/IChannelSession.cs +++ b/src/Renci.SshNet/Channels/IChannelSession.cs @@ -1,155 +1,155 @@ -using System.Collections.Generic; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Channels -{ - /// - /// Session SSH channel. - /// - internal interface IChannelSession : IChannel - { - /// - /// Opens the channel. - /// - void Open(); - - /// - /// Sends the pseudo terminal request. - /// - /// The environment variable. - /// The columns. - /// The rows. - /// The width. - /// The height. - /// The terminal mode values. - /// - /// true if request was successful; otherwise false. - /// - bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, - IDictionary terminalModeValues); - - /// - /// Sends the X11 forwarding request. - /// - /// if set to true the it is single connection. - /// The protocol. - /// The cookie. - /// The screen number. - /// - /// true if request was successful; otherwise false. - /// - bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber); - - /// - /// Sends the environment variable request. - /// - /// Name of the variable. - /// The variable value. - /// - /// true if request was successful; otherwise false. - /// - bool SendEnvironmentVariableRequest(string variableName, string variableValue); - - /// - /// Sends the shell request. - /// - /// - /// true if request was successful; otherwise false. - /// - bool SendShellRequest(); - - /// - /// Sends the exec request. - /// - /// The command. - /// - /// true if request was successful; otherwise false. - /// - bool SendExecRequest(string command); - - /// - /// Sends the exec request. - /// - /// Length of the break. - /// - /// true if request was successful; otherwise false. - /// - bool SendBreakRequest(uint breakLength); - - /// - /// Sends the subsystem request. - /// - /// The subsystem. - /// - /// true if request was successful; otherwise false. - /// - bool SendSubsystemRequest(string subsystem); - - /// - /// Sends the window change request. - /// - /// The columns. - /// The rows. - /// The width. - /// The height. - /// - /// true if request was successful; otherwise false. - /// - bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height); - - /// - /// Sends the local flow request. - /// - /// if set to true [client can do]. - /// - /// true if request was successful; otherwise false. - /// - bool SendLocalFlowRequest(bool clientCanDo); - - /// - /// Sends the signal request. - /// - /// Name of the signal. - /// - /// true if request was successful; otherwise false. - /// - bool SendSignalRequest(string signalName); - - /// - /// Sends the exit status request. - /// - /// The exit status. - /// - /// true if request was successful; otherwise false. - /// - bool SendExitStatusRequest(uint exitStatus); - - /// - /// Sends the exit signal request. - /// - /// Name of the signal. - /// if set to true [core dumped]. - /// The error message. - /// The language. - /// - /// true if request was successful; otherwise false. - /// - bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language); - - /// - /// Sends eow@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - bool SendEndOfWriteRequest(); - - /// - /// Sends keepalive@openssh.com request. - /// - /// - /// true if request was successful; otherwise false. - /// - bool SendKeepAliveRequest(); - } -} +using System.Collections.Generic; +using Renci.SshNet.Common; + +namespace Renci.SshNet.Channels +{ + /// + /// Session SSH channel. + /// + internal interface IChannelSession : IChannel + { + /// + /// Opens the channel. + /// + void Open(); + + /// + /// Sends the pseudo terminal request. + /// + /// The environment variable. + /// The columns. + /// The rows. + /// The width. + /// The height. + /// The terminal mode values. + /// + /// true if request was successful; otherwise false. + /// + bool SendPseudoTerminalRequest(string environmentVariable, uint columns, uint rows, uint width, uint height, + IDictionary terminalModeValues); + + /// + /// Sends the X11 forwarding request. + /// + /// if set to true the it is single connection. + /// The protocol. + /// The cookie. + /// The screen number. + /// + /// true if request was successful; otherwise false. + /// + bool SendX11ForwardingRequest(bool isSingleConnection, string protocol, byte[] cookie, uint screenNumber); + + /// + /// Sends the environment variable request. + /// + /// Name of the variable. + /// The variable value. + /// + /// true if request was successful; otherwise false. + /// + bool SendEnvironmentVariableRequest(string variableName, string variableValue); + + /// + /// Sends the shell request. + /// + /// + /// true if request was successful; otherwise false. + /// + bool SendShellRequest(); + + /// + /// Sends the exec request. + /// + /// The command. + /// + /// true if request was successful; otherwise false. + /// + bool SendExecRequest(string command); + + /// + /// Sends the exec request. + /// + /// Length of the break. + /// + /// true if request was successful; otherwise false. + /// + bool SendBreakRequest(uint breakLength); + + /// + /// Sends the subsystem request. + /// + /// The subsystem. + /// + /// true if request was successful; otherwise false. + /// + bool SendSubsystemRequest(string subsystem); + + /// + /// Sends the window change request. + /// + /// The columns. + /// The rows. + /// The width. + /// The height. + /// + /// true if request was successful; otherwise false. + /// + bool SendWindowChangeRequest(uint columns, uint rows, uint width, uint height); + + /// + /// Sends the local flow request. + /// + /// if set to true [client can do]. + /// + /// true if request was successful; otherwise false. + /// + bool SendLocalFlowRequest(bool clientCanDo); + + /// + /// Sends the signal request. + /// + /// Name of the signal. + /// + /// true if request was successful; otherwise false. + /// + bool SendSignalRequest(string signalName); + + /// + /// Sends the exit status request. + /// + /// The exit status. + /// + /// true if request was successful; otherwise false. + /// + bool SendExitStatusRequest(uint exitStatus); + + /// + /// Sends the exit signal request. + /// + /// Name of the signal. + /// if set to true [core dumped]. + /// The error message. + /// The language. + /// + /// true if request was successful; otherwise false. + /// + bool SendExitSignalRequest(string signalName, bool coreDumped, string errorMessage, string language); + + /// + /// Sends eow@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + bool SendEndOfWriteRequest(); + + /// + /// Sends keepalive@openssh.com request. + /// + /// + /// true if request was successful; otherwise false. + /// + bool SendKeepAliveRequest(); + } +} diff --git a/src/Renci.SshNet/Channels/ServerChannel.cs b/src/Renci.SshNet/Channels/ServerChannel.cs index 8c55248b..dc5378b3 100644 --- a/src/Renci.SshNet/Channels/ServerChannel.cs +++ b/src/Renci.SshNet/Channels/ServerChannel.cs @@ -1,33 +1,33 @@ -using Renci.SshNet.Messages.Connection; - -namespace Renci.SshNet.Channels -{ - internal abstract class ServerChannel : Channel - { - /// - /// Initializes a new instance. - /// - /// The session. - /// The local channel number. - /// Size of the window. - /// Size of the packet. - /// The remote channel number. - /// The window size of the remote party. - /// The maximum size of a data packet that we can send to the remote party. - protected ServerChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) - : base(session, localChannelNumber, localWindowSize, localPacketSize) - { - InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); - } - - protected void SendMessage(ChannelOpenConfirmationMessage message) - { - // No need to check whether channel is open when trying to open a channel - Session.SendMessage(message); - - // When we act as server, consider the channel open when we've sent the - // confirmation message to the peer - IsOpen = true; - } - } -} +using Renci.SshNet.Messages.Connection; + +namespace Renci.SshNet.Channels +{ + internal abstract class ServerChannel : Channel + { + /// + /// Initializes a new instance. + /// + /// The session. + /// The local channel number. + /// Size of the window. + /// Size of the packet. + /// The remote channel number. + /// The window size of the remote party. + /// The maximum size of a data packet that we can send to the remote party. + protected ServerChannel(ISession session, uint localChannelNumber, uint localWindowSize, uint localPacketSize, uint remoteChannelNumber, uint remoteWindowSize, uint remotePacketSize) + : base(session, localChannelNumber, localWindowSize, localPacketSize) + { + InitializeRemoteInfo(remoteChannelNumber, remoteWindowSize, remotePacketSize); + } + + protected void SendMessage(ChannelOpenConfirmationMessage message) + { + // No need to check whether channel is open when trying to open a channel + Session.SendMessage(message); + + // When we act as server, consider the channel open when we've sent the + // confirmation message to the peer + IsOpen = true; + } + } +} diff --git a/src/Renci.SshNet/CipherInfo.cs b/src/Renci.SshNet/CipherInfo.cs index 77eafdd2..e68497cd 100644 --- a/src/Renci.SshNet/CipherInfo.cs +++ b/src/Renci.SshNet/CipherInfo.cs @@ -1,35 +1,35 @@ -using System; -using Renci.SshNet.Security.Cryptography; - -namespace Renci.SshNet -{ - /// - /// Holds information about key size and cipher to use - /// - public class CipherInfo - { - /// - /// Gets the size of the key. - /// - /// - /// The size of the key. - /// - public int KeySize { get; private set; } - - /// - /// Gets the cipher. - /// - public Func Cipher { get; private set; } - - /// - /// Initializes a new instance of the class. - /// - /// Size of the key. - /// The cipher. - public CipherInfo(int keySize, Func cipher) - { - KeySize = keySize; - Cipher = (key, iv) => (cipher(key.Take(KeySize / 8), iv)); - } - } -} +using System; +using Renci.SshNet.Security.Cryptography; + +namespace Renci.SshNet +{ + /// + /// Holds information about key size and cipher to use + /// + public class CipherInfo + { + /// + /// Gets the size of the key. + /// + /// + /// The size of the key. + /// + public int KeySize { get; private set; } + + /// + /// Gets the cipher. + /// + public Func Cipher { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// Size of the key. + /// The cipher. + public CipherInfo(int keySize, Func cipher) + { + KeySize = keySize; + Cipher = (key, iv) => (cipher(key.Take(KeySize / 8), iv)); + } + } +}