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

            var response = new GenerateRequestByType().Submit(getContainerItemList, authToken);
            response.Dispose();
            Assert.That(true);
        }
 protected Mock<ICloudFilesRequest> GetMockrequest(Dictionary<GetItemListParameters, string> parameters,
                                                   out Uri uri)
 {
     var getContainerItemList = new GetContainerItemList("http://storageurl", "containername", parameters);
     var _mockrequest = new Mock<ICloudFilesRequest>();
     getContainerItemList.Apply(_mockrequest.Object);
     uri = getContainerItemList.CreateUri();
     return _mockrequest;
 }
        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,  containerName);

            var response = new GenerateRequestByType().Submit(getContainerItemList, authToken);

            response.Dispose();
            foreach (string s in response.ContentBody)
                Console.WriteLine(s);
            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_not_throw_an_exception_when_the_container_contains_utf8_characters_3()
        {
            var containerName = '\uDCFF' + "container" + new Guid();

            try
            {
                connection.CreateContainer(containerName);
                var getContainerItemList = new GetContainerItemList(storageUrl, containerName);

                var response = new GenerateRequestByType().Submit(getContainerItemList, authToken);

                response.Dispose();
                Assert.That(true);
            }
            finally
            {
                connection.DeleteContainer(containerName);
            }
        }
        public void Should_return_specific_files_under_a_directory_when_passed_a_top_directory()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                for (var 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,
                                                                                        Constants.CONTAINER_NAME, parameters);
               // getContainerItemsRequest.UserAgent = Constants.USER_AGENT;

                var response = new GenerateRequestByType().Submit(getContainerItemsRequest, authToken);

                for (var 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, Constants.CONTAINER_NAME);

                //getContainerItemsRequest.UserAgent = Constants.USER_AGENT;

                var response = new GenerateRequestByType().Submit(getContainerItemsRequest, authToken);
                response.Dispose();
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
            }
        }
        public void Should_return_objects_starting_with_2_when_setting_prefix_as_2()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                for (var i = 0; i < 12; ++i)
                    testHelper.PutItemInContainer(Constants.StorageItemName, i.ToString());

                var parameters = new Dictionary<GetItemListParameters, string>
                                                                           {{GetItemListParameters.Prefix, "2"}};

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

                var response = new GenerateRequestByType().Submit(getContainerItemsRequest, authToken);

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

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

                Assert.That(response.ContentBody.Count, Is.EqualTo(1));
                Assert.That(response.ContentBody[0], Is.EqualTo("2"));

                response.Dispose();
            }
        }
        public void should_return_401_when_the_account_name_is_wrong()
        {
            var uri = new Uri("http://henhouse-1.stg.racklabs.com/v1/Persistent");
            var getContainerItemsRequest = new GetContainerItemList(uri.ToString(), "#%");

            try
            {
                var factory = new  RequestFactoryWithAgentSupport("NASTTestUserAgent");
                var response = new GenerateRequestByType(factory).Submit(getContainerItemsRequest, authToken);
                response.Dispose();
            }
            catch (Exception ex)
            {
                Assert.That(ex, Is.TypeOf(typeof (WebException)));
            }
        }
        public void should_return_a_list_of_items_when_container_is_not_empty()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer(Constants.StorageItemName, Constants.StorageItemName);

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

                var response = new GenerateRequestByType().Submit(getContainerItemsRequest, authToken);
                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_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 setup()
 {
     getContainerItemList = new GetContainerItemList("http://storageurl", "authtoken", "containername");
 }
 public void when_getting_a_list_of_items_in_a_container_with_query_parameters()
 {
     var getContainerItemList = new GetContainerItemList("http://storageurl", "containername");
     var uri = getContainerItemList.CreateUri();
     var _mockrequest = new Mock<ICloudFilesRequest>();
     getContainerItemList.Apply(_mockrequest.Object);
     should("url should have storage url at beginning ", () => uri.StartsWith("http://storageurl"));
     should("url should have container name at the end ", () => uri.EndsWith("containername"));
     should("use HTTP GET method", () => _mockrequest.VerifySet(x => x.Method = "GET"));
 }
 public void setup()
 {
     var parameters = new Dictionary<GetItemListParameters, string>
                          {
                              { GetItemListParameters.Limit, "2" },
                              { GetItemListParameters.Marker, "abc" },
                              { GetItemListParameters.Prefix, "a" },
                              { GetItemListParameters.Path, "dir1/subdir2/" }
                          };
     getContainerItemList = new GetContainerItemList("http://storageurl", "authtoken", "containername", parameters);
 }
Beispiel #16
0
 private List<string> getContainerItemList(string containerName, Dictionary<GetItemListParameters, string> parameters)
 {
     var containerItemList = new List<string>();
     var getContainerItemList = new GetContainerItemList(StorageUrl, containerName, parameters);
     var getContainerItemListResponse = _requestfactory.Submit(getContainerItemList, AuthToken, _usercreds.ProxyCredentials);
     if (getContainerItemListResponse.Status == HttpStatusCode.OK)
     {
         containerItemList.AddRange(getContainerItemListResponse.ContentBody);
     }
     return containerItemList;
 }
        public void should_not_throw_an_exception_when_the_container_name_starts_with_pound()
        {
            var containerName = "#container" + new Guid();

            try
            {
                connection.CreateContainer(containerName);
                var getContainerItemList = new GetContainerItemList(storageUrl, containerName);

                var response = new GenerateRequestByType().Submit(getContainerItemList, authToken);
                response.Dispose();
                Assert.That(true);
            }
            finally
            {
                if(connection.GetContainers().Contains(containerName))
                    connection.DeleteContainer(containerName);
            }
        }
 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)));
     }
 }
        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_sub_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/subdir2" } };

                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(4));
                Assert.That(response.ContentBody[0], Is.EqualTo("topdir1/subdir2/0file"));
                Assert.That(response.ContentBody[1], Is.EqualTo("topdir1/subdir2/3file"));
                Assert.That(response.ContentBody[2], Is.EqualTo("topdir1/subdir2/6file"));
                Assert.That(response.ContentBody[3], Is.EqualTo("topdir1/subdir2/9file"));

                response.Dispose();
            }
        }
        public void Should_return_ten_objects_when_setting_the_limit_to_ten()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                for (var 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, Constants.CONTAINER_NAME, parameters);

                var response = new GenerateRequestByType().Submit(getContainerItemsRequest, authToken);

                for (var 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 setup()
 {
     var parameters = new Dictionary<GetItemListParameters, string> { { GetItemListParameters.Prefix, "a" } };
     getContainerItemList = new GetContainerItemList("http://storageurl", "authtoken", "containername", parameters);
 }
 public void SetUp()
 {
     getContainerItemList = new GetContainerItemList("http://storageurl", "containername");
     uri = getContainerItemList.CreateUri();
     _mockrequest = new Mock<ICloudFilesRequest>();
     getContainerItemList.Apply(_mockrequest.Object);
 }
        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();
            }
        }
        /// <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 "
                + _usercreds.Username);

            var containerItemList = new List<string>();

            try
            {
                var getContainerItemList = new GetContainerItemList(StorageUrl, containerName, parameters);
                var getContainerItemListResponse = _requestfactory.Submit(getContainerItemList, AuthToken, _usercreds.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 "
                   + _usercreds.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;
        }
        public void Should_return_7_objects_when_the_marker_is_5()
        {
            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.Marker, "5"}};

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

                var response = new GenerateRequestByType().Submit(getContainerItemsRequest, authToken);

                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(7));

                response.Dispose();
            }
        }