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_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_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/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