public void CopyObjectMatchingETagPositiveTest()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);

            var coRequest = new CopyObjectRequest(_bucketName, _sourceObjectKey, _bucketName, targetObjectKey);
            coRequest.MatchingETagConstraints.Add(_sourceObjectETag);

            _ossClient.CopyObject(coRequest);
            Assert.IsTrue(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));

            _ossClient.DeleteObject(_bucketName, targetObjectKey);
        }
        public void CopyBigObjectTestWithDefaultPartSize()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);
            try
            {
                var copyRequest = new CopyObjectRequest(_bucketName, _sourceBigObjectKey, _bucketName, targetObjectKey);
                copyRequest.MatchingETagConstraints.Add(_sourceBigObjectETag);

                var sourceObjectMeta = _ossClient.GetObjectMetadata(_bucketName, _sourceBigObjectKey);

                var result = _ossClient.CopyBigObject(copyRequest);
                Assert.IsTrue(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));

                var targetObjectMeta = _ossClient.GetObjectMetadata(_bucketName, targetObjectKey);
                Assert.AreEqual(sourceObjectMeta.ContentLength, targetObjectMeta.ContentLength);
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, targetObjectKey);
            }
        }
        public void CopyObjectBasicTest()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);

            //construct metadata
            var metadata = new ObjectMetadata();
            const string userMetaKey = "myKey";
            const string userMetaValue = "myValue";
            metadata.UserMetadata.Add(userMetaKey, userMetaValue);
            metadata.CacheControl = "No-Cache";

            var coRequest = new CopyObjectRequest(_bucketName, _sourceObjectKey, _bucketName, targetObjectKey)
            {
                NewObjectMetadata = metadata
            };

            //copy object
            _ossClient.CopyObject(coRequest);
            Assert.IsTrue(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));
            var resMetadata = _ossClient.GetObjectMetadata(_bucketName, targetObjectKey);
            Assert.AreEqual(userMetaValue, resMetadata.UserMetadata[userMetaKey]);

            _ossClient.DeleteObject(_bucketName, targetObjectKey);
        }
        public void CopyObjectMatchingETagNegativeTest()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);

            var coRequest = new CopyObjectRequest(_bucketName, _sourceObjectKey, _bucketName, targetObjectKey);
            coRequest.MatchingETagConstraints.Add("Dummy");

            try
            {
                _ossClient.CopyObject(coRequest);
                Assert.Fail("Copy object should not pass with MatchingETag set to wrong value");
            }
            catch(OssException e)
            {
                Assert.AreEqual(OssErrorCode.PreconditionFailed, e.ErrorCode);
            }
            Assert.IsFalse(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));
        }
        public void ResumableCopyObjectTest()
        { 
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);
            try
            {
                var copyRequest = new CopyObjectRequest(_bucketName, _sourceBigObjectKey, _bucketName, targetObjectKey);

                var sourceObjectMeta = _ossClient.GetObjectMetadata(_bucketName, _sourceBigObjectKey);

                _ossClient.ResumableCopyObject(copyRequest, Config.DownloadFolder);

                Assert.IsTrue(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));

                var targetObjectMeta = _ossClient.GetObjectMetadata(_bucketName, targetObjectKey);
                Assert.AreEqual(sourceObjectMeta.ContentLength, targetObjectMeta.ContentLength);
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, targetObjectKey);
            }
        }
        public void CopyObjectUnmodifiedSinceNegativeTest()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);

            var coRequest = new CopyObjectRequest(_bucketName, _sourceObjectKey, _bucketName, targetObjectKey)
            {
                UnmodifiedSinceConstraint = DateTime.Now.AddDays(-1)
            };

            try
            {
                _ossClient.CopyObject(coRequest);
                Assert.Fail("Copy object should not pass with NonMatchingETag set to correct value");
            }
            catch (OssException e)
            {
                Assert.AreEqual(OssErrorCode.PreconditionFailed, e.ErrorCode);
            }
            Assert.IsFalse(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));
        }
        public void CopyObjectUnmodifiedSincePositiveTest()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);

            var coRequest = new CopyObjectRequest(_bucketName, _sourceObjectKey, _bucketName, targetObjectKey)
            {
                UnmodifiedSinceConstraint = DateTime.Now.AddDays(1)
            };

            _ossClient.CopyObject(coRequest);
            Assert.IsTrue(OssTestUtils.ObjectExists(_ossClient, _bucketName, targetObjectKey));

            _ossClient.DeleteObject(_bucketName, targetObjectKey);
        }
        public void CopyObjectBasicTestWithInvalidBucket()
        {
            var targetObjectKey = OssTestUtils.GetObjectKey(_className);

            //construct metadata
            var metadata = new ObjectMetadata();
            const string userMetaKey = "myKey";
            const string userMetaValue = "myValue";
            metadata.UserMetadata.Add(userMetaKey, userMetaValue);
            metadata.CacheControl = "No-Cache";

            try
            {
                var coRequest = new CopyObjectRequest(_bucketName, _sourceObjectKey, "/invalid_bucket", targetObjectKey)
                {
                    NewObjectMetadata = metadata
                };

                _ossClient.CopyObject(coRequest);

                Assert.Fail("Copy object should not pass with invalid bucket name");
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }
        }
Beispiel #9
0
 public static void Move(string source, string destination)
 {
     var request = new CopyObjectRequest(_bucketName, source, _bucketName, destination);
     try
     {
         _client.CopyObject(request);
         Delete(source);
     }
     catch { }
 }
 public static Task <CopyObjectResult> CopyObjectAsync(this IOss client, CopyObjectRequest request)
 {
     return(Task.Factory.FromAsync(client.BeginCopyObject, client.EndCopyResult, request, null));
 }