public async Task UpdateAccountIdentityFromNoneToSystem() { _resourceGroup = await CreateResourceGroupAsync(); StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts(); string accountName = await CreateValidAccountNameAsync(namePrefix); var param = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS)); StorageAccount account1 = (await storageAccountCollection.CreateOrUpdateAsync(true, accountName, param)).Value; Assert.AreEqual(accountName, account1.Id.Name); VerifyAccountProperties(account1, false); Assert.Null(account1.Data.Identity); StorageAccountUpdateOptions parameters = new StorageAccountUpdateOptions() { Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned) }; account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(ManagedServiceIdentityType.SystemAssigned, account1.Data.Identity.Type); Assert.IsEmpty(account1.Data.Identity.UserAssignedIdentities); Assert.NotNull(account1.Data.Identity.PrincipalId); Assert.NotNull(account1.Data.Identity.TenantId); // validate StorageAccount account2 = await storageAccountCollection.GetAsync(accountName); Assert.AreEqual(ManagedServiceIdentityType.SystemAssigned, account2.Data.Identity.Type); Assert.IsEmpty(account2.Data.Identity.UserAssignedIdentities); Assert.NotNull(account2.Data.Identity.PrincipalId); Assert.NotNull(account2.Data.Identity.TenantId); }
public async Task BlobContainerSoftDelete() { //update storage account to v2 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { 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(true, properties)).Value; //create two blob containers and delete 1 string containerName1 = Recording.GenerateAssetName("testblob1"); string containerName2 = Recording.GenerateAssetName("testblob2"); BlobContainer container1 = (await _blobContainerCollection.CreateOrUpdateAsync(true, containerName1, new BlobContainerData())).Value; BlobContainer container2 = (await _blobContainerCollection.CreateOrUpdateAsync(true, containerName2, new BlobContainerData())).Value; await container2.DeleteAsync(true); //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(true, properties)).Value; properties = _blobService.Data; Assert.IsFalse(properties.ContainerDeleteRetentionPolicy.Enabled); }
public async Task ExtendImmutabilityPolicy() { //update storage account to v2 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { 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(true, containerName, new BlobContainerData())).Value; //create immutability policy ImmutabilityPolicyData immutabilityPolicyModel = new ImmutabilityPolicyData() { ImmutabilityPeriodSinceCreationInDays = 3 }; ImmutabilityPolicy immutabilityPolicy = (await container.GetImmutabilityPolicy().CreateOrUpdateAsync(true, 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(true); }
public async Task CreateDeleteListFileShareSnapshot() { //update storage account to v2 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { Kind = Kind.StorageV2 }; await _storageAccount.UpdateAsync(updateParameters); // Enable share soft delete in service properties _fileService = await _fileService.GetAsync(); FileServiceData properties = new FileServiceData() { ShareDeleteRetentionPolicy = new DeleteRetentionPolicy() { Enabled = true, Days = 5 } }; _fileService = (await _fileService.CreateOrUpdateAsync(true, properties)).Value; //create 2 file share and delete 1 string fileShareName1 = Recording.GenerateAssetName("testfileshare1"); string fileShareName2 = Recording.GenerateAssetName("testfileshare2"); FileShare share1 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData())).Value; FileShare share2 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName2, new FileShareData())).Value; await share2.DeleteAsync(true); //create 2 share snapshots FileShare shareSnapshot1 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData(), expand: "snapshots")).Value; FileShare shareSnapshot2 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData(), expand: "snapshots")).Value; //get single share snapshot FileShare shareSnapshot = await _fileShareCollection.GetAsync(fileShareName1, "stats", shareSnapshot1.Data.SnapshotTime.Value.UtcDateTime.ToString("o")); Assert.AreEqual(shareSnapshot.Data.SnapshotTime, shareSnapshot1.Data.SnapshotTime); //list share with snapshot List <FileShare> fileShares = await _fileShareCollection.GetAllAsync(expand : "snapshots").ToEnumerableAsync(); Assert.AreEqual(3, fileShares.Count); //delete share snapshot await shareSnapshot.DeleteAsync(true); // List share with deleted fileShares = await _fileShareCollection.GetAllAsync(expand : "deleted").ToEnumerableAsync(); Assert.AreEqual(2, fileShares.Count); }
public async Task UpdateAccountIdentityFromTwoUsersToOneUser() { _resourceGroup = await CreateResourceGroupAsync(); StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts(); string accountName = await CreateValidAccountNameAsync(namePrefix); var identity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned); var userAssignedIdentity1 = await CreateUserAssignedIdentityAsync(); identity.UserAssignedIdentities.Add(userAssignedIdentity1.Id.ToString(), new UserAssignedIdentity()); var userAssignedIdentity2 = await CreateUserAssignedIdentityAsync(); identity.UserAssignedIdentities.Add(userAssignedIdentity2.Id.ToString(), new UserAssignedIdentity()); var param = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS), identity: identity); StorageAccount account1 = (await storageAccountCollection.CreateOrUpdateAsync(true, accountName, param)).Value; Assert.AreEqual(accountName, account1.Id.Name); VerifyAccountProperties(account1, false); Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.Type); Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 2); Assert.Null(account1.Data.Identity.PrincipalId); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity1.Id.ToString()].PrincipalId); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id.ToString()].PrincipalId); account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity1.Id.ToString()] = null; StorageAccountUpdateOptions parameters = new StorageAccountUpdateOptions() { Identity = account1.Data.Identity }; account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.Type); Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1); Assert.Null(account1.Data.Identity.PrincipalId); Assert.Null(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity1.Id.ToString()]); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id.ToString()].PrincipalId); // validate StorageAccount account2 = await storageAccountCollection.GetAsync(accountName); Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.Type); Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1); Assert.Null(account1.Data.Identity.PrincipalId); Assert.IsFalse(account1.Data.Identity.UserAssignedIdentities.ContainsKey(userAssignedIdentity1.Id.ToString())); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id.ToString()].PrincipalId); }
public async Task UpdateAccountIdentityFromUserToTwoUsers() { _resourceGroup = await CreateResourceGroupAsync(); StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts(); string accountName = await CreateValidAccountNameAsync(namePrefix); var identity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned); var userAssignedIdentity = await CreateUserAssignedIdentityAsync(); identity.UserAssignedIdentities.Add(userAssignedIdentity.Id.ToString(), new UserAssignedIdentity()); var param = GetDefaultStorageAccountParameters(sku: new Sku(SkuName.StandardLRS), identity: identity); StorageAccount account1 = (await storageAccountCollection.CreateOrUpdateAsync(true, accountName, param)).Value; Assert.AreEqual(accountName, account1.Id.Name); VerifyAccountProperties(account1, false); Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.Type); Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1); Assert.Null(account1.Data.Identity.PrincipalId); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id.ToString()].PrincipalId); // With JSON Merge Patch, we only need to put the identity to add in the dictionary for update operation. var identity2 = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned); var userAssignedIdentity2 = await CreateUserAssignedIdentityAsync(); identity2.UserAssignedIdentities.Add(userAssignedIdentity2.Id.ToString(), new UserAssignedIdentity()); StorageAccountUpdateOptions parameters = new StorageAccountUpdateOptions() { Identity = identity2 }; account1 = await account1.UpdateAsync(parameters); Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account1.Data.Identity.Type); Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 2); Assert.Null(account1.Data.Identity.PrincipalId); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id.ToString()].PrincipalId); Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id.ToString()].PrincipalId); // validate StorageAccount account2 = await storageAccountCollection.GetAsync(accountName); Assert.AreEqual(ManagedServiceIdentityType.UserAssigned, account2.Data.Identity.Type); Assert.AreEqual(account2.Data.Identity.UserAssignedIdentities.Count, 2); Assert.Null(account2.Data.Identity.PrincipalId); Assert.NotNull(account2.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id.ToString()].PrincipalId); Assert.NotNull(account2.Data.Identity.UserAssignedIdentities[userAssignedIdentity2.Id.ToString()].PrincipalId); }
public async Task BlobContainersVLW() { //update storage account to v2 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { 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(true, 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(true, 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(true, containerName2, parameters2)).Value; await container2.GetImmutabilityPolicy().CreateOrUpdateAsync(true, parameters: new ImmutabilityPolicyData() { ImmutabilityPeriodSinceCreationInDays = 1 }); await container2.ObjectLevelWormAsync(true); 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 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { 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(true, 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); ArmOperation <BlobRestoreStatus> restoreOperation = _storageAccount.RestoreBlobRanges(false, parameters); //wait for restore completion Models.BlobRestoreStatus restoreStatus = await restoreOperation.WaitForCompletionAsync(); Assert.IsTrue(restoreStatus.Status == BlobRestoreProgressStatus.Complete || restoreStatus.Status == BlobRestoreProgressStatus.InProgress); }
public async Task FileShareAccessPolicy() { //update storage account to v2 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { Kind = Kind.StorageV2 }; await _storageAccount.UpdateAsync(updateParameters); //create share string fileShareName = Recording.GenerateAssetName("testfileshare"); FileShare share = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData())).Value; // Prepare signedIdentifiers to set List <SignedIdentifier> sigs = new List <SignedIdentifier>(); DateTimeOffset datenow = Recording.Now; DateTimeOffset start1 = datenow.ToUniversalTime(); DateTimeOffset end1 = datenow.AddHours(2).ToUniversalTime(); DateTimeOffset start2 = datenow.AddMinutes(1).ToUniversalTime(); DateTimeOffset end2 = datenow.AddMinutes(40).ToUniversalTime(); var updateParameters2 = new FileShareData(); SignedIdentifier sig1 = new SignedIdentifier("testSig1", new AccessPolicy(startTime: start1, expiryTime: end1, permission: "rw")); SignedIdentifier sig2 = new SignedIdentifier("testSig2", new AccessPolicy(startTime: start2, expiryTime: end2, permission: "rwdl")); updateParameters2.SignedIdentifiers.Add(sig1); updateParameters2.SignedIdentifiers.Add(sig2); // Update share share = await share.UpdateAsync(updateParameters2); Assert.AreEqual(2, share.Data.SignedIdentifiers.Count); Assert.AreEqual("testSig1", share.Data.SignedIdentifiers[0].Id); Assert.AreEqual("rw", share.Data.SignedIdentifiers[0].AccessPolicy.Permission); }
public async Task FileShareLease() { //update storage account to v2 StorageAccountUpdateOptions updateParameters = new StorageAccountUpdateOptions() { Kind = Kind.StorageV2 }; await _storageAccount.UpdateAsync(updateParameters); //create base share string fileShareName = Recording.GenerateAssetName("testfileshare"); FileShare share = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData())).Value; //create share snapshots FileShare shareSnapshot = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData(), "snapshots")).Value; // Acquire lease share string proposedLeaseID1 = "ca761232-ed42-11ce-bacd-00aa0057b223"; string proposedLeaseID2 = "dd761232-ed42-11ce-bacd-00aa0057b444"; LeaseShareResponse leaseResponse; leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Acquire) { LeaseDuration = 60, ProposedLeaseId = proposedLeaseID1 }); Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId); share = await share.GetAsync(); Assert.AreEqual(LeaseDuration.Fixed, share.Data.LeaseDuration); Assert.AreEqual(LeaseState.Leased, share.Data.LeaseState); Assert.AreEqual(LeaseStatus.Locked, share.Data.LeaseStatus); //renew lease share leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Renew) { LeaseId = proposedLeaseID1 }); Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId); // change lease share leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Change) { LeaseId = proposedLeaseID1, ProposedLeaseId = proposedLeaseID2 }); Assert.AreEqual(proposedLeaseID2, leaseResponse.LeaseId); //break lease share leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Break) { BreakPeriod = 20 }); Assert.AreEqual("20", leaseResponse.LeaseTimeSeconds); //release lease share leaseResponse = await share.LeaseAsync(parameters : new LeaseShareRequest(LeaseShareAction.Release) { LeaseId = proposedLeaseID2 }); Assert.IsNull(leaseResponse.LeaseId); //lease share snapshot leaseResponse = await share.LeaseAsync(xMsSnapshot : shareSnapshot.Data.SnapshotTime.Value.UtcDateTime.ToString("o"), parameters : new LeaseShareRequest(LeaseShareAction.Acquire) { LeaseDuration = 60, ProposedLeaseId = proposedLeaseID1 }); Assert.AreEqual(proposedLeaseID1, leaseResponse.LeaseId); shareSnapshot = await shareSnapshot.GetAsync(xMsSnapshot : shareSnapshot.Data.SnapshotTime.Value.UtcDateTime.ToString("o")); Assert.AreEqual(LeaseDuration.Fixed, share.Data.LeaseDuration); Assert.AreEqual(LeaseState.Leased, share.Data.LeaseState); Assert.AreEqual(LeaseStatus.Locked, share.Data.LeaseStatus); bool DeleteFail = false; // try delete with include = none try { await share.DeleteAsync(true, include : "none"); } catch (RequestFailedException e) when(e.Status == 409) { DeleteFail = true; } Assert.IsTrue(DeleteFail, "Delete should fail with include = none"); DeleteFail = false; // try delete with include = snapshots try { await share.DeleteAsync(true, include : "snapshots"); } catch (RequestFailedException e) when(e.Status == 409) { DeleteFail = true; } Assert.IsTrue(DeleteFail, "Delete should fail with include = snapshots"); //delete with include = leased-snapshots await share.DeleteAsync(true, include : "leased-snapshots"); }
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(true, accountName1, createParameters)).Value; StorageAccount destAccount = (await _resourceGroup.GetStorageAccounts().CreateOrUpdateAsync(true, accountName2, createParameters)).Value; //update 2 accounts properties var updateparameter = new StorageAccountUpdateOptions { 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(true, 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(true, containerName1, new BlobContainerData())).Value; BlobContainer container2 = (await blobContainerCollection2.CreateOrUpdateAsync(true, containerName2, new BlobContainerData())).Value; BlobContainer container3 = (await blobContainerCollection1.CreateOrUpdateAsync(true, containerName3, new BlobContainerData())).Value; BlobContainer container4 = (await blobContainerCollection2.CreateOrUpdateAsync(true, 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(true, "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(true); }