protected Mock<ICloudFilesRequest> GetMockrequest(Dictionary<GetListParameters, 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_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_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_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<GetListParameters, string>
                                                                           {{GetListParameters.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 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<GetListParameters, string> { { GetListParameters.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_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<GetListParameters, string>
                                                                           {{GetListParameters.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_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_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_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 SetUp()
 {
     getContainerItemList = new GetContainerItemList("http://storageurl", "containername");
     uri = getContainerItemList.CreateUri();
     _mockrequest = new Mock<ICloudFilesRequest>();
     getContainerItemList.Apply(_mockrequest.Object);
 }
Ejemplo n.º 11
0
 private List<string> getContainerItemList(string containerName, Dictionary<GetListParameters, string> parameters, bool includeFolders)
 {
     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);
     }
     if(!includeFolders)
     {
         containerItemList = containerItemList.Where(Path.HasExtension).ToList();
     }
     return containerItemList;
 }