public async Task ManagedHsmListKeys()
        {
            List <string>     resourceIds = new List <string>();
            List <ManagedHsm> vaultList   = new List <ManagedHsm>();

            Location = "westus";

            string vaultName  = Recording.GenerateAssetName("sdktestvault");
            var    parameters = new ManagedHsmData(Location)
            {
                Sku        = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
                Properties = ManagedHsmProperties
            };

            parameters.Tags.InitializeFrom(Tags);

            var managedHsm = await ManagedHsmCollection.CreateOrUpdateAsync(vaultName, parameters).ConfigureAwait(false);

            Assert.NotNull(managedHsm.Value);
            Assert.NotNull(managedHsm.Value.Id);
            resourceIds.Add(managedHsm.Value.Id);
            vaultList.Add(managedHsm.Value);

            var vaults = ManagedHsmCollection.GetAllAsync();

            await foreach (var v in vaults)
            {
                Assert.True(resourceIds.Remove(v.Id));
            }

            Assert.True(resourceIds.Count == 0);

            // Delete
            foreach (var item in vaultList)
            {
                await item.DeleteAsync();

                // Purge need to use loaction parameter. Update them later.
                //await item.PurgeDeletedAsync();
            }
        }
        public async Task ManagedHsmFull()
        {
            ManagedHsmData parameters = new ManagedHsmData(Location)
            {
                Sku        = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
                Properties = ManagedHsmProperties
            };

            parameters.Tags.InitializeFrom(Tags);

            // Create a MHSM
            ArmOperation <ManagedHsmResource> managedHsm = await ManagedHsmCollection.CreateOrUpdateAsync(WaitUntil.Completed, MHSMName, parameters).ConfigureAwait(false);

            Assert.NotNull(managedHsm.Value);
            Assert.NotNull(managedHsm.Value.Id);
            ValidateVault(managedHsm.Value.Data,
                          MHSMName,
                          ResGroupName,
                          TestEnvironment.SubscriptionId,
                          TenantIdGuid,
                          Location,
                          ManagedHsmSkuFamily.B,
                          ManagedHsmSkuName.StandardB1,
                          false,
                          true,
                          new List <string> {
                ObjectId
            },
                          ManagedHsmProperties.NetworkRuleSet,
                          PublicNetworkAccess.Disabled,
                          DefSoftDeleteRetentionInDays,
                          Tags);

            // List
            AsyncPageable <ManagedHsmResource> vaults = ManagedHsmCollection.GetAllAsync();
            int count = 0;

            await foreach (ManagedHsmResource v in vaults)
            {
                if (v.Id == managedHsm.Value.Id)
                {
                    count++;
                    break;
                }
            }
            Assert.True(count == 1);

            // Update
            ManagedHsmProperties.PublicNetworkAccess          = PublicNetworkAccess.Enabled;
            ManagedHsmProperties.NetworkRuleSet.DefaultAction = "Allow";
            parameters = new ManagedHsmData(Location)
            {
                Sku        = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1),
                Properties = ManagedHsmProperties
            };
            parameters.Tags.InitializeFrom(Tags);

            ManagedHsmResource updateManagedHsm = null;

            if (Mode == RecordedTestMode.Record)
            {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        updateManagedHsm = (await ManagedHsmCollection.CreateOrUpdateAsync(WaitUntil.Completed, MHSMName, parameters).ConfigureAwait(false)).Value;
                        break;
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(120000);
                    }
                }
            }
            else
            {
                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        updateManagedHsm = (await ManagedHsmCollection.CreateOrUpdateAsync(WaitUntil.Completed, MHSMName, parameters).ConfigureAwait(false)).Value;
                        break;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            // Get
            Response <ManagedHsmResource> retrievedVault = await ManagedHsmCollection.GetAsync(MHSMName);

            ValidateVault(retrievedVault.Value.Data,
                          MHSMName,
                          ResGroupName,
                          TestEnvironment.SubscriptionId,
                          TenantIdGuid,
                          Location,
                          ManagedHsmSkuFamily.B,
                          ManagedHsmSkuName.StandardB1,
                          false,
                          true,
                          new List <string> {
                ObjectId
            },
                          ManagedHsmProperties.NetworkRuleSet,
                          PublicNetworkAccess.Enabled,
                          DefSoftDeleteRetentionInDays,
                          Tags);

            // Delete
            await retrievedVault.Value.DeleteAsync(WaitUntil.Completed);

            Assert.ThrowsAsync <RequestFailedException>(async() =>
            {
                await ManagedHsmCollection.GetAsync(MHSMName);
            });

            // Try to purge
            try
            {
                Response <DeletedManagedHsmResource> deletedMhsm = await Subscription.GetDeletedManagedHsmAsync(Location, MHSMName);

                Assert.NotNull(managedHsm.Value);
                await deletedMhsm.Value.PurgeDeletedAsync(WaitUntil.Completed);
            }
            catch (Exception)
            {
            }
        }