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 UpdateBlobService()
        {
            //validate current file service properties
            Assert.False(_blobService.Data.DeleteRetentionPolicy.Enabled);
            Assert.Null(_blobService.Data.DeleteRetentionPolicy.Days);

            //update delete retention policy
            BlobServiceData serviceData = _blobService.Data;

            serviceData.DeleteRetentionPolicy = new DeleteRetentionPolicy
            {
                Enabled = true,
                Days    = 100
            };
            BlobService service = (await _blobService.CreateOrUpdateAsync(serviceData)).Value;

            //validate update
            Assert.True(service.Data.DeleteRetentionPolicy.Enabled);
            Assert.AreEqual(service.Data.DeleteRetentionPolicy.Days, 100);
        }
        public async Task BlobContainersVLW()
        {
            //update storage account to v2
            StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters()
            {
                Kind = Kind.StorageV2
            };

            _storageAccount = await _storageAccount.UpdateAsync(updateParameters);

            _blobService = await _blobService.GetAsync();

            //enable blob versioning
            BlobServiceData properties = _blobService.Data;

            properties.IsVersioningEnabled = true;
            _blobService = (await _blobService.CreateOrUpdateAsync(properties)).Value;
            Assert.IsTrue(properties.IsVersioningEnabled);

            //create container with VLW
            string            containerName1 = Recording.GenerateAssetName("testblob1");
            BlobContainerData parameters1    = new BlobContainerData()
            {
                ImmutableStorageWithVersioning = new ImmutableStorageWithVersioning()
                {
                    Enabled = true
                }
            };
            BlobContainer container1 = (await _blobContainerCollection.CreateOrUpdateAsync(containerName1, parameters1)).Value;

            Assert.IsTrue(container1.Data.ImmutableStorageWithVersioning.Enabled);
            Assert.IsNull(container1.Data.ImmutableStorageWithVersioning.MigrationState);

            //update container to enabled  Immutability Policy
            string            containerName2 = Recording.GenerateAssetName("testblob2");
            BlobContainerData parameters2    = new BlobContainerData();
            BlobContainer     container2     = (await _blobContainerCollection.CreateOrUpdateAsync(containerName2, parameters2)).Value;
            await container2.GetImmutabilityPolicy().CreateOrUpdateAsync(parameters: new ImmutabilityPolicyData()
            {
                ImmutabilityPeriodSinceCreationInDays = 1
            });

            await container2.ObjectLevelWormAsync();

            container2 = await container2.GetAsync();

            Assert.IsTrue(container2.Data.ImmutableStorageWithVersioning.Enabled);
            Assert.AreEqual("Completed", container2.Data.ImmutableStorageWithVersioning.MigrationState);
        }
        public async Task PITR()
        {
            //update storage account to v2
            StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters()
            {
                Kind = Kind.StorageV2
            };

            _storageAccount = await _storageAccount.UpdateAsync(updateParameters);

            _blobService = await _blobService.GetAsync();

            BlobServiceData properties = _blobService.Data;

            properties.DeleteRetentionPolicy         = new DeleteRetentionPolicy();
            properties.DeleteRetentionPolicy.Enabled = true;
            properties.DeleteRetentionPolicy.Days    = 30;
            properties.ChangeFeed          = new ChangeFeed();
            properties.ChangeFeed.Enabled  = true;
            properties.IsVersioningEnabled = true;
            properties.RestorePolicy       = new RestorePolicyProperties(true)
            {
                Days = 5
            };

            _blobService = (await _blobService.CreateOrUpdateAsync(properties)).Value;

            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(10000);
            }

            //create restore ranges
            List <Models.BlobRestoreRange> ranges = new List <Models.BlobRestoreRange>();

            ranges.Add(new Models.BlobRestoreRange("", "container1/blob1"));
            ranges.Add(new Models.BlobRestoreRange("container1/blob2", "container2/blob3"));
            ranges.Add(new Models.BlobRestoreRange("container3/blob3", ""));

            //start restore
            Models.BlobRestoreParameters             parameters       = new Models.BlobRestoreParameters(Recording.Now.AddSeconds(-1).ToUniversalTime(), ranges);
            StorageAccountRestoreBlobRangesOperation restoreOperation = _storageAccount.RestoreBlobRanges(parameters);

            //wait for restore completion
            Models.BlobRestoreStatus restoreStatus = await restoreOperation.WaitForCompletionAsync();

            Assert.IsTrue(restoreStatus.Status == BlobRestoreProgressStatus.Complete || restoreStatus.Status == BlobRestoreProgressStatus.InProgress);
        }
        public async Task CreateGetDeleteObjectReplicationPolicy()
        {
            //create 2 storage accounts
            string accountName1 = await CreateValidAccountNameAsync("teststoragemgmt");

            string accountName2 = await CreateValidAccountNameAsync("teststoragemgmt");

            StorageAccountCreateParameters createParameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2);
            StorageAccount sourceAccount = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(accountName1, createParameters)).Value;
            StorageAccount destAccount   = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(accountName2, createParameters)).Value;

            //update 2 accounts properties
            var updateparameter = new StorageAccountUpdateParameters
            {
                AllowCrossTenantReplication = true,
                EnableHttpsTrafficOnly      = true
            };

            destAccount = await destAccount.UpdateAsync(updateparameter);

            sourceAccount = await sourceAccount.UpdateAsync(updateparameter);

            BlobService blobService1 = await destAccount.GetBlobService().GetAsync();

            BlobContainerCollection blobContainerCollection1 = blobService1.GetBlobContainers();
            BlobService             blobService2             = await destAccount.GetBlobService().GetAsync();

            BlobContainerCollection blobContainerCollection2 = blobService2.GetBlobContainers();

            //enable changefeed and versoning
            blobService1.Data.IsVersioningEnabled = true;
            await blobService1.CreateOrUpdateAsync(blobService1.Data);

            //create 2 pairs of source and dest blob containers
            string        containerName1 = Recording.GenerateAssetName("testblob1");
            string        containerName2 = Recording.GenerateAssetName("testblob2");
            string        containerName3 = Recording.GenerateAssetName("testblob3");
            string        containerName4 = Recording.GenerateAssetName("testblob4");
            BlobContainer container1     = (await blobContainerCollection1.CreateOrUpdateAsync(containerName1, new BlobContainerData())).Value;
            BlobContainer container2     = (await blobContainerCollection2.CreateOrUpdateAsync(containerName2, new BlobContainerData())).Value;
            BlobContainer container3     = (await blobContainerCollection1.CreateOrUpdateAsync(containerName3, new BlobContainerData())).Value;
            BlobContainer container4     = (await blobContainerCollection2.CreateOrUpdateAsync(containerName4, new BlobContainerData())).Value;

            //prepare rules and policy
            ObjectReplicationPolicyData parameter = new ObjectReplicationPolicyData()
            {
                SourceAccount      = sourceAccount.Id.Name,
                DestinationAccount = destAccount.Id.Name
            };
            List <string> prefix = new List <string>();

            prefix.Add("aa");
            prefix.Add("bc d");
            prefix.Add("123");
            string minCreationTime = "2021-03-19T16:06:00Z";
            List <ObjectReplicationPolicyRule> rules = new List <ObjectReplicationPolicyRule>();

            parameter.Rules.Add(
                new ObjectReplicationPolicyRule(containerName1, containerName2)
            {
                Filters = new ObjectReplicationPolicyFilter(prefix, minCreationTime),
            }
                );
            parameter.Rules.Add(
                new ObjectReplicationPolicyRule(containerName3, containerName4)
                );

            //create policy
            ObjectReplicationPolicyCollection objectReplicationPolicyCollection = destAccount.GetObjectReplicationPolicies();
            ObjectReplicationPolicy           objectReplicationPolicy           = (await objectReplicationPolicyCollection.CreateOrUpdateAsync("default", parameter)).Value;

            Assert.NotNull(objectReplicationPolicy);
            Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name);
            Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name);

            //get policy
            List <ObjectReplicationPolicy> policies = await objectReplicationPolicyCollection.GetAllAsync().ToEnumerableAsync();

            objectReplicationPolicy = policies[0];
            Assert.NotNull(objectReplicationPolicy);
            Assert.AreEqual(objectReplicationPolicy.Data.DestinationAccount, destAccount.Id.Name);
            Assert.AreEqual(objectReplicationPolicy.Data.SourceAccount, sourceAccount.Id.Name);

            //delete policy
            await objectReplicationPolicy.DeleteAsync();
        }