Beispiel #1
0
        public void CopyExistingBlobControllerTest()
        {
            string destBlobUri = "http://localhost/blob/test/" + Guid.NewGuid().ToString();
            var    response    = _runner.ExecuteRequestWithHeaders(destBlobUri,
                                                                   "PUT",
                                                                   null,
                                                                   new[] {
                Tuple.Create("x-ms-version", "2013-08-15"),
                Tuple.Create("x-ms-copy-source", "http://localhost/test/fixed-test.txt"),
            },
                                                                   HttpStatusCode.Accepted);

            Assert.IsNotNull(response.Headers.GetValues("x-ms-copy-id"));
            Assert.AreEqual("success", response.Headers.GetValues("x-ms-copy-status").First());

            var    pipelineResponse = BlobPipelineTests.BlobRequest("GET", "http://localhost/blob/test/fixed-test.txt");
            string redirectHost     = new Uri(pipelineResponse.Location).Host;

            pipelineResponse = BlobPipelineTests.BlobRequest("GET", destBlobUri);
            Assert.AreEqual(redirectHost, new Uri(pipelineResponse.Location).Host);

            string redirectUrl = new Uri(pipelineResponse.Location).GetLeftPart(UriPartial.Path);

            // Repeat the copy to verify the operation is idempotent
            response = _runner.ExecuteRequestWithHeaders(destBlobUri,
                                                         "PUT",
                                                         null,
                                                         new[] {
                Tuple.Create("x-ms-version", "2013-08-15"),
                Tuple.Create("x-ms-copy-source", "http://localhost/test/fixed-test.txt"),
            },
                                                         HttpStatusCode.Accepted);
            pipelineResponse = BlobPipelineTests.BlobRequest("GET", destBlobUri);
            Assert.AreEqual(redirectUrl, new Uri(pipelineResponse.Location).GetLeftPart(UriPartial.Path));

            // Copy a different source to the same destination & verify that destination moves to the same account as the new source
            pipelineResponse = BlobPipelineTests.BlobRequest("GET", "http://localhost/blob/test/test_in_different_data_account.txt");
            var newSourceAccount = new Uri(pipelineResponse.Location).Host;

            response = _runner.ExecuteRequestWithHeaders(destBlobUri,
                                                         "PUT",
                                                         null,
                                                         new[] {
                Tuple.Create("x-ms-version", "2013-08-15"),
                Tuple.Create("x-ms-copy-source", "http://localhost/test/test_in_different_data_account.txt"),
            },
                                                         HttpStatusCode.Accepted);
            pipelineResponse = BlobPipelineTests.BlobRequest("GET", destBlobUri);
            Assert.AreEqual(newSourceAccount, new Uri(pipelineResponse.Location).Host);

            // Cleanup
            _runner.ExecuteRequest(destBlobUri,
                                   "DELETE",
                                   expectedStatusCode: HttpStatusCode.Accepted);
        }
Beispiel #2
0
        public void CopyBlobToExistingDestinationControllerTest()
        {
            string destBlobUri      = String.Empty;
            var    pipelineResponse = BlobPipelineTests.BlobRequest("GET", "http://localhost/blob/test/test.txt");
            string sourceHost       = new Uri(pipelineResponse.Location).Host;

            while (true)
            {
                // Loop until we place a blob in a different storage account than our source
                destBlobUri = "http://localhost/blob/test/" + Guid.NewGuid().ToString();
                var content = new StringContent("hello world", System.Text.Encoding.UTF8, "text/plain");
                content.Headers.Add("x-ms-blob-type", "BlockBlob");
                _runner.ExecuteRequest(destBlobUri, "PUT", content);
                // See where the blob landed
                pipelineResponse = BlobPipelineTests.BlobRequest("GET", destBlobUri);
                if (!String.Equals(new Uri(pipelineResponse.Location).Host, sourceHost, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }
                // Cleanup
                _runner.ExecuteRequest(destBlobUri,
                                       "DELETE",
                                       expectedStatusCode: HttpStatusCode.Accepted);
            }
            var response = _runner.ExecuteRequestWithHeaders(destBlobUri,
                                                             "PUT",
                                                             null,
                                                             new[] {
                Tuple.Create("x-ms-version", "2013-08-15"),
                Tuple.Create("x-ms-copy-source", "http://localhost/test/test.txt"),
            },
                                                             HttpStatusCode.Accepted);

            Assert.IsNotNull(response.Headers.GetValues("x-ms-copy-id"));
            Assert.AreEqual("success", response.Headers.GetValues("x-ms-copy-status").First());

            pipelineResponse = BlobPipelineTests.BlobRequest("GET", destBlobUri);
            Assert.AreEqual(sourceHost, new Uri(pipelineResponse.Location).Host);

            // Cleanup
            _runner.ExecuteRequest(destBlobUri,
                                   "DELETE",
                                   expectedStatusCode: HttpStatusCode.Accepted);
        }