コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static HttpWebRequest GetBlockListRequest(BlobContext context, string containerName, string blobName, BlockListingFilter typesOfBlocks, AccessCondition accessCondition)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName, blobName);
            OperationContext opContext = new OperationContext();
            HttpWebRequest   request   = BlobHttpWebRequestFactory.GetBlockList(uri, context.Timeout, null /* snapshot */, typesOfBlocks, accessCondition, opContext);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual("GET", request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #4
0
        public static HttpWebRequest ListContainersRequest(BlobContext context, ListingContext listingContext)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address);
            OperationContext opContext = new OperationContext();
            HttpWebRequest   request   = ContainerHttpWebRequestFactory.List(uri, context.Timeout, listingContext, ContainerListingDetails.Metadata, opContext);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual("GET", request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #5
0
        public static HttpWebRequest DeleteBlobRequest(BlobContext context, string containerName, string blobName, AccessCondition accessCondition)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName, blobName);
            OperationContext opContext = new OperationContext();
            HttpWebRequest   request   = BlobHttpWebRequestFactory.Delete(uri, context.Timeout, null /* snapshot */, DeleteSnapshotsOption.None, accessCondition, true, opContext);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual("DELETE", request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #6
0
        public static HttpWebRequest CreateContainerRequest(BlobContext context, string containerName)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
            OperationContext opContext = new OperationContext();
            HttpWebRequest   request   = ContainerHttpWebRequestFactory.Create(uri, context.Timeout, opContext);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual("PUT", request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #7
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);
        }
コード例 #8
0
 /// <summary>
 /// Validates a response to a break lease operation.
 /// </summary>
 /// <param name="response">The response to validate.</param>
 /// <param name="expectedLeaseTime">The expected remaining lease time.</param>
 /// <param name="errorMargin">The error margin on the expected remaining lease time.</param>
 /// <param name="expectedError">The error status code to expect.</param>
 public static void BreakLeaseResponse(HttpWebResponse response, int expectedLeaseTime, int errorMargin, HttpStatusCode?expectedError)
 {
     Assert.IsNotNull(response);
     if (expectedError == null)
     {
         Assert.AreEqual(HttpStatusCode.Accepted, response.StatusCode, response.StatusDescription);
         BlobTestUtils.LeaseIdHeader(response, null);
         BlobTestUtils.LeaseTimeHeader(response, expectedLeaseTime, errorMargin);
         BlobTestUtils.RequestIdHeader(response);
     }
     else
     {
         Assert.AreEqual(expectedError, response.StatusCode, response.StatusDescription);
     }
 }
コード例 #9
0
 /// <summary>
 /// Validates a response to a release lease operation.
 /// </summary>
 /// <param name="response">The response to validate.</param>
 /// <param name="expectedError">The error status code to expect.</param>
 public static void ReleaseLeaseResponse(HttpWebResponse response, HttpStatusCode?expectedError)
 {
     Assert.IsNotNull(response);
     if (expectedError == null)
     {
         Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, response.StatusDescription);
         BlobTestUtils.LeaseIdHeader(response, null);
         BlobTestUtils.LeaseTimeHeader(response, null, null);
         BlobTestUtils.RequestIdHeader(response);
     }
     else
     {
         Assert.AreEqual(expectedError, response.StatusCode, response.StatusDescription);
     }
 }
コード例 #10
0
        public static HttpRequestMessage GetBlockListRequest(BlobContext context, string containerName, string blobName, BlockListingFilter typesOfBlocks, AccessCondition accessCondition)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName, blobName);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = BlobHttpRequestMessageFactory.GetBlockList(uri, context.Timeout, null /* snapshot */, typesOfBlocks, accessCondition, null,
                                                                                      opContext,
                                                                                      SharedKeyCanonicalizer.Instance,
                                                                                      context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Get, request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #11
0
        public static HttpRequestMessage ListContainersRequest(BlobContext context, ListingContext listingContext)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = ContainerHttpRequestMessageFactory.List(uri, context.Timeout, listingContext, ContainerListingDetails.Metadata, null,
                                                                                   opContext,
                                                                                   SharedKeyCanonicalizer.Instance,
                                                                                   context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Get, request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #12
0
        public static HttpRequestMessage DeleteContainerRequest(BlobContext context, string containerName, AccessCondition accessCondition)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = ContainerHttpRequestMessageFactory.Delete(uri, context.Timeout, accessCondition, null,
                                                                                     opContext,
                                                                                     SharedKeyCanonicalizer.Instance,
                                                                                     context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Delete, request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
コード例 #13
0
        /// <summary>
        /// Generates and validates a request to release 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="leaseID">The lease ID.</param>
        /// <returns>A web request for the operation.</returns>
        public static HttpWebRequest ReleaseLeaseRequest(BlobContext context, string containerName, string blobName, AccessCondition accessCondition)
        {
            HttpWebRequest   request;
            OperationContext opContext = new OperationContext();

            if (blobName != null)
            {
                // blob lease
                Uri uri = BlobTests.ConstructPutUri(context.Address, containerName, blobName);
                request = BlobHttpWebRequestFactory.Lease(
                    uri,
                    context.Timeout,
                    LeaseAction.Release,
                    null /* proposed lease ID */,
                    null /* lease duration */,
                    null /* break period */,
                    accessCondition,
                    opContext);
            }
            else
            {
                // container lease
                Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
                request = ContainerHttpWebRequestFactory.Lease(
                    uri,
                    context.Timeout,
                    LeaseAction.Release,
                    null /* proposed lease ID */,
                    null /* lease duration */,
                    null /* break period */,
                    accessCondition,
                    opContext);
            }
            Assert.IsNotNull(request);
            Assert.AreEqual("PUT", request.Method);
            BlobTestUtils.VersionHeader(request, false);
            BlobTestUtils.LeaseIdHeader(request, accessCondition == null ? null : accessCondition.LeaseId);
            BlobTestUtils.LeaseActionHeader(request, "release");
            BlobTestUtils.LeaseDurationHeader(request, null);
            BlobTestUtils.ProposedLeaseIdHeader(request, null);
            BlobTestUtils.BreakPeriodHeader(request, null);
            return(request);
        }
コード例 #14
0
        /// <summary>
        /// Validates a response to an acquire lease operation.
        /// </summary>
        /// <param name="response">The response to validate.</param>
        /// <param name="expectedLeaseId">The expected lease ID.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        public static void AcquireLeaseResponse(HttpWebResponse response, string expectedLeaseId, HttpStatusCode?expectedError)
        {
            Assert.IsNotNull(response);
            if (expectedError == null)
            {
                Assert.AreEqual(HttpStatusCode.Created, response.StatusCode, response.StatusDescription);

                if (expectedLeaseId != null)
                {
                    BlobTestUtils.LeaseIdHeader(response, expectedLeaseId);
                }
                else
                {
                    BlobTestUtils.LeaseIdHeader(response);
                }

                BlobTestUtils.LeaseTimeHeader(response, null, null);
                BlobTestUtils.RequestIdHeader(response);
            }
            else
            {
                Assert.AreEqual(expectedError, response.StatusCode, response.StatusDescription);
            }
        }
コード例 #15
0
        /// <summary>
        /// Validates a response to a change lease operation.
        /// </summary>
        /// <param name="response">The response to validate.</param>
        /// <param name="expectedLeaseId">The expected lease ID.</param>
        /// <param name="expectedError">The error status code to expect.</param>
        public static void ChangeLeaseResponse(HttpResponseMessage response, string expectedLeaseId, HttpStatusCode?expectedError)
        {
            Assert.IsNotNull(response);
            if (expectedError == null)
            {
                Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, response.ReasonPhrase);

                if (expectedLeaseId != null)
                {
                    BlobTestUtils.LeaseIdHeader(response, expectedLeaseId);
                }
                else
                {
                    BlobTestUtils.LeaseIdHeader(response);
                }

                BlobTestUtils.LeaseTimeHeader(response, null, null);
                BlobTestUtils.RequestIdHeader(response);
            }
            else
            {
                Assert.AreEqual(expectedError, response.StatusCode, response.ReasonPhrase);
            }
        }