@@ -43,11 +43,11 @@ protected override void SetupData()
43
43
_path = random . Next ( ) . ToString ( CultureInfo . InvariantCulture ) ;
44
44
_handle = GenerateRandom ( random . Next ( 2 , 6 ) , random ) ;
45
45
_bufferSize = ( uint ) random . Next ( 1 , 1000 ) ;
46
- _readBufferSize = ( uint ) random . Next ( 1 , 1000 ) ;
47
- _writeBufferSize = ( uint ) random . Next ( 100 , 1000 ) ;
48
46
_readBytes1 = new byte [ 5 ] ;
49
47
_readBytes2 = new byte [ random . Next ( 1 , 3 ) ] ;
50
48
_actualReadBytes = GenerateRandom ( _readBytes1 . Length + _readBytes2 . Length + 2 , random ) ; // server returns more bytes than the caller requested
49
+ _readBufferSize = ( uint ) random . Next ( _actualReadBytes . Length , _actualReadBytes . Length * 2 ) ;
50
+ _writeBufferSize = ( uint ) random . Next ( 100 , 1000 ) ;
51
51
_length = _readBytes1 . Length + _readBytes2 . Length + 5 ;
52
52
53
53
_fileAttributes = new SftpFileAttributesBuilder ( ) . WithExtension ( "X" , "ABC" )
@@ -99,7 +99,11 @@ protected override void Arrange()
99
99
{
100
100
base . Arrange ( ) ;
101
101
102
- _sftpFileStream = new SftpFileStream ( SftpSessionMock . Object , _path , FileMode . Open , FileAccess . ReadWrite , ( int ) _bufferSize ) ;
102
+ _sftpFileStream = new SftpFileStream ( SftpSessionMock . Object ,
103
+ _path ,
104
+ FileMode . Open ,
105
+ FileAccess . ReadWrite ,
106
+ ( int ) _bufferSize ) ;
103
107
_sftpFileStream . Read ( _readBytes1 , 0 , _readBytes1 . Length ) ;
104
108
_sftpFileStream . Read ( _readBytes2 , 0 , _readBytes2 . Length ) ; // this will return bytes from the buffer
105
109
}
@@ -143,14 +147,19 @@ public void ReadShouldReadStartFromSamePositionAsBeforeSetLength()
143
147
{
144
148
SftpSessionMock . InSequence ( _sequence ) . Setup ( p => p . IsOpen ) . Returns ( true ) ;
145
149
SftpSessionMock . InSequence ( _sequence )
146
- . Setup ( p => p . RequestRead ( _handle , ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) , _readBufferSize ) )
147
- . Returns ( new byte [ ] { 0x0f } ) ;
150
+ . Setup ( p => p . RequestRead ( _handle ,
151
+ ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) ,
152
+ _readBufferSize ) )
153
+ . Returns ( new byte [ ] { 0x0f } ) ;
148
154
149
155
var byteRead = _sftpFileStream . ReadByte ( ) ;
150
156
151
157
Assert . AreEqual ( 0x0f , byteRead ) ;
152
158
153
- SftpSessionMock . Verify ( p => p . RequestRead ( _handle , ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) , _readBufferSize ) , Times . Once ) ;
159
+ SftpSessionMock . Verify ( p => p . RequestRead ( _handle ,
160
+ ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) ,
161
+ _readBufferSize ) ,
162
+ Times . Once ) ;
154
163
SftpSessionMock . Verify ( p => p . IsOpen , Times . Exactly ( 4 ) ) ;
155
164
}
156
165
@@ -162,20 +171,34 @@ public void WriteShouldStartFromSamePositionAsBeforeSetLength()
162
171
163
172
SftpSessionMock . InSequence ( _sequence ) . Setup ( p => p . IsOpen ) . Returns ( true ) ;
164
173
SftpSessionMock . InSequence ( _sequence )
165
- . Setup ( p => p . RequestWrite ( _handle , ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) , It . IsAny < byte [ ] > ( ) , 0 , bytesToWrite . Length , It . IsAny < AutoResetEvent > ( ) , null ) )
166
- . Callback < byte [ ] , ulong , byte [ ] , int , int , AutoResetEvent , Action < SftpStatusResponse > > ( ( handle , serverOffset , data , offset , length , wait , writeCompleted ) =>
167
- {
168
- bytesWritten = data . Take ( offset , length ) ;
169
- wait . Set ( ) ;
170
- } ) ;
174
+ . Setup ( p => p . RequestWrite ( _handle ,
175
+ ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) ,
176
+ It . IsAny < byte [ ] > ( ) ,
177
+ 0 ,
178
+ bytesToWrite . Length ,
179
+ It . IsAny < AutoResetEvent > ( ) ,
180
+ null ) )
181
+ . Callback < byte [ ] , ulong , byte [ ] , int , int , AutoResetEvent , Action < SftpStatusResponse > > (
182
+ ( handle , serverOffset , data , offset , length , wait , writeCompleted ) =>
183
+ {
184
+ bytesWritten = data . Take ( offset , length ) ;
185
+ wait . Set ( ) ;
186
+ } ) ;
171
187
172
188
_sftpFileStream . Write ( bytesToWrite , 0 , bytesToWrite . Length ) ;
173
189
174
190
Assert . IsNotNull ( bytesWritten ) ;
175
191
CollectionAssert . AreEqual ( bytesToWrite , bytesWritten ) ;
176
192
177
- SftpSessionMock . Verify ( p => p . RequestWrite ( _handle , ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) , It . IsAny < byte [ ] > ( ) , 0 , bytesToWrite . Length , It . IsAny < AutoResetEvent > ( ) , null ) , Times . Once ) ;
193
+ SftpSessionMock . Verify ( p => p . RequestWrite ( _handle ,
194
+ ( uint ) ( _readBytes1 . Length + _readBytes2 . Length ) ,
195
+ It . IsAny < byte [ ] > ( ) ,
196
+ 0 ,
197
+ bytesToWrite . Length ,
198
+ It . IsAny < AutoResetEvent > ( ) ,
199
+ null ) ,
200
+ Times . Once ) ;
178
201
SftpSessionMock . Verify ( p => p . IsOpen , Times . Exactly ( 4 ) ) ;
179
202
}
180
203
}
181
- }
204
+ }
0 commit comments