public void GetsResourcesGroups() { List <Resource> result = new List <Resource>(); Resource expected = new Resource() { Id = "/subscriptions/aaaa/resourceGroups/foo/providers/Microsoft.Web/serverFarms/" + resourceName, Name = resourceName, Location = resourceGroupLocation, Type = resourceType, ProvisioningState = "Running", Properties = serializedProperties }; FilterResourcesOptions inputParameters = new FilterResourcesOptions { Name = resourceName, ResourceType = resourceType, ResourceGroup = resourceGroupName, }; result.Add(expected); resourcesClientMock.Setup(f => f.FilterResources(inputParameters)).Returns(result); cmdlet.ResourceGroupName = resourceGroupName; cmdlet.ExecuteCmdlet(); Assert.Equal(1, result.Count); Assert.Equal(resourceGroupLocation, result[0].Location); Assert.Equal(resourceType, result[0].Type); Assert.Equal("Running", result[0].ProvisioningState); Assert.Equal(serializedProperties, result[0].Properties); }
public static List <GenericResource> FilterResources(this IResourceManagementClient client, FilterResourcesOptions options) { List <GenericResource> resources = new List <GenericResource>(); if (!string.IsNullOrEmpty(options.ResourceGroup) && !string.IsNullOrEmpty(options.Name)) { resources.Add(client.Resources.Get(options.ResourceGroup, null, null, null, options.Name, null)); } else { if (!string.IsNullOrEmpty(options.ResourceGroup)) { Rest.Azure.IPage <GenericResource> result = client.ResourceGroups.ListResources(options.ResourceGroup, new Rest.Azure.OData.ODataQuery <GenericResourceFilter>(r => r.ResourceType == options.ResourceType)); resources.AddRange(result); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = client.ResourceGroups.ListResourcesNext(result.NextPageLink); resources.AddRange(result); } } else { Rest.Azure.IPage <GenericResource> result = client.Resources.List( new Rest.Azure.OData.ODataQuery <GenericResourceFilter>(r => r.ResourceType == options.ResourceType)); resources.AddRange(result); while (!string.IsNullOrEmpty(result.NextPageLink)) { result = client.Resources.ListNext(result.NextPageLink); resources.AddRange(result); } } } foreach (var resource in resources) { var identifier = new ResourceIdentifier(resource.Id); resource.ResourceGroupName = identifier.ResourceGroupName; } return(resources); }