Пример #1
0
        /// <summary>
        /// Test blob reads, expecting lease failure.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="targetBlob">The blob to use for the target of copy operations.</param>
        /// <param name="testAccessCondition">The failing access condition to use.</param>
        /// <param name="expectedErrorCode">The expected error code.</param>
        /// <param name="description">The reason why these calls should fail.</param>
        private async Task BlobReadExpectLeaseFailureAsync(CloudBlockBlob testBlob, CloudBlockBlob targetBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
        {
            OperationContext operationContext = new OperationContext();

            // FetchAttributes is a HEAD request with no extended error info, so it returns with the generic ConditionFailed error code.
            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.FetchAttributesAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + "(Fetch Attributes)",
                HttpStatusCode.PreconditionFailed);

            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.SnapshotAsync(null /* metadata */, testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Create Snapshot)",
                expectedStatusCode,
                expectedErrorCode);
            await TestHelper.ExpectedExceptionAsync(
                async () => await DownloadTextAsync(testBlob, Encoding.UTF8, testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Download Text)",
                expectedStatusCode,
                expectedErrorCode);

            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.OpenReadAsync(testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Read Stream)",
                expectedStatusCode/*,
                expectedErrorCode*/);
        }
Пример #2
0
        /// <summary>
        /// Test blob reads, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="targetBlob">The blob to use for the target of copy operations.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private async Task BlobReadExpectLeaseSuccessAsync(CloudBlockBlob testBlob, AccessCondition testAccessCondition)
        {
            await testBlob.FetchAttributesAsync(testAccessCondition, null /* options */, null);
            await (await testBlob.SnapshotAsync(null /* metadata */, testAccessCondition, null /* options */, null)).DeleteAsync();
            await DownloadTextAsync(testBlob, Encoding.UTF8, testAccessCondition, null /* options */, null);

            var readStream = await testBlob.OpenReadAsync(testAccessCondition, null /* options */, null);
            Stream stream = readStream.AsStreamForRead();
            stream.ReadByte();
        }
Пример #3
0
        /// <summary>
        /// Test blob reads, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private void BlobReadExpectLeaseSuccessTask(CloudBlockBlob testBlob, AccessCondition testAccessCondition)
        {
            testBlob.FetchAttributesAsync(testAccessCondition, null /* options */, new OperationContext());
            testBlob.SnapshotAsync(null /* metadata */, testAccessCondition, null /* options */, new OperationContext()).Result.Delete();
            DownloadTextTask(testBlob, Encoding.UTF8, testAccessCondition, null /* options */);

            Stream stream = testBlob.OpenReadAsync(testAccessCondition, null /* options */, new OperationContext()).Result;
            stream.ReadByte();
        }