1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
2
using System . Text ;
5
3
using System . Threading . Tasks ;
6
4
using Xunit ;
7
5
using Amazon . S3 ;
8
-
9
- using Amazon . DNXCore . IntegrationTests ;
10
6
using Amazon . S3 . Model ;
11
7
using System . Net ;
12
8
using System . Threading ;
13
9
using System . IO ;
10
+ using Amazon . S3 . Util ;
14
11
15
12
namespace Amazon . DNXCore . IntegrationTests . S3
16
13
{
17
14
/// <summary>
18
15
/// Summary description for PutObjectTest
19
16
/// </summary>
20
-
17
+
21
18
public class PutObjectTest : TestBase < AmazonS3Client >
22
19
{
23
20
public static readonly long MEG_SIZE = ( int ) Math . Pow ( 2 , 20 ) ;
@@ -34,7 +31,7 @@ public PutObjectTest()
34
31
File . WriteAllText ( filePath , "This is some sample text.!!" ) ;
35
32
bucketName = UtilityMethods . CreateBucketAsync ( Client , "PutObjectTest" , true ) . Result ;
36
33
}
37
-
34
+
38
35
protected override void Dispose ( bool disposing )
39
36
{
40
37
UtilityMethods . DeleteBucketWithObjectsAsync ( Client , bucketName ) . Wait ( ) ;
@@ -43,7 +40,7 @@ protected override void Dispose(bool disposing)
43
40
{
44
41
File . Delete ( filePath ) ;
45
42
}
46
-
43
+
47
44
base . Dispose ( disposing ) ;
48
45
}
49
46
@@ -130,8 +127,8 @@ public async Task SimplePathPutObjectTest(bool useChunkEncoding)
130
127
131
128
Console . WriteLine ( "S3 generated ETag: {0}" , response . ETag ) ;
132
129
Assert . True ( response . ETag . Length > 0 ) ;
133
- }
134
-
130
+ }
131
+
135
132
[ Theory ]
136
133
[ InlineData ( true ) ]
137
134
[ InlineData ( false ) ]
@@ -189,6 +186,48 @@ public async Task PutObjectWithoutContentEncoding(bool useChunkEncoding)
189
186
Assert . Null ( headers . ContentEncoding ) ;
190
187
}
191
188
189
+ /// <summary>
190
+ /// Reported in https://github.com/aws/aws-sdk-net/issues/3629
191
+ /// </summary>
192
+ [ Fact ]
193
+ public async Task TestResetStreamPosition ( )
194
+ {
195
+ var memoryStream = new MemoryStream ( ) ;
196
+ long offset ;
197
+
198
+ using ( var writer = new StreamWriter ( memoryStream , Encoding . UTF8 , 1024 , leaveOpen : true ) )
199
+ {
200
+ writer . AutoFlush = true ;
201
+ await writer . WriteAsync ( "Hello" ) ;
202
+ offset = memoryStream . Position ;
203
+ await writer . WriteAsync ( "World" ) ;
204
+ await writer . FlushAsync ( ) ;
205
+ }
206
+
207
+ memoryStream . Seek ( offset , SeekOrigin . Begin ) ;
208
+
209
+ var putRequest = new PutObjectRequest
210
+ {
211
+ CannedACL = S3CannedACL . NoACL ,
212
+ BucketName = bucketName ,
213
+ Key = "test-file.txt" ,
214
+ AutoResetStreamPosition = false ,
215
+ AutoCloseStream = ! memoryStream . CanSeek ,
216
+ InputStream = memoryStream . CanSeek ? memoryStream : AmazonS3Util . MakeStreamSeekable ( memoryStream ) ,
217
+ UseChunkEncoding = false ,
218
+ } ;
219
+
220
+ var putResponse = await Client . PutObjectAsync ( putRequest ) ;
221
+ Assert . True ( putResponse . HttpStatusCode == HttpStatusCode . OK ) ;
222
+
223
+ var getResponse = await Client . GetObjectAsync ( bucketName , "test-file.txt" ) ;
224
+ using ( var reader = new StreamReader ( getResponse . ResponseStream ) )
225
+ {
226
+ var content = await reader . ReadToEndAsync ( ) ;
227
+ Assert . Equal ( "World" , content ) ;
228
+ }
229
+ }
230
+
192
231
private async Task < HeadersCollection > TestPutAndGet ( PutObjectRequest request )
193
232
{
194
233
await Client . PutObjectAsync ( request ) ;
0 commit comments