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);
        }
        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_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()));
        }
        public void Should_return_ok_if_the_item_exists()
        {
            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_if_the_item_exists_and_has_been_modified_since_designated_time()
        {
            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));
                }
                finally
                {
                    if (getStorageItemResponse != null) getStorageItemResponse.Dispose();
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
 public void Should_add_if_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.IfMatch), DUMMY_ETAG);
 }
 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));
 }
 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));
 }
 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));
 }
 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)));
 }
Exemplo n.º 11
0
        private void getStorageItem(string containerName, string storageItemName, string localFileName, Dictionary<RequestHeaderFields, string> requestHeaderFields)
        {
            var getStorageItem = new GetStorageItem(StorageUrl, containerName, storageItemName, requestHeaderFields);
            var getStorageItemResponse = _requestfactory.Submit(getStorageItem, AuthToken, _usercreds.ProxyCredentials);
            foreach (var callback in _callbackFuncs)
            {
                getStorageItemResponse.Progress += callback;
            }
            var stream = getStorageItemResponse.GetResponseStream();

            StoreFile(localFileName, stream);
        }
        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_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_partial_content_if_the_item_exists_and_only_range_from_is_set()
        {
            requestHeaderFields.Add(RequestHeaderFields.Range, "10-");
            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_ok_if_the_object_exists_and_valid_content_type_of_image_jpeg()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemNameJpg);
                    var getStorageItem = new GetStorageItem(storageUrl, Constants.CONTAINER_NAME, Constants.StorageItemNameJpg);

                    getStorageItemResponse = new GenerateRequestByType().Submit(getStorageItem, authToken);
                    Assert.That(getStorageItemResponse.Status, Is.EqualTo(HttpStatusCode.OK));
                    Assert.That(getStorageItemResponse.Headers["Content-Type"], Is.EqualTo("image/jpeg"));
                }
                finally
                {
                    if (getStorageItemResponse != null) getStorageItemResponse.Dispose();
                    testHelper.DeleteItemFromContainer(Constants.StorageItemNameJpg);
                }
            }
        }
        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);
            }
        }
Exemplo n.º 17
0
        private StorageItem getStorageItem(string containerName, string storageItemName, Dictionary<RequestHeaderFields, string> requestHeaderFields)
        {
            var getStorageItem = new GetStorageItem(StorageUrl, containerName, storageItemName, requestHeaderFields);
            var getStorageItemResponse = _requestfactory.Submit(getStorageItem, AuthToken, _usercreds.ProxyCredentials);

            var metadata = GetMetadata(getStorageItemResponse);
            var storageItem = new StorageItem(storageItemName, metadata, getStorageItemResponse.ContentType, getStorageItemResponse.GetResponseStream(), getStorageItemResponse.ContentLength, getStorageItemResponse.LastModified);
            //                getStorageItemResponse.Dispose();
            return storageItem;
        }
        public void Should_return_412_precondition_failed_if_the_item_exists_and_has_been_modified_since_designated_time()
        {
            requestHeaderFields = new Dictionary<RequestHeaderFields, string>
            {{RequestHeaderFields.IfUnmodifiedSince, pastDateTime.ToString()}};

            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                ICloudFilesResponse getStorageItemResponse = null;
                var exceptionWasThrown = false;
                try
                {
                    testHelper.PutItemInContainer();
                    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));
                }
                catch (WebException ex)
                {
                    var response = (HttpWebResponse)ex.Response;
                    Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.PreconditionFailed));
                    exceptionWasThrown = true;
                }
                finally
                {
                    if (getStorageItemResponse != null) getStorageItemResponse.Dispose();
                    testHelper.DeleteItemFromContainer();
                }

                Assert.That(exceptionWasThrown, Is.True);
            }
        }