Exemple #1
0
        public void Should_add_if_unmodified_since_request_field_to_request_ifmodifiedsince_property_successfully()
        {
            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "containername", Constants.STORAGE_ITEM_NAME, requestHeaderFields);

            Asserts.AssertHeaders(getStorageItem, EnumHelper.GetDescription(RequestHeaderFields.IfUnmodifiedSince), String.Format("{0:r}", modifiedDateTime));
            //  Assert.That(getStorageItem.Headers[EnumHelper.GetDescription(RequestHeaderFields.IfUnmodifiedSince)], Is.EqualTo(String.Format("{0:r}", modifiedDateTime)));
        }
        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);
            }
        }
        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_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_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();
                }
            }
        }
        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();
                }
            }
        }
        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);
            }
        }
Exemple #8
0
        public void Should_throw_is_modified_since_header_exception_if_date_time_provided_is_not_even_a_date()
        {
            requestHeaderFields[RequestHeaderFields.IfModifiedSince] = "test_jibberish";

            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "containername", Constants.STORAGE_ITEM_NAME, requestHeaderFields);

            Asserts.AssertHeaders(getStorageItem, EnumHelper.GetDescription(RequestHeaderFields.IfModifiedSince), modifiedDateTime);
        }
Exemple #9
0
        public void Should_have_a_negative_range_to_property_if_the_range_to_property_is_set_correctly_and_no_range_from_is_specified()
        {
            requestHeaderFields[RequestHeaderFields.Range] = "-10";
            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "containername", Constants.STORAGE_ITEM_NAME, requestHeaderFields);
            var            request        = Asserts.GetMock(getStorageItem);

            request.VerifySet(x => x.RangeTo = -10);
            // Assert.That(getStorageItem.RangeTo, Is.EqualTo(-10));
        }
Exemple #10
0
        public void Should_have_a_range_from_property_if_the_range_from_property_is_set_correctly()
        {
            requestHeaderFields[RequestHeaderFields.Range] = "10-";
            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "containername", Constants.STORAGE_ITEM_NAME, requestHeaderFields);
            var            request        = Asserts.GetMock(getStorageItem);

            request.VerifySet(x => x.RangeFrom = 10);
            // Assert.That(request.RangeFrom, Is.EqualTo(10));
        }
Exemple #11
0
        public void Should_add_if_modified_since_request_field_to_request_ifmodifiedsince_property_successfully()
        {
            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "containername", Constants.STORAGE_ITEM_NAME, requestHeaderFields);
            var            request        = Asserts.GetMock(getStorageItem);

            request.VerifySet(x => x.IfModifiedSince = modifiedDateTime);
            // Assert.That(request.ModifiedSince.ToShortDateString(), Is.EqualTo(modifiedDateTime.ToShortDateString()));
            //Assert.That(request.ModifiedSince.ToShortTimeString(), Is.EqualTo(modifiedDateTime.ToShortTimeString()));
        }
Exemple #12
0
        public void Should_have_range_from_and_range_to_if_both_are_set_and_are_valid_integers()
        {
            requestHeaderFields[RequestHeaderFields.Range] = "1-10";
            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "containername", Constants.STORAGE_ITEM_NAME, requestHeaderFields);
            var            request        = Asserts.GetMock(getStorageItem);

            request.VerifySet(x => x.RangeFrom = 1);
            request.VerifySet(x => x.RangeTo   = 10);
            //Assert.That(getStorageItem.RangeFrom, Is.EqualTo(1));
            // Assert.That(getStorageItem.RangeTo, Is.EqualTo(10));
        }
Exemple #13
0
        public void should_be_able_to_return_stream_more_than_once()
        {
            ICloudFilesResponse getStorageItemResponse = null;
            Stream stream     = null;
            Stream streamcopy = null;

            try
            {
                connection.CreateContainer(Constants.CONTAINER_NAME);
                connection.PutStorageItem(Constants.CONTAINER_NAME, Constants.StorageItemName);

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

                getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                stream     = getStorageItemResponse.GetResponseStream();
                streamcopy = getStorageItemResponse.GetResponseStream();
                Assert.AreEqual(stream.Length, streamcopy.Length);
                Assert.Greater(getStorageItemResponse.ContentLength, 0);
                Assert.IsTrue(stream.CanRead);
                Assert.IsTrue(streamcopy.CanRead);
            }
            finally
            {
                if (getStorageItemResponse != null)
                {
                    getStorageItemResponse.Close();
                }
                if (stream != null)
                {
                    stream.Close();
                }
                if (streamcopy != null)
                {
                    streamcopy.Close();
                }
                connection.DeleteStorageItem(Constants.CONTAINER_NAME, Constants.StorageItemName);
                connection.DeleteContainer(Constants.CONTAINER_NAME);
            }
        }
        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();
                }
            }
        }
Exemple #15
0
        public void Should_add_if_none_match_request_field_header_to_request_successfully()
        {
            GetStorageItem getStorageItem = new GetStorageItem("http://storageurl", "NotEmptyString", Constants.STORAGE_ITEM_NAME, requestHeaderFields);

            Asserts.AssertHeaders(getStorageItem, EnumHelper.GetDescription(RequestHeaderFields.IfNoneMatch), DUMMY_ETAG);
        }