コード例 #1
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();
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
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();
            }
        }
コード例 #5
0
        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();
                }
            }
        }
コード例 #6
0
        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();
                }
            }
        }
コード例 #7
0
        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();
                }
            }
        }
コード例 #8
0
        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();
                }
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        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("[]"));
        }
コード例 #11
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));
            }
        }
コード例 #12
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();
            }
        }
コード例 #13
0
        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();
        }
コード例 #14
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)));
            }
        }
コード例 #15
0
        public void Should_get_serialized_xml_format()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer(Constants.StorageItemNameJpg);
                var getContainerInformation = new GetContainerInformationSerialized(storageUrl, Constants.CONTAINER_NAME, Format.XML);

                var xmlResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken);
                Assert.That(xmlResponse.Status, Is.EqualTo(HttpStatusCode.OK));
                var xmlReturnValue = String.Join("", xmlResponse.ContentBody.ToArray());
                xmlResponse.Dispose();
                var expectedSubString = "<container name=\"" + Constants.CONTAINER_NAME + "\"><object><name>" + Constants.StorageItemNameJpg + "<\\/name><hash>b44a59383b3123a747d139bd0e71d2df<\\/hash><bytes>\\d+<\\/bytes><content_type>image.*jpeg<\\/content_type><last_modified>" + String.Format("{0:yyyy-MM}", DateTime.Now);

                Assert.That(Regex.Match(xmlReturnValue, expectedSubString).Success || string.IsNullOrEmpty(xmlReturnValue), Is.True);
                testHelper.DeleteItemFromContainer(Constants.StorageItemNameJpg);
            }
        }
コード例 #16
0
        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();
            }
        }
コード例 #17
0
        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);
            }
        }
コード例 #18
0
        public void should_return_account_name_and_ok_status_200()
        {
            var accountInformationXml            = new GetAccountInformationSerialized(storageUrl, Format.XML);
            var getAccountInformationXmlResponse = new GenerateRequestByType().Submit(accountInformationXml, authToken);

            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));
        }
コード例 #19
0
        public void should_return_account_information_in_xml_format_including_name_count_and_size()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var accountInformationXml            = new GetAccountInformationSerialized(storageUrl, Format.XML);
                    var getAccountInformationXmlResponse = new GenerateRequestByType().Submit(accountInformationXml, authToken);

                    if (getAccountInformationXmlResponse.ContentBody.Count == 0)
                    {
                        Assert.Ignore("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);
                    }

                    const string expectedSubString = "<container><name>" + Constants.CONTAINER_NAME + "</name><count>\\d*</count><bytes>\\d+</bytes></container>";
                    Assert.That(Regex.Match(contentBody, expectedSubString).Success, Is.True);
                }
                finally
                {
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
コード例 #20
0
 public void Should_return_the_list_of_containers()
 {
     using (new TestHelper(authToken, storageUrl))
     {
         ICloudFilesResponse response = null;
         try
         {
             GetContainers request = new GetContainers(storageUrl);
             response = new GenerateRequestByType().Submit(request, authToken);
             Assert.That(response.ContentBody.Count, Is.GreaterThan(0));
         }
         finally
         {
             if (response != null)
             {
                 response.Dispose();
             }
         }
     }
 }
コード例 #21
0
        public void Should_get_serialized_json_format()
        {
            var testHelper = new TestHelper(authToken, storageUrl);

            testHelper.PutItemInContainer(Constants.StorageItemNameJpg);
            var getContainerInformation = new GetContainerInformationSerialized(storageUrl, Constants.CONTAINER_NAME, Format.JSON);

            var jsonResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken);

            Assert.That(jsonResponse.Status, Is.EqualTo(HttpStatusCode.OK));
            var jsonReturnValue = String.Join("", jsonResponse.ContentBody.ToArray());

            jsonResponse.Dispose();
            var expectedSubString = "[{\"name\":[ ]?\"" + Constants.StorageItemNameJpg + "\",[ ]?\"hash\":[ ]?\"b44a59383b3123a747d139bd0e71d2df\",[ ]?\"bytes\":[ ]?\\d+,[ ]?\"content_type\":[ ]?\"image.*jpeg\",[ ]?\"last_modified\":[ ]?\"" + String.Format("{0:yyyy-MM}", DateTime.Now);


            Assert.That(Regex.Match(jsonReturnValue, expectedSubString).Success, Is.True);
            testHelper.DeleteItemFromContainer(Constants.StorageItemNameJpg);
            testHelper.Dispose();
        }
コード例 #22
0
        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);
                }
            }
        }
コード例 #23
0
        public void Should_return_ok_if_the_object_exists()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                try
                {
                    testHelper.PutItemInContainer();
                    var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemName);

                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                    Assert.That(getStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.OK));
                }
                finally
                {
                    if (getStorageItemResponse != null)
                    {
                        getStorageItemResponse.Dispose();
                    }
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
コード例 #24
0
        public void Should_return_OK_status()
        {
            using (new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse response = null;
                try
                {
                    GetContainers request = new GetContainers(storageUrl);


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

                    Assert.That(response.Status, Is.EqualTo(HttpStatusCode.OK));
                    Assert.That(response.ContentBody, Is.Not.Null);
                }
                finally
                {
                    if (response != null)
                    {
                        response.Dispose();
                    }
                }
            }
        }