Esempio n. 1
0
        public async Task TestInitiatedResumableUpload(
            [CombinatorialValues("", "text/plain")] string contentType)
        {
            using (var server = new SingleChunkServer(_server))
                using (var service = new MockClientService(server.HttpPrefix))
                {
                    var content     = new MemoryStream(uploadTestBytes);
                    var tmpUploader = new TestResumableUpload(
                        service, "SingleChunk", "POST", content, contentType, uploadLength);
                    var uploadUri = await tmpUploader.InitiateSessionAsync();

                    var uploader = ResumableUpload.CreateFromUploadUri(uploadUri, content);
                    var progress = uploader.Upload();

                    Assert.Equal(2, server.Requests.Count);
                    var r0 = server.Requests[0];
                    Assert.Equal(contentType, r0.Headers["X-Upload-Content-Type"]);
                    Assert.Equal(uploadTestBytes.Length.ToString(), r0.Headers["X-Upload-Content-Length"]);
                    var r1 = server.Requests[1];
                    Assert.Equal(uploadPath, server.RemovePrefix(r1.Url.AbsolutePath));
                    Assert.Equal($"bytes 0-{uploadLength - 1}/{uploadLength}", r1.Headers["Content-Range"]);
                    Assert.Equal(UploadStatus.Completed, progress.Status);
                    Assert.Equal(uploadTestBytes.Length, progress.BytesSent);
                }
        }
Esempio n. 2
0
        public void TestInitiatedResumableUpload(
            [Values("", "text/plain")] string contentType)
        {
            using (var server = new SingleChunkServer(_server))
                using (var service = new MockClientService(server.HttpPrefix))
                {
                    var content     = new MemoryStream(uploadTestBytes);
                    var tmpUploader = new TestResumableUpload(
                        service, "SingleChunk", "POST", content, contentType, uploadLength);
                    Uri uploadUri = null;
                    tmpUploader.UploadSessionData += sessionData => {
                        uploadUri = sessionData.UploadUri;
                        // Throw an exception so the upload fails.
                        throw new Exception();
                    };
                    var progress = tmpUploader.Upload();
                    Assert.That(progress.Status, Is.EqualTo(UploadStatus.Failed));

                    var uploader = ResumableUpload.CreateFromUploadUri(uploadUri, content);
                    progress = uploader.Upload();

                    Assert.That(server.Requests.Count, Is.EqualTo(2));
                    var r0 = server.Requests[0];
                    Assert.That(r0.Headers["X-Upload-Content-Type"], Is.EqualTo(contentType));
                    Assert.That(r0.Headers["X-Upload-Content-Length"], Is.EqualTo(uploadTestBytes.Length.ToString()));
                    var r1 = server.Requests[1];
                    Assert.That(server.RemovePrefix(r1.Url.AbsolutePath), Is.EqualTo(uploadPath));
                    Assert.That(r1.Headers["Content-Range"], Is.EqualTo($"bytes 0-{uploadLength - 1}/{uploadLength}"));
                    Assert.That(progress.Status, Is.EqualTo(UploadStatus.Completed));
                    Assert.That(progress.BytesSent, Is.EqualTo(uploadTestBytes.Length));
                }
        }
Esempio n. 3
0
 public void TestUploadStreamDisposedBetweenConstructionAndUpload()
 {
     using (var server = new SingleChunkServer(_server))
         using (var service = new MockClientService(server.HttpPrefix))
         {
             var content  = new MemoryStream(new byte[10]);
             var uploader = new TestResumableUpload(service, "SingleChunk", "POST", content, "text/plain", 100);
             content.Dispose();
             var progress = uploader.Upload();
             Assert.IsType <ObjectDisposedException>(progress.Exception);
         }
 }
Esempio n. 4
0
 public void TestUploadEmptyFile(
     [CombinatorialValues(true, false)] bool knownSize)
 {
     using (var server = new SingleChunkServer(_server))
         using (var service = new MockClientService(server.HttpPrefix))
         {
             var content  = knownSize ? new MemoryStream(new byte[0]) : new UnknownSizeMemoryStream(new byte[0]);
             var uploader = new TestResumableUpload(service, "SingleChunk", "POST", content, "text/plain", 100);
             var progress = uploader.Upload();
             Assert.Equal(2, server.Requests.Count);
             var r0 = server.Requests[0];
             Assert.Equal(knownSize ? "0" : null, r0.Headers["X-Upload-Content-Length"]);
             var r1 = server.Requests[1];
             Assert.Equal(uploadPath, server.RemovePrefix(r1.Url.AbsolutePath));
             Assert.Equal("bytes *" + "/0", r1.Headers["Content-Range"]);
             Assert.Equal(UploadStatus.Completed, progress.Status);
             Assert.Equal(0, progress.BytesSent);
         }
 }
Esempio n. 5
0
 public void TestUploadInSingleChunk(
     [CombinatorialValues(true, false)] bool knownSize,
     [CombinatorialValues("", "text/plain")] string contentType,
     [CombinatorialValues(0, 10)] int chunkSizeDelta)
 {
     using (var server = new SingleChunkServer(_server))
         using (var service = new MockClientService(server.HttpPrefix))
         {
             var content  = knownSize ? new MemoryStream(uploadTestBytes) : new UnknownSizeMemoryStream(uploadTestBytes);
             var uploader = new TestResumableUpload(
                 service, "SingleChunk", "POST", content, contentType, uploadLength + chunkSizeDelta);
             var progress = uploader.Upload();
             Assert.Equal(2, server.Requests.Count);
             var r0 = server.Requests[0];
             Assert.Equal(contentType, r0.Headers["X-Upload-Content-Type"]);
             Assert.Equal(knownSize ? uploadTestBytes.Length.ToString() : null, r0.Headers["X-Upload-Content-Length"]);
             var r1 = server.Requests[1];
             Assert.Equal(uploadPath, server.RemovePrefix(r1.Url.AbsolutePath));
             Assert.Equal($"bytes 0-{uploadLength - 1}/{uploadLength}", r1.Headers["Content-Range"]);
             Assert.Equal(UploadStatus.Completed, progress.Status);
             Assert.Equal(uploadTestBytes.Length, progress.BytesSent);
         }
 }