private void ResumableUploadResumeTest_InitDelayTest()
        {
            var    bucket = _fixture.SingleVersionBucket;
            var    name   = GenerateName();
            var    data   = _fixture.SmallContent;
            string url    = null;

            _fixture.RegisterDelayTest(_duration,
                                       beforeDelay: async duration =>
            {
                url            = _fixture.UrlSigner.Sign(bucket, name, duration, UrlSigner.ResumableHttpMethod);
                var sessionUri = await SignedUrlResumableUpload.InitiateSessionAsync(url);

                // Verify that the URL works initially.
                var uploader = ResumableUpload.CreateFromUploadUri(sessionUri, new MemoryStream(data));
                var progress = await uploader.ResumeAsync(sessionUri);
                Assert.Null(progress.Exception);
                Assert.Equal(UploadStatus.Completed, progress.Status);

                var result = new MemoryStream();
                await _fixture.Client.DownloadObjectAsync(bucket, name, result);
                Assert.Equal(result.ToArray(), data);

                // Reset the state.
                await _fixture.Client.DeleteObjectAsync(bucket, name);
            },
                                       afterDelay: async() =>
            {
                // Verify that the URL no longer works.
                await Assert.ThrowsAsync <GoogleApiException>(() => SignedUrlResumableUpload.InitiateSessionAsync(url));

                var obj = await _fixture.Client.ListObjectsAsync(bucket, name).FirstOrDefault(o => o.Name == name);
                Assert.Null(obj);
            });
        }
Esempio n. 2
0
        private static void ResumableUploadResumeTest_Common(StorageFixture fixture, SigningVersion signingVersion, [CallerMemberName] string caller = null)
        {
            var bucket          = fixture.SingleVersionBucket;
            var name            = IdGenerator.FromGuid();
            var requestTemplate = RequestTemplate
                                  .FromBucket(bucket)
                                  .WithObjectName(name)
                                  .WithHttpMethod(ResumableHttpMethod);
            var    content = fixture.SmallContent;
            string url     = null;

            fixture.RegisterDelayTest(
                s_duration,
                beforeDelay: async duration =>
            {
                url            = fixture.UrlSigner.Sign(requestTemplate, Options.FromDuration(duration).WithSigningVersion(signingVersion));
                var sessionUri = await SignedUrlResumableUpload.InitiateSessionAsync(url);

                // Verify that the URL works initially.
                var uploader = ResumableUpload.CreateFromUploadUri(sessionUri, new MemoryStream(content));
                var progress = await uploader.ResumeAsync(sessionUri);
                Assert.Null(progress.Exception);
                Assert.Equal(UploadStatus.Completed, progress.Status);

                var result = new MemoryStream();
                await fixture.Client.DownloadObjectAsync(bucket, name, result);
                AssertContentEqual(content, result.ToArray());

                // Reset the state.
                await fixture.Client.DeleteObjectAsync(bucket, name);
            },
                afterDelay: async() =>
            {
                // Verify that the URL no longer works.
                await Assert.ThrowsAsync <GoogleApiException>(() => SignedUrlResumableUpload.InitiateSessionAsync(url));

                var obj = await fixture.Client.ListObjectsAsync(bucket, name).FirstOrDefaultAsync(o => o.Name == name);
                Assert.Null(obj);
            },
                caller);
        }