@@ -30,6 +30,8 @@ public class TransferUtilityTests : TestBase<AmazonS3Client>
3030 private static string fullPath ;
3131 private const string testContent = "This is the content body!" ;
3232 private const string testFile = "PutObjectFile.txt" ;
33+ private static string testFilePath ;
34+ private const string testKey = "SimpleUploadProgressTotalBytesTestFile.txt" ;
3335
3436 [ ClassInitialize ( ) ]
3537 public static void ClassInitialize ( TestContext a )
@@ -66,6 +68,7 @@ public static void ClassInitialize(TestContext a)
6668
6769 fullPath = Path . GetFullPath ( testFile ) ;
6870 File . WriteAllText ( fullPath , testContent ) ;
71+ testFilePath = fullPath ; // Use the same file for the TotalBytes test
6972 }
7073
7174 [ ClassCleanup ]
@@ -444,41 +447,36 @@ public void UploadUnSeekableStreamFileSizeEqualToPartBufferSize()
444447 }
445448
446449 [ TestMethod ]
447- [ TestCategory ( "S3" ) ]
448- public void UploadUnseekableStreamFileSizeBetweenMinPartSizeAndPartBufferSize ( )
450+ public void SimpleUploadProgressTotalBytesTest ( )
449451 {
450- var client = Client ;
451- var fileName = UtilityMethods . GenerateName ( @"SimpleUploadTest\BetweenMinPartSizeAndPartBufferSize" ) ;
452- var path = Path . Combine ( BasePath , fileName ) ;
453- // there was a bug where the transfer utility was uploading 13MB file
454- // when the file size was between 5MB and (5MB + 8192). 8192 is the s3Client.Config.BufferSize
455- var fileSize = 5 * MEG_SIZE + 1 ;
456-
457- UtilityMethods . GenerateFile ( path , fileSize ) ;
458- //take the generated file and turn it into an unseekable stream
459-
460- var stream = GenerateUnseekableStreamFromFile ( path ) ;
461- using ( var tu = new Amazon . S3 . Transfer . TransferUtility ( client ) )
452+ var transferConfig = new TransferUtilityConfig ( )
462453 {
463- tu . Upload ( stream , bucketName , fileName ) ;
454+ MinSizeBeforePartUpload = 20 * MEG_SIZE ,
455+ } ;
464456
465- var metadata = Client . GetObjectMetadata ( new GetObjectMetadataRequest
457+ var progressValidator = new TransferProgressValidator < UploadProgressArgs >
458+ {
459+ Validate = ( progress ) =>
466460 {
467- BucketName = bucketName ,
468- Key = fileName
469- } ) ;
470- Assert . AreEqual ( fileSize , metadata . ContentLength ) ;
461+ Assert . IsTrue ( progress . TotalBytes > 0 , "TotalBytes should be greater than 0" ) ;
462+ Assert . AreEqual ( testContent . Length , progress . TotalBytes , "TotalBytes should equal file length" ) ;
463+ }
464+ } ;
471465
472- //Download the file and validate content of downloaded file is equal.
473- var downloadPath = path + ".download" ;
474- var downloadRequest = new TransferUtilityDownloadRequest
466+ using ( var fileTransferUtility = new TransferUtility ( Client , transferConfig ) )
467+ {
468+ var request = new TransferUtilityUploadRequest ( )
475469 {
476470 BucketName = bucketName ,
477- Key = fileName ,
478- FilePath = downloadPath
471+ FilePath = testFilePath ,
472+ Key = testKey
479473 } ;
480- tu . Download ( downloadRequest ) ;
481- UtilityMethods . CompareFiles ( path , downloadPath ) ;
474+
475+ request . UploadProgressEvent += progressValidator . OnProgressEvent ;
476+
477+ fileTransferUtility . Upload ( request ) ;
478+
479+ progressValidator . AssertOnCompletion ( ) ;
482480 }
483481 }
484482
0 commit comments