示例#1
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();
            }
        }
        /// <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 async Task GetBlobRangeScenarioTest(string containerName, string blobName, string leaseId, byte[] content, long offset, long?count, HttpStatusCode?expectedError)
        {
            HttpRequestMessage request = BlobTests.GetBlobRangeRequest(BlobContext, containerName, blobName, offset, count, AccessCondition.GenerateLeaseCondition(leaseId));

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

            using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
            {
                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);
            }
        }