protected void CleanupResourceGroups() { if (Mode != RecordedTestMode.Playback) { Parallel.ForEach(ResourceGroupCleanupPolicy.ResourceGroupsCreated, resourceGroup => { try { var sub = _cleanupClient.GetSubscriptions().GetIfExists(TestEnvironment.SubscriptionId); sub.Value?.GetResourceGroups().Get(resourceGroup).Value.Delete(waitForCompletion: _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.GetManagementGroup(mgmtGroupId).Delete(waitForCompletion: _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 DeploymentCollection GetDeploymentCollection(ArmClient armClient, ResourceIdentifier resourceIdentifier, string scope) { switch (scope) { case LanguageConstants.TargetScopeTypeResourceGroup: var resourceGroup = armClient.GetResourceGroup(resourceIdentifier); return(resourceGroup.GetDeployments()); case LanguageConstants.TargetScopeTypeSubscription: var subscription = armClient.GetSubscription(resourceIdentifier); return(subscription.GetDeployments()); case LanguageConstants.TargetScopeTypeManagementGroup: var managementGroup = armClient.GetManagementGroup(resourceIdentifier); return(managementGroup.GetDeployments()); default: throw new Exception(string.Format(LangServerResources.UnsupportedTargetScopeMessage, scope)); } }