public void should_not_throw_an_exception_when_the_container_name_starts_with_pound()
        {
            var getContainerItemList = new GetContainerItemList(storageUrl, authToken, "#container");

            var response =
                new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                    new CloudFilesRequest((getContainerItemList)));

            response.Dispose();
            Assert.That(true);
        }
        public void should_not_throw_an_exception_when_the_container_contains_utf8_characters_3()
        {
            var containerName = '\uDCFF' + "container";
            var getContainerItemList = new GetContainerItemList(storageUrl, authToken, containerName);

            var response =
                new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                    new CloudFilesRequest((getContainerItemList)));

            response.Dispose();
            foreach (string s in response.ContentBody)
                Console.WriteLine(s);
            Assert.That(true);
        }
        public void Should_return_OK_status()
        {
            using(new TestHelper(authToken, storageUrl))
            {
                CloudFilesResponseWithContentBody response = null;
                try
                {
                    GetContainers request = new GetContainers(storageUrl, authToken);
                    request.UserAgent = "NASTTestUserAgent";

                    response = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(request));

                    Assert.That(response.Status, Is.EqualTo(HttpStatusCode.OK));
                    Assert.That(response.ContentBody, Is.Not.Null);
                }
                finally
                {
                    if(response != null)
                        response.Dispose();
                }
            }
        }
        public void Should_return_the_list_of_containers()
        {
            //            Console.WriteLine("Begin listing containers");

            using (new TestHelper(authToken, storageUrl))
            {
                IResponseWithContentBody response = null;
                try
                {
                    GetContainers request = new GetContainers(storageUrl, authToken);
                    response = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(request));
                    Assert.That(response.ContentBody.Count, Is.GreaterThan(0));
            //                    foreach (string s in response.ContentBody)
            //                        Console.WriteLine(s);
            //                    Console.WriteLine("End of listing containers");
                }
                finally
                {
                    if (response != null)
                        response.Dispose();
                }
            }
        }
示例#5
0
        /// <summary>
        /// This method retrieves the names of the of the containers made public on the CDN
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// List{string} containers = connection.GetPublicContainers();
        /// </code>
        /// </example>
        /// <returns>A list of the public containers</returns>
        public List<string> GetPublicContainers()
        {
            Log.Info(this, "Getting public containers for user " + UserCredentials.Username);

            try
            {
                var getPublicContainers = new GetPublicContainers(CdnManagementUrl, AuthToken);
                var getPublicContainersResponse =
                    new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getPublicContainers));
                var containerList = getPublicContainersResponse.ContentBody;
                getPublicContainersResponse.Dispose();

                return containerList;
            }
            catch(WebException we)
            {
                Log.Error(this, "Error getting public containers 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;
            }
        }
        public void Should_return_ten_objects_when_setting_the_limit_to_ten()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                for (int i = 0; i < 12; ++i)
                    testHelper.PutItemInContainer(Constants.StorageItemName, i.ToString());

                var parameters = new Dictionary<GetItemListParameters, string>
                                                                           {{GetItemListParameters.Limit, "10"}};

                var getContainerItemsRequest = new GetContainerItemList(storageUrl,
                                                                                         authToken, Constants.CONTAINER_NAME, parameters);
                getContainerItemsRequest.UserAgent = Constants.USER_AGENT;

                var response =
                    new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                        new CloudFilesRequest(getContainerItemsRequest));

                for (int i = 0; i < 12; ++i)
                    testHelper.DeleteItemFromContainer(i.ToString());

                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.OK));
                Assert.That(response.ContentBody.Count, Is.EqualTo(10));

                response.Dispose();
            }
        }
        public void Should_return_specific_files_under_a_directory_when_passed_a_top_directory()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                for (int i = 0; i < 12; ++i)
                {
                    if(i % 3 == 0)
                    {
                        testHelper.PutItemInContainer(Constants.StorageItemName, "topdir1/subdir2/" + i + "file");
                        continue;
                    }
                    testHelper.PutItemInContainer(Constants.StorageItemName, "topdir1/" + i + "file");
                }

                var parameters = new Dictionary<GetItemListParameters, string> { { GetItemListParameters.Path, "topdir1" } };

                var getContainerItemsRequest = new GetContainerItemList(storageUrl,
                                                                                         authToken, Constants.CONTAINER_NAME, parameters);
                getContainerItemsRequest.UserAgent = Constants.USER_AGENT;

                var response =
                    new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                        new CloudFilesRequest(getContainerItemsRequest));

                for (int i = 0; i < 12; ++i)
                {
                    if (i % 3 == 0)
                    {
                        testHelper.DeleteItemFromContainer("topdir1/subdir2/" + i + "file");
                        continue;
                    }
                    testHelper.DeleteItemFromContainer("topdir1/" + i + "file");
                }

                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.OK));
                Assert.That(response.ContentBody.Count, Is.EqualTo(8));
                Assert.That(response.ContentBody[0], Is.EqualTo("topdir1/10file"));
                Assert.That(response.ContentBody[1], Is.EqualTo("topdir1/11file"));
                Assert.That(response.ContentBody[2], Is.EqualTo("topdir1/1file"));
                Assert.That(response.ContentBody[3], Is.EqualTo("topdir1/2file"));
                Assert.That(response.ContentBody[4], Is.EqualTo("topdir1/4file"));
                Assert.That(response.ContentBody[5], Is.EqualTo("topdir1/5file"));
                Assert.That(response.ContentBody[6], Is.EqualTo("topdir1/7file"));
                Assert.That(response.ContentBody[7], Is.EqualTo("topdir1/8file"));

                response.Dispose();
            }
        }
        public void should_return_no_content_status_when_container_is_empty()
        {
            using (new TestHelper(authToken, storageUrl))
            {
                var getContainerItemsRequest = new GetContainerItemList(storageUrl, authToken, Constants.CONTAINER_NAME);
                getContainerItemsRequest.UserAgent = Constants.USER_AGENT;

                var response =
                    new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                        new CloudFilesRequest(getContainerItemsRequest));
                response.Dispose();
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
            }
        }
        public void should_return_a_list_of_items_when_container_is_not_empty()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer(Constants.StorageItemName, Constants.StorageItemName);

                var getContainerItemsRequest = new GetContainerItemList(storageUrl, authToken, Constants.CONTAINER_NAME);
                getContainerItemsRequest.UserAgent = Constants.USER_AGENT;

                var response =
                    new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                        new CloudFilesRequest(getContainerItemsRequest));
                testHelper.DeleteItemFromContainer(Constants.StorageItemName);

                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.OK));
                Assert.That(response.ContentType, Is.Not.Null);
                response.Dispose();
            }
        }
        public void should_return_account_name_and_ok_status_200()
        {
            var accountInformationXml = new GetAccountInformationSerialized(storageUrl, authToken, Format.XML);
            var getAccountInformationXmlResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(accountInformationXml));
            Assert.That(getAccountInformationXmlResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            var contentBody = "";
            foreach (var s in getAccountInformationXmlResponse.ContentBody)
            {
                contentBody += s;
            }

            getAccountInformationXmlResponse.Dispose();
            const string expectedSubString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><account name=\"MossoCloudFS_5d8f3dca-7eb9-4453-aa79-2eea1b980353\"></account>";
            Assert.That(contentBody, Is.EqualTo(expectedSubString));
        }
        public void Should_return_No_Content_status()
        {
            //Assert.Ignore("Is returning OK instead of NoContent, need to investigate - 2/3/2009");
            GetContainers request = new GetContainers(storageUrl, authToken);
            request.UserAgent = "NASTTestUserAgent";

            var response = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(request));

            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
            if(response.ContentBody != null)
                Assert.That(response.ContentBody.Count, Is.EqualTo(0));
            response.Dispose();
        }
        public void should_return_empty_brackets_and_ok_status_200()
        {
            var getAccountInformationJson = new GetAccountInformationSerialized(storageUrl, authToken, Format.JSON);
            var getAccountInformationJsonResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getAccountInformationJson));
            Assert.That(getAccountInformationJsonResponse.Status, Is.EqualTo(HttpStatusCode.OK));
            var contentBody = String.Join("",getAccountInformationJsonResponse.ContentBody.ToArray());
            getAccountInformationJsonResponse.Dispose();

            Assert.That(contentBody, Is.EqualTo("[]"));
        }
示例#13
0
 /// <summary>
 /// This method retrieves a list of containers associated with a given account
 /// </summary>
 /// <example>
 /// <code>
 /// UserCredentials userCredentials = new UserCredentials("username", "api key");
 /// IConnection connection = new Connection(userCredentials);
 /// List{string} containers = connection.GetContainers();
 /// </code>
 /// </example>
 /// <returns>An instance of List, containing the names of the containers this account owns</returns>
 public List<string> GetContainers()
 {
     Log.Info(this, "Getting containers for user " + UserCredentials.Username);
     try
     {
         List<string> containerList = null;
         var getContainers = new GetContainers(StorageUrl, AuthToken);
         var getContainersResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getContainers, UserCredentials.ProxyCredentials));
         if (getContainersResponse.Status == HttpStatusCode.OK)
         {
             containerList = getContainersResponse.ContentBody;
         }
         return containerList;
     }
     catch(Exception ex)
     {
         Log.Error(this, "Error getting containers for user " + UserCredentials.Username, ex);
         throw;
     }
 }
示例#14
0
        /// <summary>
        /// This method retrieves the contents of a container
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Dictionary{GetItemListParameters, string} parameters = new Dictionary{GetItemListParameters, string}();
        /// parameters.Add(GetItemListParameters.Limit, 2);
        /// parameters.Add(GetItemListParameters.Marker, 1);
        /// parameters.Add(GetItemListParameters.Prefix, "a");
        /// List{string} containerItemList = connection.GetContainerItemList("container name", parameters);
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container</param>
        /// <param name="parameters">Parameters to feed to the request to filter the returned list</param>
        /// <returns>An instance of List, containing the names of the storage objects in the give container</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public List<string> GetContainerItemList(string containerName, Dictionary<GetItemListParameters, string> parameters)
        {
            if (string.IsNullOrEmpty(containerName))
                 throw new ArgumentNullException();

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

            var containerItemList = new List<string>();

             try
             {
                 var getContainerItemList = new GetContainerItemList(StorageUrl, AuthToken, containerName, parameters);
                 var getContainerItemListResponse =
                     new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                         new CloudFilesRequest(getContainerItemList, UserCredentials.ProxyCredentials));
                 if (getContainerItemListResponse.Status == HttpStatusCode.OK)
                 {
                     containerItemList.AddRange(getContainerItemListResponse.ContentBody);
                 }
             }
             catch (WebException we)
             {
                 Log.Error(this, "Error getting containers item list 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!");

                 throw;
             }
             return containerItemList;
        }
示例#15
0
        /// <summary>
        /// XML serialized format of the container's objects
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// XmlDocument xmlResponse = connection.GetContainerInformationXml("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">name of the container to get information</param>
        /// <returns>xml document of object information inside the container</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public XmlDocument GetContainerInformationXml(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

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

            try
            {
                var getContainerInformation = new GetContainerInformationSerialized(StorageUrl, AuthToken, containerName, Format.XML);
                var getSerializedResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getContainerInformation, UserCredentials.ProxyCredentials));
                var xmlResponse = String.Join("", getSerializedResponse.ContentBody.ToArray());
                getSerializedResponse.Dispose();

                if (xmlResponse == null) return new XmlDocument();

                var xmlDocument = new XmlDocument();
                try
                {
                    xmlDocument.LoadXml(xmlResponse);

                }
                catch (XmlException)
                {
                    return xmlDocument;
                }

                return xmlDocument;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container information (XML format) 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");

                throw;
            }
        }
示例#16
0
        /// <summary>
        /// Get account information in xml format
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// XmlDocument xmlReturnValue = connection.GetAccountInformationXml();
        /// </code>
        /// </example>
        /// <returns>XML serialized format of the account information</returns>
        public XmlDocument GetAccountInformationXml()
        {
            try
            {
                Log.Info(this, "Getting account information (XML format) for user " + UserCredentials.Username);
                var accountInformationXml = new GetAccountInformationSerialized(StorageUrl, AuthToken, Format.XML);
                var getAccountInformationXmlResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(accountInformationXml));

                if (getAccountInformationXmlResponse.ContentBody.Count == 0) return new XmlDocument();

                var contentBody = String.Join("", getAccountInformationXmlResponse.ContentBody.ToArray());
                getAccountInformationXmlResponse.Dispose();

                var xmlDocument = new XmlDocument();
                try
                {
                    xmlDocument.LoadXml(contentBody);
                }
                catch (XmlException)
                {
                    return xmlDocument;
                }

                return xmlDocument;
            }
            catch(Exception ex)
            {
                Log.Error(this, "Error getting account information (XML format) for user "
                    + UserCredentials.Username, ex);
                throw;
            }
        }
示例#17
0
        /// <summary>
        /// Get account information in json format
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// string jsonReturnValue = connection.GetAccountInformationJson();
        /// </code>
        /// </example>
        /// <returns>JSON serialized format of the account information</returns>
        public string GetAccountInformationJson()
        {
            try
            {
                Log.Info(this, "Getting account information (JSON format) for user " + UserCredentials.Username);
                var getAccountInformationJson = new GetAccountInformationSerialized(StorageUrl, AuthToken, Format.JSON);
                var getAccountInformationJsonResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>()
                    .Create(new CloudFilesRequest(getAccountInformationJson));

                if (getAccountInformationJsonResponse.ContentBody.Count == 0) return "";
                var jsonResponse = String.Join("", getAccountInformationJsonResponse.ContentBody.ToArray());

                getAccountInformationJsonResponse.Dispose();
                return jsonResponse;
            }
            catch (Exception ex)
            {
                Log.Error(this, "Error getting account information (JSON format) for user "
                                + UserCredentials.Username, ex);
                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);
            }
        }
示例#19
0
        /// <summary>
        /// An alternate method for downloading storage objects. This one allows specification of special HTTP 1.1 compliant GET headers
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials); 
        /// Dictionary{RequestHeaderFields, string} requestHeaderFields = Dictionary{RequestHeaderFields, string}();
        /// string dummy_etag = "5c66108b7543c6f16145e25df9849f7f";
        /// requestHeaderFields.Add(RequestHeaderFields.IfMatch, dummy_etag);
        /// requestHeaderFields.Add(RequestHeaderFields.IfNoneMatch, dummy_etag);
        /// requestHeaderFields.Add(RequestHeaderFields.IfModifiedSince, DateTime.Now.AddDays(6).ToString());
        /// requestHeaderFields.Add(RequestHeaderFields.IfUnmodifiedSince, DateTime.Now.AddDays(-6).ToString());
        /// requestHeaderFields.Add(RequestHeaderFields.Range, "0-5");
        /// StorageItem storageItem = connection.GetStorageItem("container name", "RemoteStorageItem.txt", requestHeaderFields);
        /// </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>
        /// <param name="requestHeaderFields">A dictionary containing the special headers and their values</param>
        /// <returns>An instance of StorageItem with the stream containing the bytes representing the desired storage object</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public StorageItem GetStorageItem(string containerName, string storageItemName, Dictionary<RequestHeaderFields, string> requestHeaderFields)
        {
            if (string.IsNullOrEmpty(containerName) ||
               string.IsNullOrEmpty(storageItemName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting storage item "
                + storageItemName + " with request Header fields in container '"
                + containerName + "' for user "
                + UserCredentials.Username);

            try
            {
                var getStorageItem = new GetStorageItem(StorageUrl, AuthToken, containerName, storageItemName, requestHeaderFields);
                var getStorageItemResponse = new ResponseFactoryWithContentBody<GetStorageItemResponse>().Create(new CloudFilesRequest(getStorageItem, UserCredentials.ProxyCredentials));

                var metadata = GetMetadata(getStorageItemResponse);
                var storageItem = new StorageItem(storageItemName, metadata, getStorageItemResponse.ContentType, getStorageItemResponse.ContentStream, long.Parse(getStorageItemResponse.ContentLength));
            //                getStorageItemResponse.Dispose();
                return storageItem;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting storage item "
                    + storageItemName + " with request Header fields in container '"
                    + containerName + "' for user "
                    + UserCredentials.Username, we);

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

                throw;
            }
        }
        public void should_return_account_information_in_xml_format_including_name_count_and_size()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var accountInformationXml = new GetAccountInformationSerialized(storageUrl, authToken, Format.XML);
                    var getAccountInformationXmlResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(accountInformationXml));

                    if (getAccountInformationXmlResponse.ContentBody.Count == 0)
                        Assert.Fail("No content body returned in response");

                    var contentBody = "";
                    foreach (var s in getAccountInformationXmlResponse.ContentBody)
                    {
                        contentBody += s;
                    }

                    getAccountInformationXmlResponse.Dispose();
                    var xmlDocument = new XmlDocument();
                    try
                    {
                        xmlDocument.LoadXml(contentBody);
                    }
                    catch(XmlException e)
                    {
                        Console.WriteLine(e.Message);
                    }

            //                    Console.WriteLine(xmlDocument.InnerXml);
                    var expectedSubString = "<container><name>"+ Constants.CONTAINER_NAME +"</name><count>1</count><bytes>34</bytes></container>";
                    Assert.That(contentBody.IndexOf(expectedSubString) > 0, Is.True);
                }
                finally
                {
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
示例#21
0
        /// <summary>
        /// An alternate method for downloading storage objects from cloudfiles directly to a file name specified in the method
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// Dictionary{RequestHeaderFields, string} requestHeaderFields = Dictionary{RequestHeaderFields, string}();
        /// string dummy_etag = "5c66108b7543c6f16145e25df9849f7f";
        /// requestHeaderFields.Add(RequestHeaderFields.IfMatch, dummy_etag);
        /// requestHeaderFields.Add(RequestHeaderFields.IfNoneMatch, dummy_etag);
        /// requestHeaderFields.Add(RequestHeaderFields.IfModifiedSince, DateTime.Now.AddDays(6).ToString());
        /// requestHeaderFields.Add(RequestHeaderFields.IfUnmodifiedSince, DateTime.Now.AddDays(-6).ToString());
        /// requestHeaderFields.Add(RequestHeaderFields.Range, "0-5");
        /// StorageItem storageItem = connection.GetStorageItem("container name", "RemoteFileName.txt", "C:\Local\File\Path\file.txt", requestHeaderFields);
        /// </code>
        /// </example>
        /// <param name="containerName">The name of the container that contains the storage object to retrieve</param>
        /// <param name="storageItemName">The name of the storage object to retrieve</param>
        /// <param name="localFileName">The file name to save the storage object into on disk</param>
        /// <param name="requestHeaderFields">A dictionary containing the special headers and their values</param>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public void GetStorageItem(string containerName, string storageItemName, string localFileName, Dictionary<RequestHeaderFields, string> requestHeaderFields)
        {
            if (string.IsNullOrEmpty(containerName) ||
               string.IsNullOrEmpty(storageItemName) ||
                string.IsNullOrEmpty(localFileName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting storage item "
                + storageItemName + " with request Header fields in container '"
                + containerName + "' for user "
                + UserCredentials.Username + " and name it "
                + localFileName + " locally");

            var getStorageItem = new GetStorageItem(StorageUrl, AuthToken, containerName, storageItemName, requestHeaderFields);

            try
            {
                var getStorageItemResponse = new ResponseFactoryWithContentBody<GetStorageItemResponse>().Create(new CloudFilesRequest(getStorageItem, UserCredentials.ProxyCredentials));
                foreach (var callback in callbackFuncs)
                {
                    getStorageItemResponse.Progress += callback;
                }
                getStorageItemResponse.SaveStreamToDisk(localFileName);
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting storage item "
                    + storageItemName + " with request Header fields in container '"
                    + containerName + "' for user "
                    + UserCredentials.Username, we);

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

                throw;
            }
        }
        public void should_return_account_information_in_json_format_including_name_count_and_bytes()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var getAccountInformationJson = new GetAccountInformationSerialized(storageUrl, authToken, Format.JSON);
                    var getAccountInformationJsonResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getAccountInformationJson));

                    if(getAccountInformationJsonResponse.ContentBody.Count == 0)
                        Assert.Fail("No content body returned in response");

            //                    foreach (string s in getAccountInformationJsonResponse.ContentBody)
            //                    {
            //                        Console.WriteLine(s);
            //                    }

                    var expectedSubString = "{\"name\": \"" + Constants.CONTAINER_NAME + "\", \"count\": 1, \"bytes\": 34}";
                    var contentBody = getAccountInformationJsonResponse.ContentBody;
                    getAccountInformationJsonResponse.Dispose();
                    foreach (var s in contentBody)
                    {
                        if (s.IndexOf(expectedSubString) > -1) return;
                    }

                    Assert.Fail("Expected value: " + expectedSubString + " not found");

                }
                finally
                {

                    testHelper.DeleteItemFromContainer();
                }
            }
        }
 public void should_return_401_when_the_account_name_is_wrong()
 {
     Uri uri = new Uri("http://henhouse-1.stg.racklabs.com/v1/Persistent");
     GetContainerItemList getContainerItemsRequest = new GetContainerItemList(uri.ToString(), authToken, "#%");
     getContainerItemsRequest.UserAgent = "NASTTestUserAgent";
     try
     {
         var response =
             new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(
                 new CloudFilesRequest(getContainerItemsRequest));
         response.Dispose();
     }
     catch (Exception ex)
     {
         Assert.That(ex, Is.TypeOf(typeof (WebException)));
     }
 }