public async Task AppendBlobReadLockToETagTestAsync() { byte[] outBuffer = new byte[1 * 1024 * 1024]; byte[] buffer = GetRandomBuffer(2 * outBuffer.Length); CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); CloudAppendBlob blob = container.GetAppendBlobReference("blob1"); await blob.CreateOrReplaceAsync(); blob.StreamMinimumReadSizeInBytes = outBuffer.Length; using (MemoryStream wholeBlob = new MemoryStream(buffer)) { #if !FACADE_NETCORE await blob.AppendBlockAsync(wholeBlob); #else await blob.AppendBlockAsync(wholeBlob, string.Empty, null, null, null, CancellationToken.None); #endif } OperationContext opContext = new OperationContext(); using (Stream blobStream = await blob.OpenReadAsync(null, null, opContext)) { Stream blobStreamForRead = blobStream; await blobStreamForRead.ReadAsync(outBuffer, 0, outBuffer.Length); await blob.SetMetadataAsync(); await TestHelper.ExpectedExceptionAsync( async() => await blobStreamForRead.ReadAsync(outBuffer, 0, outBuffer.Length), opContext, "Blob read stream should fail if blob is modified during read", HttpStatusCode.PreconditionFailed); } opContext = new OperationContext(); using (Stream blobStream = await blob.OpenReadAsync(null, null, opContext)) { Stream blobStreamForRead = blobStream; long length = blobStreamForRead.Length; await blob.SetMetadataAsync(); await TestHelper.ExpectedExceptionAsync( async() => await blobStreamForRead.ReadAsync(outBuffer, 0, outBuffer.Length), opContext, "Blob read stream should fail if blob is modified during read", HttpStatusCode.PreconditionFailed); } opContext = new OperationContext(); AccessCondition accessCondition = AccessCondition.GenerateIfNotModifiedSinceCondition(DateTimeOffset.Now.Subtract(TimeSpan.FromHours(1))); await blob.SetMetadataAsync(); await TestHelper.ExpectedExceptionAsync( async() => await blob.OpenReadAsync(accessCondition, null, opContext), opContext, "Blob read stream should fail if blob is modified during read", HttpStatusCode.PreconditionFailed); } finally { container.DeleteIfExistsAsync().Wait(); } }