public async void AcquireLease_WhenALeaseExists_ExceptionShouldBeThrown() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); var blobClient = blobContainerClient.GetBlobClient(blobName); blobClient.DeleteIfExists(); Assert.False(blobClient.Exists()); // create a new blob string blobContent = "example"; var blobUrl_1 = await blobProvider.CreateBlobAsync(blobName, new MemoryStream(Encoding.ASCII.GetBytes(blobContent)), CancellationToken.None); Assert.True(blobClient.Exists()); var lease = await blobProvider.AcquireLeaseAsync(blobName, null, TimeSpan.FromSeconds(30), default); Assert.NotNull(lease); var lease2 = await blobProvider.AcquireLeaseAsync(blobName, null, TimeSpan.FromSeconds(30), default); Assert.Null(lease2); var lease3 = await blobProvider.AcquireLeaseAsync(blobName, lease, TimeSpan.FromSeconds(30), default); Assert.Equal(lease, lease3); await blobContainerClient.DeleteAsync(); }
public async void AcquireLease_WhenBlobNotExists_NoLeaseShouldReturn() { var uniqueContainerName = Guid.NewGuid().ToString("N"); AzureBlobContainerClient blobProvider = GetTestBlobProvider(ConnectionString, uniqueContainerName); string blobName = Guid.NewGuid().ToString("N"); var lease = await blobProvider.AcquireLeaseAsync(blobName, null, TimeSpan.FromSeconds(30), default); Assert.Null(lease); var blobContainerClient = new BlobContainerClient(ConnectionString, uniqueContainerName); await blobContainerClient.DeleteIfExistsAsync(); }