Exemple #1
0
        /// <summary>
        /// Validates a lease time header in a response.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="expectedValue">The expected value.</param>
        /// <param name="errorMargin">The margin of error in the value.</param>
        public static void LeaseTimeHeader(HttpResponseMessage response, int?expectedValue, int?errorMargin)
        {
            int?leaseTime = BlobHttpResponseParsers.GetRemainingLeaseTime(response);

            Assert.IsFalse((expectedValue != null) && (leaseTime == null));
            if (leaseTime != null)
            {
                int error = Math.Abs(expectedValue.Value - leaseTime.Value);
                Assert.IsTrue(error < errorMargin, "Lease Time header is not within expected range.");
            }
        }
Exemple #2
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);
            }
        }