public async Task CreateDeleteBlobContainer() { //create blob container string containerName = Recording.GenerateAssetName("testblob"); BlobContainer container1 = (await _blobContainerCollection.CreateOrUpdateAsync(containerName, new BlobContainerData())).Value; Assert.IsNotNull(container1); Assert.AreEqual(container1.Id.Name, containerName); //validate if created successfully BlobContainer container2 = await _blobContainerCollection.GetAsync(containerName); AssertBlobContainerEqual(container1, container2); Assert.IsTrue(await _blobContainerCollection.CheckIfExistsAsync(containerName)); Assert.IsFalse(await _blobContainerCollection.CheckIfExistsAsync(containerName + "1")); BlobContainerData containerData = container1.Data; Assert.IsEmpty(containerData.Metadata); Assert.IsFalse(containerData.HasLegalHold); Assert.IsNull(containerData.PublicAccess); Assert.False(containerData.HasImmutabilityPolicy); //delete blob container BlobContainerDeleteOperation blobContainerDeleteOperation = await container1.DeleteAsync(); await blobContainerDeleteOperation.WaitForCompletionResponseAsync(); //validate if deleted successfully BlobContainer blobContainer3 = await _blobContainerCollection.GetIfExistsAsync(containerName); Assert.IsNull(blobContainer3); Assert.IsFalse(await _blobContainerCollection.CheckIfExistsAsync(containerName)); }
public async Task SaveAsync(int categoryId, string base64Img) { var categoryE = await CategoryRepository.FindAsync(categoryId) ?? throw new Exception(); if (!ImageManipulator.IsImageStream(base64Img)) { throw new Exception(); } var buffer = Convert.FromBase64String(base64Img); var resizedImgBuffer = ImageManipulator.ResizeImage( buffer, Options.CategoryThumbnail.Width, Options.CategoryThumbnail.Height, Options.CategoryThumbnail.ImageFormat); var hash = Md5Hasher.GenerateBase16Hash(resizedImgBuffer); var randomizedHash = Randomize(hash); var fileName = string.Format("{0}.{1}", randomizedHash, Options.CategoryThumbnail.ImageFormat.ToString()); await BlobContainer.DeleteAsync(categoryE.CategoryThumbnail); await BlobContainer.SaveBytesAsync(fileName, resizedImgBuffer); categoryE.CategoryThumbnail = fileName; await CategoryRepository.UpdateAsync(categoryE, autoSave : true); }
public async Task DeleteAsync(string name) { if (name == null) { throw new ArgumentNullException(); } await BlobContainer.DeleteAsync(name); }
public async Task DeleteAsync(string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentException(); } await BlobContainer.DeleteAsync(fileName); }
public async Task Delete() { #region Snippet:Managing_BlobContainers_DeleteBlobContainer BlobContainerCollection blobContainerCollection = blobService.GetBlobContainers(); BlobContainer blobContainer = await blobContainerCollection.GetAsync("myBlobContainer"); await blobContainer.DeleteAsync(WaitUntil.Completed); #endregion }
public async Task Delete() { #region Snippet:Managing_BlobContainers_DeleteBlobContainer BlobContainerContainer blobContainerContainer = blobService.GetBlobContainers(); BlobContainer blobContainer = await blobContainerContainer.GetAsync("myBlobContainer"); await blobContainer.DeleteAsync(); #endregion }
public async Task BlobContainerSoftDelete() { //update storage account to v2 StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters() { Kind = Kind.StorageV2 }; await _storageAccount.UpdateAsync(updateParameters); _blobService = await _blobService.GetAsync(); BlobServiceData properties = _blobService.Data; //enable container softdelete properties.ContainerDeleteRetentionPolicy = new DeleteRetentionPolicy(); properties.ContainerDeleteRetentionPolicy.Enabled = true; properties.ContainerDeleteRetentionPolicy.Days = 30; _blobService = (await _blobService.CreateOrUpdateAsync(properties)).Value; //create two blob containers and delete 1 string containerName1 = Recording.GenerateAssetName("testblob1"); string containerName2 = Recording.GenerateAssetName("testblob2"); BlobContainer container1 = (await _blobContainerCollection.CreateOrUpdateAsync(containerName1, new BlobContainerData())).Value; BlobContainer container2 = (await _blobContainerCollection.CreateOrUpdateAsync(containerName2, new BlobContainerData())).Value; await container2.DeleteAsync(); //list delete included List <BlobContainer> blobContainers = await _blobContainerCollection.GetAllAsync(include : ListContainersInclude.Deleted).ToEnumerableAsync(); Assert.AreEqual(2, blobContainers.Count); foreach (BlobContainer con in blobContainers) { if (con.Data.Name == containerName1) { Assert.IsFalse(con.Data.Deleted); } else { Assert.IsTrue(con.Data.Deleted); Assert.NotNull(con.Data.RemainingRetentionDays); } } //list without delete included blobContainers = await _blobContainerCollection.GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(1, blobContainers.Count); //disable container softdelete properties = _blobService.Data; properties.ContainerDeleteRetentionPolicy = new DeleteRetentionPolicy(); properties.DeleteRetentionPolicy.Enabled = false; _blobService = (await _blobService.CreateOrUpdateAsync(properties)).Value; properties = _blobService.Data; Assert.IsFalse(properties.ContainerDeleteRetentionPolicy.Enabled); }
public async Task ExtendImmutabilityPolicy() { //update storage account to v2 StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters() { Kind = Kind.StorageV2 }; _storageAccount = await _storageAccount.UpdateAsync(updateParameters); _blobService = await _blobService.GetAsync(); // create a blob container string containerName = Recording.GenerateAssetName("testblob"); BlobContainerData data = new BlobContainerData(); BlobContainer container = (await _blobContainerCollection.CreateOrUpdateAsync(containerName, new BlobContainerData())).Value; //create immutability policy ImmutabilityPolicyData immutabilityPolicyModel = new ImmutabilityPolicyData() { ImmutabilityPeriodSinceCreationInDays = 3 }; ImmutabilityPolicy immutabilityPolicy = (await container.GetImmutabilityPolicy().CreateOrUpdateAsync(ifMatch: "", parameters: immutabilityPolicyModel)).Value; //validate Assert.NotNull(immutabilityPolicy.Data.Id); Assert.NotNull(immutabilityPolicy.Data.Type); Assert.NotNull(immutabilityPolicy.Data.Name); Assert.AreEqual(3, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays); Assert.AreEqual(ImmutabilityPolicyState.Unlocked, immutabilityPolicy.Data.State); //lock immutability policy immutabilityPolicy = await container.GetImmutabilityPolicy().LockImmutabilityPolicyAsync(ifMatch: immutabilityPolicy.Data.Etag); Assert.NotNull(immutabilityPolicy.Data.Id); Assert.NotNull(immutabilityPolicy.Data.Type); Assert.NotNull(immutabilityPolicy.Data.Name); Assert.AreEqual(3, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays); Assert.AreEqual(ImmutabilityPolicyState.Locked, immutabilityPolicy.Data.State); //extend immutability policy immutabilityPolicyModel = new ImmutabilityPolicyData() { ImmutabilityPeriodSinceCreationInDays = 100 }; immutabilityPolicy = await container.GetImmutabilityPolicy().ExtendImmutabilityPolicyAsync(ifMatch: immutabilityPolicy.Data.Etag, parameters: immutabilityPolicyModel); Assert.NotNull(immutabilityPolicy.Data.Id); Assert.NotNull(immutabilityPolicy.Data.Type); Assert.NotNull(immutabilityPolicy.Data.Name); Assert.AreEqual(100, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays); Assert.AreEqual(ImmutabilityPolicyState.Locked, immutabilityPolicy.Data.State); await container.DeleteAsync(); }
public async Task DeleteContainer() { var data = BlobServiceClientBuilder.GenerateSeedData(); var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data); string containerName = data.Containers[0].Name; BlobContainer container = await client.GetContainerReferenceAsync(containerName); await container.DeleteAsync(); Assert.DoesNotContain(data.Containers, c => c.Name == container.Name); }
public async Task DeleteContainer_ShouldReturnServerError() { var data = BlobServiceClientBuilder.GenerateSeedData(); var apiMockOptiosn = new ApiMockOptions() { ThrowInternalServerError = true }; var client = BlobServiceClientBuilder.GetBlobServiceClientMock(data, apiMockOptiosn); string containerName = data.Containers[data.Containers.Count - 1].Name; BlobContainer container = await client.GetContainerReferenceAsync(containerName); Exception ex = await Assert.ThrowsAsync <BlobServiceException>( async() => await container.DeleteAsync()); }
public virtual async Task DeleteAsync(string name) { await BlobContainer.DeleteAsync(name); }
public async Task GetBlobContainer() { string containerName = Recording.GenerateAssetName("testblob"); BlobContainer container = (await _blobContainerCollection.CreateOrUpdateAsync(true, containerName, new BlobContainerData())).Value; Assert.IsEmpty(container.Data.Metadata); Assert.Null(container.Data.PublicAccess); LegalHold legalHoldModel = new LegalHold(new List <string> { "tag1", "tag2", "tag3" }); LegalHold legalHold = await container.SetLegalHoldAsync(legalHoldModel); Assert.IsTrue(legalHold.HasLegalHold); Assert.AreEqual(new List <string> { "tag1", "tag2", "tag3" }, legalHold.Tags); ImmutabilityPolicyData immutabilityPolicyModel = new ImmutabilityPolicyData() { ImmutabilityPeriodSinceCreationInDays = 3 }; ImmutabilityPolicy immutabilityPolicy = (await container.GetImmutabilityPolicy().CreateOrUpdateAsync(true, immutabilityPolicyModel)).Value; Assert.NotNull(immutabilityPolicy.Id); Assert.NotNull(immutabilityPolicy.Data.Type); Assert.NotNull(immutabilityPolicy.Data.Name); Assert.AreEqual(3, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays); Assert.AreEqual(ImmutabilityPolicyState.Unlocked, immutabilityPolicy.Data.State); immutabilityPolicy = await container.GetImmutabilityPolicy().LockImmutabilityPolicyAsync(immutabilityPolicy.Data.Etag); Assert.NotNull(immutabilityPolicy.Id); Assert.NotNull(immutabilityPolicy.Data.Type); Assert.NotNull(immutabilityPolicy.Data.Name); Assert.AreEqual(3, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays); Assert.AreEqual(ImmutabilityPolicyState.Locked, immutabilityPolicy.Data.State); immutabilityPolicyModel = new ImmutabilityPolicyData() { ImmutabilityPeriodSinceCreationInDays = 100 }; immutabilityPolicy = await container.GetImmutabilityPolicy().ExtendImmutabilityPolicyAsync(immutabilityPolicy.Data.Etag, parameters: immutabilityPolicyModel); Assert.NotNull(immutabilityPolicy.Id); Assert.NotNull(immutabilityPolicy.Data.Type); Assert.NotNull(immutabilityPolicy.Data.Name); Assert.AreEqual(100, immutabilityPolicy.Data.ImmutabilityPeriodSinceCreationInDays); Assert.AreEqual(ImmutabilityPolicyState.Locked, immutabilityPolicy.Data.State); container = await container.GetAsync(); Assert.IsEmpty(container.Data.Metadata); Assert.AreEqual(PublicAccess.None, container.Data.PublicAccess); Assert.AreEqual(3, container.Data.ImmutabilityPolicy.UpdateHistory.Count); Assert.AreEqual(ImmutabilityPolicyUpdateType.Put, container.Data.ImmutabilityPolicy.UpdateHistory[0].Update); Assert.AreEqual(ImmutabilityPolicyUpdateType.Lock, container.Data.ImmutabilityPolicy.UpdateHistory[1].Update); Assert.AreEqual(ImmutabilityPolicyUpdateType.Extend, container.Data.ImmutabilityPolicy.UpdateHistory[2].Update); Assert.IsTrue(container.Data.LegalHold.HasLegalHold); Assert.AreEqual(3, container.Data.LegalHold.Tags.Count); Assert.AreEqual("tag1", container.Data.LegalHold.Tags[0].Tag); Assert.AreEqual("tag2", container.Data.LegalHold.Tags[1].Tag); Assert.AreEqual("tag3", container.Data.LegalHold.Tags[2].Tag); legalHold = await container.ClearLegalHoldAsync(legalHold); Assert.IsFalse(legalHold.HasLegalHold); await container.DeleteAsync(true); }