Browse Source

Remove unnecessary SftpFileStream unit tests and dedup Open{Async} (#1680)

* deletions

* test additions/tweaks

* dedup SftpFileStream init logic
Rob Hague 2 tháng trước cách đây
mục cha
commit
13bcb7713e
100 tập tin đã thay đổi với 560 bổ sung10618 xóa
  1. 1 1
      .editorconfig
  2. 0 18
      src/Renci.SshNet/Common/Extensions.cs
  3. 1 57
      src/Renci.SshNet/ISubsystemSession.cs
  4. 3 3
      src/Renci.SshNet/Sftp/ISftpSession.cs
  5. 40 136
      src/Renci.SshNet/Sftp/SftpFileStream.cs
  6. 3 3
      src/Renci.SshNet/Sftp/SftpSession.cs
  7. 5 17
      src/Renci.SshNet/SftpClient.cs
  8. 3 151
      src/Renci.SshNet/SubsystemSession.cs
  9. 206 145
      test/Renci.SshNet.IntegrationTests/SftpTests.cs
  10. 298 0
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest.cs
  11. 0 68
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTestBase.cs
  12. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs
  13. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs
  14. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs
  15. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs
  16. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs
  17. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs
  18. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs
  19. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs
  20. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs
  21. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs
  22. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs
  23. 0 76
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs
  24. 0 80
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs
  25. 0 81
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs
  26. 0 78
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs
  27. 0 80
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs
  28. 0 56
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileAccessInvalid.cs
  29. 0 58
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessRead.cs
  30. 0 58
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessReadWrite.cs
  31. 0 185
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessWrite.cs
  32. 0 58
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessRead.cs
  33. 0 167
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs
  34. 0 158
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessWrite.cs
  35. 0 58
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessRead.cs
  36. 0 170
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs
  37. 0 155
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs
  38. 0 162
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs
  39. 0 158
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessWrite_FileExists.cs
  40. 0 56
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeInvalid.cs
  41. 0 178
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs
  42. 0 155
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs
  43. 0 158
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessWrite.cs
  44. 0 178
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs
  45. 0 155
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs
  46. 0 158
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessWrite.cs
  47. 0 58
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessRead.cs
  48. 0 167
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs
  49. 0 158
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessWrite.cs
  50. 0 81
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs
  51. 0 78
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs
  52. 0 80
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs
  53. 0 80
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs
  54. 0 94
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs
  55. 0 116
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs
  56. 0 123
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs
  57. 0 116
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs
  58. 0 84
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_SessionNotOpen.cs
  59. 0 152
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs
  60. 0 120
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs
  61. 0 57
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.cs
  62. 0 59
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs
  63. 0 59
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite.cs
  64. 0 164
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite.cs
  65. 0 59
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead.cs
  66. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite.cs
  67. 0 145
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite.cs
  68. 0 59
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead.cs
  69. 0 147
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs
  70. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists.cs
  71. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs
  72. 0 145
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists.cs
  73. 0 57
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeInvalid.cs
  74. 0 142
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead.cs
  75. 0 147
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite.cs
  76. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite.cs
  77. 0 143
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead.cs
  78. 0 147
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite.cs
  79. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite.cs
  80. 0 59
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs
  81. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite.cs
  82. 0 137
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite.cs
  83. 0 160
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs
  84. 0 153
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs
  85. 0 144
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs
  86. 0 88
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadByte_ReadMode_NoDataInWriteBufferAndNoDataInReadBuffer_Eof.cs
  87. 0 93
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadByte_ReadMode_NoDataInWriteBufferAndNoDataInReadBuffer_LessDataThanReadBufferSizeAvailable.cs
  88. 0 158
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs
  89. 0 151
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs
  90. 0 142
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs
  91. 0 100
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetNegative.cs
  92. 0 90
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetPositive.cs
  93. 0 88
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetZero.cs
  94. 0 106
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetNegative.cs
  95. 0 106
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetPositive.cs
  96. 0 106
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetZero.cs
  97. 0 125
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_NoBuffering.cs
  98. 0 143
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs
  99. 0 90
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs
  100. 0 209
      test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs

+ 1 - 1
.editorconfig

@@ -719,7 +719,7 @@ dotnet_code_quality.CA1828.api_surface = all
 dotnet_diagnostic.CA1852.severity = none
 
 # CA1848: don't enforce LoggerMessage pattern
-dotnet_diagnostic.CA1848.severity = suggestion
+dotnet_diagnostic.CA1848.severity = silent
 
 # CA1859: Change return type for improved performance
 #

+ 0 - 18
src/Renci.SshNet/Common/Extensions.cs

@@ -1,12 +1,10 @@
 using System;
 using System.Collections.Generic;
-using System.Diagnostics;
 using System.Globalization;
 using System.Net;
 using System.Net.Sockets;
 using System.Numerics;
 using System.Runtime.CompilerServices;
-using System.Text;
 using System.Threading;
 
 using Renci.SshNet.Abstractions;
@@ -153,22 +151,6 @@ namespace Renci.SshNet.Common
             }
         }
 
-        /// <summary>
-        /// Prints out the specified bytes.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        internal static void DebugPrint(this IEnumerable<byte> bytes)
-        {
-            var sb = new StringBuilder();
-
-            foreach (var b in bytes)
-            {
-                _ = sb.AppendFormat(CultureInfo.CurrentCulture, "0x{0:x2}, ", b);
-            }
-
-            Debug.WriteLine(sb.ToString());
-        }
-
         internal static void ValidatePort(this uint value, [CallerArgumentExpression(nameof(value))] string argument = null)
         {
             if (value > IPEndPoint.MaxPort)

+ 1 - 57
src/Renci.SshNet/ISubsystemSession.cs

@@ -84,57 +84,11 @@ namespace Renci.SshNet
         /// <returns>A <see cref="Task"/> representing the wait.</returns>
         Task<T> WaitOnHandleAsync<T>(TaskCompletionSource<T> tcs, int millisecondsTimeout, CancellationToken cancellationToken);
 
-        /// <summary>
-        /// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
-        /// 32-bit signed integer to specify the time interval in milliseconds.
-        /// </summary>
-        /// <param name="waitHandle">The handle to wait for.</param>
-        /// <param name="millisecondsTimeout">To number of milliseconds to wait for <paramref name="waitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
-        /// <returns>
-        /// <see langword="true"/> if <paramref name="waitHandle"/> received a signal within the specified timeout;
-        /// otherwise, <see langword="false"/>.
-        /// </returns>
-        /// <exception cref="SshException">The connection was closed by the server.</exception>
-        /// <exception cref="SshException">The channel was closed.</exception>
-        /// <remarks>
-        /// The blocking wait is also interrupted when either the established channel is closed, the current
-        /// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
-        /// or session event.
-        /// </remarks>
-        bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout);
-
-        /// <summary>
-        /// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
-        /// 32-bit signed integer to specify the time interval in milliseconds.
-        /// </summary>
-        /// <param name="waitHandleA">The first handle to wait for.</param>
-        /// <param name="waitHandleB">The second handle to wait for.</param>
-        /// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
-        /// <returns>
-        /// <c>0</c> if <paramref name="waitHandleA"/> received a signal within the specified timeout and <c>1</c>
-        /// if <paramref name="waitHandleB"/> received a signal within the specified timeout, or <see cref="WaitHandle.WaitTimeout"/>
-        /// if no object satisfied the wait.
-        /// </returns>
-        /// <exception cref="SshException">The connection was closed by the server.</exception>
-        /// <exception cref="SshException">The channel was closed.</exception>
-        /// <remarks>
-        /// <para>
-        /// The blocking wait is also interrupted when either the established channel is closed, the current
-        /// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
-        /// or session event.
-        /// </para>
-        /// <para>
-        /// When both <paramref name="waitHandleA"/> and <paramref name="waitHandleB"/> are signaled during the call,
-        /// then <c>0</c> is returned.
-        /// </para>
-        /// </remarks>
-        int WaitAny(WaitHandle waitHandleA, WaitHandle waitHandleB, int millisecondsTimeout);
-
         /// <summary>
         /// Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed
         /// integer to specify the time interval.
         /// </summary>
-        /// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray(WaitHandle[])"/> - containing the objects to wait for.</param>
+        /// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray"/> - containing the objects to wait for.</param>
         /// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or <c>-1</c> to wait indefinitely.</param>
         /// <returns>
         /// The array index of the first non-system object that satisfied the wait.
@@ -147,16 +101,6 @@ namespace Renci.SshNet
         /// </remarks>
         int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout);
 
-        /// <summary>
-        /// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
-        /// elements.
-        /// </summary>
-        /// <param name="waitHandles">A <see cref="WaitHandle"/> array containing the objects to wait for.</param>
-        /// <returns>
-        /// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
-        /// </returns>
-        WaitHandle[] CreateWaitHandleArray(params WaitHandle[] waitHandles);
-
         /// <summary>
         /// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
         /// elements.

+ 3 - 3
src/Renci.SshNet/Sftp/ISftpSession.cs

@@ -40,7 +40,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="path">The new working directory.</param>
         /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
         /// <returns>A <see cref="Task"/> that tracks the asynchronous change working directory request.</returns>
-        Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default);
+        Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken);
 
         /// <summary>
         /// Resolves a given path into an absolute path on the server.
@@ -168,7 +168,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="path">The path.</param>
         /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
         /// <returns>A <see cref="Task"/> that represents the asynchronous <c>SSH_FXP_MKDIR</c> operation.</returns>
-        Task RequestMkDirAsync(string path, CancellationToken cancellationToken = default);
+        Task RequestMkDirAsync(string path, CancellationToken cancellationToken);
 
         /// <summary>
         /// Performs a <c>SSH_FXP_OPEN</c> request.
@@ -389,7 +389,7 @@ namespace Renci.SshNet.Sftp
         /// <returns>
         /// A task that represents the asynchronous <c>SSH_FXP_RMDIR</c> request.
         /// </returns>
-        Task RequestRmDirAsync(string path, CancellationToken cancellationToken = default);
+        Task RequestRmDirAsync(string path, CancellationToken cancellationToken);
 
         /// <summary>
         /// Performs SSH_FXP_SETSTAT request.

+ 40 - 136
src/Renci.SshNet/Sftp/SftpFileStream.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Diagnostics;
 using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.IO;
@@ -191,7 +192,7 @@ namespace Renci.SshNet.Sftp
             }
         }
 
-        private SftpFileStream(ISftpSession session, string path, FileAccess access, int bufferSize, byte[] handle, long position)
+        private SftpFileStream(ISftpSession session, string path, FileAccess access, int readBufferSize, int writeBufferSize, byte[] handle, long position)
         {
             Timeout = TimeSpan.FromSeconds(30);
             Name = path;
@@ -202,25 +203,24 @@ namespace Renci.SshNet.Sftp
             _canWrite = (access & FileAccess.Write) == FileAccess.Write;
 
             _handle = handle;
+            _readBufferSize = readBufferSize;
+            _writeBufferSize = writeBufferSize;
+            _position = position;
+        }
 
-            /*
-             * Instead of using the specified buffer size as is, we use it to calculate a buffer size
-             * that ensures we always receive or send the max. number of bytes in a single SSH_FXP_READ
-             * or SSH_FXP_WRITE message.
-             */
-
-            _readBufferSize = (int)session.CalculateOptimalReadLength((uint)bufferSize);
-            _writeBufferSize = (int)session.CalculateOptimalWriteLength((uint)bufferSize, _handle);
+        internal static SftpFileStream Open(ISftpSession session, string path, FileMode mode, FileAccess access, int bufferSize)
+        {
+            return Open(session, path, mode, access, bufferSize, isAsync: false, CancellationToken.None).GetAwaiter().GetResult();
+        }
 
-            _position = position;
+        internal static Task<SftpFileStream> OpenAsync(ISftpSession session, string path, FileMode mode, FileAccess access, int bufferSize, CancellationToken cancellationToken)
+        {
+            return Open(session, path, mode, access, bufferSize, isAsync: true, cancellationToken);
         }
 
-        internal SftpFileStream(ISftpSession session, string path, FileMode mode, FileAccess access, int bufferSize)
+        private static async Task<SftpFileStream> Open(ISftpSession session, string path, FileMode mode, FileAccess access, int bufferSize, bool isAsync, CancellationToken cancellationToken)
         {
-            if (session is null)
-            {
-                throw new SshConnectionException("Client not connected.");
-            }
+            Debug.Assert(isAsync || cancellationToken == default);
 
             ThrowHelper.ThrowIfNull(path);
 
@@ -229,14 +229,10 @@ namespace Renci.SshNet.Sftp
                 throw new ArgumentOutOfRangeException(nameof(bufferSize), "Cannot be less than or equal to zero.");
             }
 
-            Timeout = TimeSpan.FromSeconds(30);
-            Name = path;
-
-            // Initialize the object state.
-            _session = session;
-            _canRead = (access & FileAccess.Read) == FileAccess.Read;
-            _canSeek = true;
-            _canWrite = (access & FileAccess.Write) == FileAccess.Write;
+            if (session is null)
+            {
+                throw new SshConnectionException("Client not connected.");
+            }
 
             var flags = Flags.None;
 
@@ -284,16 +280,7 @@ namespace Renci.SshNet.Sftp
                     flags |= Flags.Append | Flags.CreateNewOrOpen;
                     break;
                 case FileMode.Create:
-                    _handle = _session.RequestOpen(path, flags | Flags.Truncate, nullOnError: true);
-                    if (_handle is null)
-                    {
-                        flags |= Flags.CreateNew;
-                    }
-                    else
-                    {
-                        flags |= Flags.Truncate;
-                    }
-
+                    flags |= Flags.CreateNewOrOpen | Flags.Truncate;
                     break;
                 case FileMode.CreateNew:
                     flags |= Flags.CreateNew;
@@ -310,7 +297,16 @@ namespace Renci.SshNet.Sftp
                     throw new ArgumentOutOfRangeException(nameof(mode));
             }
 
-            _handle ??= _session.RequestOpen(path, flags);
+            byte[] handle;
+
+            if (isAsync)
+            {
+                handle = await session.RequestOpenAsync(path, flags, cancellationToken).ConfigureAwait(false);
+            }
+            else
+            {
+                handle = session.RequestOpen(path, flags);
+            }
 
             /*
              * Instead of using the specified buffer size as is, we use it to calculate a buffer size
@@ -318,119 +314,27 @@ namespace Renci.SshNet.Sftp
              * or SSH_FXP_WRITE message.
              */
 
-            _readBufferSize = (int)session.CalculateOptimalReadLength((uint)bufferSize);
-            _writeBufferSize = (int)session.CalculateOptimalWriteLength((uint)bufferSize, _handle);
+            var readBufferSize = (int)session.CalculateOptimalReadLength((uint)bufferSize);
+            var writeBufferSize = (int)session.CalculateOptimalWriteLength((uint)bufferSize, handle);
 
+            long position = 0;
             if (mode == FileMode.Append)
             {
-                var attributes = _session.RequestFStat(_handle, nullOnError: false);
-                _position = attributes.Size;
-            }
-        }
-
-        internal static async Task<SftpFileStream> OpenAsync(ISftpSession session, string path, FileMode mode, FileAccess access, int bufferSize, CancellationToken cancellationToken)
-        {
-            if (session is null)
-            {
-                throw new SshConnectionException("Client not connected.");
-            }
-
-            ThrowHelper.ThrowIfNull(path);
-
-            if (bufferSize <= 0)
-            {
-                throw new ArgumentOutOfRangeException(nameof(bufferSize), "Cannot be less than or equal to zero.");
-            }
-
-            var flags = Flags.None;
-
-            switch (access)
-            {
-                case FileAccess.Read:
-                    flags |= Flags.Read;
-                    break;
-                case FileAccess.Write:
-                    flags |= Flags.Write;
-                    break;
-                case FileAccess.ReadWrite:
-                    flags |= Flags.Read;
-                    flags |= Flags.Write;
-                    break;
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(access));
-            }
-
-            if ((access & FileAccess.Read) == FileAccess.Read && mode == FileMode.Append)
-            {
-                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
-                                                          "{0} mode can be requested only when combined with write-only access.",
-                                                          mode.ToString("G")),
-                                            nameof(mode));
-            }
+                SftpFileAttributes attributes;
 
-            if ((access & FileAccess.Write) != FileAccess.Write)
-            {
-                if (mode is FileMode.Create or FileMode.CreateNew or FileMode.Truncate or FileMode.Append)
+                if (isAsync)
                 {
-                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
-                                                              "Combining {0}: {1} with {2}: {3} is invalid.",
-                                                              nameof(FileMode),
-                                                              mode,
-                                                              nameof(FileAccess),
-                                                              access),
-                                                nameof(mode));
+                    attributes = await session.RequestFStatAsync(handle, cancellationToken).ConfigureAwait(false);
                 }
-            }
-
-            switch (mode)
-            {
-                case FileMode.Append:
-                    flags |= Flags.Append | Flags.CreateNewOrOpen;
-                    break;
-                case FileMode.Create:
-                    flags |= Flags.CreateNewOrOpen | Flags.Truncate;
-                    break;
-                case FileMode.CreateNew:
-                    flags |= Flags.CreateNew;
-                    break;
-                case FileMode.Open:
-                    break;
-                case FileMode.OpenOrCreate:
-                    flags |= Flags.CreateNewOrOpen;
-                    break;
-                case FileMode.Truncate:
-                    flags |= Flags.Truncate;
-                    break;
-                default:
-                    throw new ArgumentOutOfRangeException(nameof(mode));
-            }
-
-            var handle = await session.RequestOpenAsync(path, flags, cancellationToken).ConfigureAwait(false);
-
-            long position = 0;
-            if (mode == FileMode.Append)
-            {
-                try
+                else
                 {
-                    var attributes = await session.RequestFStatAsync(handle, cancellationToken).ConfigureAwait(false);
-                    position = attributes.Size;
+                    attributes = session.RequestFStat(handle, nullOnError: false);
                 }
-                catch
-                {
-                    try
-                    {
-                        await session.RequestCloseAsync(handle, cancellationToken).ConfigureAwait(false);
-                    }
-                    catch
-                    {
-                        // The original exception is presumably more informative, so we just ignore this one.
-                    }
 
-                    throw;
-                }
+                position = attributes.Size;
             }
 
-            return new SftpFileStream(session, path, access, bufferSize, handle, position);
+            return new SftpFileStream(session, path, access, readBufferSize, writeBufferSize, handle, position);
         }
 
         /// <summary>

+ 3 - 3
src/Renci.SshNet/Sftp/SftpSession.cs

@@ -90,7 +90,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="path">The new working directory.</param>
         /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
         /// <returns>A <see cref="Task"/> that tracks the asynchronous change working directory request.</returns>
-        public async Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken = default)
+        public async Task ChangeDirectoryAsync(string path, CancellationToken cancellationToken)
         {
             cancellationToken.ThrowIfCancellationRequested();
 
@@ -1469,7 +1469,7 @@ namespace Renci.SshNet.Sftp
         /// <param name="path">The path.</param>
         /// <param name="cancellationToken">The <see cref="CancellationToken"/> to observe.</param>
         /// <returns>A <see cref="Task"/> that represents the asynchronous <c>SSH_FXP_MKDIR</c> operation.</returns>
-        public Task RequestMkDirAsync(string path, CancellationToken cancellationToken = default)
+        public Task RequestMkDirAsync(string path, CancellationToken cancellationToken)
         {
             if (cancellationToken.IsCancellationRequested)
             {
@@ -1529,7 +1529,7 @@ namespace Renci.SshNet.Sftp
         }
 
         /// <inheritdoc />
-        public Task RequestRmDirAsync(string path, CancellationToken cancellationToken = default)
+        public Task RequestRmDirAsync(string path, CancellationToken cancellationToken)
         {
             if (cancellationToken.IsCancellationRequested)
             {

+ 5 - 17
src/Renci.SshNet/SftpClient.cs

@@ -1423,7 +1423,7 @@ namespace Renci.SshNet
             CheckDisposed();
             ThrowHelper.ThrowIfNull(encoding);
 
-            return new StreamWriter(new SftpFileStream(_sftpSession, path, FileMode.Append, FileAccess.Write, (int)_bufferSize), encoding);
+            return new StreamWriter(Open(path, FileMode.Append, FileAccess.Write), encoding);
         }
 
         /// <summary>
@@ -1442,9 +1442,7 @@ namespace Renci.SshNet
         /// </remarks>
         public SftpFileStream Create(string path)
         {
-            CheckDisposed();
-
-            return new SftpFileStream(_sftpSession, path, FileMode.Create, FileAccess.ReadWrite, (int)_bufferSize);
+            return Create(path, (int)_bufferSize);
         }
 
         /// <summary>
@@ -1466,7 +1464,7 @@ namespace Renci.SshNet
         {
             CheckDisposed();
 
-            return new SftpFileStream(_sftpSession, path, FileMode.Create, FileAccess.ReadWrite, bufferSize);
+            return SftpFileStream.Open(_sftpSession, path, FileMode.Create, FileAccess.ReadWrite, bufferSize);
         }
 
         /// <summary>
@@ -1642,7 +1640,7 @@ namespace Renci.SshNet
         {
             CheckDisposed();
 
-            return new SftpFileStream(_sftpSession, path, mode, access, (int)_bufferSize);
+            return SftpFileStream.Open(_sftpSession, path, mode, access, (int)_bufferSize);
         }
 
         /// <summary>
@@ -1662,14 +1660,6 @@ namespace Renci.SshNet
         public Task<SftpFileStream> OpenAsync(string path, FileMode mode, FileAccess access, CancellationToken cancellationToken)
         {
             CheckDisposed();
-            ThrowHelper.ThrowIfNull(path);
-
-            if (_sftpSession is null)
-            {
-                throw new SshConnectionException("Client not connected.");
-            }
-
-            cancellationToken.ThrowIfCancellationRequested();
 
             return SftpFileStream.OpenAsync(_sftpSession, path, mode, access, (int)_bufferSize, cancellationToken);
         }
@@ -1719,9 +1709,7 @@ namespace Renci.SshNet
         /// </remarks>
         public SftpFileStream OpenWrite(string path)
         {
-            CheckDisposed();
-
-            return new SftpFileStream(_sftpSession, path, FileMode.OpenOrCreate, FileAccess.Write, (int)_bufferSize);
+            return Open(path, FileMode.OpenOrCreate, FileAccess.Write);
         }
 
         /// <summary>

+ 3 - 151
src/Renci.SshNet/SubsystemSession.cs

@@ -18,7 +18,7 @@ namespace Renci.SshNet
     {
         /// <summary>
         /// Holds the number of system wait handles that are returned as the leading entries in the array returned
-        /// in <see cref="CreateWaitHandleArray(WaitHandle[])"/>.
+        /// in <see cref="CreateWaitHandleArray"/>.
         /// </summary>
         private const int SystemWaitHandleCount = 3;
 
@@ -335,124 +335,7 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
-        /// 32-bit signed integer to specify the time interval in milliseconds.
-        /// </summary>
-        /// <param name="waitHandle">The handle to wait for.</param>
-        /// <param name="millisecondsTimeout">To number of milliseconds to wait for <paramref name="waitHandle"/> to get signaled, or -1 to wait indefinitely.</param>
-        /// <returns>
-        /// <see langword="true"/> if <paramref name="waitHandle"/> received a signal within the specified timeout;
-        /// otherwise, <see langword="false"/>.
-        /// </returns>
-        /// <exception cref="SshException">The connection was closed by the server.</exception>
-        /// <exception cref="SshException">The channel was closed.</exception>
-        /// <remarks>
-        /// The blocking wait is also interrupted when either the established channel is closed, the current
-        /// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
-        /// or session event.
-        /// </remarks>
-        public bool WaitOne(WaitHandle waitHandle, int millisecondsTimeout)
-        {
-            var waitHandles = new[]
-                {
-                    _errorOccurredWaitHandle,
-                    _sessionDisconnectedWaitHandle,
-                    _channelClosedWaitHandle,
-                    waitHandle
-                };
-
-            var result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
-            switch (result)
-            {
-                case 0:
-                    ExceptionDispatchInfo.Capture(_exception).Throw();
-                    return false; // unreached
-                case 1:
-                    throw new SshException("Connection was closed by the server.");
-                case 2:
-                    throw new SshException("Channel was closed.");
-                case 3:
-                    return true;
-                case WaitHandle.WaitTimeout:
-                    return false;
-                default:
-                    throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "WaitAny return value '{0}' is not implemented.", result));
-            }
-        }
-
-        /// <summary>
-        /// Blocks the current thread until the specified <see cref="WaitHandle"/> gets signaled, using a
-        /// 32-bit signed integer to specify the time interval in milliseconds.
-        /// </summary>
-        /// <param name="waitHandleA">The first handle to wait for.</param>
-        /// <param name="waitHandleB">The second handle to wait for.</param>
-        /// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or -1 to wait indefinitely.</param>
-        /// <returns>
-        /// <c>0</c> if <paramref name="waitHandleA"/> received a signal within the specified timeout, and <c>1</c>
-        /// if <paramref name="waitHandleB"/> received a signal within the specified timeout.
-        /// </returns>
-        /// <exception cref="SshException">The connection was closed by the server.</exception>
-        /// <exception cref="SshException">The channel was closed.</exception>
-        /// <exception cref="SshOperationTimeoutException">The handle did not get signaled within the specified timeout.</exception>
-        /// <remarks>
-        /// <para>
-        /// The blocking wait is also interrupted when either the established channel is closed, the current
-        /// session is disconnected or an unexpected <see cref="Exception"/> occurred while processing a channel
-        /// or session event.
-        /// </para>
-        /// <para>
-        /// When both <paramref name="waitHandleA"/> and <paramref name="waitHandleB"/> are signaled during the call,
-        /// then <c>0</c> is returned.
-        /// </para>
-        /// </remarks>
-        public int WaitAny(WaitHandle waitHandleA, WaitHandle waitHandleB, int millisecondsTimeout)
-        {
-            var waitHandles = new[]
-                {
-                    _errorOccurredWaitHandle,
-                    _sessionDisconnectedWaitHandle,
-                    _channelClosedWaitHandle,
-                    waitHandleA,
-                    waitHandleB
-                };
-
-            var result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
-            switch (result)
-            {
-                case 0:
-                    ExceptionDispatchInfo.Capture(_exception).Throw();
-                    return -1; // unreached
-                case 1:
-                    throw new SshException("Connection was closed by the server.");
-                case 2:
-                    throw new SshException("Channel was closed.");
-                case 3:
-                    return 0;
-                case 4:
-                    return 1;
-                case WaitHandle.WaitTimeout:
-                    throw new SshOperationTimeoutException("Operation has timed out.");
-                default:
-                    throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture, "WaitAny return value '{0}' is not implemented.", result));
-            }
-        }
-
-        /// <summary>
-        /// Waits for any of the elements in the specified array to receive a signal, using a 32-bit signed
-        /// integer to specify the time interval.
-        /// </summary>
-        /// <param name="waitHandles">A <see cref="WaitHandle"/> array - constructed using <see cref="CreateWaitHandleArray(WaitHandle[])"/> - containing the objects to wait for.</param>
-        /// <param name="millisecondsTimeout">To number of milliseconds to wait for a <see cref="WaitHandle"/> to get signaled, or -1 to wait indefinitely.</param>
-        /// <returns>
-        /// The array index of the first non-system object that satisfied the wait.
-        /// </returns>
-        /// <exception cref="SshException">The connection was closed by the server.</exception>
-        /// <exception cref="SshException">The channel was closed.</exception>
-        /// <exception cref="SshOperationTimeoutException">No object satisfied the wait and a time interval equivalent to <paramref name="millisecondsTimeout"/> has passed.</exception>
-        /// <remarks>
-        /// For the return value, the index of the first non-system object is considered to be zero.
-        /// </remarks>
+        /// <inheritdoc/>
         public int WaitAny(WaitHandle[] waitHandles, int millisecondsTimeout)
         {
             var result = WaitHandle.WaitAny(waitHandles, millisecondsTimeout);
@@ -472,15 +355,7 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
-        /// elements.
-        /// </summary>
-        /// <param name="waitHandle1">The first <see cref="WaitHandle"/> to wait for.</param>
-        /// <param name="waitHandle2">The second <see cref="WaitHandle"/> to wait for.</param>
-        /// <returns>
-        /// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
-        /// </returns>
+        /// <inheritdoc/>
         public WaitHandle[] CreateWaitHandleArray(WaitHandle waitHandle1, WaitHandle waitHandle2)
         {
             return new WaitHandle[]
@@ -493,29 +368,6 @@ namespace Renci.SshNet
                 };
         }
 
-        /// <summary>
-        /// Creates a <see cref="WaitHandle"/> array that is composed of system objects and the specified
-        /// elements.
-        /// </summary>
-        /// <param name="waitHandles">A <see cref="WaitHandle"/> array containing the objects to wait for.</param>
-        /// <returns>
-        /// A <see cref="WaitHandle"/> array that is composed of system objects and the specified elements.
-        /// </returns>
-        public WaitHandle[] CreateWaitHandleArray(params WaitHandle[] waitHandles)
-        {
-            var array = new WaitHandle[waitHandles.Length + SystemWaitHandleCount];
-            array[0] = _errorOccurredWaitHandle;
-            array[1] = _sessionDisconnectedWaitHandle;
-            array[2] = _channelClosedWaitHandle;
-
-            for (var i = 0; i < waitHandles.Length; i++)
-            {
-                array[i + SystemWaitHandleCount] = waitHandles[i];
-            }
-
-            return array;
-        }
-
         private void Session_Disconnected(object sender, EventArgs e)
         {
             _ = _sessionDisconnectedWaitHandle?.Set();

+ 206 - 145
test/Renci.SshNet.IntegrationTests/SftpTests.cs

@@ -49,7 +49,8 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var memoryStream = new MemoryStream(size))
                     {
-                        client.DownloadFile(remoteFile, memoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, memoryStream);
+
                         memoryStream.Position = 0;
                         Assert.AreEqual(CreateFileHash(file), CreateHash(memoryStream));
                     }
@@ -164,7 +165,7 @@ namespace Renci.SshNet.IntegrationTests
                     // check uploaded file
                     using (var memoryStream = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, memoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, memoryStream);
                         memoryStream.Position = 0;
                         var remoteContent = Encoding.ASCII.GetString(memoryStream.ToArray());
                         Assert.AreEqual(content, remoteContent);
@@ -300,18 +301,12 @@ namespace Renci.SshNet.IntegrationTests
                     {
                         using (var fs = client.Create(remoteFile))
                         {
-                            byte[] buffer = new byte[Math.Min(client.BufferSize, imageStream.Length)];
-                            int bytesRead;
-
-                            while ((bytesRead = imageStream.Read(buffer, offset: 0, buffer.Length)) > 0)
-                            {
-                                fs.Write(buffer, offset: 0, bytesRead);
-                            }
+                            imageStream.CopyTo(fs);
                         }
 
                         using (var memoryStream = new MemoryStream())
                         {
-                            client.DownloadFile(remoteFile, memoryStream);
+                            DownloadFileRandomMethod(client, remoteFile, memoryStream);
 
                             memoryStream.Position = 0;
                             imageStream.Position = 0;
@@ -3192,7 +3187,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloadMemoryStream = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloadMemoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, downloadMemoryStream);
 
                         downloadMemoryStream.Position = 0;
 
@@ -3242,7 +3237,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloadMemoryStream = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloadMemoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, downloadMemoryStream);
 
                         downloadMemoryStream.Position = 0;
 
@@ -3328,7 +3323,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloadMemoryStream = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloadMemoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, downloadMemoryStream);
 
                         downloadMemoryStream.Position = 0;
 
@@ -3463,7 +3458,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloadMemoryStream = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloadMemoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, downloadMemoryStream);
 
                         downloadMemoryStream.Position = 0;
 
@@ -3515,7 +3510,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloadMemoryStream = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloadMemoryStream);
+                        DownloadFileRandomMethod(client, remoteFile, downloadMemoryStream);
 
                         downloadMemoryStream.Position = 0;
 
@@ -3556,20 +3551,25 @@ namespace Renci.SshNet.IntegrationTests
                 {
                     var memoryStream = CreateMemoryStream(size);
                     memoryStream.Position = 0;
+                    var expectedHash = CreateHash(memoryStream);
+                    memoryStream.Position = 0;
 
                     client.UploadFile(memoryStream, remoteFile);
 
+                    memoryStream.SetLength(0);
+
                     var stopwatch = new Stopwatch();
                     stopwatch.Start();
 
-                    // check uploaded file
-                    memoryStream = new MemoryStream();
                     client.DownloadFile(remoteFile, memoryStream);
 
-                    Assert.AreEqual(size, memoryStream.Length);
-
                     stopwatch.Stop();
 
+                    Assert.AreEqual(size, memoryStream.Length);
+                    memoryStream.Position = 0;
+                    var actualHash = CreateHash(memoryStream);
+                    Assert.AreEqual(expectedHash, actualHash);
+
                     Console.WriteLine(@"Elapsed: {0} ms", stopwatch.ElapsedMilliseconds);
                     Console.WriteLine(@"Transfer speed: {0:N2} KB/s",
                                       CalculateTransferSpeed(memoryStream.Length, stopwatch.ElapsedMilliseconds));
@@ -4140,46 +4140,6 @@ namespace Renci.SshNet.IntegrationTests
             }
         }
 
-        [TestMethod]
-        public void Sftp_DownloadFile_MemoryStream()
-        {
-            const int fileSize = 500 * 1024;
-
-            using (var client = new SftpClient(_connectionInfoFactory.Create()))
-            {
-                client.Connect();
-
-                var remoteFile = GenerateUniqueRemoteFileName();
-
-                SftpCreateRemoteFile(client, remoteFile, fileSize);
-
-                try
-                {
-                    using (var memoryStream = new MemoryStream())
-                    {
-                        var stopwatch = new Stopwatch();
-                        stopwatch.Start();
-
-                        client.DownloadFile(remoteFile, memoryStream);
-                        stopwatch.Stop();
-
-                        var transferSpeed = CalculateTransferSpeed(memoryStream.Length, stopwatch.ElapsedMilliseconds);
-                        Console.WriteLine(@"Elapsed: {0} ms", stopwatch.ElapsedMilliseconds);
-                        Console.WriteLine(@"Transfer speed: {0:N2} KB/s", transferSpeed);
-
-                        Assert.AreEqual(fileSize, memoryStream.Length);
-                    }
-                }
-                finally
-                {
-                    if (client.Exists(remoteFile))
-                    {
-                        client.DeleteFile(remoteFile);
-                    }
-                }
-            }
-        }
-
         [TestMethod]
         public void Sftp_SubsystemExecution_Failed()
         {
@@ -4229,6 +4189,75 @@ namespace Renci.SshNet.IntegrationTests
 
         [TestMethod]
         public void Sftp_SftpFileStream_ReadAndWrite()
+        {
+            TestReadAndWrite(
+                (s, buffer, offset, count) => s.Read(buffer, offset, count),
+                (s, buffer, offset, count) => s.Write(buffer, offset, count));
+        }
+
+        [TestMethod]
+        public void Sftp_SftpFileStream_ReadAndWriteByte()
+        {
+            TestReadAndWrite(
+                read: (s, buffer, offset, count) =>
+                {
+                    int bytesRead = 0;
+                    int b;
+
+                    while (bytesRead < count && (b = s.ReadByte()) != -1)
+                    {
+                        buffer[offset + bytesRead] = (byte)b;
+                        bytesRead++;
+                    }
+
+                    return bytesRead;
+                },
+                write: (s, buffer, offset, count) =>
+                {
+                    for (int i = 0; i < count; i++)
+                    {
+                        s.WriteByte(buffer[offset + i]);
+                    }
+                });
+        }
+
+        [TestMethod]
+        public void Sftp_SftpFileStream_ReadAndWriteAsync()
+        {
+            TestReadAndWrite(
+                (s, buffer, offset, count) => s.ReadAsync(buffer, offset, count).GetAwaiter().GetResult(),
+                (s, buffer, offset, count) => s.WriteAsync(buffer, offset, count).GetAwaiter().GetResult());
+        }
+
+        [TestMethod]
+        public void Sftp_SftpFileStream_ReadAndWriteBeginEnd()
+        {
+            TestReadAndWrite(
+                (s, buffer, offset, count) => s.EndRead(s.BeginRead(buffer, offset, count, null, null)),
+                (s, buffer, offset, count) => s.EndWrite(s.BeginWrite(buffer, offset, count, null, null)));
+        }
+
+#if NET
+        [TestMethod]
+        public void Sftp_SftpFileStream_ReadAndWriteSpan()
+        {
+            TestReadAndWrite(
+                (s, buffer, offset, count) => s.Read(buffer.AsSpan(offset, count)),
+                (s, buffer, offset, count) => s.Write(buffer.AsSpan(offset, count)));
+        }
+
+        [TestMethod]
+        public void Sftp_SftpFileStream_ReadAndWriteAsyncMemory()
+        {
+            TestReadAndWrite(
+                (s, buffer, offset, count) => s.ReadAsync(buffer.AsMemory(offset, count)).AsTask().GetAwaiter().GetResult(),
+                (s, buffer, offset, count) => s.WriteAsync(buffer.AsMemory(offset, count)).AsTask().GetAwaiter().GetResult());
+        }
+#endif
+
+        private void TestReadAndWrite(
+            Func<SftpFileStream, byte[], int, int, int> read,
+            Action<SftpFileStream, byte[], int, int> write)
         {
             using (var client = new SftpClient(_connectionInfoFactory.Create()))
             {
@@ -4245,60 +4274,69 @@ namespace Renci.SshNet.IntegrationTests
                 {
                     using (var s = client.Open(remoteFile, FileMode.CreateNew, FileAccess.Write))
                     {
-                        s.Write(new byte[] { 5, 4, 3, 2, 1 }, 1, 3);
+                        Assert.IsFalse(s.CanRead);
+                        Assert.IsTrue(s.CanWrite);
+
+                        write(s, new byte[] { 5, 4, 3, 2, 1 }, 1, 3);
                     }
 
                     // switch from read to write mode
                     using (var s = client.Open(remoteFile, FileMode.Open, FileAccess.ReadWrite))
                     {
-                        Assert.AreEqual(4, s.ReadByte());
-                        Assert.AreEqual(3, s.ReadByte());
+                        Assert.IsTrue(s.CanRead);
+                        Assert.IsTrue(s.CanWrite);
+
+                        Assert.AreEqual(4, ReadByte(s));
+                        Assert.AreEqual(3, ReadByte(s));
 
                         Assert.AreEqual(2, s.Position);
 
-                        s.WriteByte(7);
-                        s.Write(new byte[] { 8, 9, 10, 11, 12 }, 1, 3);
+                        WriteByte(s, 7);
+                        write(s, new byte[] { 8, 9, 10, 11, 12 }, 1, 3);
 
                         Assert.AreEqual(6, s.Position);
                     }
 
                     using (var s = client.Open(remoteFile, FileMode.Open, FileAccess.Read))
                     {
+                        Assert.IsTrue(s.CanRead);
+                        Assert.IsFalse(s.CanWrite);
+
                         Assert.AreEqual(6, s.Length);
 
                         var buffer = new byte[s.Length];
-                        Assert.AreEqual(6, s.Read(buffer, offset: 0, buffer.Length));
+                        Assert.AreEqual(6, read(s, buffer, 0, buffer.Length));
 
                         CollectionAssert.AreEqual(new byte[] { 4, 3, 7, 9, 10, 11 }, buffer);
 
                         // Ensure we've reached end of the stream
-                        Assert.AreEqual(-1, s.ReadByte());
+                        Assert.AreEqual(-1, ReadByte(s));
                     }
 
                     // switch from read to write mode, and back to read mode and finally
                     // append a byte
                     using (var s = client.Open(remoteFile, FileMode.Open, FileAccess.ReadWrite))
                     {
-                        Assert.AreEqual(4, s.ReadByte());
-                        Assert.AreEqual(3, s.ReadByte());
-                        Assert.AreEqual(7, s.ReadByte());
+                        Assert.AreEqual(4, ReadByte(s));
+                        Assert.AreEqual(3, ReadByte(s));
+                        Assert.AreEqual(7, ReadByte(s));
 
-                        s.Write(new byte[] { 0, 1, 6, 4 }, 1, 2);
+                        write(s, new byte[] { 0, 1, 6, 4 }, 1, 2);
 
-                        Assert.AreEqual(11, s.ReadByte());
+                        Assert.AreEqual(11, ReadByte(s));
 
                         // Ensure we've reached end of the stream
-                        Assert.AreEqual(-1, s.ReadByte());
+                        Assert.AreEqual(-1, ReadByte(s));
 
-                        s.WriteByte(12);
+                        WriteByte(s, 12);
                     }
 
                     // switch from write to read mode, and back to write mode
                     using (var s = client.Open(remoteFile, FileMode.Open, FileAccess.ReadWrite))
                     {
-                        s.WriteByte(5);
-                        Assert.AreEqual(3, s.ReadByte());
-                        s.WriteByte(13);
+                        WriteByte(s, 5);
+                        Assert.AreEqual(3, ReadByte(s));
+                        WriteByte(s, 13);
 
                         Assert.AreEqual(3, s.Position);
                     }
@@ -4308,12 +4346,12 @@ namespace Renci.SshNet.IntegrationTests
                         Assert.AreEqual(7, s.Length);
 
                         var buffer = new byte[s.Length];
-                        Assert.AreEqual(7, s.Read(buffer, offset: 0, buffer.Length));
+                        Assert.AreEqual(7, read(s, buffer, 0, buffer.Length));
 
                         CollectionAssert.AreEqual(new byte[] { 5, 3, 13, 1, 6, 11, 12 }, buffer);
 
                         // Ensure we've reached end of the stream
-                        Assert.AreEqual(-1, s.ReadByte());
+                        Assert.AreEqual(-1, ReadByte(s));
                     }
                 }
                 finally
@@ -4324,6 +4362,18 @@ namespace Renci.SshNet.IntegrationTests
                     }
                 }
             }
+
+            int ReadByte(SftpFileStream s)
+            {
+                var buffer = new byte[1];
+                var bytesRead = read(s, buffer, 0, 1);
+                return bytesRead == 0 ? -1 : buffer[0];
+            }
+
+            void WriteByte(SftpFileStream s, byte b)
+            {
+                write(s, [b], 0, 1);
+            }
         }
 
         [TestMethod]
@@ -4502,6 +4552,7 @@ namespace Renci.SshNet.IntegrationTests
 
                         Assert.AreEqual(3, newPosition);
                         Assert.AreEqual(3, fs.Position);
+                        Assert.AreEqual(1, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -4529,6 +4580,7 @@ namespace Renci.SshNet.IntegrationTests
 
                         Assert.AreEqual(700, newPosition);
                         Assert.AreEqual(700, fs.Position);
+                        Assert.AreEqual(1, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -4563,6 +4615,8 @@ namespace Renci.SshNet.IntegrationTests
                         Assert.AreEqual(seekOffset, fs.Position);
 
                         fs.Write(writeBuffer, offset: 0, writeBuffer.Length);
+
+                        Assert.AreEqual(seekOffset + writeBuffer.Length, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -4605,6 +4659,8 @@ namespace Renci.SshNet.IntegrationTests
                         Assert.AreEqual(seekOffset, fs.Position);
 
                         fs.Write(writeBuffer, offset: 0, writeBuffer.Length);
+
+                        Assert.AreEqual(seekOffset + writeBuffer.Length, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -4742,6 +4798,7 @@ namespace Renci.SshNet.IntegrationTests
 
                         Assert.AreEqual(4, newPosition);
                         Assert.AreEqual(4, fs.Position);
+                        Assert.AreEqual(1, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -4769,6 +4826,7 @@ namespace Renci.SshNet.IntegrationTests
 
                         Assert.AreEqual(701, newPosition);
                         Assert.AreEqual(701, fs.Position);
+                        Assert.AreEqual(1, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -4803,6 +4861,8 @@ namespace Renci.SshNet.IntegrationTests
                         Assert.AreEqual(4, fs.Position);
 
                         fs.Write(writeBuffer, offset: 0, writeBuffer.Length);
+
+                        Assert.AreEqual(1 + seekOffset + writeBuffer.Length, fs.Length);
                     }
 
                     using (var fs = client.OpenRead(remoteFile))
@@ -5455,7 +5515,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(new byte[size]), CreateHash(downloaded));
                     }
@@ -5495,6 +5555,9 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var s = client.Open(remoteFile, FileMode.Append, FileAccess.Write))
                     {
+                        Assert.IsFalse(s.CanRead);
+                        Assert.IsTrue(s.CanWrite);
+
                         var buffer = new byte[] { 0x05, 0x0f, 0x0d, 0x0a, 0x04 };
                         s.Write(buffer, offset: 0, buffer.Length);
                         input.Write(buffer, offset: 0, buffer.Length);
@@ -5502,7 +5565,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
 
                         input.Position = 0;
                         downloaded.Position = 0;
@@ -5562,7 +5625,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(content), CreateHash(downloaded));
                     }
@@ -5579,8 +5642,6 @@ namespace Renci.SshNet.IntegrationTests
             }
         }
 
-
-
         [TestMethod]
         public void Sftp_Open_PathAndMode_ModeIsCreate_FileDoesNotExist()
         {
@@ -5619,12 +5680,15 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var s = client.Open(remoteFile, FileMode.Create))
                     {
+                        Assert.IsTrue(s.CanRead);
+                        Assert.IsTrue(s.CanWrite);
+
                         s.Write(content, offset: 0, content.Length);
                     }
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(content), CreateHash(downloaded));
                     }
@@ -5730,7 +5794,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(content), CreateHash(downloaded));
                     }
@@ -5823,7 +5887,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
 
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(newContent), CreateHash(downloaded));
@@ -5882,7 +5946,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(content), CreateHash(downloaded));
                     }
@@ -5940,7 +6004,7 @@ namespace Renci.SshNet.IntegrationTests
                     // Verify that the file was not modified
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
 
                         input.Position = 0;
                         downloaded.Position = 0;
@@ -6000,7 +6064,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(content), CreateHash(downloaded));
                     }
@@ -6048,7 +6112,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
 
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(expectedContent), CreateHash(downloaded));
@@ -6138,7 +6202,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
 
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(expectedContent), CreateHash(downloaded));
@@ -6197,7 +6261,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
                         downloaded.Position = 0;
                         Assert.AreEqual(CreateHash(content), CreateHash(downloaded));
                     }
@@ -6214,12 +6278,6 @@ namespace Renci.SshNet.IntegrationTests
             }
         }
 
-
-
-
-
-
-
         [TestMethod]
         public void Sftp_Open_Truncate_Write_ExistingFile()
         {
@@ -6255,7 +6313,7 @@ namespace Renci.SshNet.IntegrationTests
 
                     using (var downloaded = new MemoryStream())
                     {
-                        client.DownloadFile(remoteFile, downloaded);
+                        DownloadFileRandomMethod(client, remoteFile, downloaded);
 
                         input.Position = 0;
                         downloaded.Position = 0;
@@ -6311,49 +6369,6 @@ namespace Renci.SshNet.IntegrationTests
             }
         }
 
-        [TestMethod]
-        public void Sftp_OpenRead()
-        {
-            const int fileSize = 5 * 1024 * 1024;
-
-            using (var client = new SftpClient(_connectionInfoFactory.Create()))
-            {
-                client.Connect();
-
-                var remoteFile = GenerateUniqueRemoteFileName();
-
-                SftpCreateRemoteFile(client, remoteFile, fileSize);
-
-                try
-                {
-                    using (var s = client.OpenRead(remoteFile))
-                    {
-                        var buffer = new byte[s.Length];
-
-                        var stopwatch = new Stopwatch();
-                        stopwatch.Start();
-
-                        var bytesRead = s.Read(buffer, offset: 0, buffer.Length);
-
-                        stopwatch.Stop();
-
-                        var transferSpeed = CalculateTransferSpeed(bytesRead, stopwatch.ElapsedMilliseconds);
-                        Console.WriteLine(@"Elapsed: {0} ms", stopwatch.ElapsedMilliseconds);
-                        Console.WriteLine(@"Transfer speed: {0:N2} KB/s", transferSpeed);
-
-                        Assert.AreEqual(fileSize, bytesRead);
-                    }
-                }
-                finally
-                {
-                    if (client.Exists(remoteFile))
-                    {
-                        client.DeleteFile(remoteFile);
-                    }
-                }
-            }
-        }
-
         [TestMethod]
         public void Sftp_SetLastAccessTime()
         {
@@ -6468,17 +6483,63 @@ namespace Renci.SshNet.IntegrationTests
 
         private static Encoding GetRandomEncoding()
         {
-            var random = new Random().Next(1, 3);
+            var random = new Random().Next(1, 4);
             switch (random)
             {
                 case 1:
                     return Encoding.Unicode;
                 case 2:
                     return Encoding.UTF8;
-                case 3:
+                default:
+                    Debug.Assert(random == 3);
                     return Encoding.UTF32;
+            }
+        }
+
+        private void DownloadFileRandomMethod(SftpClient client, string path, Stream output)
+        {
+            Console.Write($"Downloading '{path}'");
+
+            var random = new Random().Next(1, 6);
+            switch (random)
+            {
+                case 1:
+                    Console.WriteLine($" with {nameof(SftpClient.DownloadFile)}");
+
+                    client.DownloadFile(path, output);
+
+                    break;
+                case 2:
+                    Console.WriteLine($" with {nameof(SftpClient.DownloadFileAsync)}");
+
+                    client.DownloadFileAsync(path, output).GetAwaiter().GetResult();
+
+                    break;
+                case 3:
+                    Console.WriteLine($" with {nameof(SftpClient.BeginDownloadFile)}");
+
+                    client.EndDownloadFile(client.BeginDownloadFile(path, output));
+
+                    break;
+                case 4:
+                    Console.WriteLine($" with {nameof(SftpFileStream.CopyTo)}");
+
+                    using (var fs = client.OpenRead(path))
+                    {
+                        fs.CopyTo(output);
+                    }
+
+                    break;
                 default:
-                    throw new NotImplementedException();
+                    Debug.Assert(random == 5);
+                    Console.WriteLine($" with {nameof(SftpFileStream.CopyToAsync)}");
+
+                    using (var fs = client.OpenAsync(path, FileMode.Open, FileAccess.Read, CancellationToken.None).GetAwaiter().GetResult())
+                    {
+                        fs.CopyToAsync(output).GetAwaiter().GetResult();
+                    }
+
+                    break;
             }
         }
 

+ 298 - 0
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest.cs

@@ -0,0 +1,298 @@
+using System;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Moq;
+
+using Renci.SshNet.Common;
+using Renci.SshNet.Sftp;
+using Renci.SshNet.Sftp.Responses;
+
+namespace Renci.SshNet.Tests.Classes.Sftp
+{
+    [TestClass]
+    public class SftpFileStreamTest
+    {
+        [DataTestMethod]
+        [DataRow(false)]
+        [DataRow(true)]
+        public async Task BadFileMode_ThrowsArgumentOutOfRangeException(bool isAsync)
+        {
+            ArgumentOutOfRangeException ex;
+
+            if (isAsync)
+            {
+                ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() =>
+                    SftpFileStream.OpenAsync(new Mock<ISftpSession>().Object, "file.txt", mode: 0, FileAccess.Read, bufferSize: 1024, CancellationToken.None));
+            }
+            else
+            {
+                ex = Assert.Throws<ArgumentOutOfRangeException>(() =>
+                    SftpFileStream.Open(new Mock<ISftpSession>().Object, "file.txt", mode: 0, FileAccess.Read, bufferSize: 1024));
+            }
+
+            Assert.AreEqual("mode", ex.ParamName);
+        }
+
+        [DataTestMethod]
+        [DataRow(false)]
+        [DataRow(true)]
+        public async Task BadFileAccess_ThrowsArgumentOutOfRangeException(bool isAsync)
+        {
+            ArgumentOutOfRangeException ex;
+
+            if (isAsync)
+            {
+                ex = await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() =>
+                    SftpFileStream.OpenAsync(new Mock<ISftpSession>().Object, "file.txt", FileMode.Open, access: 0, bufferSize: 1024, CancellationToken.None));
+            }
+            else
+            {
+                ex = Assert.Throws<ArgumentOutOfRangeException>(() =>
+                    SftpFileStream.Open(new Mock<ISftpSession>().Object, "file.txt", FileMode.Open, access: 0, bufferSize: 1024));
+            }
+
+            Assert.AreEqual("access", ex.ParamName);
+        }
+
+        [TestMethod]
+        [DataRow(FileMode.Append, FileAccess.Read, false)]
+        [DataRow(FileMode.Append, FileAccess.Read, true)]
+        [DataRow(FileMode.Append, FileAccess.ReadWrite, false)]
+        [DataRow(FileMode.Append, FileAccess.ReadWrite, true)]
+        [DataRow(FileMode.Create, FileAccess.Read, false)]
+        [DataRow(FileMode.Create, FileAccess.Read, true)]
+        [DataRow(FileMode.CreateNew, FileAccess.Read, false)]
+        [DataRow(FileMode.CreateNew, FileAccess.Read, true)]
+        [DataRow(FileMode.Truncate, FileAccess.Read, false)]
+        [DataRow(FileMode.Truncate, FileAccess.Read, true)]
+        public async Task InvalidModeAccessCombination_ThrowsArgumentException(FileMode mode, FileAccess access, bool isAsync)
+        {
+            ArgumentException ex;
+
+            if (isAsync)
+            {
+                ex = await Assert.ThrowsAsync<ArgumentException>(() =>
+                    SftpFileStream.OpenAsync(new Mock<ISftpSession>().Object, "file.txt", mode, access, bufferSize: 1024, CancellationToken.None));
+            }
+            else
+            {
+                ex = Assert.Throws<ArgumentException>(() =>
+                    SftpFileStream.Open(new Mock<ISftpSession>().Object, "file.txt", mode, access, bufferSize: 1024));
+            }
+
+            Assert.AreEqual("mode", ex.ParamName);
+        }
+
+        [TestMethod]
+        public void ReadWithWriteAccess_ThrowsNotSupportedException()
+        {
+            var sessionMock = new Mock<ISftpSession>();
+
+            sessionMock.Setup(s => s.IsOpen).Returns(true);
+
+            SetupRemoteSize(sessionMock, 128);
+
+            var s = SftpFileStream.Open(sessionMock.Object, "file.txt", FileMode.Create, FileAccess.Write, bufferSize: 1024);
+
+            Assert.IsFalse(s.CanRead);
+
+            Assert.Throws<NotSupportedException>(() => _ = s.Read(new byte[4], 0, 4));
+            Assert.Throws<NotSupportedException>(() => _ = s.ReadByte());
+            Assert.Throws<NotSupportedException>(() => _ = s.ReadAsync(new byte[4], 0, 4).GetAwaiter().GetResult());
+            Assert.Throws<NotSupportedException>(() => _ = s.EndRead(s.BeginRead(new byte[4], 0, 4, null, null)));
+#if NET
+            Assert.Throws<NotSupportedException>(() => _ = s.Read(new byte[4]));
+            Assert.Throws<NotSupportedException>(() => _ = s.ReadAsync(new byte[4]).AsTask().GetAwaiter().GetResult());
+#endif
+            Assert.Throws<NotSupportedException>(() => s.CopyTo(Stream.Null));
+            Assert.Throws<NotSupportedException>(() => s.CopyToAsync(Stream.Null).GetAwaiter().GetResult());
+        }
+
+        [TestMethod]
+        public void WriteWithReadAccess_ThrowsNotSupportedException()
+        {
+            var sessionMock = new Mock<ISftpSession>();
+
+            sessionMock.Setup(s => s.IsOpen).Returns(true);
+
+            var s = SftpFileStream.Open(sessionMock.Object, "file.txt", FileMode.Open, FileAccess.Read, bufferSize: 1024);
+
+            Assert.IsFalse(s.CanWrite);
+
+            Assert.Throws<NotSupportedException>(() => s.Write(new byte[4], 0, 4));
+            Assert.Throws<NotSupportedException>(() => s.WriteByte(0xf));
+            Assert.Throws<NotSupportedException>(() => s.WriteAsync(new byte[4], 0, 4).GetAwaiter().GetResult());
+            Assert.Throws<NotSupportedException>(() => s.EndWrite(s.BeginWrite(new byte[4], 0, 4, null, null)));
+#if NET
+            Assert.Throws<NotSupportedException>(() => s.Write(new byte[4]));
+            Assert.Throws<NotSupportedException>(() => s.WriteAsync(new byte[4]).AsTask().GetAwaiter().GetResult());
+#endif
+            Assert.Throws<NotSupportedException>(() => s.SetLength(1024));
+        }
+
+        [Ignore("TODO Currently throws EndOfStreamException in all cases.")]
+        [TestMethod]
+        [DataRow(-1, SeekOrigin.Begin)]
+        [DataRow(-1, SeekOrigin.Current)]
+        [DataRow(-1000, SeekOrigin.End)]
+        public void SeekBeforeBeginning_ThrowsIOException(long offset, SeekOrigin origin)
+        {
+            var sessionMock = new Mock<ISftpSession>();
+
+            sessionMock.Setup(s => s.IsOpen).Returns(true);
+
+            SetupRemoteSize(sessionMock, 128);
+
+            var s = SftpFileStream.Open(sessionMock.Object, "file.txt", FileMode.Open, FileAccess.Read, bufferSize: 1024);
+
+            Assert.Throws<IOException>(() => s.Seek(offset, origin));
+        }
+
+        private static void SetupRemoteSize(Mock<ISftpSession> sessionMock, long size)
+        {
+            sessionMock.Setup(s => s.RequestFStat(It.IsAny<byte[]>(), It.IsAny<bool>())).Returns(new SftpFileAttributes(
+                default, default, size: size, default, default, default, default
+                ));
+        }
+
+        // Operations which should cause writes to be flushed because they depend on
+        // the remote file being up to date.
+        // Most of these are already implicitly covered by integration tests and may
+        // not be so valuable here.
+        [TestMethod]
+        public void Flush_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => s.Flush());
+        }
+
+        [TestMethod]
+        public void Read_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => _ = s.Read(new byte[16], 0, 16));
+        }
+
+        [TestMethod]
+        public void Seek_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => _ = s.Seek(-1, SeekOrigin.Current));
+        }
+
+        [TestMethod]
+        public void SetPosition_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => s.Position++);
+        }
+
+        [TestMethod]
+        public void SetLength_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => s.SetLength(256));
+        }
+
+        [TestMethod]
+        public void GetLength_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => _ = s.Length);
+        }
+
+        [TestMethod]
+        public void Dispose_SendsBufferedWrites()
+        {
+            TestSendsBufferedWrites(s => s.Dispose());
+        }
+
+        private void TestSendsBufferedWrites(Action<SftpFileStream> flushAction)
+        {
+            var sessionMock = new Mock<ISftpSession>();
+
+            sessionMock.Setup(s => s.CalculateOptimalWriteLength(It.IsAny<uint>(), It.IsAny<byte[]>())).Returns<uint, byte[]>((x, _) => x);
+            sessionMock.Setup(s => s.IsOpen).Returns(true);
+            SetupRemoteSize(sessionMock, 0);
+
+            var s = SftpFileStream.Open(sessionMock.Object, "file.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, bufferSize: 1024);
+
+            // Buffer some data
+            byte[] newData = "Some new bytes"u8.ToArray();
+            s.Write(newData, 0, newData.Length);
+
+            byte[] newData2 = "Some more bytes"u8.ToArray();
+            s.Write(newData2, 0, newData2.Length);
+
+            // The written data does not exceed bufferSize so we do not expect
+            // it to have been sent.
+            sessionMock.Verify(s => s.RequestWrite(
+                It.IsAny<byte[]>(),
+                It.IsAny<ulong>(),
+                It.IsAny<byte[]>(),
+                It.IsAny<int>(),
+                It.IsAny<int>(),
+                It.IsAny<AutoResetEvent>(),
+                It.IsAny<Action<SftpStatusResponse>>()),
+                Times.Never);
+
+            // Whatever is called here should trigger the bytes to be sent
+            flushAction(s);
+
+            VerifyRequestWrite(sessionMock, newData.Concat(newData2), serverOffset: 0);
+        }
+
+        [TestMethod]
+        public void Dispose()
+        {
+            var sessionMock = new Mock<ISftpSession>();
+
+            sessionMock.Setup(s => s.IsOpen).Returns(true);
+
+            var s = SftpFileStream.Open(sessionMock.Object, "file.txt", FileMode.Create, FileAccess.ReadWrite, bufferSize: 1024);
+
+            Assert.IsTrue(s.CanRead);
+            Assert.IsTrue(s.CanSeek);
+            Assert.IsTrue(s.CanWrite);
+
+            s.Dispose();
+            sessionMock.Verify(p => p.RequestClose(It.IsAny<byte[]>()), Times.Once);
+
+            Assert.IsFalse(s.CanRead);
+            Assert.IsFalse(s.CanSeek);
+            Assert.IsFalse(s.CanWrite);
+
+            Assert.Throws<ObjectDisposedException>(() => s.Read(new byte[16], 0, 16));
+            Assert.Throws<ObjectDisposedException>(() => s.ReadByte());
+            Assert.Throws<ObjectDisposedException>(() => s.Write(new byte[16], 0, 16));
+            Assert.Throws<ObjectDisposedException>(() => s.WriteByte(0xf));
+            Assert.Throws<ObjectDisposedException>(() => s.CopyTo(Stream.Null));
+            Assert.Throws<ObjectDisposedException>(s.Flush);
+            Assert.Throws<ObjectDisposedException>(() => s.Seek(0, SeekOrigin.Begin));
+            Assert.Throws<ObjectDisposedException>(() => s.SetLength(128));
+            Assert.Throws<ObjectDisposedException>(() => _ = s.Length);
+
+            // Test no-op second dispose
+            s.Dispose();
+            sessionMock.Verify(p => p.RequestClose(It.IsAny<byte[]>()), Times.Once);
+        }
+
+        private static void VerifyRequestWrite(Mock<ISftpSession> sessionMock, ReadOnlyMemory<byte> newData, int serverOffset)
+        {
+            sessionMock.Verify(s => s.RequestWrite(
+                /* handle: */         It.IsAny<byte[]>(),
+                /* serverOffset: */   (ulong)serverOffset,
+                /* data: */           It.Is<byte[]>(x => IndexOf(x, newData) >= 0),
+                /* offset: */         It.IsAny<int>(),
+                /* length: */         newData.Length,
+                /* wait: */           It.IsAny<AutoResetEvent>(),
+                /* writeCompleted: */ It.IsAny<Action<SftpStatusResponse>>()),
+                Times.Once);
+        }
+
+        private static int IndexOf(byte[] searchSpace, ReadOnlyMemory<byte> searchValue)
+        {
+            // Needed in a (non-local) function because expression lambdas can't contain spans
+            return searchSpace.AsSpan().IndexOf(searchValue.Span);
+        }
+    }
+}

+ 0 - 68
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTestBase.cs

@@ -1,68 +0,0 @@
-using System;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    public abstract class SftpFileStreamTestBase
-    {
-        internal Mock<ISftpSession> SftpSessionMock;
-        protected MockSequence MockSequence;
-
-        protected virtual void Arrange()
-        {
-            SetupData();
-            CreateMocks();
-            SetupMocks();
-        }
-
-        protected virtual void SetupData()
-        {
-            MockSequence = new MockSequence();
-        }
-
-        protected abstract void SetupMocks();
-
-        private void CreateMocks()
-        {
-            SftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
-        }
-
-        [TestInitialize]
-        public void SetUp()
-        {
-            Arrange();
-            Act();
-        }
-
-        protected abstract void Act();
-
-        protected byte[] GenerateRandom(int length)
-        {
-            return GenerateRandom(length, new Random());
-        }
-
-        protected byte[] GenerateRandom(int length, Random random)
-        {
-            var buffer = new byte[length];
-            random.NextBytes(buffer);
-            return buffer;
-        }
-
-        protected byte[] GenerateRandom(uint length)
-        {
-            return GenerateRandom(length, new Random());
-        }
-
-        protected byte[] GenerateRandom(uint length, Random random)
-        {
-            var buffer = new byte[length];
-            random.NextBytes(buffer);
-            return buffer;
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessRead.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanRead_Closed_FileAccessRead : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(3, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanRead;
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanRead_Closed_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(3, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.ReadWrite,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanRead;
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Closed_FileAccessWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanRead_Closed_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(3, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanRead;
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessRead.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanRead_Disposed_FileAccessRead : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanRead;
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanRead_Disposed_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.ReadWrite,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanRead;
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanRead_Disposed_FileAccessWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanRead_Disposed_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanRead;
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessRead.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanWrite_Closed_FileAccessRead : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanWrite;
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanWrite_Closed_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.ReadWrite,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanWrite;
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Closed_FileAccessWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanWrite_Closed_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanWrite;
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessRead.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanWrite_Disposed_FileAccessRead : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanWrite;
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanWrite_Disposed_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.ReadWrite,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanWrite;
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 76
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite.cs

@@ -1,76 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_CanWrite_Disposed_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private bool _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Write, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.CanWrite;
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_actual);
-        }
-    }
-}

+ 0 - 80
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Closed.cs

@@ -1,80 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Close_Closed
-    {
-        private Mock<ISftpSession> _sftpSessionMock;
-        private string _path;
-        private SftpFileStream _sftpFileStream;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        [TestInitialize]
-        public void Setup()
-        {
-            Arrange();
-            Act();
-        }
-
-        protected void Arrange()
-        {
-            var random = new Random();
-            _path = random.Next().ToString(CultureInfo.InvariantCulture);
-            _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(0, 1000);
-            _writeBufferSize = (uint)random.Next(0, 1000);
-
-            _sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
-
-            var sequence = new MockSequence();
-
-            _ = _sftpSessionMock.InSequence(sequence)
-                                .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                                .Returns(_handle);
-            _ = _sftpSessionMock.InSequence(sequence)
-                                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                                .Returns(_readBufferSize);
-            _ = _sftpSessionMock.InSequence(sequence)
-                                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                                .Returns(_writeBufferSize);
-            _ = _sftpSessionMock.InSequence(sequence)
-                                .Setup(p => p.IsOpen)
-                                .Returns(true);
-            _ = _sftpSessionMock.InSequence(sequence)
-                                .Setup(p => p.RequestClose(_handle));
-
-            _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Open, FileAccess.Read, (int)_bufferSize);
-            _sftpFileStream.Close();
-        }
-
-        protected void Act()
-        {
-            _sftpFileStream.Close();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            _sftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldBeInvokedOnce()
-        {
-            _sftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
-        }
-    }
-}

+ 0 - 81
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_Disposed.cs

@@ -1,81 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Close_Disposed : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(2, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _target.Close();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
-        }
-    }
-}

+ 0 - 78
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionNotOpen.cs

@@ -1,78 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Close_SessionNotOpen : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(2, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(false);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target.Close();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldNeverBeInvoked()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never);
-        }
-    }
-}

+ 0 - 80
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Close_SessionOpen.cs

@@ -1,80 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Close_SessionOpen : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(2, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target.Close();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
-        }
-    }
-}

+ 0 - 56
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileAccessInvalid.cs

@@ -1,56 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileAccessInvalid : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentOutOfRangeException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = 0;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentOutOfRangeException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual("access", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 58
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessRead.cs

@@ -1,58 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeAppend_FileAccessRead : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Append;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("{0} mode can be requested only when combined with write-only access.", _fileMode), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 58
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessReadWrite.cs

@@ -1,58 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeAppend_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Append;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("{0} mode can be requested only when combined with write-only access.", _fileMode), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 185
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeAppend_FileAccessWrite.cs

@@ -1,185 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeAppend_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private SftpFileAttributes _fileAttributes;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Append;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _fileAttributes = new SftpFileAttributesBuilder().WithLastAccessTime(DateTime.UtcNow.AddSeconds(_random.Next()))
-                                                             .WithLastWriteTime(DateTime.UtcNow.AddSeconds(_random.Next()))
-                                                             .WithSize(_random.Next())
-                                                             .WithUserId(_random.Next())
-                                                             .WithGroupId(_random.Next())
-                                                             .WithPermissions((uint)_random.Next())
-                                                             .Build();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestFStat(_handle, false))
-                               .Returns(_fileAttributes);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSizeOfFile()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(_fileAttributes.Size, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            try
-            {
-                _ = _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtEndOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWrite(_handle, (ulong)_fileAttributes.Size, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, (ulong)_fileAttributes.Size, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, false), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestFStatOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestFStat(_handle, false), Times.Once);
-        }
-    }
-}

+ 0 - 58
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessRead.cs

@@ -1,58 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessRead : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.CreateNew;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                _ = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("Combining {0}: {1} with {2}: {3} is invalid.", nameof(FileMode), _fileMode, nameof(FileAccess), _fileAccess), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 167
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite.cs

@@ -1,167 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.CreateNew;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.CreateNew, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.CreateNew, false), Times.Once);
-        }
-    }
-}

+ 0 - 158
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessWrite.cs

@@ -1,158 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreateNew_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.CreateNew;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNew, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNew, false), Times.Once);
-        }
-    }
-}

+ 0 - 58
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessRead.cs

@@ -1,58 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreate_FileAccessRead : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                _ = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("Combining {0}: {1} with {2}: {3} is invalid.", nameof(FileMode), _fileMode, nameof(FileAccess), _fileAccess), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 170
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs

@@ -1,170 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileDoesNotExist : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true))
-                               .Returns((byte[])null);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.CreateNew, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true), Times.Once);
-        }
-    }
-}

+ 0 - 155
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists.cs

@@ -1,155 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreate_FileAccessReadWrite_FileExists : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)).Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, true), Times.Once);
-        }
-    }
-}

+ 0 - 162
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs

@@ -1,162 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreate_FileAccessWrite_FileDoesNotExist : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
-                           .Returns((byte[])null);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNew, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnceWithTruncateAndOnceWithCreateNew()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true), Times.Once);
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNew, false), Times.Once);
-        }
-    }
-}

+ 0 - 158
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeCreate_FileAccessWrite_FileExists.cs

@@ -1,158 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeCreate_FileAccessWrite_FileExists : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true), Times.Once);
-        }
-    }
-}

+ 0 - 56
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeInvalid.cs

@@ -1,56 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeInvalid : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentOutOfRangeException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = 0;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentOutOfRangeException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 178
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead.cs

@@ -1,178 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessRead : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)).Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.Write(buffer, 0, buffer.Length);
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Write not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.WriteByte(0x0a);
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Write not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false), Times.Once);
-        }
-    }
-}

+ 0 - 155
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite.cs

@@ -1,155 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)).Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen, false), Times.Once);
-        }
-    }
-}

+ 0 - 158
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessWrite.cs

@@ -1,158 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeOpenOrCreate_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNewOrOpen, false), Times.Once);
-        }
-    }
-}

+ 0 - 178
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead.cs

@@ -1,178 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeOpen_FileAccessRead : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)).Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.Write(buffer, 0, buffer.Length);
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Write not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.WriteByte(0x0a);
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Write not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read, false), Times.Once);
-        }
-    }
-}

+ 0 - 155
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite.cs

@@ -1,155 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeOpen_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize)).Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false), Times.Once);
-        }
-    }
-}

+ 0 - 158
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeOpen_FileAccessWrite.cs

@@ -1,158 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeOpen_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write, false), Times.Once);
-        }
-    }
-}

+ 0 - 58
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessRead.cs

@@ -1,58 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessRead : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Truncate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                _ = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("Combining {0}: {1} with {2}: {3} is invalid.", nameof(FileMode), _fileMode, nameof(FileAccess), _fileAccess), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 167
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite.cs

@@ -1,167 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessReadWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Truncate;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                                .Setup(p => p.IsOpen)
-                                .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(data);
-
-            var actual = _target.Read(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void ReadByteShouldStartReadingAtBeginningOfFile()
-        {
-            var data = GenerateRandom(5, _random);
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(data);
-
-            var actual = _target.ReadByte();
-
-            Assert.AreEqual(data[0], actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Once);
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.Truncate, false), Times.Once);
-        }
-    }
-}

+ 0 - 158
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessWrite.cs

@@ -1,158 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Ctor_FileModeTruncate_FileAccessWrite : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Truncate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         _fileMode,
-                                         _fileAccess,
-                                         _bufferSize);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = _target.Read(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void ReadByteShouldThrowNotSupportedException()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _target.ReadByte();
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Read not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null));
-
-            _target.Write(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle, 0UL, buffer, 0, buffer.Length, It.IsNotNull<AutoResetEvent>(), null), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, false), Times.Once);
-        }
-    }
-}

+ 0 - 81
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Closed.cs

@@ -1,81 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Dispose_Closed : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(random.Next(1, 5), random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _target.Close();
-        }
-
-        protected override void Act()
-        {
-            _target.Dispose();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
-        }
-    }
-}

+ 0 - 78
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_Disposed.cs

@@ -1,78 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Dispose_Disposed : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.OpenOrCreate,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-            _target.Dispose();
-        }
-
-        protected override void Act()
-        {
-            _target.Dispose();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
-        }
-    }
-}

+ 0 - 80
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionNotOpen.cs

@@ -1,80 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Dispose_SessionNotOpen : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(2, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.CreateNew, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(false);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.CreateNew,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target.Dispose();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldNeverBeInvoked()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never);
-        }
-    }
-}

+ 0 - 80
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Dispose_SessionOpen.cs

@@ -1,80 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Dispose_SessionOpen : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString(CultureInfo.InvariantCulture);
-            _handle = GenerateRandom(2, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen).Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Truncate,
-                                         FileAccess.Write,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _target.Dispose();
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Once);
-        }
-    }
-}

+ 0 - 94
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Finalize_SessionOpen.cs

@@ -1,94 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Finalize_SessionOpen : SftpFileStreamTestBase
-    {
-        private WeakReference<SftpFileStream> _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString(CultureInfo.InvariantCulture);
-            _handle = GenerateRandom(7, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = CreateWeakSftpFileStream();
-        }
-
-        protected override void Act()
-        {
-            GC.Collect();
-            GC.WaitForPendingFinalizers();
-        }
-
-        [TestMethod]
-        public void SftpFileStreamShouldHaveBeenFinalized()
-        {
-            Assert.IsFalse(_target.TryGetTarget(out _));
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldNeverBeInvoked()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Never);
-        }
-
-        [TestMethod]
-        public void RequestCloseOnSftpSessionShouldNeverBeInvoked()
-        {
-            SftpSessionMock.Verify(p => p.RequestClose(_handle), Times.Never);
-        }
-
-        private WeakReference<SftpFileStream> CreateWeakSftpFileStream()
-        {
-            var sftpFileStream = new SftpFileStream(SftpSessionMock.Object,
-                                                    _path,
-                                                    FileMode.OpenOrCreate,
-                                                    FileAccess.ReadWrite,
-                                                    (int)_bufferSize);
-            return new WeakReference<SftpFileStream>(sftpFileStream);
-        }
-    }
-}

+ 0 - 116
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer.cs

@@ -1,116 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Flush_ReadMode_DataInBuffer_NotReadFromBuffer : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _readBytes;
-        private byte[] _serverBytes;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 100;
-            _writeBufferSize = 500;
-            _readBytes = new byte[random.Next(1, (int)_readBufferSize - 10)];
-            _serverBytes = GenerateRandom(_readBytes.Length + 5); // store 5 bytes in read buffer
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(_serverBytes);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _ = _target.Read(_readBytes, 0, _readBytes.Length);
-        }
-
-        protected override void Act()
-        {
-            _target.Flush();
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSameValueAsBeforeFlush()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            Assert.AreEqual(_readBytes.Length, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-
-        [TestMethod]
-        public void ReadShouldReadFromServer()
-        {
-            var serverBytes2 = GenerateRandom(5);
-            var readBytes2 = new byte[5];
-            var expectedReadBytes = new ArrayBuilder<byte>().Add(new byte[2])
-                                                            .Add(serverBytes2.Take(0, 3))
-                                                            .Build();
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, (ulong)_readBytes.Length, _readBufferSize))
-                               .Returns(serverBytes2);
-
-            var bytesRead = _target.Read(readBytes2, 2, 3);
-
-            Assert.AreEqual(3, bytesRead);
-            CollectionAssert.AreEqual(expectedReadBytes, readBytes2);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_readBytes.Length, _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 123
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer.cs

@@ -1,123 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Flush_ReadMode_DataInBuffer_ReadFromBuffer : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _readBytes1;
-        private byte[] _readBytes2;
-        private byte[] _serverBytes;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 100;
-            _writeBufferSize = 500;
-            _readBytes1 = new byte[random.Next(1, (int)_readBufferSize - 10)];
-            _readBytes2 = new byte[random.Next(1, 3)];
-            _serverBytes = GenerateRandom(_readBytes1.Length + 10); // store 5 bytes in read buffer
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(_serverBytes);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _ = _target.Read(_readBytes1, 0, _readBytes1.Length);
-            _ = _target.Read(_readBytes2, 0, _readBytes2.Length);
-        }
-
-        protected override void Act()
-        {
-            _target.Flush();
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSameValueAsBeforeFlush()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            Assert.AreEqual(_readBytes1.Length + _readBytes2.Length, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
-        }
-
-        [TestMethod]
-        public void ReadShouldReadFromServer()
-        {
-            var serverBytes3 = GenerateRandom(5);
-            var readBytes3 = new byte[3];
-            var expectedReadBytes = new ArrayBuilder<byte>().Add(new byte[1])
-                                                            .Add(serverBytes3.Take(0, 2))
-                                                            .Build();
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, (ulong)(_readBytes1.Length + _readBytes2.Length), _readBufferSize))
-                               .Returns(serverBytes3);
-
-            var bytesRead = _target.Read(readBytes3, 1, 2);
-
-            Assert.AreEqual(2, bytesRead);
-            CollectionAssert.AreEqual(expectedReadBytes, readBytes3);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)(_readBytes1.Length + _readBytes2.Length), _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
-        }
-    }
-}

+ 0 - 116
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer.cs

@@ -1,116 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Flush_ReadMode_NoDataInBuffer : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _readBytes;
-        private byte[] _serverBytes;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 100;
-            _writeBufferSize = 500;
-            _readBytes = new byte[random.Next(1, (int)_readBufferSize)];
-            _serverBytes = GenerateRandom(_readBytes.Length);
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                               .Returns(_serverBytes);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-            _ = _target.Read(_readBytes, 0, _readBytes.Length);
-        }
-
-        protected override void Act()
-        {
-            _target.Flush();
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSameValueAsBeforeFlush()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            Assert.AreEqual(_readBytes.Length, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-
-        [TestMethod]
-        public void ReadShouldReadFromServer()
-        {
-            var serverBytes2 = GenerateRandom(5);
-            var readBytes2 = new byte[5];
-            var expectedReadBytes = new ArrayBuilder<byte>().Add(new byte[2])
-                                                            .Add(serverBytes2.Take(0, 3))
-                                                            .Build();
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, (ulong)_readBytes.Length, _readBufferSize))
-                               .Returns(serverBytes2);
-
-            var bytesRead = _target.Read(readBytes2, 2, 3);
-
-            Assert.AreEqual(3, bytesRead);
-            CollectionAssert.AreEqual(expectedReadBytes, readBytes2);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_readBytes.Length, _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 84
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_SessionNotOpen.cs

@@ -1,84 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Flush_SessionNotOpen : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private ObjectDisposedException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(false);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                _target.Flush();
-                Assert.Fail();
-            }
-            catch (ObjectDisposedException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void FlushShouldHaveThrownObjectDisposedException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual(string.Format("Cannot access a closed SFTP session.{0}Object name: '{1}'.", Environment.NewLine, _actualException.ObjectName), _actualException.Message);
-            Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName);
-        }
-    }
-}

+ 0 - 152
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_DataInBuffer.cs

@@ -1,152 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Sftp.Responses;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Flush_WriteMode_DataInBuffer : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _writeBytes1;
-        private byte[] _writeBytes2;
-        private byte[] _writeBytes3;
-        private byte[] _flushedBytes;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 100;
-            _writeBufferSize = 500;
-            _writeBytes1 = GenerateRandom(_writeBufferSize);
-            _writeBytes2 = GenerateRandom(2);
-            _writeBytes3 = GenerateRandom(3);
-            _flushedBytes = null;
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                               .Returns(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWrite(_handle, 0UL, It.IsAny<byte[]>(), 0, _writeBytes1.Length, It.IsAny<AutoResetEvent>(), null))
-                               .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>((handle, serverOffset, data, offset, length, wait, writeCompleted) =>
-                                   {
-                                       _ = wait.Set();
-                                   });
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWrite(_handle, (ulong)_writeBytes1.Length, It.IsAny<byte[]>(), 0, _writeBytes2.Length + _writeBytes3.Length, It.IsAny<AutoResetEvent>(), null))
-                               .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>((handle, serverOffset, data, offset, length, wait, writeCompleted) =>
-                                   {
-                                       _flushedBytes = data.Take(offset, length);
-                                       _ = wait.Set();
-                                   });
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.ReadWrite,
-                                         (int)_bufferSize);
-            _target.Write(_writeBytes1, 0, _writeBytes1.Length);
-            _target.Write(_writeBytes2, 0, _writeBytes2.Length);
-            _target.Write(_writeBytes3, 0, _writeBytes3.Length);
-        }
-
-        protected override void Act()
-        {
-            _target.Flush();
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSameValueAsBeforeFlush()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            Assert.AreEqual(_writeBytes1.Length + _writeBytes2.Length + _writeBytes3.Length, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(5));
-        }
-
-        [TestMethod]
-        public void BufferedBytesShouldHaveBeenWrittenToTheServer()
-        {
-            var expected = new ArrayBuilder<byte>().Add(_writeBytes2)
-                                                   .Add(_writeBytes3)
-                                                   .Build();
-
-            Assert.IsNotNull(_flushedBytes);
-            CollectionAssert.AreEqual(expected, _flushedBytes);
-        }
-
-        [TestMethod]
-        public void ReadShouldReadFromServer()
-        {
-            var serverBytes = GenerateRandom(5);
-            var readBytes = new byte[5];
-            var expectedReadBytes = new ArrayBuilder<byte>().Add(new byte[2])
-                                                            .Add(serverBytes.Take(0, 3))
-                                                            .Build();
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestRead(_handle, (ulong)(_writeBytes1.Length + _writeBytes2.Length + _writeBytes3.Length), _readBufferSize))
-                               .Returns(serverBytes);
-
-            var bytesRead = _target.Read(readBytes, 2, 3);
-
-            Assert.AreEqual(3, bytesRead);
-            CollectionAssert.AreEqual(expectedReadBytes, readBytes);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)(_writeBytes1.Length + _writeBytes2.Length + _writeBytes3.Length), _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(5));
-        }
-    }
-}

+ 0 - 120
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer.cs

@@ -1,120 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Sftp.Responses;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Flush_WriteMode_NoDataInBuffer : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _writeBytes;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 100;
-            _writeBufferSize = 500;
-            _writeBytes = GenerateRandom(_writeBufferSize);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestWrite(_handle, 0UL, It.IsAny<byte[]>(), 0, _writeBytes.Length, It.IsAny<AutoResetEvent>(), null))
-                           .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>((handle, serverOffset, data, offset, length, wait, writeCompleted)
-                               =>
-                           {
-                               wait.Set();
-                           });
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.ReadWrite,
-                                         (int)_bufferSize);
-            _target.Write(_writeBytes, 0, _writeBytes.Length);
-        }
-
-        protected override void Act()
-        {
-            _target.Flush();
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSameValueAsBeforeFlush()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-
-            Assert.AreEqual(_writeBytes.Length, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-
-        [TestMethod]
-        public void ReadShouldReadFromServer()
-        {
-            var serverBytes = GenerateRandom(5);
-            var readBytes = new byte[5];
-            var expectedReadBytes = new ArrayBuilder<byte>().Add(new byte[2])
-                                                            .Add(serverBytes.Take(0, 3))
-                                                            .Build();
-
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, (ulong)_writeBytes.Length, _readBufferSize))
-                           .Returns(serverBytes);
-
-            var bytesRead = _target.Read(readBytes, 2, 3);
-
-            Assert.AreEqual(3, bytesRead);
-            CollectionAssert.AreEqual(expectedReadBytes, readBytes);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_writeBytes.Length, _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 57
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileAccessInvalid.cs

@@ -1,57 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileAccessInvalid : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentOutOfRangeException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = 0;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentOutOfRangeException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual("access", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 59
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead.cs

@@ -1,59 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessRead : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Append;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("{0} mode can be requested only when combined with write-only access.", _fileMode), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 59
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite.cs

@@ -1,59 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessReadWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Append;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("{0} mode can be requested only when combined with write-only access.", _fileMode), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 164
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite.cs

@@ -1,164 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeAppend_FileAccessWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private SftpFileAttributes _fileAttributes;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Append;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _fileAttributes = new SftpFileAttributesBuilder().WithLastAccessTime(DateTime.UtcNow.AddSeconds(_random.Next()))
-                                                             .WithLastWriteTime(DateTime.UtcNow.AddSeconds(_random.Next()))
-                                                             .WithSize(_random.Next())
-                                                             .WithUserId(_random.Next())
-                                                             .WithGroupId(_random.Next())
-                                                             .WithPermissions((uint)_random.Next())
-                                                             .Build();
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpenAsync(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, _cancellationToken))
-                               .ReturnsAsync(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestFStatAsync(_handle, _cancellationToken))
-                               .ReturnsAsync(_fileAttributes);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSizeOfFile()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(_fileAttributes.Size, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length, _cancellationToken);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtEndOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWriteAsync(_handle, (ulong)_fileAttributes.Size, buffer, 0, buffer.Length, _cancellationToken))
-                               .Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length, _cancellationToken);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, (ulong)_fileAttributes.Size, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.Append | Flags.CreateNewOrOpen, default), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestFStatOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestFStatAsync(_handle, default), Times.Once);
-        }
-    }
-}

+ 0 - 59
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead.cs

@@ -1,59 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessRead : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.CreateNew;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                _ = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("Combining {0}: {1} with {2}: {3} is invalid.", nameof(FileMode), _fileMode, nameof(FileAccess), _fileAccess), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessReadWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.CreateNew;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNew, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken)).ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length, _cancellationToken);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length, _cancellationToken);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNew, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 145
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite.cs

@@ -1,145 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreateNew_FileAccessWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.CreateNew;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNew, _cancellationToken))
-                               .ReturnsAsync(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken))
-                               .Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNew, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 59
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead.cs

@@ -1,59 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessRead : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                _ = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("Combining {0}: {1} with {2}: {3} is invalid.", nameof(FileMode), _fileMode, nameof(FileAccess), _fileAccess), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 147
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist.cs

@@ -1,147 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileDoesNotExist : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken))
-                               .ReturnsAsync(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken))
-                               .ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken))
-                               .Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessReadWrite_FileExists : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken)).ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileDoesNotExist : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnceWithTruncateAndOnceWithCreateNew()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 145
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists.cs

@@ -1,145 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeCreate_FileAccessWrite_FileExists : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Create;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken))
-                               .ReturnsAsync(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken))
-                               .Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen | Flags.Truncate, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 57
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeInvalid.cs

@@ -1,57 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeInvalid : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentOutOfRangeException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = 0;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentOutOfRangeException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 142
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead.cs

@@ -1,142 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessRead : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.CreateNewOrOpen, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken)).ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                await _target.WriteAsync(buffer, 0, buffer.Length);
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.CreateNewOrOpen, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 147
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite.cs

@@ -1,147 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessReadWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen, _cancellationToken))
-                               .ReturnsAsync(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken))
-                               .ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken))
-                               .Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.CreateNewOrOpen, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeOpenOrCreate_FileAccessWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.CreateNewOrOpen, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 143
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead.cs

@@ -1,143 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessRead : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Read, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken)).ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length, _cancellationToken);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                await _target.WriteAsync(buffer, 0, buffer.Length, _cancellationToken);
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-                Assert.AreEqual("Write not supported.", ex.Message);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 147
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite.cs

@@ -1,147 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessReadWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write, _cancellationToken))
-                               .ReturnsAsync(_handle);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                               .Returns(_readBufferSize);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                               .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken))
-                               .ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.IsOpen)
-                               .Returns(true);
-            _ = SftpSessionMock.InSequence(MockSequence)
-                               .Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken))
-                               .Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeOpen_FileAccessWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Open;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Write, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 59
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead.cs

@@ -1,59 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessRead : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private ArgumentException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Truncate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-        }
-
-        protected override async Task ActAsync()
-        {
-            try
-            {
-                _ = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, default);
-                Assert.Fail();
-            }
-            catch (ArgumentException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void CtorShouldHaveThrownArgumentException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            ArgumentExceptionAssert.MessageEquals(string.Format("Combining {0}: {1} with {2}: {3} is invalid.", nameof(FileMode), _fileMode, nameof(FileAccess), _fileAccess), _actualException);
-            Assert.AreEqual("mode", _actualException.ParamName);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessReadWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Truncate;
-            _fileAccess = FileAccess.ReadWrite;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.Truncate, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldStartReadingAtBeginningOfFile()
-        {
-            var buffer = new byte[8];
-            var data = new byte[] { 5, 4, 3, 2, 1 };
-            var expected = new byte[] { 0, 5, 4, 3, 2, 1, 0, 0 };
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken)).ReturnsAsync(data);
-
-            var actual = await _target.ReadAsync(buffer, 1, data.Length);
-
-            Assert.AreEqual(data.Length, actual);
-            Assert.IsTrue(buffer.IsEqualTo(expected));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Read | Flags.Write | Flags.Truncate, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 137
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite.cs

@@ -1,137 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_OpenAsync_FileModeTruncate_FileAccessWrite : SftpFileStreamAsyncTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private CancellationToken _cancellationToken;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.Truncate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _cancellationToken = new CancellationToken();
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpenAsync(_path, Flags.Write | Flags.Truncate, _cancellationToken))
-                           .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize, _cancellationToken);
-        }
-
-        [TestMethod]
-        public void CanReadShouldReturnFalse()
-        {
-            Assert.IsFalse(_target.CanRead);
-        }
-
-        [TestMethod]
-        public void CanSeekShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanSeek);
-        }
-
-        [TestMethod]
-        public void CanWriteShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanWrite);
-        }
-
-        [TestMethod]
-        public void CanTimeoutShouldReturnTrue()
-        {
-            Assert.IsTrue(_target.CanTimeout);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var actual = _target.Position;
-
-            Assert.AreEqual(0L, actual);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldThrowNotSupportedException()
-        {
-            var buffer = new byte[_readBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            try
-            {
-                _ = await _target.ReadAsync(buffer, 0, buffer.Length);
-                Assert.Fail();
-            }
-            catch (NotSupportedException ex)
-            {
-                Assert.IsNull(ex.InnerException);
-            }
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-        }
-
-        [TestMethod]
-        public async Task WriteShouldStartWritingAtBeginningOfFile()
-        {
-            var buffer = new byte[_writeBufferSize];
-
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken)).Returns(Task.CompletedTask);
-
-            await _target.WriteAsync(buffer, 0, buffer.Length);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(1));
-            SftpSessionMock.Verify(p => p.RequestWriteAsync(_handle, 0UL, buffer, 0, buffer.Length, _cancellationToken), Times.Once);
-        }
-
-        [TestMethod]
-        public void RequestOpenOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestOpenAsync(_path, Flags.Write | Flags.Truncate, _cancellationToken), Times.Once);
-        }
-    }
-}

+ 0 - 160
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs

@@ -1,160 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize : SftpFileStreamAsyncTestBase
-    {
-        private string _path;
-        private SftpFileStream _target;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _buffer;
-        private byte[] _serverData1;
-        private byte[] _serverData2;
-        private int _serverData1Length;
-        private int _serverData2Length;
-        private int _numberOfBytesToRead;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-
-            _numberOfBytesToRead = (int)_readBufferSize + 5; // greather than read buffer size
-            _buffer = new byte[_numberOfBytesToRead];
-            _serverData1Length = (int)_readBufferSize; // equal to read buffer size
-            _serverData1 = GenerateRandom(_serverData1Length, random);
-            _serverData2Length = (int)_readBufferSize; // equal to read buffer size
-            _serverData2 = GenerateRandom(_serverData2Length, random);
-
-            Assert.IsTrue(_serverData1Length < _numberOfBytesToRead && _serverData1Length == _readBufferSize);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestOpenAsync(_path, Flags.Read, default))
-                .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, default))
-                .ReturnsAsync(_serverData1);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestReadAsync(_handle, (ulong)_serverData1.Length, _readBufferSize, default))
-                .ReturnsAsync(_serverData2);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override async Task ArrangeAsync()
-        {
-            await base.ArrangeAsync();
-
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize,
-                                         default);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _actual = await _target.ReadAsync(_buffer, 0, _numberOfBytesToRead, default);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveReturnedTheNumberOfBytesRequested()
-        {
-            Assert.AreEqual(_numberOfBytesToRead, _actual);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveWrittenBytesToTheCallerSuppliedBuffer()
-        {
-            Assert.IsTrue(_serverData1.IsEqualTo(_buffer.Take(_serverData1Length)));
-
-            var bytesWrittenFromSecondRead = _numberOfBytesToRead - _serverData1Length;
-            Assert.IsTrue(_serverData2.Take(bytesWrittenFromSecondRead).IsEqualTo(_buffer.Take(_serverData1Length, bytesWrittenFromSecondRead)));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnNumberOfBytesWrittenToCallerProvidedBuffer()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumberOfRemainingBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead;
-
-            _buffer = new byte[numberOfBytesRemainingInReadBuffer];
-
-            var actual = await _target.ReadAsync(_buffer, 0, _buffer.Length);
-
-            Assert.AreEqual(_buffer.Length, actual);
-            Assert.IsTrue(_serverData2.Take(_numberOfBytesToRead - _serverData1Length, _buffer.Length).IsEqualTo(_buffer));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public async Task ReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize, default)).ReturnsAsync(Array.Empty<byte>());
-
-            var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead;
-
-            _buffer = new byte[numberOfBytesRemainingInReadBuffer + 1];
-
-            var actual = await _target.ReadAsync(_buffer, 0, _buffer.Length);
-
-            Assert.AreEqual(numberOfBytesRemainingInReadBuffer, actual);
-            Assert.IsTrue(_serverData2.Take(_numberOfBytesToRead - _serverData1Length, numberOfBytesRemainingInReadBuffer).IsEqualTo(_buffer.Take(numberOfBytesRemainingInReadBuffer)));
-            Assert.AreEqual(0, _buffer[numberOfBytesRemainingInReadBuffer]);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize, default));
-        }
-    }
-}

+ 0 - 153
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs

@@ -1,153 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize : SftpFileStreamAsyncTestBase
-    {
-        private string _path;
-        private SftpFileStream _target;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _buffer;
-        private byte[] _serverData;
-        private int _serverDataLength;
-        private int _numberOfBytesToRead;
-        private byte[] _originalBuffer;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-
-            _numberOfBytesToRead = (int)_readBufferSize + 2; // greater than read buffer size
-            _originalBuffer = GenerateRandom(_numberOfBytesToRead, random);
-            _buffer = _originalBuffer.Copy();
-
-            _serverDataLength = (int)_readBufferSize - 1; // less than read buffer size
-            _serverData = GenerateRandom(_serverDataLength, random);
-
-            Assert.IsTrue(_serverDataLength < _numberOfBytesToRead && _serverDataLength < _readBufferSize);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestOpenAsync(_path, Flags.Read, default))
-                .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, default))
-                .ReturnsAsync(_serverData);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override async Task ArrangeAsync()
-        {
-            await base.ArrangeAsync();
-
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize,
-                                         default);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _actual = await _target.ReadAsync(_buffer, 0, _numberOfBytesToRead, default);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveReturnedTheNumberOfBytesReturnedByTheReadFromTheServer()
-        {
-            Assert.AreEqual(_serverDataLength, _actual);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveWrittenBytesToTheCallerSuppliedBufferAndRemainingBytesShouldRemainUntouched()
-        {
-            Assert.IsTrue(_serverData.IsEqualTo(_buffer.Take(_serverDataLength)));
-            Assert.IsTrue(_originalBuffer.Take(_serverDataLength, _originalBuffer.Length - _serverDataLength).IsEqualTo(_buffer.Take(_serverDataLength, _buffer.Length - _serverDataLength)));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnNumberOfBytesWrittenToCallerProvidedBuffer()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public async Task SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndReturnZeroWhenServerReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestReadAsync(_handle, (ulong)_actual, _readBufferSize, default))
-                .ReturnsAsync(Array.Empty<byte>());
-
-            var buffer = _originalBuffer.Copy();
-            var actual = await _target.ReadAsync(buffer, 0, buffer.Length);
-
-            Assert.AreEqual(0, actual);
-            Assert.IsTrue(_originalBuffer.IsEqualTo(buffer));
-
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, (ulong)_actual, _readBufferSize, default), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public async Task SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndNotUpdatePositionWhenServerReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestReadAsync(_handle, (ulong)_actual, _readBufferSize, default))
-                .ReturnsAsync(Array.Empty<byte>());
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            _ = await _target.ReadAsync(new byte[10], 0, 10);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, (ulong)_actual, _readBufferSize, default), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 144
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs

@@ -1,144 +0,0 @@
-using System;
-using System.IO;
-using System.Threading.Tasks;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_ReadAsync_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount : SftpFileStreamAsyncTestBase
-    {
-        private string _path;
-        private SftpFileStream _target;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _buffer;
-        private byte[] _serverData;
-        private int _numberOfBytesToWriteToReadBuffer;
-        private int _numberOfBytesToRead;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-
-            _numberOfBytesToRead = 20;
-            _buffer = new byte[_numberOfBytesToRead];
-            _numberOfBytesToWriteToReadBuffer = 10; // should be less than _readBufferSize
-            _serverData = GenerateRandom(_numberOfBytesToRead + _numberOfBytesToWriteToReadBuffer, random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestOpenAsync(_path, Flags.Read, default))
-                .ReturnsAsync(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestReadAsync(_handle, 0UL, _readBufferSize, default))
-                .ReturnsAsync(_serverData);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override async Task ArrangeAsync()
-        {
-            await base.ArrangeAsync();
-
-            _target = await SftpFileStream.OpenAsync(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize,
-                                         default);
-        }
-
-        protected override async Task ActAsync()
-        {
-            _actual = await _target.ReadAsync(_buffer, 0, _numberOfBytesToRead, default);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveReturnedTheNumberOfBytesWrittenToCallerSuppliedBuffer()
-        {
-            Assert.AreEqual(_numberOfBytesToRead, _actual);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveWrittenBytesToTheCallerSuppliedBuffer()
-        {
-            Assert.IsTrue(_serverData.Take(_actual).IsEqualTo(_buffer));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnNumberOfBytesWrittenToCallerProvidedBuffer()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public async Task SubsequentReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumberOfRemainingBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var buffer = new byte[_numberOfBytesToWriteToReadBuffer];
-
-            var actual = await _target.ReadAsync(buffer, 0, _numberOfBytesToWriteToReadBuffer, default);
-
-            Assert.AreEqual(_numberOfBytesToWriteToReadBuffer, actual);
-            Assert.IsTrue(_serverData.Take(_numberOfBytesToRead, _numberOfBytesToWriteToReadBuffer).IsEqualTo(buffer));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public async Task SubsequentReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, (ulong)(_serverData.Length), _readBufferSize, default)).ReturnsAsync(Array.Empty<byte>());
-
-            var buffer = new byte[_numberOfBytesToWriteToReadBuffer + 1];
-
-            var actual = await _target.ReadAsync(buffer, 0, buffer.Length);
-
-            Assert.AreEqual(_numberOfBytesToWriteToReadBuffer, actual);
-            Assert.IsTrue(_serverData.Take(_numberOfBytesToRead, _numberOfBytesToWriteToReadBuffer).IsEqualTo(buffer.Take(_numberOfBytesToWriteToReadBuffer)));
-            Assert.AreEqual(0, buffer[_numberOfBytesToWriteToReadBuffer]);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-            SftpSessionMock.Verify(p => p.RequestReadAsync(_handle, (ulong)(_serverData.Length), _readBufferSize, default));
-        }
-    }
-}

+ 0 - 88
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadByte_ReadMode_NoDataInWriteBufferAndNoDataInReadBuffer_Eof.cs

@@ -1,88 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_ReadByte_ReadMode_NoDataInWriteBufferAndNoDataInReadBuffer_Eof : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(1, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(1, 1000);
-            _writeBufferSize = (uint)random.Next(1, 1000);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(new byte[0]);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.ReadByte();
-        }
-
-        [TestMethod]
-        public void ReadByteShouldReturnMinusOne()
-        {
-            Assert.AreEqual(-1, _actual);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(0L, _target.Position);
-        }
-    }
-}

+ 0 - 93
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_ReadByte_ReadMode_NoDataInWriteBufferAndNoDataInReadBuffer_LessDataThanReadBufferSizeAvailable.cs

@@ -1,93 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    /// <summary>
-    /// Test for issue #173.
-    /// </summary>
-    [TestClass]
-    public class SftpFileStreamTest_ReadByte_ReadMode_NoDataInWriteBufferAndNoDataInReadBuffer_LessDataThanReadBufferSizeAvailable : SftpFileStreamTestBase
-    {
-        private SftpFileStream _target;
-        private string _path;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _data;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(5, 1000);
-            _readBufferSize = (uint)random.Next(10, 100);
-            _writeBufferSize = (uint)random.Next(10, 100);
-            _data = GenerateRandom((int)_readBufferSize - 2, random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(_data);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.ReadByte();
-        }
-
-        [TestMethod]
-        public void ReadByteShouldReturnFirstByteThatWasReadFromServer()
-        {
-            Assert.AreEqual(_data[0], _actual);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnOne()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(1L, _target.Position);
-        }
-    }
-}

+ 0 - 158
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize.cs

@@ -1,158 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndEqualToBufferSize : SftpFileStreamTestBase
-    {
-        private string _path;
-        private SftpFileStream _target;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _buffer;
-        private byte[] _serverData1;
-        private byte[] _serverData2;
-        private int _serverData1Length;
-        private int _serverData2Length;
-        private int _numberOfBytesToRead;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-
-            _numberOfBytesToRead = (int)_readBufferSize + 5; // greather than read buffer size
-            _buffer = new byte[_numberOfBytesToRead];
-            _serverData1Length = (int)_readBufferSize; // equal to read buffer size
-            _serverData1 = GenerateRandom(_serverData1Length, random);
-            _serverData2Length = (int)_readBufferSize; // equal to read buffer size
-            _serverData2 = GenerateRandom(_serverData2Length, random);
-
-            Assert.IsTrue(_serverData1Length < _numberOfBytesToRead && _serverData1Length == _readBufferSize);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(_serverData1);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestRead(_handle, (ulong)_serverData1.Length, _readBufferSize))
-                .Returns(_serverData2);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Read(_buffer, 0, _numberOfBytesToRead);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveReturnedTheNumberOfBytesRequested()
-        {
-            Assert.AreEqual(_numberOfBytesToRead, _actual);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveWrittenBytesToTheCallerSuppliedBuffer()
-        {
-            Assert.IsTrue(_serverData1.IsEqualTo(_buffer.Take(_serverData1Length)));
-
-            var bytesWrittenFromSecondRead = _numberOfBytesToRead - _serverData1Length;
-            Assert.IsTrue(_serverData2.Take(bytesWrittenFromSecondRead).IsEqualTo(_buffer.Take(_serverData1Length, bytesWrittenFromSecondRead)));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnNumberOfBytesWrittenToCallerProvidedBuffer()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void ReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumberOfRemainingBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead;
-
-            _buffer = new byte[numberOfBytesRemainingInReadBuffer];
-
-            var actual = _target.Read(_buffer, 0, _buffer.Length);
-
-            Assert.AreEqual(_buffer.Length, actual);
-            Assert.IsTrue(_serverData2.Take(_numberOfBytesToRead - _serverData1Length, _buffer.Length).IsEqualTo(_buffer));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void ReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize)).Returns(Array.Empty<byte>());
-
-            var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead;
-
-            _buffer = new byte[numberOfBytesRemainingInReadBuffer + 1];
-
-            var actual = _target.Read(_buffer, 0, _buffer.Length);
-
-            Assert.AreEqual(numberOfBytesRemainingInReadBuffer, actual);
-            Assert.IsTrue(_serverData2.Take(_numberOfBytesToRead - _serverData1Length, numberOfBytesRemainingInReadBuffer).IsEqualTo(_buffer.Take(numberOfBytesRemainingInReadBuffer)));
-            Assert.AreEqual(0, _buffer[numberOfBytesRemainingInReadBuffer]);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize));
-        }
-    }
-}

+ 0 - 151
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize.cs

@@ -1,151 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Tests.Common;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadLessBytesFromServerThanCountAndLessThanBufferSize : SftpFileStreamTestBase
-    {
-        private string _path;
-        private SftpFileStream _target;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _buffer;
-        private byte[] _serverData;
-        private int _serverDataLength;
-        private int _numberOfBytesToRead;
-        private byte[] _originalBuffer;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-
-            _numberOfBytesToRead = (int)_readBufferSize + 2; // greater than read buffer size
-            _originalBuffer = GenerateRandom(_numberOfBytesToRead, random);
-            _buffer = _originalBuffer.Copy();
-
-            _serverDataLength = (int)_readBufferSize - 1; // less than read buffer size
-            _serverData = GenerateRandom(_serverDataLength, random);
-
-            Assert.IsTrue(_serverDataLength < _numberOfBytesToRead && _serverDataLength < _readBufferSize);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(_serverData);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Read(_buffer, 0, _numberOfBytesToRead);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveReturnedTheNumberOfBytesReturnedByTheReadFromTheServer()
-        {
-            Assert.AreEqual(_serverDataLength, _actual);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveWrittenBytesToTheCallerSuppliedBufferAndRemainingBytesShouldRemainUntouched()
-        {
-            Assert.IsTrue(_serverData.IsEqualTo(_buffer.Take(_serverDataLength)));
-            Assert.IsTrue(_originalBuffer.Take(_serverDataLength, _originalBuffer.Length - _serverDataLength).IsEqualTo(_buffer.Take(_serverDataLength, _buffer.Length - _serverDataLength)));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnNumberOfBytesWrittenToCallerProvidedBuffer()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndReturnZeroWhenServerReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize))
-                .Returns(Array.Empty<byte>());
-
-            var buffer = _originalBuffer.Copy();
-            var actual = _target.Read(buffer, 0, buffer.Length);
-
-            Assert.AreEqual(0, actual);
-            Assert.IsTrue(_originalBuffer.IsEqualTo(buffer));
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndNotUpdatePositionWhenServerReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize))
-                .Returns(Array.Empty<byte>());
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            _ = _target.Read(new byte[10], 0, 10);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize), Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 142
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount.cs

@@ -1,142 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Read_ReadMode_NoDataInReaderBufferAndReadMoreBytesFromServerThanCount : SftpFileStreamTestBase
-    {
-        private string _path;
-        private SftpFileStream _target;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _actual;
-        private byte[] _buffer;
-        private byte[] _serverData;
-        private int _numberOfBytesToWriteToReadBuffer;
-        private int _numberOfBytesToRead;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            var random = new Random();
-            _path = random.Next().ToString();
-            _handle = GenerateRandom(5, random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = 500;
-
-            _numberOfBytesToRead = 20;
-            _buffer = new byte[_numberOfBytesToRead];
-            _numberOfBytesToWriteToReadBuffer = 10; // should be less than _readBufferSize
-            _serverData = GenerateRandom(_numberOfBytesToRead + _numberOfBytesToWriteToReadBuffer, random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestOpen(_path, Flags.Read, false))
-                .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                .Returns(_serverData);
-        }
-
-        [TestCleanup]
-        public void TearDown()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestClose(_handle));
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object,
-                                         _path,
-                                         FileMode.Open,
-                                         FileAccess.Read,
-                                         (int)_bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Read(_buffer, 0, _numberOfBytesToRead);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveReturnedTheNumberOfBytesWrittenToCallerSuppliedBuffer()
-        {
-            Assert.AreEqual(_numberOfBytesToRead, _actual);
-        }
-
-        [TestMethod]
-        public void ReadShouldHaveWrittenBytesToTheCallerSuppliedBuffer()
-        {
-            Assert.IsTrue(_serverData.Take(_actual).IsEqualTo(_buffer));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnNumberOfBytesWrittenToCallerProvidedBuffer()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_actual, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void SubsequentReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumberOfRemainingBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            var buffer = new byte[_numberOfBytesToWriteToReadBuffer];
-
-            var actual = _target.Read(buffer, 0, _numberOfBytesToWriteToReadBuffer);
-
-            Assert.AreEqual(_numberOfBytesToWriteToReadBuffer, actual);
-            Assert.IsTrue(_serverData.Take(_numberOfBytesToRead, _numberOfBytesToWriteToReadBuffer).IsEqualTo(buffer));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void SubsequentReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData.Length), _readBufferSize)).Returns(Array.Empty<byte>());
-
-            var buffer = new byte[_numberOfBytesToWriteToReadBuffer + 1];
-
-            var actual = _target.Read(buffer, 0, buffer.Length);
-
-            Assert.AreEqual(_numberOfBytesToWriteToReadBuffer, actual);
-            Assert.IsTrue(_serverData.Take(_numberOfBytesToRead, _numberOfBytesToWriteToReadBuffer).IsEqualTo(buffer.Take(_numberOfBytesToWriteToReadBuffer)));
-            Assert.AreEqual(0, buffer[_numberOfBytesToWriteToReadBuffer]);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, (ulong)(_serverData.Length), _readBufferSize));
-        }
-    }
-}

+ 0 - 100
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetNegative.cs

@@ -1,100 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetNegative : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private int _offset;
-        private EndOfStreamException _actualException;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _offset = _random.Next(int.MinValue, -1);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-        }
-
-        protected override void Act()
-        {
-            try
-            {
-                _target.Seek(_offset, SeekOrigin.Begin);
-                Assert.Fail();
-            }
-            catch (EndOfStreamException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveThrownEndOfStreamException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual("Attempted to read past the end of the stream.", _actualException.Message);
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(0L, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-    }
-}

+ 0 - 90
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetPositive.cs

@@ -1,90 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetPositive : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private int _offset;
-        private long _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _offset = _random.Next(1, int.MaxValue);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(_offset, SeekOrigin.Begin);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedOffset()
-        {
-            Assert.AreEqual(_offset, _actual);
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnOffset()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_offset, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-    }
-}

+ 0 - 88
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetZero.cs

@@ -1,88 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginBeginAndOffsetZero : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private long _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(0L, SeekOrigin.Begin);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedZero()
-        {
-            Assert.AreEqual(0L, _actual);
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Once);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(0L, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-    }
-}

+ 0 - 106
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetNegative.cs

@@ -1,106 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetNegative : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _length;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private int _offset;
-        private SftpFileAttributes _attributes;
-        private long _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _length = _random.Next(5, 10000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _offset = _random.Next(-_length, -1);
-            _attributes = SftpFileAttributes.Empty;
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestOpen(_path, Flags.Write | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFStat(_handle, false))
-                           .Returns(_attributes);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFSetStat(_handle, _attributes));
-            SftpSessionMock.InSequence(MockSequence).Setup(session => session.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFStat(_handle, false))
-                           .Returns(_attributes);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-            _target.SetLength(_length);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(_offset, SeekOrigin.End);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedOffset()
-        {
-            Assert.AreEqual(_attributes.Size + _offset, _actual);
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedTwice()
-        {
-            SftpSessionMock.Verify(session => session.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnOffset()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(session => session.IsOpen).Returns(true);
-
-            Assert.AreEqual(_attributes.Size + _offset, _target.Position);
-
-            SftpSessionMock.Verify(session => session.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 106
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetPositive.cs

@@ -1,106 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetPositive : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _length;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private int _offset;
-        private SftpFileAttributes _attributes;
-        private long _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _length = _random.Next(5, 10000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _offset = _random.Next(1, int.MaxValue);
-            _attributes = SftpFileAttributes.Empty;
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestOpen(_path, Flags.Write | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFStat(_handle, false))
-                           .Returns(_attributes);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFSetStat(_handle, _attributes));
-            SftpSessionMock.InSequence(MockSequence).Setup(session => session.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFStat(_handle, false))
-                           .Returns(_attributes);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-            _target.SetLength(_length);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(_offset, SeekOrigin.End);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedOffset()
-        {
-            Assert.AreEqual(_attributes.Size + _offset, _actual);
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedTwice()
-        {
-            SftpSessionMock.Verify(session => session.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnOffset()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(session => session.IsOpen).Returns(true);
-
-            Assert.AreEqual(_attributes.Size + _offset, _target.Position);
-
-            SftpSessionMock.Verify(session => session.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 106
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetZero.cs

@@ -1,106 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtBeginningOfStream_OriginEndAndOffsetZero : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private int _length;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private int _offset;
-        private SftpFileAttributes _attributes;
-        private long _actual;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Write;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = (uint)_random.Next(5, 1000);
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _length = _random.Next(5, 10000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _offset = 0;
-            _attributes = SftpFileAttributes.Empty;
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestOpen(_path, Flags.Write | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFStat(_handle, false))
-                           .Returns(_attributes);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFSetStat(_handle, _attributes));
-            SftpSessionMock.InSequence(MockSequence).Setup(session => session.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(session => session.RequestFStat(_handle, false))
-                           .Returns(_attributes);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-            _target.SetLength(_length);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(_offset, SeekOrigin.End);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedSize()
-        {
-            Assert.AreEqual(_attributes.Size, _actual);
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedTwice()
-        {
-            SftpSessionMock.Verify(session => session.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSize()
-        {
-            SftpSessionMock.InSequence(MockSequence).Setup(session => session.IsOpen).Returns(true);
-
-            Assert.AreEqual(_attributes.Size, _target.Position);
-
-            SftpSessionMock.Verify(session => session.IsOpen, Times.Exactly(3));
-        }
-    }
-}

+ 0 - 125
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_NoBuffering.cs

@@ -1,125 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_NoBuffering : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private long _actual;
-        private byte[] _buffer;
-        private byte[] _serverData;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _buffer = new byte[_readBufferSize];
-            _serverData = GenerateRandom(_buffer.Length, _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(_serverData);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-            int readBytesCount = _target.Read(_buffer, 0, _buffer.Length);
-            Assert.AreEqual(_buffer.Length, readBytesCount);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(0L, SeekOrigin.Begin);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedZero()
-        {
-            Assert.AreEqual(0L, _actual);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-
-            Assert.AreEqual(0L, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedTwice()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void ReadShouldReturnReadBytesFromServer()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(new byte[] { 0x05, 0x04 });
-
-            var buffer = new byte[1];
-
-            var bytesRead = _target.Read(buffer, 0, buffer.Length);
-
-            Assert.AreEqual(buffer.Length, bytesRead);
-            Assert.AreEqual(0x05, buffer[0]);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Exactly(2));
-        }
-    }
-}

+ 0 - 143
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer.cs

@@ -1,143 +0,0 @@
-using System;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_Seek_PositionedAtMiddleOfStream_OriginBeginAndOffsetZero_ReadBuffer : SftpFileStreamTestBase
-    {
-        private Random _random;
-        private string _path;
-        private FileMode _fileMode;
-        private FileAccess _fileAccess;
-        private int _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private byte[] _handle;
-        private SftpFileStream _target;
-        private long _actual;
-        private byte[] _buffer;
-        private byte[] _serverData1;
-        private byte[] _serverData2;
-
-        protected override void SetupData()
-        {
-            base.SetupData();
-
-            _random = new Random();
-            _path = _random.Next().ToString();
-            _fileMode = FileMode.OpenOrCreate;
-            _fileAccess = FileAccess.Read;
-            _bufferSize = _random.Next(5, 1000);
-            _readBufferSize = 20;
-            _writeBufferSize = (uint)_random.Next(5, 1000);
-            _handle = GenerateRandom(_random.Next(1, 10), _random);
-            _buffer = new byte[2]; // should be less than size of read buffer
-            _serverData1 = GenerateRandom((int)_readBufferSize, _random);
-            _serverData2 = GenerateRandom((int)_readBufferSize, _random);
-        }
-
-        protected override void SetupMocks()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.CreateNewOrOpen, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalReadLength((uint)_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.CalculateOptimalWriteLength((uint)_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(_serverData1);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _target = new SftpFileStream(SftpSessionMock.Object, _path, _fileMode, _fileAccess, _bufferSize);
-            int readBytesCount = _target.Read(_buffer, 0, _buffer.Length);
-            Assert.AreEqual(_buffer.Length, readBytesCount);
-        }
-
-        protected override void Act()
-        {
-            _actual = _target.Seek(0L, SeekOrigin.Begin);
-        }
-
-        [TestMethod]
-        public void SeekShouldHaveReturnedZero()
-        {
-            Assert.AreEqual(0L, _actual);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnZero()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-
-            Assert.AreEqual(0L, _target.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-        }
-
-        [TestMethod]
-        public void IsOpenOnSftpSessionShouldHaveBeenInvokedTwice()
-        {
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void ReadBytesThatWereNotBufferedBeforeSeekShouldReadBytesFromServer()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(_serverData2);
-
-            var bytesRead = _target.Read(_buffer, 0, _buffer.Length);
-
-            Assert.AreEqual(_buffer.Length, bytesRead);
-            Assert.IsTrue(_serverData2.Take(_buffer.Length).IsEqualTo(_buffer));
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(3));
-            SftpSessionMock.Verify(p => p.RequestRead(_handle, 0UL, _readBufferSize), Times.Exactly(2));
-        }
-
-        [TestMethod]
-        public void ReadBytesThatWereBufferedBeforeSeekShouldReadBytesFromServer()
-        {
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(MockSequence)
-                           .Setup(p => p.RequestRead(_handle, 0UL, _readBufferSize))
-                           .Returns(_serverData2);
-
-            var buffer = new byte[_buffer.Length + 1]; // we read one byte that was previously buffered
-            var bytesRead = _target.Read(buffer, 0, buffer.Length);
-
-            Assert.AreEqual(buffer.Length, bytesRead);
-            Assert.IsTrue(_serverData2.Take(buffer.Length).IsEqualTo(buffer));
-        }
-    }
-}

+ 0 - 90
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_Closed.cs

@@ -1,90 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Sftp;
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    [TestClass]
-    public class SftpFileStreamTest_SetLength_Closed
-    {
-        private Mock<ISftpSession> _sftpSessionMock;
-        private string _path;
-        private SftpFileStream _sftpFileStream;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private ObjectDisposedException _actualException;
-
-        [TestInitialize]
-        public void Setup()
-        {
-            Arrange();
-            Act();
-        }
-
-        protected void Arrange()
-        {
-            var random = new Random();
-            _path = random.Next().ToString(CultureInfo.InvariantCulture);
-            _handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBufferSize = (uint)random.Next(0, 1000);
-            _writeBufferSize = (uint)random.Next(0, 1000);
-
-            _sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
-
-            var sequence = new MockSequence();
-            _sftpSessionMock.InSequence(sequence)
-                .Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
-                .Returns(_handle);
-            _sftpSessionMock.InSequence(sequence)
-                .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                .Returns(_readBufferSize);
-            _sftpSessionMock.InSequence(sequence)
-                .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                .Returns(_writeBufferSize);
-            _sftpSessionMock.InSequence(sequence)
-                .Setup(p => p.IsOpen)
-                .Returns(true);
-            _sftpSessionMock.InSequence(sequence)
-                .Setup(p => p.RequestClose(_handle));
-
-            _sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize);
-            _sftpFileStream.Close();
-        }
-
-        protected void Act()
-        {
-            try
-            {
-                _sftpFileStream.SetLength(5);
-                Assert.Fail();
-            }
-            catch (ObjectDisposedException ex)
-            {
-                _actualException = ex;
-            }
-        }
-
-        [TestMethod]
-        public void SetLengthShouldHaveThrownObjectDisposedException()
-        {
-            Assert.IsNotNull(_actualException);
-            Assert.IsNull(_actualException.InnerException);
-            Assert.AreEqual(
-                string.Format(
-                    "Cannot access a disposed object.{0}Object name: '{1}'.",
-                    Environment.NewLine,
-                    _actualException.ObjectName),
-                _actualException.Message);
-            Assert.AreEqual(typeof(SftpFileStream).FullName, _actualException.ObjectName);
-        }
-    }
-}

+ 0 - 209
test/Renci.SshNet.Tests/Classes/Sftp/SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition.cs

@@ -1,209 +0,0 @@
-using System;
-using System.Globalization;
-using System.IO;
-using System.Threading;
-
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-using Moq;
-
-using Renci.SshNet.Common;
-using Renci.SshNet.Sftp;
-using Renci.SshNet.Sftp.Responses;
-using Renci.SshNet.Tests.Common;
-
-
-namespace Renci.SshNet.Tests.Classes.Sftp
-{
-    /// <summary>
-    /// - In read mode
-    /// - Bytes read from (read) buffer
-    /// - New length greater than client position and greater than server position
-    /// </summary>
-    [TestClass]
-    public class SftpFileStreamTest_SetLength_DataInReadBuffer_NewLengthGreatherThanPosition : SftpFileStreamTestBase
-    {
-        private string _path;
-        private SftpFileStream _sftpFileStream;
-        private byte[] _handle;
-        private uint _bufferSize;
-        private uint _readBufferSize;
-        private uint _writeBufferSize;
-        private MockSequence _sequence;
-        private long _length;
-
-        private SftpFileAttributes _fileAttributes;
-        private SftpFileAttributes _originalFileAttributes;
-        private SftpFileAttributes _newFileAttributes;
-        private byte[] _readBytes1;
-        private byte[] _readBytes2;
-        private byte[] _actualReadBytes;
-
-        protected override void SetupData()
-        {
-            var random = new Random();
-
-            _path = random.Next().ToString(CultureInfo.InvariantCulture);
-            _handle = GenerateRandom(random.Next(2, 6), random);
-            _bufferSize = (uint)random.Next(1, 1000);
-            _readBytes1 = new byte[5];
-            _readBytes2 = new byte[random.Next(1, 3)];
-            _actualReadBytes = GenerateRandom(_readBytes1.Length + _readBytes2.Length + 2, random); // server returns more bytes than the caller requested
-            _readBufferSize = (uint)random.Next(_actualReadBytes.Length, _actualReadBytes.Length * 2);
-            _writeBufferSize = (uint)random.Next(100, 1000);
-            _length = _readBytes1.Length + _readBytes2.Length + 5;
-
-            _fileAttributes = new SftpFileAttributesBuilder().WithExtension("X", "ABC")
-                                                             .WithExtension("V", "VValue")
-                                                             .WithGroupId(random.Next())
-                                                             .WithLastAccessTime(DateTime.UtcNow.AddSeconds(random.Next()))
-                                                             .WithLastWriteTime(DateTime.UtcNow.AddSeconds(random.Next()))
-                                                             .WithPermissions((uint)random.Next())
-                                                             .WithSize(_length + 100)
-                                                             .WithUserId(random.Next())
-                                                             .Build();
-            _originalFileAttributes = _fileAttributes.Clone();
-            _newFileAttributes = null;
-        }
-
-        protected override void SetupMocks()
-        {
-            _sequence = new MockSequence();
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.RequestOpen(_path, Flags.Read | Flags.Write, false))
-                           .Returns(_handle);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.CalculateOptimalReadLength(_bufferSize))
-                           .Returns(_readBufferSize);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
-                           .Returns(_writeBufferSize);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.RequestRead(_handle, 0, _readBufferSize))
-                           .Returns(_actualReadBytes);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.IsOpen)
-                           .Returns(true);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.RequestFStat(_handle, false))
-                           .Returns(_fileAttributes);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.RequestFSetStat(_handle, _fileAttributes))
-                           .Callback<byte[], SftpFileAttributes>((bytes, attributes) => _newFileAttributes = attributes.Clone());
-        }
-
-        protected override void Arrange()
-        {
-            base.Arrange();
-
-            _sftpFileStream = new SftpFileStream(SftpSessionMock.Object,
-                                                 _path,
-                                                 FileMode.Open,
-                                                 FileAccess.ReadWrite,
-                                                 (int)_bufferSize);
-            int readBytesCount1 = _sftpFileStream.Read(_readBytes1, 0, _readBytes1.Length);
-            Assert.AreEqual(_readBytes1.Length, readBytesCount1);
-            int readBytesCount2 = _sftpFileStream.Read(_readBytes2, 0, _readBytes2.Length); // this will return bytes from the buffer
-            Assert.AreEqual(_readBytes2.Length, readBytesCount2);
-        }
-
-        protected override void Act()
-        {
-            _sftpFileStream.SetLength(_length);
-        }
-
-        [TestMethod]
-        public void PositionShouldReturnSamePositionAsBeforeSetLength()
-        {
-            SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true);
-
-            Assert.AreEqual(_readBytes1.Length + _readBytes2.Length, _sftpFileStream.Position);
-
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
-        }
-
-        [TestMethod]
-        public void RequestFSetStatOnSftpSessionShouldBeInvokedOnce()
-        {
-            SftpSessionMock.Verify(p => p.RequestFSetStat(_handle, _fileAttributes), Times.Once);
-        }
-
-        [TestMethod]
-        public void SizeOfSftpFileAttributesShouldBeModifiedToNewLengthBeforePassedToRequestFSetStat()
-        {
-            DictionaryAssert.AreEqual(_originalFileAttributes.Extensions, _newFileAttributes.Extensions);
-            Assert.AreEqual(_originalFileAttributes.GroupId, _newFileAttributes.GroupId);
-            Assert.AreEqual(_originalFileAttributes.LastAccessTime, _newFileAttributes.LastAccessTime);
-            Assert.AreEqual(_originalFileAttributes.LastWriteTime, _newFileAttributes.LastWriteTime);
-            Assert.AreEqual(_originalFileAttributes.Permissions, _newFileAttributes.Permissions);
-            Assert.AreEqual(_originalFileAttributes.UserId, _newFileAttributes.UserId);
-
-            Assert.AreEqual(_length, _newFileAttributes.Size);
-        }
-
-        [TestMethod]
-        public void ReadShouldReadStartFromSamePositionAsBeforeSetLength()
-        {
-            SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.RequestRead(_handle,
-                                                     (uint)(_readBytes1.Length + _readBytes2.Length),
-                                                     _readBufferSize))
-                           .Returns(new byte[] { 0x0f });
-
-            var byteRead = _sftpFileStream.ReadByte();
-
-            Assert.AreEqual(0x0f, byteRead);
-
-            SftpSessionMock.Verify(p => p.RequestRead(_handle,
-                                                      (uint)(_readBytes1.Length + _readBytes2.Length),
-                                                      _readBufferSize),
-                                   Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
-        }
-
-        [TestMethod]
-        public void WriteShouldStartFromSamePositionAsBeforeSetLength()
-        {
-            var bytesToWrite = GenerateRandom(_writeBufferSize);
-            byte[] bytesWritten = null;
-
-            SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true);
-            SftpSessionMock.InSequence(_sequence)
-                           .Setup(p => p.RequestWrite(_handle,
-                                                      (uint)(_readBytes1.Length + _readBytes2.Length),
-                                                      It.IsAny<byte[]>(),
-                                                      0,
-                                                      bytesToWrite.Length,
-                                                      It.IsAny<AutoResetEvent>(),
-                                                      null))
-                           .Callback<byte[], ulong, byte[], int, int, AutoResetEvent, Action<SftpStatusResponse>>(
-                               (handle, serverOffset, data, offset, length, wait, writeCompleted) =>
-                               {
-                                   bytesWritten = data.Take(offset, length);
-                                   wait.Set();
-                               });
-
-            _sftpFileStream.Write(bytesToWrite, 0, bytesToWrite.Length);
-
-            Assert.IsNotNull(bytesWritten);
-            CollectionAssert.AreEqual(bytesToWrite, bytesWritten);
-
-            SftpSessionMock.Verify(p => p.RequestWrite(_handle,
-                                                       (uint)(_readBytes1.Length + _readBytes2.Length),
-                                                       It.IsAny<byte[]>(),
-                                                       0,
-                                                       bytesToWrite.Length,
-                                                       It.IsAny<AutoResetEvent>(),
-                                                       null),
-                                   Times.Once);
-            SftpSessionMock.Verify(p => p.IsOpen, Times.Exactly(4));
-        }
-    }
-}

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác