protected void CleanupResourceGroups()
        {
            if (Mode != RecordedTestMode.Playback)
            {
                Parallel.ForEach(ResourceGroupCleanupPolicy.ResourceGroupsCreated, resourceGroup =>
                {
                    try
                    {
                        SubscriptionResource sub = _cleanupClient.GetSubscriptions().Exists(TestEnvironment.SubscriptionId)
                            ? _cleanupClient.GetSubscriptions().Get(TestEnvironment.SubscriptionId)
                            : null;
                        sub?.GetResourceGroups().Get(resourceGroup).Value.Delete(_waitForCleanup);
                    }
                    catch (RequestFailedException e) when(e.Status == 404)
                    {
                        //we assume the test case cleaned it up if it no longer exists.
                    }
                });

                Parallel.ForEach(ManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId =>
                {
                    try
                    {
                        _cleanupClient.GetManagementGroupResource(new ResourceIdentifier(mgmtGroupId)).Delete(_waitForCleanup);
                    }
                    catch (RequestFailedException e) when(e.Status == 404 || e.Status == 403)
                    {
                        //we assume the test case cleaned it up if it no longer exists.
                    }
                });
            }
        }
        public ArmDeploymentCollection GetDeploymentCollection(ArmClient armClient, ResourceIdentifier resourceIdentifier, string scope)
        {
            switch (scope)
            {
            case LanguageConstants.TargetScopeTypeResourceGroup:
                var resourceGroup = armClient.GetResourceGroupResource(resourceIdentifier);
                return(resourceGroup.GetArmDeployments());

            case LanguageConstants.TargetScopeTypeSubscription:
                var subscription = armClient.GetSubscriptionResource(resourceIdentifier);
                return(subscription.GetArmDeployments());

            case LanguageConstants.TargetScopeTypeManagementGroup:
                var managementGroup = armClient.GetManagementGroupResource(resourceIdentifier);
                return(managementGroup.GetArmDeployments());

            default:
                throw new Exception(string.Format(LangServerResources.UnsupportedTargetScopeMessage, scope));
            }
        }