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();
                }
            }
        }
        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);
            }
        }
        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_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_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)));
     }
 }
Example #10
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;
            }
        }
Example #11
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;
            }
        }
Example #12
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;
            }
        }
Example #13
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_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("[]"));
        }
        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();
                }
            }
        }
        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_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_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));
            }
        }