diff --git a/src/cs-S3Zip.Tests/S3ZipTests.cs b/src/cs-S3Zip.Tests/S3ZipTests.cs index e79ae99307a14681d0f9bd857afa6cd93f9e68a0..76e07ddfcad991b45d4a06bf73348bb1ba0ae789 100644 --- a/src/cs-S3Zip.Tests/S3ZipTests.cs +++ b/src/cs-S3Zip.Tests/S3ZipTests.cs @@ -3,6 +3,7 @@ using Amazon.S3; using Amazon.S3.Model; using NUnit.Framework; using System; +using System.IO.Compression; using System.Linq; namespace coscine.cs_S3Zip.Tests @@ -36,107 +37,31 @@ namespace coscine.cs_S3Zip.Tests }; } - // Calling library functions without executable. - /*[Test] - public void Test() + [Test] + [Ignore("Meant for manual testing.")] + public void TestUpload() { var key = "test.zip"; - int length = 3000; + // uploading var zipUtilities = new ZipUtilities(_s3MultipartStreamConfiguration); - _s3MultipartStreamConfiguration.ChunckSize = ONE_MB * 50; - - - /*using (var client = new AmazonS3Client(_s3MultipartStreamConfiguration.AccessKey, _s3MultipartStreamConfiguration.SecretKey, _s3MultipartStreamConfiguration.AmazonS3Config)) - { - var transferUtility = new TransferUtility(client); - transferUtility.AbortMultipartUploads(_s3MultipartStreamConfiguration.BucketName, DateTime.Now.AddDays(-7)); - }*/ - - //zipUtilities.ZipAndUploadFolder(@"C:\temp\test\", key); - - /*var request = new GetObjectRequest - { - BucketName = _s3MultipartStreamConfiguration.BucketName, - Key = key - }; - - using (var client = new AmazonS3Client(_s3MultipartStreamConfiguration.AccessKey, _s3MultipartStreamConfiguration.SecretKey, _s3MultipartStreamConfiguration.AmazonS3Config)) - { - using (var response = client.GetObject(request)) - { - // Was request successfull? - Assert.IsTrue(response.HttpStatusCode == System.Net.HttpStatusCode.OK); - - using (var responseStream = response.ResponseStream) - { - using (var fileStream = new FileStream(@"C:\temp\test.zip", FileMode.CreateNew)) - { - responseStream.CopyTo(fileStream); - } - } - } - } - - var seed = DateTime.Now.Millisecond; - var random = new Random(seed); - var randomBuffer = new byte[_s3MultipartStreamConfiguration.ChunckSize]; - FillArrayWithRandomChars(randomBuffer, randomBuffer.Length, charArray, random); - - var stopWatch = new Stopwatch(); - stopWatch.Start(); - - using (var s3MultipartUploadStream = new S3MultipartUploadStream(key, _s3MultipartStreamConfiguration)) - { - for (int i = 0; i < length / 50; i++) - { - s3MultipartUploadStream.Write(randomBuffer, 0, randomBuffer.Length); - } - } + zipUtilities.ZipAndUploadFolder(@"c:\temp\test", key); + } - stopWatch.Stop(); + [Test] + [Ignore("Meant for manual testing.")] + public void TestDownload() + { + var key = "test.zip"; - /*using (var s3MultipartDownloadStream = new S3MultipartDownloadStream(key, _s3MultipartStreamConfiguration)) + var zipUtilities = new ZipUtilities(_s3MultipartStreamConfiguration); + using (var s3MultipartDownloadStream = new S3MultipartDownloadStream(key, _s3MultipartStreamConfiguration)) { using (var archive = new ZipArchive(s3MultipartDownloadStream, ZipArchiveMode.Read, true)) { - zipUtilities.UnzipToFolder(archive, @"C:\temp\test2\"); + zipUtilities.UnzipToFolder(archive, @"c:\temp\test2\"); } - }*/ - - /*using (var client = new AmazonS3Client(_s3MultipartStreamConfiguration.AccessKey, _s3MultipartStreamConfiguration.SecretKey, _s3MultipartStreamConfiguration.AmazonS3Config)) - { - var meta = client.GetObjectMetadata(new GetObjectMetadataRequest() - { - BucketName = _s3MultipartStreamConfiguration.BucketName, - Key = key - }); - - var fileSize = meta.Headers.ContentLength; - - var buffer = new byte[ONE_MB]; - using (var response = client.GetObject(request)) - { - // Was request successfull? - Assert.IsTrue(response.HttpStatusCode == System.Net.HttpStatusCode.OK); - - using (var responseStream = response.ResponseStream) - { - using (var archive = new ZipArchive(responseStream, ZipArchiveMode.Read, true)) - { - zipUtilities.UnzipToFolder(archive, @"C:\temp\test2\"); - } - } - } - }* - - TimeSpan ts = stopWatch.Elapsed; - - // Format and display the TimeSpan value. - string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds / 10); - Console.WriteLine("RunTime " + elapsedTime); - }*/ + } + } [TestCase(110, 50)] [TestCase(110, 5)] diff --git a/src/cs-S3Zip/ZipUtilities.cs b/src/cs-S3Zip/ZipUtilities.cs index c8d7562ead88cf3ee7f8e00407ccbc2bb040ee84..a71f637e1b67552dff1d77c39dc2ac175ab64e7c 100644 --- a/src/cs-S3Zip/ZipUtilities.cs +++ b/src/cs-S3Zip/ZipUtilities.cs @@ -81,7 +81,7 @@ namespace coscine.cs_S3Zip { foreach (ZipArchiveEntry entry in archive.Entries) { - var fileName = directoryInfo.FullName.EndsWith($"{Path.DirectorySeparatorChar}") ? directoryInfo.FullName : directoryInfo.FullName.Length + $"{Path.DirectorySeparatorChar}{entry.FullName}"; + var fileName = directoryInfo.FullName.EndsWith($"{Path.DirectorySeparatorChar}") ? $"{directoryInfo.FullName}{entry.FullName}" : directoryInfo.FullName + $"{directoryInfo.FullName}{Path.DirectorySeparatorChar}{entry.FullName}"; if (!Directory.Exists(Path.GetDirectoryName(fileName))) {