public async Task Exists() { ResourceProviderResource provider = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceProviders().GetAsync("Microsoft.Compute"); Assert.IsTrue(await provider.GetFeatures().ExistsAsync("AHUB")); Assert.IsFalse(await provider.GetFeatures().ExistsAsync("DoesNotExist")); }
public async Task Get() { ResourceProviderCollection providerCollection = (await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceProviders(); Response <ResourceProviderResource> response = await providerCollection.GetAsync("microsoft.insights"); ResourceProviderResource result = response.Value; Assert.IsNotNull(result); ResourceIdentifier fakeId = new ResourceIdentifier(result.Data.Id.ToString() + "x"); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await Client.GetResourceProviderResource(new ResourceIdentifier(fakeId)).GetAsync()); Assert.AreEqual(404, ex.Status); }
public async Task Get() { ResourceProviderResource provider = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceProviders().GetAsync("Microsoft.Compute"); FeatureResource feature = await provider.GetFeatures().GetAsync("AHUB"); Assert.IsNotNull(feature); Assert.IsNotNull(feature.Data.Id); Assert.AreEqual("Microsoft.Compute/AHUB", feature.Data.Name); Assert.IsNotNull(feature.Data.Properties); Assert.IsNotNull(feature.Data.ResourceType); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => _ = await provider.GetFeatures().GetAsync("DoesNotExist")); Assert.AreEqual(404, ex.Status); }
public async Task GetProviderPermissions() { var subscription = await Client.GetDefaultSubscriptionAsync(); var collection = subscription.GetResourceProviders(); ResourceProviderResource provider = await collection.GetAsync("Microsoft.Resources"); int count = 0; await foreach (var permission in provider.ProviderPermissionsAsync()) { count++; } Assert.Greater(count, 0); }
public async Task List() { ResourceProviderResource provider = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceProviders().GetAsync("Microsoft.Compute"); FeatureResource testFeature = null; await foreach (var feature in provider.GetFeatures().GetAllAsync()) { testFeature = feature; break; } Assert.IsNotNull(testFeature); Assert.IsNotNull(testFeature.Data.Id); Assert.IsNotNull(testFeature.Data.Name); Assert.IsNotNull(testFeature.Data.Properties); Assert.IsNotNull(testFeature.Data.ResourceType); }
public async Task RegisterAndUnregister() { //testing both register and unregister in the same test to avoid feature creep in our test subscription ResourceProviderResource provider = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceProviders().GetAsync("Microsoft.Compute"); FeatureResource feature = await provider.GetFeatures().GetAsync("AHUB"); FeatureResource afterRegister = await feature.RegisterAsync(); Assert.AreEqual(feature.Data.Id, afterRegister.Data.Id); Assert.AreEqual(feature.Data.Name, afterRegister.Data.Name); Assert.AreEqual("Pending", afterRegister.Data.Properties.State); Assert.AreEqual(feature.Data.ResourceType, afterRegister.Data.ResourceType); FeatureResource afterUnRegister = await feature.UnregisterAsync(); Assert.AreEqual(feature.Data.Id, afterUnRegister.Data.Id); Assert.AreEqual(feature.Data.Name, afterUnRegister.Data.Name); Assert.AreEqual("Unregistering", afterUnRegister.Data.Properties.State); Assert.AreEqual(feature.Data.ResourceType, afterUnRegister.Data.ResourceType); }
public async Task Get() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); ResourceProviderResource provider = await subscription.GetResourceProviders().GetAsync("Microsoft.Compute"); FeatureResource featureFromCollection = await GetFirst(provider.GetFeatures().GetAllAsync()); FeatureResource feature = await featureFromCollection.GetAsync(); Assert.AreEqual(featureFromCollection.Data.Id, feature.Data.Id); Assert.AreEqual(featureFromCollection.Data.Name, feature.Data.Name); Assert.AreEqual(featureFromCollection.Data.Properties.State, feature.Data.Properties.State); Assert.AreEqual(featureFromCollection.Data.ResourceType, feature.Data.ResourceType); ResourceIdentifier invalidId = new ResourceIdentifier(feature.Data.Id.ToString() + "x"); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => _ = await Client.GetFeatureResource(invalidId).GetAsync()); Assert.AreEqual(404, ex.Status); }
/// Get a default resource location for a given resource type /// <summary> /// </summary> /// <param name="client">The resource management client</param> /// <param name="resourceType">The type of resource to create</param> /// <returns>A location where this resource type is supported for the current subscription</returns> public static async Task <string> GetResourceLocation(ArmClient client, string resourceType) { string location = null; string[] parts = resourceType.Split('/'); string providerName = parts[0]; SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync(); ResourceProviderResource provider = await subscription.GetResourceProviders().GetAsync(providerName); foreach (var resource in provider.Data.ResourceTypes) { if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase)) { location = resource.Locations.LastOrDefault(); } } return(location); }
/// <summary> /// Get a default resource location for a given resource type /// </summary> /// <param name="client">The resource management client</param> /// <param name="resourceType">The type of resource to create</param> /// <returns>A location where this resource type is supported for the current subscription</returns> public static async Task <string> GetResourceLocation(ArmClient client, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default) { SubscriptionResource subscription = await client.GetDefaultSubscriptionAsync(); HashSet <string> supportedLocations = null; switch (feature) { case FeaturesInfo.Type.Default: supportedLocations = FeaturesInfo.DefaultLocations; break; case FeaturesInfo.Type.All: supportedLocations = FeaturesInfo.AllFeaturesSupportedLocations; break; case FeaturesInfo.Type.IPv6: supportedLocations = FeaturesInfo.IPv6SupportedLocations; break; case FeaturesInfo.Type.MultiCA: supportedLocations = FeaturesInfo.DefaultLocations; break; } string[] parts = resourceType.Split('/'); string providerName = parts[0]; ResourceProviderResource provider = await subscription.GetResourceProviders().GetAsync(providerName); foreach (var resource in provider.Data.ResourceTypes) { if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase)) { return(resource.Locations.FirstOrDefault(supportedLocations.Contains)); } } return(null); }
public virtual ResourceProviderResource GetResourceProviderResource(ResourceIdentifier id) { ResourceProviderResource.ValidateResourceId(id); return(new ResourceProviderResource(this, id)); }