public void Should_return_no_content_when_the_container_exists()
 {
     PutContainer(storageUrl, Constants.CONTAINER_NAME);
     var deleteContainer = new DeleteContainer(storageUrl, authToken, Constants.CONTAINER_NAME);
     var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(deleteContainer));
     Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
 }
        public void Should_return_conflict_status_when_the_container_exists_and_is_not_empty()
        {
            try
            {
                using (new TestHelper(authToken, storageUrl))
                {
                    var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName, Constants.StorageItemName);
                    Assert.That(putStorageItem.ContentLength, Is.GreaterThan(0));

                    var putStorageItemResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                    Assert.That(putStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Created));
                }
                Assert.Fail("409 conflict expected");
            }
            catch (WebException we)
            {
                var response = (HttpWebResponse)we.Response;
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict));
            }
            finally
            {
                new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(
                    new DeleteStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName)));
                new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(
                    new DeleteContainer(storageUrl, authToken, Constants.CONTAINER_NAME)));
            }
        }
 public void Should_get_storage_url_when_authenticated_correctly()
 {
     var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(request, null));
     Assert.That(response.Headers[Constants.XStorageUrl].Length, Is.GreaterThan(0));
     Uri storageUri = new Uri(response.Headers[Constants.XStorageUrl]);
     Assert.That(storageUri.AbsolutePath, Is.EqualTo("/v1/MossoCloudFS_" + STORAGE_TOKEN));
 }
 public void Should_get_auth_token_when_authenticated_correctly()
 {
     var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(request));
     var authToken = response.Headers[Constants.XAuthToken];
     Assert.That(authToken.Length, Is.GreaterThan(0));
     Assert.That(authToken.Length, Is.EqualTo(STORAGE_TOKEN.Length));
 }
        public void Should_return_created_status_when_the_container_does_not_exist()
        {
            CreateContainer createContainer = new CreateContainer(storageUrl, authToken, Constants.CONTAINER_NAME);

            IResponse response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(createContainer));
            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));

            DeleteContainer(storageUrl, Constants.CONTAINER_NAME);
        }
 public void AddMetadataToItem(string storageItemName)
 {
     var metadata = new Dictionary<string, string> {{"Test", "test"}, {"Test2", "test2"}};
     var setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, authToken, containerName, storageItemName, metadata);
     var postStorageItemResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(setStorageItemMetaInformation));
     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"));
 }
Beispiel #7
0
        public void SetUpBase()
        {
            var request = new GetAuthentication(new UserCredentials(Credentials.USERNAME, Credentials.API_KEY));
            var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(request));

            storageUrl = response.Headers[Constants.XStorageUrl];
            authToken = response.Headers[Constants.XAuthToken];
            Assert.That(authToken.Length, Is.EqualTo(36));
            connection = new Connection(new UserCredentials(Credentials.USERNAME, Credentials.API_KEY));
            SetUp();
        }
 public void Should_return_created_when_a_stream_is_passed_instead_of_a_file_name()
 {
     using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
     {
         var fs = new FileStream(Constants.StorageItemName, FileMode.Open);
         var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName, fs, null);
         var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
         fs.Close();
         Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
         testHelper.DeleteItemFromContainer();
     }
 }
        public void Should_return_created_when_content_type_is_not_supplied_because_it_is_optional()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName, Constants.StorageItemName);
                putStorageItem.Headers.Remove("Content-Type");

                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(putStorageItem.ETag));
                testHelper.DeleteItemFromContainer();
            }
        }
        public void should_return_204_no_content_when_the_item_exists()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer();

                var deleteStorageItem = new DeleteStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName);
                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(deleteStorageItem));

                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
                Assert.That(response.Headers["Content-Type"].Contains("text/plain"), Is.True);
            }
        }
        public void Should_return_created_as_status_when_the_file_does_not_already_exist()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName, Constants.StorageItemName);

                Assert.That(putStorageItem.ContentLength, Is.EqualTo(34));

                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(putStorageItem.ETag));
                testHelper.DeleteItemFromContainer();
            }
        }
Beispiel #12
0
        public void SetUpBase()
        {
            var credentials = new UserCredentials(new Uri(Credentials.AUTH_ENDPOINT), Credentials.USERNAME,Credentials.API_KEY);
            var request = new GetAuthentication(credentials);
            var cfrequest = new CloudFilesRequest((HttpWebRequest) WebRequest.Create(request.CreateUri()));
            request.Apply(cfrequest);
            var response =
                new ResponseFactory().Create(cfrequest);

            storageUrl = response.Headers[Constants.XStorageUrl];
            authToken = response.Headers[Constants.XAuthToken];
            connection = new Connection(credentials);

            if (!connection.HasCDN()) Assert.Ignore("Provider does not support CDN Management");

            SetUp();
        }
        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();
            }
        }
        public void Should_throw_an_exception_when_the_container_name_exceeds_the_maximum_length()
        {
            string containerName = new string('a', Constants.MaximumContainerNameLength + 1);
            try
            {
                using (new TestHelper(authToken, storageUrl, containerName))
                {
                    var putStorageItem = new PutStorageItem(storageUrl, authToken, containerName, Constants.StorageItemName, Constants.StorageItemName);
                    Assert.That(putStorageItem.ContentLength, Is.GreaterThan(0));

                    var putStorageItemResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                    Assert.That(putStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Created));
                }
                Assert.Fail("ContainerNameException expected");
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.TypeOf(typeof (ContainerNameException)));
            }
        }
 public void should_return_number_of_containers_and_bytes_used()
 {
     try
     {
         connection.CreateContainer(Constants.CONTAINER_NAME);
         connection.PutStorageItem(Constants.CONTAINER_NAME, Constants.StorageItemName);
     }
     finally
     {
         connection.DeleteStorageItem(Constants.CONTAINER_NAME, Constants.StorageItemName);
         connection.DeleteContainer(Constants.CONTAINER_NAME);
     }
     using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
     {
         testHelper.PutItemInContainer(Constants.StorageItemName, Constants.StorageItemName);
         GetAccountInformation getAccountInformation = new GetAccountInformation(storageUrl, authToken);
         var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(getAccountInformation));
         Assert.That(response.Headers[Constants.XAccountBytesUsed], Is.Not.Null);
         Assert.That(response.Headers[Constants.XAccountContainerCount], Is.Not.Null);
         testHelper.DeleteItemFromContainer(Constants.StorageItemName);
     }
 }
Beispiel #16
0
        public void SetUpBase()
        {
            Uri uri = new Uri(Constants.AUTH_URL);

            GetAuthentication request =
                new GetAuthentication(
                    new UserCredentials(
                        uri,
                        Constants.CREDENTIALS_USER_NAME,
                        Constants.CREDENTIALS_PASSWORD,
                        Constants.CREDENTIALS_CLOUD_VERSION,
                        Constants.CREDENTIALS_ACCOUNT_NAME));

            IResponse response =
                new ResponseFactory<CloudFilesResponse>().Create(
                    new CloudFilesRequest(request));

            storageUrl = response.Headers[utils.Constants.X_STORAGE_URL];
            authToken = response.Headers[utils.Constants.X_AUTH_TOKEN];
            Assert.That(authToken.Length, Is.EqualTo(32));
            SetUp();
        }
        public void Should_get_204_No_Content_when_item_exists()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.HeadStorageItemName);
                    testHelper.AddMetadataToItem(Constants.HeadStorageItemName);

                    var getStorageItemInformation = new GetStorageItemInformation(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.HeadStorageItemName);
                    var getStorageItemInformationResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(getStorageItemInformation));
                    Assert.That(getStorageItemInformationResponse.Status, Is.EqualTo(HttpStatusCode.NoContent));

                    var metadata = getStorageItemInformationResponse.Metadata;
                    Assert.That(metadata["Test"], Is.EqualTo("test"));
                    Assert.That(metadata["Test2"], Is.EqualTo("test2"));
                }
                finally
                {
                    testHelper.DeleteItemFromContainer(Constants.HeadStorageItemName);
                }
            }
        }
        public void Should_return_created_as_status()
        {
            Dictionary<string, string> metadata = new Dictionary<string, string>
                                                      {
                                                          {Constants.MetadataKey, Constants.MetadataValue}
                                                      };
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemName, Constants.StorageItemName, metadata);

                Assert.That(putStorageItem.ContentLength, Is.GreaterThan(0));

                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(putStorageItem.ETag));
                testHelper.DeleteItemFromContainer();
            }
        }
        /// <summary>
        /// This method retrieves meta information and size, in bytes, of a requested storage object
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// StorageItem storageItem = connection.GetStorageItemInformation("container name", "RemoteStorageItem.txt");
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container that contains the storage object</param>
        /// <param name="storageItemName">The name of the storage object</param>
        /// <returns>An instance of StorageItem containing the byte size and meta information associated with the container</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public StorageItemInformation GetStorageItemInformation(string containerName, string storageItemName)
        {
            if (string.IsNullOrEmpty(containerName) ||
               string.IsNullOrEmpty(storageItemName))
                throw new ArgumentNullException();

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

            try
            {
                var getStorageItemInformation = new GetStorageItemInformation(StorageUrl, AuthToken, containerName, storageItemName);
                var getStorageItemInformationResponse =
                    new ResponseFactory<CloudFilesResponse>()
                    .Create(new CloudFilesRequest(getStorageItemInformation, UserCredentials.ProxyCredentials));
                var storageItemInformation = new StorageItemInformation(getStorageItemInformationResponse.Headers);

                return storageItemInformation;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting storage item "
                    + storageItemName + " information in container '"
                    + containerName + "' for user "
                    + UserCredentials.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;
            }
        }
        private void PutContainer(string storageUri, String containerName)
        {
            var createContainer = new CreateContainer(storageUri, authToken, containerName);

            IResponse response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(createContainer));
            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
        }
 public void should_return_204_no_content_when_the_account_has_no_containers()
 {
     GetAccountInformation getAccountInformation = new GetAccountInformation(storageUrl, authToken);
     var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(getAccountInformation));
     Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
 }
        private void DeleteContainer(string storageUri, string containerName)
        {
            DeleteContainer deleteContainer = new DeleteContainer(storageUri, authToken, containerName);

            IResponse response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(deleteContainer));
            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
        }
        /// <summary>
        /// This method sets a container as public on the CDN
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Uri containerPublicUrl = connection.MarkContainerAsPublic("container name", 12345);
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container to mark public</param>
        /// <param name="timeToLiveInSeconds">The maximum time (in seconds) content should be kept alive on the CDN before it checks for freshness.</param>
        /// <returns>A string representing the URL of the public container or null</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public Uri MarkContainerAsPublic(string containerName,int timeToLiveInSeconds)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Marking container '"
                + containerName + "' as public with TTL of "
                + timeToLiveInSeconds + " seconds for user "
                + UserCredentials.Username);

            try
            {
                var request = new MarkContainerAsPublic(CdnManagementUrl, AuthToken, containerName, timeToLiveInSeconds);
                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(request));

                return response == null ? null : new Uri(response.Headers[Constants.X_CDN_URI]);
            }
            catch(WebException we)
            {
                Log.Error(this, "Error marking container '"
                    + containerName + "' as public with TTL of "
                    + timeToLiveInSeconds + " seconds for user "
                    + UserCredentials.Username, we);
                var response = (HttpWebResponse)we.Response;
                if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
                    throw new AuthenticationFailedException("You do not have permission to request the list of public containers.");
                throw;
            }
        }
        /// <summary>
        /// This method is used to create a container on cloudfiles with a given name
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// connection.CreateContainer("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">The desired name of the container</param>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public void CreateContainer(string containerName)
        {
            try
            {
                if (string.IsNullOrEmpty(containerName))
                    throw new ArgumentNullException();

                Log.Info(this, "Creating container '" + containerName + "' for user " + UserCredentials.Username);

                var createContainer = new CreateContainer(StorageUrl, AuthToken, containerName);
                var createContainerResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(createContainer, UserCredentials.ProxyCredentials));
                if (createContainerResponse.Status == HttpStatusCode.Accepted)
                    throw new ContainerAlreadyExistsException("The container already exists");
            }
            catch(Exception ex)
            {
                Log.Error(this, "Error creating container '"
                    + containerName + "' for user "
                    + UserCredentials.Username, ex);
                throw;
            }
        }
        private void Authenticate()
        {
            Log.Info(this, "Authenticating user " + UserCredentials.Username);
            try
            {
                var getAuthentication = new GetAuthentication(UserCredentials);
                var getAuthenticationResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(getAuthentication, UserCredentials.ProxyCredentials));
                if (getAuthenticationResponse.Status == HttpStatusCode.NoContent)
                {
                    StorageUrl = getAuthenticationResponse.Headers[Constants.X_STORAGE_URL];
                    AuthToken = getAuthenticationResponse.Headers[Constants.X_AUTH_TOKEN];
                    CdnManagementUrl = getAuthenticationResponse.Headers[Constants.X_CDN_MANAGEMENT_URL];
                    return;
                }

                if (!retry && getAuthenticationResponse.Status == HttpStatusCode.Unauthorized)
                {
                    retry = true;
                    Authenticate();
                    return;
                }
            }
            catch(Exception ex)
            {
                Log.Error(this, "Error authenticating user " + UserCredentials.Username, ex);
                throw;
            }
        }
 /// <summary>
 /// This method returns the number of containers and the size, in bytes, of the specified account
 /// </summary>
 /// <example>
 /// <code>
 /// UserCredentials userCredentials = new UserCredentials("username", "api key");
 /// IConnection connection = new Connection(userCredentials);
 /// AccountInformation accountInformation = connection.GetAccountInformation();
 /// </code>
 /// </example>
 /// <returns>An instance of AccountInformation, containing the byte size and number of containers associated with this account</returns>
 public AccountInformation GetAccountInformation()
 {
     Log.Info(this, "Getting account information for user " + UserCredentials.Username);
     try
     {
         var getAccountInformation = new GetAccountInformation(StorageUrl, AuthToken);
         var getAccountInformationResponse =
             new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(getAccountInformation));
         return new AccountInformation(getAccountInformationResponse.Headers[Constants.X_ACCOUNT_CONTAINER_COUNT],
                                       getAccountInformationResponse.Headers[Constants.X_ACCOUNT_BYTES_USED]);
     }
     catch (Exception ex)
     {
         Log.Error(this, "Error getting account information for user "
                 + UserCredentials.Username, ex);
         throw;
     }
 }
        public void Should_set_content_type_of_gif_for_local_file_upload()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, Constants.StorageItemNameGif, Constants.StorageItemNameGif);

                Assert.That(putStorageItem.ContentLength, Is.GreaterThan(0));
                Assert.That(putStorageItem.ContentType, Is.EqualTo("image/gif"));

                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(putStorageItem.ETag));
                testHelper.DeleteItemFromContainer(Constants.StorageItemNameGif);
            }
        }
        /// <summary>
        /// This method retrieves the number of storage objects in a container, and the total size, in bytes, of the container
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Container container = connection.GetContainerInformation("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container to query about</param>
        /// <returns>An instance of container, with the number of storage objects contained and total byte allocation</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public Container GetContainerInformation(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting container information for container '"
                + containerName + "' for user "
                + UserCredentials.Username);

            try
            {
                var getContainerInformation = new GetContainerInformation(StorageUrl, AuthToken, containerName);
                var getContainerInformationResponse = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(getContainerInformation, UserCredentials.ProxyCredentials));
                var container = new Container(containerName);
                container.ByteCount = long.Parse(getContainerInformationResponse.Headers[Constants.X_CONTAINER_BYTES_USED]);
                container.ObjectCount = long.Parse(getContainerInformationResponse.Headers[Constants.X_CONTAINER_STORAGE_OBJECT_COUNT]);
                var url  = getContainerCDNUri(container) ;
                if(!string.IsNullOrEmpty(url))
                    url += "/";
                container.CdnUri = url;
                return container;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container information for container '"
                    + containerName + "' for user "
                    + UserCredentials.Username, we);

                var response = (HttpWebResponse)we.Response;
                if (response != null && response.StatusCode == HttpStatusCode.NotFound)
                    throw new ContainerNotFoundException("The requested container does not exist");
                if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
                    throw new AuthenticationFailedException(we.Message);
                throw;
            }
        }
        /// <summary>
        /// Retrieves a Container object containing the public CDN information
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Container container = connection.GetPublicContainerInformation("container name")
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container to query about</param>
        /// <returns>An instance of Container with appropriate CDN information or null</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public Container GetPublicContainerInformation(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting public container "
                    + containerName + " information for user "
                    + UserCredentials.Username);

            try
            {
                var request = new GetPublicContainerInformation(CdnManagementUrl, AuthToken, containerName);
                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(request));

                return response == null ?
                    null
                    : new Container(containerName)
                    { CdnUri = response.Headers[Constants.X_CDN_URI], TTL = Convert.ToInt32(response.Headers[Constants.X_CDN_TTL])};
            }
            catch (WebException ex)
            {
                Log.Error(this, "Error getting public container "
                    + containerName + " information for user "
                    + UserCredentials.Username, ex);

                var webResponse = (HttpWebResponse)ex.Response;
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.Unauthorized)
                    throw new UnauthorizedAccessException("Your authorization credentials are invalid or have expired.");
                if (webResponse != null && webResponse.StatusCode == HttpStatusCode.NotFound)
                    throw new ContainerNotFoundException("The specified container does not exist.");
                throw;
            }
        }
        public void Should_still_come_back_as_pdf_even_when_sent_up_as_octet_stream()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                var file = new FileInfo(Constants.StorageItemNamePdf);
                var metadata = new Dictionary<string, string>();
                metadata.Add("Source", "1");
                metadata.Add("Note", "2");
                const string DUMMY_FILE_NAME = "HAHAHA";

                var putStorageItem = new PutStorageItem(storageUrl, authToken, Constants.CONTAINER_NAME, DUMMY_FILE_NAME, file.Open(FileMode.Open), metadata);

                Assert.That(putStorageItem.ContentLength, Is.GreaterThan(0));
                Assert.That(putStorageItem.ContentType, Is.EqualTo("application/octet-stream"));

                var response = new ResponseFactory<CloudFilesResponse>().Create(new CloudFilesRequest(putStorageItem));
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(putStorageItem.ETag));

                var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, DUMMY_FILE_NAME, authToken);
                var getStorageItemResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getStorageItem));
                Assert.That(getStorageItemResponse.ContentType, Is.EqualTo("application/octet-stream"));
                getStorageItemResponse.Dispose();

                testHelper.DeleteItemFromContainer(DUMMY_FILE_NAME);
            }
        }