Example #1
0
 public void AddMetadataToItem(string storageItemName)
 {
     var metadata = new Dictionary<string, string> {{"Test", "test"}, {"Test2", "test2"}};
     var setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, containerName, storageItemName, metadata);
     var postStorageItemResponse = new GenerateRequestByType().Submit(setStorageItemMetaInformation, authToken);
     Assert.That(postStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Accepted));
     Assert.That(postStorageItemResponse.Headers["Content-Type"].Contains("text/plain"), Is.True);
     Assert.That(postStorageItemResponse.Headers["Content-Length"], Is.EqualTo("0"));
 }
Example #2
0
        public void AddMetadataToItem(string storageItemName)
        {
            var metadata = new Dictionary <string, string> {
                { "Test", "test" }, { "Test2", "test2" }
            };
            var setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, containerName, storageItemName, metadata);
            var postStorageItemResponse       = new GenerateRequestByType().Submit(setStorageItemMetaInformation, authToken);

            Assert.That(postStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Accepted));
            Assert.That(postStorageItemResponse.Headers["Content-Type"].Contains("text/plain"), Is.True);
            var contentLength = postStorageItemResponse.Headers["Content-Length"];

            Assert.That(contentLength == "58" || contentLength == "0", Is.True);
        }
 public void Should_return_404_not_found_when_requested_object_does_not_exist()
 {
     using (new TestHelper(authToken, storageUrl))
     {
         try
         {
             Dictionary<string, string> metadata = new Dictionary<string, string>();
             SetStorageItemMetaInformation setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, authToken, Constants.CONTAINER_NAME, Guid.NewGuid().ToString(), metadata);
             new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(setStorageItemMetaInformation));
         }
         catch (Exception ex)
         {
             Assert.That(ex, Is.TypeOf(typeof (WebException)));
         }
     }
 }
        public void Should_return_accepted_when_meta_information_is_supplied()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer();

                Dictionary<string, string> metadata = new Dictionary<string, string>();
                metadata.Add("Test", "test");
                metadata.Add("Test2", "test2");

                SetStorageItemMetaInformation setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName, metadata);

                var metaInformationResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(setStorageItemMetaInformation));

                Assert.That(metaInformationResponse.Status, Is.EqualTo(HttpStatusCode.Accepted));
                testHelper.DeleteItemFromContainer();
            }
        }
        //    private event ProgressCallback Progress;
        /// <summary>
        /// This method applies meta tags to a storage object on cloudfiles
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Dictionary{string, string} metadata = new Dictionary{string, string}();
        /// metadata.Add("key1", "value1");
        /// metadata.Add("key2", "value2");
        /// metadata.Add("key3", "value3");
        /// connection.SetStorageItemMetaInformation("container name", "C:\Local\File\Path\file.txt", metadata);
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container containing the storage object</param>
        /// <param name="storageItemName">The name of the storage object</param>
        /// <param name="metadata">A dictionary containiner key/value pairs representing the meta data for this storage object</param>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public void SetStorageItemMetaInformation(string containerName, string storageItemName, Dictionary<string, string> metadata)
        {
            if (string.IsNullOrEmpty(containerName) ||
               string.IsNullOrEmpty(storageItemName))
                throw new ArgumentNullException();

            Log.Info(this, "Setting storage item "
                + storageItemName + " meta information for container '"
                + containerName + "' for user");

            try
            {
                var setStorageItemInformation = new SetStorageItemMetaInformation(StorageUrl, containerName, storageItemName, metadata);
                _requestfactory.Submit(setStorageItemInformation, AuthToken, _usercreds.ProxyCredentials);
            }
            catch (WebException we)
            {
                Log.Error(this, "Error setting metainformation for storage item "
                    + storageItemName + " in container '"
                    + containerName + "' for user "
                    + _usercreds.Username, we);

                var response = (HttpWebResponse)we.Response;
                if (response != null && response.StatusCode == HttpStatusCode.NotFound)
                    throw new StorageItemNotFoundException("The requested storage object does not exist");

                throw;
            }
        }
 public void setup()
 {
     var metadata = new Dictionary<string, string>{{"key1", "value1"},{"key2", "value2"}};
     setStorageItemInformation = new SetStorageItemMetaInformation("http://storageurl", "containername", "storageitemname", metadata);
 }
 public void Should_throw_exception_when_meta_key_exceeds_128_characters()
 {
     using (new TestHelper(authToken, storageUrl))
     {
         try
         {
             Dictionary<string, string> metadata = new Dictionary<string, string> {{new string('a', 129), "test"}};
             SetStorageItemMetaInformation setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, authToken, Constants.CONTAINER_NAME, Guid.NewGuid().ToString(), metadata);
             new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(setStorageItemMetaInformation));
         }
         catch (Exception ex)
         {
             Assert.That(ex, Is.TypeOf(typeof (MetaKeyLengthException)));
         }
     }
 }
Example #8
0
 private void setStorageItemMetaInformation(string containerName, string storageItemName, Dictionary<string, string> metadata)
 {
     var setStorageItemInformation = new SetStorageItemMetaInformation(StorageUrl, containerName, storageItemName, metadata);
     _requestfactory.Submit(setStorageItemInformation, AuthToken, _usercreds.ProxyCredentials);
 }
 public void Should_throw_exception_when_meta_value_exceeds_256_characters()
 {
     using (new TestHelper(authToken, storageUrl))
     {
         try
         {
             Dictionary<string, string> metadata = new Dictionary<string, string> {{new string('a', 10), new string('f', 257)}};
             SetStorageItemMetaInformation setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, Constants.CONTAINER_NAME, Guid.NewGuid().ToString(), metadata);
             new GenerateRequestByType().Submit(setStorageItemMetaInformation, authToken);
         }
         catch (Exception ex)
         {
             Assert.That(ex, Is.TypeOf(typeof (MetaValueLengthException)));
         }
     }
 }