public void Should_return_partial_content_if_the_item_exists_and_only_range_to_is_set()
        {
            requestHeaderFields.Add(RequestHeaderFields.Range, "-8");
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                try
                {
                    testHelper.PutItemInContainer();

                    var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, requestHeaderFields);

                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                    Assert.That(getStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.PartialContent));
                }
                finally
                {
                    if (getStorageItemResponse != null)
                    {
                        getStorageItemResponse.Dispose();
                    }
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
        public void Should_return_not_found_if_the_object_does_not_exist()
        {
            using (new TestHelper(authToken, storageUrl))
            {
                var getStorageItem     = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName);
                var exceptionWasThrown = false;

                ICloudFilesResponse getStorageItemResponse = null;
                try
                {
                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                }
                catch (WebException ex)
                {
                    exceptionWasThrown = true;
                    var code = ((HttpWebResponse)ex.Response).StatusCode;
                    Assert.That(code, Is.EqualTo(HttpStatusCode.NotFound));
                    if (getStorageItemResponse != null)
                    {
                        getStorageItemResponse.Dispose();
                    }
                }

                Assert.That(exceptionWasThrown, Is.True);
            }
        }
        public void Should_return_item_if_the_item_exists_and_it_hasnt_been_modified()
        {
            requestHeaderFields = new Dictionary <RequestHeaderFields, string>
            {
                { RequestHeaderFields.IfUnmodifiedSince, futureDateTime.ToString() }
            };

            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                try
                {
                    testHelper.PutItemInContainer();
                    var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, requestHeaderFields);
                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                    Assert.That(getStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.OK));
                }
                finally
                {
                    if (getStorageItemResponse != null)
                    {
                        getStorageItemResponse.Dispose();
                    }
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
示例#4
0
        private void DeleteContainer()
        {
            var deleteContainer         = new DeleteContainer(storageUrl, containerName);
            var deleteContainerResponse = new GenerateRequestByType().Submit(deleteContainer, authToken);

            Assert.That(deleteContainerResponse.Status, Is.EqualTo(HttpStatusCode.NoContent));
        }
        public void Should_return_not_modified_if_the_item_exists_and_it_hasnt_been_modified()
        {
            requestHeaderFields = new Dictionary <RequestHeaderFields, string>
            {
                { RequestHeaderFields.IfModifiedSince, futureDateTime.ToString() }
            };

            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                var exceptionWasThrown = false;
                try
                {
                    testHelper.PutItemInContainer();
                    var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, requestHeaderFields);
                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                }
                catch (WebException ex)
                {
                    var response = (HttpWebResponse)ex.Response;
                    Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotModified));
                    exceptionWasThrown = true;
                }
                finally
                {
                    if (getStorageItemResponse != null)
                    {
                        getStorageItemResponse.Dispose();
                    }
                    testHelper.DeleteItemFromContainer();
                }

                Assert.That(exceptionWasThrown, Is.True);
            }
        }
示例#6
0
        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();
            }
        }
示例#7
0
        public void DeleteItemFromContainer(string storageItemName)
        {
            var deleteStorageItem         = new DeleteStorageItem(storageUrl, containerName, storageItemName);
            var deleteStorageItemResponse = new GenerateRequestByType().Submit(deleteStorageItem, authToken);

            Assert.That(deleteStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.NoContent));
        }
示例#8
0
        public void Should_return_conflict_status_when_the_container_exists_and_is_not_empty()
        {
            try
            {
                using (new TestHelper(authToken, storageUrl))
                {
                    var putStorageItem = new PutStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, Constants.StorageItemName);

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

                    var putStorageItemResponse = new GenerateRequestByType().Submit(putStorageItem, authToken);
                    Assert.That(putStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Created));
                }
                Assert.Fail("409 conflict expected");
            }
            catch (WebException we)
            {
                var response = (HttpWebResponse)we.Response;
                Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Conflict));
            }
            finally
            {
                var genrequest = new GenerateRequestByType();
                genrequest.Submit(new DeleteStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName), authToken);
                genrequest.Submit(new DeleteContainer(storageUrl, Constants.CONTAINER_NAME), authToken);
            }
        }
示例#9
0
        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();
            }
        }
示例#10
0
        public void PutItemInContainer(string storageItemName, string remoteName)
        {
            var putStorageItem         = new PutStorageItem(storageUrl, containerName, remoteName, storageItemName);
            var putStorageItemResponse = new GenerateRequestByType().Submit(putStorageItem, authToken);

            Assert.That(putStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Created));
        }
        public void Should_still_come_back_as_pdf_even_when_sent_up_as_octet_stream()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                var file     = new FileInfo(Constants.StorageItemNamePdf);
                var metadata = new Dictionary <string, string> {
                    { "Source", "1" }, { "Note", "2" }
                };
                const string DUMMY_FILE_NAME = "HAHAHA";

                var putStorageItem = new PutStorageItem(storageUrl, 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 GenerateRequestByType().Submit(putStorageItem, authToken);
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(response.ETag));

                var getStorageItem         = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, DUMMY_FILE_NAME);
                var getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                Assert.That(getStorageItemResponse.ContentType, Is.EqualTo("application/octet-stream"));
                getStorageItemResponse.Dispose();

                testHelper.DeleteItemFromContainer(DUMMY_FILE_NAME);
            }
        }
示例#12
0
        private void CreateContainer()
        {
            var createContainer      = new CreateContainer(storageUrl, containerName);
            var putContainerResponse = new GenerateRequestByType().Submit(createContainer, authToken);

            Assert.That(putContainerResponse.Status, Is.EqualTo(HttpStatusCode.Created));
        }
        public void should_return_account_information_in_json_format_including_name_count_and_bytes()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var getAccountInformationJson         = new GetAccountInformationSerialized(storageUrl, Format.JSON);
                    var getAccountInformationJsonResponse = new GenerateRequestByType().Submit(getAccountInformationJson, authToken);

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

                    const string expectedSubString = "{\"name\":[ ]?\"" + Constants.CONTAINER_NAME + "\",[ ]?\"count\":[ ]?\\d+,[ ]?\"bytes\":[ ]?\\d+}";
                    var          contentBody       = getAccountInformationJsonResponse.ContentBody;
                    getAccountInformationJsonResponse.Dispose();
                    foreach (var s in contentBody)
                    {
                        if (Regex.Match(s, expectedSubString).Success)
                        {
                            return;
                        }
                    }

                    Assert.Fail("Expected value: " + expectedSubString + " not found");
                }
                finally
                {
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
        public void should_return_204_no_content_when_the_account_has_no_containers()
        {
            var getAccountInformation = new GetAccountInformation(storageUrl);
            var response = new GenerateRequestByType().Submit(getAccountInformation, authToken);

            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
        }
        public void should_return_item_with_last_modified_date_within_a_minute_of_object_creation()
        {
            requestHeaderFields = new Dictionary <RequestHeaderFields, string>
            {
                { RequestHeaderFields.IfModifiedSince, pastDateTime.ToString() }
            };

            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                try
                {
                    testHelper.PutItemInContainer();
                    var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, requestHeaderFields);

                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                    Assert.That(getStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.OK));
                    Assert.That(getStorageItemResponse.LastModified, Is.AtLeast(DateTime.Now.AddMinutes(-1)));
                    Assert.That(getStorageItemResponse.LastModified, Is.AtMost(DateTime.Now.AddMinutes(2)));
                }
                finally
                {
                    if (getStorageItemResponse != null)
                    {
                        getStorageItemResponse.Dispose();
                    }
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
示例#16
0
        private void PutContainer(string storageUri, String containerName)
        {
            var createContainer = new CreateContainer(storageUri, containerName);

            IResponse response = new GenerateRequestByType().Submit(createContainer, authToken);

            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
        }
示例#17
0
        public void Should_return_no_content_when_the_container_exists()
        {
            PutContainer(storageUrl, Constants.CONTAINER_NAME);
            var deleteContainer = new DeleteContainer(storageUrl, Constants.CONTAINER_NAME);
            var response        = new GenerateRequestByType().Submit(deleteContainer, authToken);

            Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
        }
示例#18
0
        public void Should_return_created_status_when_the_container_does_not_exist()
        {
            CreateContainer createContainer = new CreateContainer(storageUrl, Constants.CONTAINER_NAME);

            IResponse response = new GenerateRequestByType( ).Submit(createContainer, authToken);

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

            DeleteContainer(storageUrl, Constants.CONTAINER_NAME);
        }
        public void should_return_empty_brackets_and_ok_status_200()
        {
            var getAccountInformationJson         = new GetAccountInformationSerialized(storageUrl, Format.JSON);
            var getAccountInformationJsonResponse = new GenerateRequestByType().Submit(getAccountInformationJson, authToken);

            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_created_when_a_stream_is_passed_instead_of_a_file_name()
 {
     using (var testHelper = new TestHelper(authToken, storageUrl))
     {
         var fs             = new FileStream(Constants.StorageItemName, FileMode.Open, FileAccess.Read);
         var putStorageItem = new PutStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, fs, null);
         var response       = new GenerateRequestByType().Submit(putStorageItem, authToken);
         fs.Close();
         Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
         testHelper.DeleteItemFromContainer();
     }
 }
        public void Should_set_content_type_of_jpg_for_stream_upload()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                var fileStream     = new FileStream(Constants.StorageItemNameJpg, FileMode.Open, FileAccess.Read);
                var putStorageItem = new PutStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemNameJpg, fileStream);

                var response = new GenerateRequestByType().Submit(putStorageItem, authToken);
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(response.ETag));
                testHelper.DeleteItemFromContainer(Constants.StorageItemNameJpg);
            }
        }
        public void should_return_204_no_content_when_the_item_exists()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer();

                var deleteStorageItem = new DeleteStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName);
                var response          = new GenerateRequestByType().Submit(deleteStorageItem, authToken);

                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.NoContent));
                Assert.That(response.Headers["Content-Type"].Contains("text/plain"), Is.True);
            }
        }
示例#23
0
        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_created_as_status_when_the_file_does_not_already_exist()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                var putStorageItem = new PutStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName, Constants.StorageItemName);

                // Assert.That(putStorageItem.ContentLength, Is.EqualTo(34)); //does not belong in this test

                var response = new GenerateRequestByType().Submit(putStorageItem, authToken);
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(response.ETag));
                testHelper.DeleteItemFromContainer();
            }
        }
        public void Should_return_no_content_when_the_container_exists()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer(Constants.StorageItemName, Constants.StorageItemName);
                var getContainerInformation = new GetContainerInformation(storageUrl, Constants.CONTAINER_NAME);

                var informationResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken);
                Assert.That(informationResponse.Status, Is.EqualTo(HttpStatusCode.NoContent));
                Assert.That(informationResponse.Headers[Constants.XContainerObjectCount], Is.EqualTo("1"));
                Assert.That(informationResponse.Headers[Constants.XContainerBytesUsed], (Is.Not.Null));
                testHelper.DeleteItemFromContainer(Constants.StorageItemName);
            }
        }
示例#26
0
        public void AddMetadataToItem(string storageItemName)
        {
            var metadata = new Dictionary <string, string> {
                { "Test", "test" }, { "Test2", "test2" }
            };
            var setStorageItemMetaInformation = new SetStorageItemMetaInformation(storageUrl, containerName, storageItemName, metadata);
            var postStorageItemResponse       = new GenerateRequestByType().Submit(setStorageItemMetaInformation, authToken);

            Assert.That(postStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.Accepted));
            Assert.That(postStorageItemResponse.Headers["Content-Type"].Contains("text/plain"), Is.True);
            var contentLength = postStorageItemResponse.Headers["Content-Length"];

            Assert.That(contentLength == "58" || contentLength == "0", Is.True);
        }
示例#27
0
        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()
        {
            Assert.Ignore("Is returning OK instead of NoContent, need to investigate - 7/14/2010");
            var request = new GetContainers(storageUrl);

            var response = new GenerateRequestByType(
                new RequestFactoryWithAgentSupport("NASTTestUserAgent")).Submit(request, authToken);

            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_set_content_type_of_gif_for_local_file_upload()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                var putStorageItem = new PutStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemNameGif, Constants.StorageItemNameGif);

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

                var response = new GenerateRequestByType().Submit(putStorageItem, authToken);
                Assert.That(response.Status, Is.EqualTo(HttpStatusCode.Created));
                Assert.That(response.Headers[Constants.ETAG], Is.EqualTo(response.ETag));
                testHelper.DeleteItemFromContainer(Constants.StorageItemNameGif);
            }
        }
示例#30
0
        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)));
            }
        }