コード例 #1
0
ファイル: BlobProtocolTest.cs プロジェクト: Ankitvaibs/SM
        public void BlobProtocolGetContainerWithEmptyHeader()
        {
            ListingContext listingContext = new ListingContext("default", null);

            cloudOwnerAsync.CreateContainer("emptyheadercontainer", true);

            HttpWebRequest request = BlobTests.ListContainersRequest(cloudOwnerAsync.BlobContext, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (cloudOwnerAsync.BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, cloudOwnerAsync.BlobContext);
                request.Headers.Add("x-ms-blob-application-metadata", "");
            }
            using (HttpWebResponse response = BlobTestUtils.GetResponse(request, cloudOwnerAsync.BlobContext))
            {
                BlobTests.ListContainersResponse(response, cloudOwnerAsync.BlobContext, null);
            }

            request = BlobTests.ListContainersRequest(cloudOwnerAsync.BlobContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (cloudOwnerAsync.BlobContext.Credentials != null)
            {
                request.Headers.Add("x-ms-blob-application-metadata", "");
                BlobTests.SignRequest(request, cloudOwnerAsync.BlobContext);
            }
            using (HttpWebResponse response = BlobTestUtils.GetResponse(request, cloudOwnerAsync.BlobContext))
            {
                BlobTests.ListContainersResponse(response, cloudOwnerAsync.BlobContext, HttpStatusCode.OK);
            }
        }
コード例 #2
0
        public void GetBlockListScenarioTest(string containerName, string blobName, BlockListingFilter typesOfBlocks, string leaseId, HttpStatusCode?expectedError, params string[] expectedBlocks)
        {
            HttpWebRequest request = BlobTests.GetBlockListRequest(BlobContext, containerName, blobName, typesOfBlocks, AccessCondition.GenerateLeaseCondition(leaseId));

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);

            try
            {
                BlobTests.GetBlockListResponse(response, BlobContext, expectedError);
                GetBlockListResponse getBlockListResponse = new GetBlockListResponse(response.GetResponseStream());
                int i = 0;
                foreach (ListBlockItem item in getBlockListResponse.Blocks)
                {
                    if (expectedBlocks == null)
                    {
                        Assert.Fail("Should not have blocks.");
                    }
                    Assert.IsTrue(i < expectedBlocks.Length, "Unexpected block: " + item.Name);
                    Assert.AreEqual <string>(expectedBlocks[i++], item.Name, "Incorrect block.");
                }
                if (expectedBlocks != null && i < expectedBlocks.Length)
                {
                    Assert.Fail("Missing block: " + expectedBlocks[i] + "(and " + (expectedBlocks.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Close();
            }
        }
コード例 #3
0
        /// <summary>
        /// Validates a lease ID header in a response.
        /// </summary>
        /// <param name="response">The response.</param>
        public static void LeaseIdHeader(HttpResponseMessage response)
        {
            string leaseId = BlobHttpResponseParsers.GetLeaseId(response);

            Assert.IsNotNull(leaseId);
            Assert.IsTrue(BlobTests.LeaseIdValidator(AccessCondition.GenerateLeaseCondition(leaseId)));
        }
コード例 #4
0
        public async Task CreateBlob(string containerName, string blobName, bool isPublic)
        {
            Properties = new BlobProperties()
            {
                BlobType = BlobType.BlockBlob
            };
            HttpRequestMessage request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, Properties, BlobType.BlockBlob, Content, 0, null);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");

            //HttpRequestHandler.SetContentLength(request, Content.Length);

            CancellationTokenSource timeout = new CancellationTokenSource(30000);

            request.Content = new ByteArrayContent(Content);
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext, timeout))
            {
                HttpStatusCode statusCode        = response.StatusCode;
                string         statusDescription = response.ReasonPhrase;

                if (statusCode != HttpStatusCode.Created)
                {
                    Assert.Fail(string.Format("Failed to create blob: {0}, Status: {1}, Status Description: {2}", containerName, statusCode, statusDescription));
                }
            }
        }
コード例 #5
0
        public void CreateContainer(string containerName, bool isPublic, int retries, int millisecondsBetweenRetries)
        {
            while (true)
            {
                HttpWebRequest request = BlobTests.CreateContainerRequest(BlobContext, containerName);
                Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
                if (isPublic)
                {
                    request.Headers["x-ms-blob-public-access"] = "container";
                }
                if (BlobContext.Credentials != null)
                {
                    BlobTests.SignRequest(request, BlobContext);
                }
                HttpWebResponse response              = BlobTestUtils.GetResponse(request, BlobContext);
                HttpStatusCode  statusCode            = response.StatusCode;
                string          statusDescription     = response.StatusDescription;
                StorageExtendedErrorInformation error = StorageExtendedErrorInformation.ReadFromStream(response.GetResponseStream());
                response.Close();

                // if the container is being deleted, retry up to the specified times.
                if (statusCode == HttpStatusCode.Conflict && error != null && error.ErrorCode == BlobErrorCodeStrings.ContainerBeingDeleted && retries > 0)
                {
                    Thread.Sleep(millisecondsBetweenRetries);
                    retries--;
                    continue;
                }

                break;
            }
        }
コード例 #6
0
        public void PutBlockListScenarioTest(string containerName, string blobName, List <PutBlockListItem> blocks, BlobProperties blobProperties, string leaseId, HttpStatusCode?expectedError)
        {
            HttpWebRequest request = BlobTests.PutBlockListRequest(BlobContext, containerName, blobName, blobProperties, AccessCondition.GenerateLeaseCondition(leaseId));

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            byte[] content;
            using (MemoryStream stream = new MemoryStream())
            {
                BlobRequest.WriteBlockListBody(blocks, stream);
                stream.Seek(0, SeekOrigin.Begin);
                content = new byte[stream.Length];
                stream.Read(content, 0, content.Length);
            }
            request.ContentLength = content.Length;
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            BlobTestUtils.SetRequest(request, BlobContext, content);
            HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);

            try
            {
                BlobTests.PutBlockListResponse(response, BlobContext, expectedError);
            }
            finally
            {
                response.Close();
            }
        }
コード例 #7
0
        /// <summary>
        /// Sends a get blob range request with the given parameters and validates both request and response.
        /// </summary>
        /// <param name="containerName">The blob's container's name.</param>
        /// <param name="blobName">The blob's name.</param>
        /// <param name="leaseId">The lease ID, or null if there is no lease.</param>
        /// <param name="content">The total contents of the blob.</param>
        /// <param name="offset">The offset of the contents we will get.</param>
        /// <param name="count">The number of bytes we will get, or null to get the rest of the blob.</param>
        /// <param name="expectedError">The error code we expect from this operation, or null if we expect it to succeed.</param>
        public void GetBlobRangeScenarioTest(string containerName, string blobName, string leaseId, byte[] content, long offset, long?count, HttpStatusCode?expectedError)
        {
            HttpWebRequest request = BlobTests.GetBlobRangeRequest(BlobContext, containerName, blobName, offset, count, AccessCondition.GenerateLeaseCondition(leaseId));

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");

            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }

            HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);

            try
            {
                long   endRange        = count.HasValue ? count.Value + offset - 1 : content.Length - 1;
                byte[] selectedContent = null;

                // Compute expected content only if call is expected to succeed.
                if (expectedError == null)
                {
                    selectedContent = new byte[endRange - offset + 1];
                    Array.Copy(content, offset, selectedContent, 0, selectedContent.Length);
                }

                BlobTests.CheckBlobRangeResponse(response, BlobContext, selectedContent, offset, endRange, content.Length, expectedError);
            }
            finally
            {
                response.Close();
            }
        }
コード例 #8
0
        public void CopyFromToRestoreSnapshot(BlobContext context, string containerName, string blobName)
        {
            string oldText = "Old stuff";
            string newText = "New stuff";

            StorageCredentials  accountAndKey = new StorageCredentials(context.Account, context.Key);
            CloudStorageAccount account       = new CloudStorageAccount(accountAndKey, false);
            CloudBlobClient     blobClient    = new CloudBlobClient(new Uri(context.Address), account.Credentials);
            CloudBlobContainer  container     = blobClient.GetContainerReference(containerName);
            CloudBlockBlob      blob          = container.GetBlockBlobReference(blobName);

            BlobTestBase.UploadText(blob, oldText, Encoding.UTF8);
            CloudBlockBlob snapshot = blob.CreateSnapshot();

            Assert.IsNotNull(snapshot.SnapshotTime);
            BlobTestBase.UploadText(blob, newText, Encoding.UTF8);

            Uri sourceUri = new Uri(snapshot.Uri.AbsoluteUri + "?snapshot=" + BlobRequest.ConvertDateTimeToSnapshotString(snapshot.SnapshotTime.Value));
            OperationContext opContext = new OperationContext();
            HttpWebRequest   request   = BlobHttpWebRequestFactory.CopyFrom(blob.Uri, 30, sourceUri, null, null, opContext);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            BlobTests.SignRequest(request, context);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            Assert.AreEqual <HttpStatusCode>(response.StatusCode, HttpStatusCode.Accepted);

            string text = BlobTestBase.DownloadText(blob, Encoding.UTF8);

            Assert.AreEqual <string>(text, oldText);

            blob.Delete(DeleteSnapshotsOption.IncludeSnapshots, null, null);
        }
コード例 #9
0
        public async Task BlobProtocolGetContainerWithEmptyHeader()
        {
            ListingContext listingContext = new ListingContext("default", null);
            await cloudOwnerAsync.CreateContainer("emptyheadercontainer", true);

            HttpRequestMessage request = BlobTests.ListContainersRequest(cloudOwnerAsync.BlobContext, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            if (cloudOwnerAsync.BlobContext.Credentials != null)
            {
                request.Headers.Add("x-ms-blob-application-metadata", "");
            }
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, cloudOwnerAsync.BlobContext))
            {
                BlobTests.ListContainersResponse(response, cloudOwnerAsync.BlobContext, HttpStatusCode.OK /*HttpStatusCode.Forbidden*/);
            }

            request = BlobTests.ListContainersRequest(cloudOwnerAsync.BlobContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            if (cloudOwnerAsync.BlobContext.Credentials != null)
            {
                request.Headers.Add("x-ms-blob-application-metadata", "");
            }
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, cloudOwnerAsync.BlobContext))
            {
                BlobTests.ListContainersResponse(response, cloudOwnerAsync.BlobContext, HttpStatusCode.OK);
            }
        }
コード例 #10
0
        public static HttpWebRequest GetBlobRequest(BlobContext context, string containerName, string blobName, AccessCondition accessCondition)
        {
            bool valid = BlobTests.ContainerNameValidator(containerName) &&
                         BlobTests.BlobNameValidator(blobName) &&
                         BlobTests.LeaseIdValidator(accessCondition);

            Uri              uri       = BlobTests.ConstructGetUri(context.Address, containerName, blobName);
            HttpWebRequest   request   = null;
            OperationContext opContext = new OperationContext();

            try
            {
                request = BlobHttpWebRequestFactory.Get(uri, context.Timeout, null /* snapshot */, accessCondition, opContext);
            }
            catch (InvalidOperationException)
            {
                if (valid)
                {
                    Assert.Fail();
                }
            }
            if (valid)
            {
                Assert.IsNotNull(request);
                Assert.IsNotNull(request.Method);
                Assert.AreEqual("GET", request.Method);
                BlobTestUtils.RangeHeader(request, null);
                BlobTestUtils.LeaseIdHeader(request, accessCondition == null ? null : accessCondition.LeaseId);
            }
            return(request);
        }
コード例 #11
0
        public void ListContainersScenarioTest(ListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedContainers)
        {
            HttpWebRequest request = BlobTests.ListContainersRequest(BlobContext, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);

            try
            {
                BlobTests.ListContainersResponse(response, BlobContext, expectedError);
                ListContainersResponse listContainersResponse = new ListContainersResponse(response.GetResponseStream());
                int i = 0;
                foreach (BlobContainerEntry item in listContainersResponse.Containers)
                {
                    if (expectedContainers == null)
                    {
                        Assert.Fail("Should not have containers.");
                    }
                    Assert.IsTrue(i < expectedContainers.Length, "Unexpected container: " + item.Name);
                    Assert.AreEqual <string>(expectedContainers[i++], item.Name, "Incorrect container.");
                }
                if (expectedContainers != null && i < expectedContainers.Length)
                {
                    Assert.Fail("Missing container: " + expectedContainers[i] + "(and " + (expectedContainers.Length - i - 1) + " more).");
                }
            }
            finally
            {
                response.Close();
            }
        }
コード例 #12
0
        public async Task DeleteBlob(string containerName, string blobName)
        {
            HttpRequestMessage request = BlobTests.DeleteBlobRequest(BlobContext, containerName, blobName, null);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            await BlobTestUtils.GetResponse(request, BlobContext);
        }
コード例 #13
0
        /// <summary>
        /// Generates a get blob request over the specified range, and checks the request for consistency.
        /// </summary>
        /// <param name="context">The testing context.</param>
        /// <param name="containerName">The name of the container.</param>
        /// <param name="blobName">The name of the blob.</param>
        /// <param name="offset">The offset to the range.</param>
        /// <param name="count">The number of elements in the range.</param>
        /// <param name="leaseId">The lease ID, or null if the blob is not leased.</param>
        /// <returns>A web request for getting a blob range.</returns>
        public static HttpRequestMessage GetBlobRangeRequest(BlobContext context, string containerName, string blobName, long offset, long?count, AccessCondition accessCondition)
        {
            bool valid = BlobTests.ContainerNameValidator(containerName) &&
                         BlobTests.BlobNameValidator(blobName) &&
                         BlobTests.LeaseIdValidator(accessCondition);

            Uri uri = BlobTests.ConstructGetUri(context.Address, containerName, blobName);
            HttpRequestMessage request   = null;
            OperationContext   opContext = new OperationContext();

            try
            {
                request = BlobHttpRequestMessageFactory.Get(uri, context.Timeout, null /* snapshot */, offset, count, false, accessCondition, null, opContext, SharedKeyCanonicalizer.Instance, context.Credentials);
            }
            catch (InvalidOperationException)
            {
                if (valid)
                {
                    Assert.Fail();
                }
            }

            if (valid)
            {
                Assert.IsNotNull(request);
                Assert.IsNotNull(request.Method);
                Assert.AreEqual(HttpMethod.Get, request.Method);
                BlobTestUtils.RangeHeader(request, offset, count.HasValue ? (long?)(count.Value + offset - 1) : null);
                BlobTestUtils.LeaseIdHeader(request, accessCondition == null ? null : accessCondition.LeaseId);
            }

            return(request);
        }
コード例 #14
0
        public void CreateBlob(string containerName, string blobName, bool isPublic)
        {
            Properties = new BlobProperties()
            {
                BlobType = BlobType.BlockBlob
            };
            HttpWebRequest request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, Properties, BlobType.BlockBlob, Content, 0, null);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");

            request.ContentLength = Content.Length;
            request.Timeout       = 30000;
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            Stream stream = request.GetRequestStream();

            stream.Write(Content, 0, Content.Length);
            stream.Flush();
            stream.Close();
            HttpWebResponse response          = BlobTestUtils.GetResponse(request, BlobContext);
            HttpStatusCode  statusCode        = response.StatusCode;
            string          statusDescription = response.StatusDescription;

            response.Close();
            if (statusCode != HttpStatusCode.Created)
            {
                Assert.Fail(string.Format("Failed to create blob: {0}, Status: {1}, Status Description: {2}", containerName, statusCode, statusDescription));
            }
        }
コード例 #15
0
        public async Task CreateContainer(string containerName, bool isPublic, int retries, int millisecondsBetweenRetries)
        {
            HttpStatusCode statusCode;
            StorageExtendedErrorInformation error;

            while (true)
            {
                HttpRequestMessage request = BlobTests.CreateContainerRequest(BlobContext, containerName);
                Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
                if (isPublic)
                {
                    request.Headers.Add("x-ms-blob-public-access", "container");
                }

                using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
                {
                    statusCode = response.StatusCode;
                    string statusDescription = response.ReasonPhrase;
                    error = await StorageExtendedErrorInformation.ReadFromStreamAsync(
                        HttpResponseParsers.GetResponseStream(response));
                }

                // if the container is being deleted, retry up to the specified times.
                if (statusCode == HttpStatusCode.Conflict && error != null && error.ErrorCode == BlobErrorCodeStrings.ContainerBeingDeleted && retries > 0)
                {
                    await Task.Delay(millisecondsBetweenRetries);

                    retries--;
                    continue;
                }

                break;
            }
        }
コード例 #16
0
        public async Task GetBlockListScenarioTest(string containerName, string blobName, BlockListingFilter typesOfBlocks, string leaseId, HttpStatusCode?expectedError, params string[] expectedBlocks)
        {
            HttpRequestMessage request = BlobTests.GetBlockListRequest(BlobContext, containerName, blobName, typesOfBlocks, AccessCondition.GenerateLeaseCondition(leaseId));

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.GetBlockListResponse(response, BlobContext, expectedError);
                var getBlockListResponse = await GetBlockListResponse.ParseAsync(HttpResponseParsers.GetResponseStream(response), CancellationToken.None);

                int i = 0;
                foreach (ListBlockItem item in getBlockListResponse)
                {
                    if (expectedBlocks == null)
                    {
                        Assert.Fail("Should not have blocks.");
                    }
                    Assert.IsTrue(i < expectedBlocks.Length, "Unexpected block: " + item.Name);
                    Assert.AreEqual <string>(expectedBlocks[i++], item.Name, "Incorrect block.");
                }
                if (expectedBlocks != null && i < expectedBlocks.Length)
                {
                    Assert.Fail("Missing block: " + expectedBlocks[i] + "(and " + (expectedBlocks.Length - i - 1) + " more).");
                }
            }
        }
コード例 #17
0
        public async Task ListContainersScenarioTest(ListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedContainers)
        {
            HttpRequestMessage request = BlobTests.ListContainersRequest(BlobContext, listingContext);

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.ListContainersResponse(response, BlobContext, expectedError);
                ListContainersResponse listContainersResponse = await ListContainersResponse.ParseAsync(HttpResponseParsers.GetResponseStream(response), CancellationToken.None);

                int i = 0;
                foreach (BlobContainerEntry item in listContainersResponse.Containers)
                {
                    if (expectedContainers == null)
                    {
                        Assert.Fail("Should not have containers.");
                    }
                    Assert.IsTrue(i < expectedContainers.Length, "Unexpected container: " + item.Name);
                    Assert.AreEqual <string>(expectedContainers[i++], item.Name, "Incorrect container.");
                }
                if (expectedContainers != null && i < expectedContainers.Length)
                {
                    Assert.Fail("Missing container: " + expectedContainers[i] + "(and " + (expectedContainers.Length - i - 1) + " more).");
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Scenario test for releasing a lease.
        /// </summary>
        /// <param name="containerName">The name of the container.</param>
        /// <param name="blobName">The name of the blob, if any.</param>
        /// <param name="leaseId">The lease ID.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        public async Task ReleaseLeaseScenarioTest(string containerName, string blobName, string leaseId, HttpStatusCode?expectedError)
        {
            // Create and validate the web request
            HttpRequestMessage request = BlobTests.ReleaseLeaseRequest(BlobContext, containerName, blobName, AccessCondition.GenerateLeaseCondition(leaseId));

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.ReleaseLeaseResponse(response, expectedError);
            }
        }
コード例 #19
0
        public static void AcquireAndReleaseLeaseTest(BlobContext context, string containerName, string blobName)
        {
            CloudStorageAccount account   = new CloudStorageAccount(new StorageCredentials(context.Account, context.Key), false);
            CloudBlobClient     client    = new CloudBlobClient(new Uri(context.Address), account.Credentials);
            CloudBlobContainer  container = client.GetContainerReference(containerName);
            CloudBlockBlob      blob      = container.GetBlockBlobReference(blobName);

            BlobTestBase.UploadText(blob, "Text sent to cloud", Encoding.UTF8);

            // acquire a release on the blob and check LeaseStatus to be "locked"
            OperationContext opContext   = new OperationContext();
            HttpWebRequest   blobRequest = BlobHttpWebRequestFactory.Lease(
                blob.Uri,
                context.Timeout,
                LeaseAction.Acquire,
                null /* proposed lease ID */,
                60 /* lease duration */,
                null /* break period */,
                null /* access condition */,
                opContext);

            BlobTests.SignRequest(blobRequest, context);
            string leaseId = null;

            using (HttpWebResponse response = (HttpWebResponse)blobRequest.GetResponse())
            {
                leaseId = response.Headers["x-ms-lease-id"];
                Assert.AreEqual <HttpStatusCode>(response.StatusCode, HttpStatusCode.Created);
            }

            blob.FetchAttributes();
            Assert.AreEqual <LeaseStatus>(blob.Properties.LeaseStatus, LeaseStatus.Locked);

            // release the release on the blob and check LeaseStatus to be "unlocked"
            opContext   = new OperationContext();
            blobRequest = BlobHttpWebRequestFactory.Lease(
                blob.Uri,
                context.Timeout,
                LeaseAction.Release,
                null /* proposed lease ID */,
                null /* lease duration */,
                null /* break period */,
                AccessCondition.GenerateLeaseCondition(leaseId),
                opContext);
            BlobTests.SignRequest(blobRequest, context);
            using (HttpWebResponse response = (HttpWebResponse)blobRequest.GetResponse())
            {
                Assert.AreEqual <HttpStatusCode>(response.StatusCode, HttpStatusCode.OK);
            }

            blob.FetchAttributes();
            Assert.AreEqual <LeaseStatus>(blob.Properties.LeaseStatus, LeaseStatus.Unlocked);

            blob.Delete();
        }
コード例 #20
0
        /// <summary>
        /// Scenario test for changing a lease.
        /// </summary>
        /// <param name="containerName">The name of the container.</param>
        /// <param name="blobName">The name of the blob, if any.</param>
        /// <param name="leaseId">The lease ID.</param>
        /// <param name="proposedLeaseId">The proposed lease ID.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        /// <returns>The lease ID.</returns>
        public async Task <string> ChangeLeaseScenarioTest(string containerName, string blobName, string leaseId, string proposedLeaseId, HttpStatusCode?expectedError)
        {
            // Create and validate the web request
            HttpRequestMessage request = BlobTests.ChangeLeaseRequest(BlobContext, containerName, blobName, proposedLeaseId, AccessCondition.GenerateLeaseCondition(leaseId));

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.ChangeLeaseResponse(response, proposedLeaseId, expectedError);

                return(BlobHttpResponseParsers.GetLeaseId(response));
            }
        }
コード例 #21
0
        public async Task PutBlockScenarioTest(string containerName, string blobName, string blockId, string leaseId, byte[] content, HttpStatusCode?expectedError)
        {
            HttpRequestMessage request = BlobTests.PutBlockRequest(BlobContext, containerName, blobName, blockId, AccessCondition.GenerateLeaseCondition(leaseId));

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            //HttpRequestHandler.SetContentLength(request, content.Length);
            request.Content = new ByteArrayContent(content);
            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.PutBlockResponse(response, BlobContext, expectedError);
            }
        }
コード例 #22
0
        public async Task GetBlobScenarioTest(string containerName, string blobName, BlobProperties properties, string leaseId,
                                              byte[] content, HttpStatusCode?expectedError)
        {
            HttpRequestMessage request = BlobTests.GetBlobRequest(BlobContext, containerName, blobName, AccessCondition.GenerateLeaseCondition(leaseId));

            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.GetBlobResponse(response, BlobContext, properties, content, expectedError);
            }
        }
コード例 #23
0
        /// <summary>
        /// Scenario test for acquiring a lease.
        /// </summary>
        /// <param name="containerName">The name of the container.</param>
        /// <param name="blobName">The name of the blob, if any.</param>
        /// <param name="leaseDuration">The lease duration.</param>
        /// <param name="proposedLeaseId">The proposed lease ID.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        /// <returns>The lease ID.</returns>
        public async Task <string> AcquireLeaseScenarioTest(string containerName, string blobName, int leaseDuration, string proposedLeaseId, HttpStatusCode?expectedError)
        {
            // Create and validate the web request
            HttpRequestMessage request = BlobTests.AcquireLeaseRequest(BlobContext, containerName, blobName, leaseDuration, proposedLeaseId, null);

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.AcquireLeaseResponse(response, proposedLeaseId, expectedError);

                return(BlobHttpResponseParsers.GetLeaseId(response));
            }
        }
コード例 #24
0
        public async Task PutBlobScenarioTest(string containerName, string blobName, BlobProperties properties, BlobType blobType, byte[] content, HttpStatusCode?expectedError)
        {
            HttpRequestMessage request = BlobTests.PutBlobRequest(BlobContext, containerName, blobName, properties, blobType, content, content.Length, null);

            request.Content = new ByteArrayContent(content);
            Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
            //HttpRequestHandler.SetContentLength(request, content.Length);

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.PutBlobResponse(response, BlobContext, expectedError);
            }
        }
コード例 #25
0
        public void DeleteBlob(string containerName, string blobName)
        {
            HttpWebRequest request = BlobTests.DeleteBlobRequest(BlobContext, containerName, blobName, null);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);

            response.Close();
        }
コード例 #26
0
        /// <summary>
        /// Scenario test for breaking a lease.
        /// </summary>
        /// <param name="containerName">The name of the container.</param>
        /// <param name="blobName">The name of the blob, if any.</param>
        /// <param name="breakPeriod">The break period.</param>
        /// <param name="expectedRemainingTime">The expected remaining time.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        /// <returns>The remaining lease time.</returns>
        public async Task <int> BreakLeaseScenarioTest(string containerName, string blobName, int?breakPeriod, int?expectedRemainingTime, HttpStatusCode?expectedError)
        {
            // Create and validate the web request
            HttpRequestMessage request = BlobTests.BreakLeaseRequest(BlobContext, containerName, blobName, breakPeriod, null);

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                int expectedTime = expectedRemainingTime ?? breakPeriod.Value;
                int errorMargin  = 10;
                BlobTests.BreakLeaseResponse(response, expectedTime, errorMargin, expectedError);

                return(expectedError.HasValue ? 0 : BlobHttpResponseParsers.GetRemainingLeaseTime(response).Value);
            }
        }
コード例 #27
0
        /// <summary>
        /// Generates and validates a request to break a lease.
        /// </summary>
        /// <param name="context">The blob context.</param>
        /// <param name="containerName">The container name.</param>
        /// <param name="blobName">The blob name.</param>
        /// <param name="breakPeriod">The break period.</param>
        /// <returns>A web request for the operation.</returns>
        public static HttpRequestMessage BreakLeaseRequest(BlobContext context, string containerName, string blobName, int?breakPeriod, AccessCondition accessCondition)
        {
            HttpRequestMessage request;
            OperationContext   opContext = new OperationContext();

            if (blobName != null)
            {
                // blob lease
                Uri uri = BlobTests.ConstructPutUri(context.Address, containerName, blobName);
                request = BlobHttpRequestMessageFactory.Lease(
                    uri,
                    context.Timeout,
                    LeaseAction.Break,
                    null /* proposed lease ID */,
                    null /* lease duration */,
                    breakPeriod,
                    accessCondition,
                    null,
                    opContext,
                    SharedKeyCanonicalizer.Instance,
                    context.Credentials);
            }
            else
            {
                // container lease
                Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
                request = ContainerHttpRequestMessageFactory.Lease(
                    uri,
                    context.Timeout,
                    LeaseAction.Break,
                    null /* proposed lease ID */,
                    null /* lease duration */,
                    breakPeriod,
                    accessCondition,
                    null,
                    opContext,
                    SharedKeyCanonicalizer.Instance,
                    context.Credentials);
            }
            Assert.IsNotNull(request);
            Assert.AreEqual(HttpMethod.Put, request.Method);
            BlobTestUtils.VersionHeader(request, false);
            BlobTestUtils.LeaseIdHeader(request, null);
            BlobTestUtils.LeaseActionHeader(request, "break");
            BlobTestUtils.LeaseDurationHeader(request, null);
            BlobTestUtils.ProposedLeaseIdHeader(request, null);
            BlobTestUtils.BreakPeriodHeader(request, breakPeriod.HasValue ? breakPeriod.Value.ToString() : null);
            return(request);
        }
コード例 #28
0
        public static HttpWebRequest PutBlockListRequest(BlobContext context, string containerName, string blobName, BlobProperties blobProperties, AccessCondition accessCondition)
        {
            Uri              uri       = BlobTests.ConstructPutUri(context.Address, containerName, blobName);
            HttpWebRequest   request   = null;
            OperationContext opContext = new OperationContext();

            request = BlobHttpWebRequestFactory.PutBlockList(uri, context.Timeout, blobProperties, accessCondition, opContext);
            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual("PUT", request.Method);
            BlobTestUtils.VersionHeader(request, false);
            BlobTestUtils.ContentLanguageHeader(request, null);
            BlobTestUtils.ContentMd5Header(request, null);
            return(request);
        }
コード例 #29
0
        public void DeleteContainer(string containerName)
        {
            HttpWebRequest request = BlobTests.DeleteContainerRequest(BlobContext, containerName, null);

            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }
            HttpWebResponse response          = BlobTestUtils.GetResponse(request, BlobContext);
            HttpStatusCode  statusCode        = response.StatusCode;
            string          statusDescription = response.StatusDescription;

            response.Close();
        }
コード例 #30
0
        /// <summary>
        /// Scenario test for releasing a lease.
        /// </summary>
        /// <param name="containerName">The name of the container.</param>
        /// <param name="blobName">The name of the blob, if any.</param>
        /// <param name="leaseId">The lease ID.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        public void ReleaseLeaseScenarioTest(string containerName, string blobName, string leaseId, HttpStatusCode?expectedError)
        {
            // Create and validate the web request
            HttpWebRequest request = BlobTests.ReleaseLeaseRequest(BlobContext, containerName, blobName, AccessCondition.GenerateLeaseCondition(leaseId));

            if (BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, BlobContext);
            }

            using (HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext))
            {
                BlobTests.ReleaseLeaseResponse(response, expectedError);
            }
        }