public async Task UnregisterSubscriptionLocation(string location) { await Task.Delay(TimeSpan.FromMilliseconds(1)); lock (locker) { var managementClient = ServiceLocator.Instance.Locate <IHDInsightManagementRestClientFactory>().Create(this.credentials, IntegrationTestBase.GetAbstractionContext(), false); var payload = managementClient.ListCloudServices().WaitForResult(); var clusters = new PayloadConverter().DeserializeListContainersResult(payload.Content, this.credentials.DeploymentNamespace, this.credentials.SubscriptionId); if (clusters.Any(cluster => cluster.Location == location)) { throw new InvalidOperationException("Cannot unregister a subscription location if it contains clusters"); } List <string> registeredLocations; if (!subcriptions.TryGetValue(credentials.SubscriptionId, out registeredLocations)) { throw new InvalidOperationException("Invalid subscription"); } // The service doesn't fail if the location wasn't registered if (!registeredLocations.Any(registeredLocation => string.Equals(registeredLocation, location))) { var resolver = ServiceLocator.Instance.Locate <ICloudServiceNameResolver>(); string regionCloudServicename = resolver.GetCloudServiceName(this.credentials.SubscriptionId, this.credentials.DeploymentNamespace, location); throw new HttpLayerException( HttpStatusCode.NotFound, string.Format("The cloud service with name {0} was not found.", regionCloudServicename)); } registeredLocations.Remove(registeredLocations.First(registeredLocation => string.Equals(registeredLocation, location))); } }