public async Task GetProviderWithAliases()
        {
            var computeNamespace = "Microsoft.Compute";

            var reg = await ProvidersOperations.RegisterAsync(computeNamespace);

            Assert.NotNull(reg);

            var result = await ProvidersOperations.ListAsync(expand : "resourceTypes/aliases").ToEnumerableAsync();

            // Validate result
            Assert.True(result.Any());
            var computeProvider = result.First(
                provider => string.Equals(provider.Namespace, computeNamespace, StringComparison.OrdinalIgnoreCase));

            Assert.IsNotEmpty(computeProvider.ResourceTypes);
            var virtualMachinesType = computeProvider.ResourceTypes.First(
                resourceType => string.Equals(resourceType.ResourceType, "virtualMachines", StringComparison.OrdinalIgnoreCase));

            Assert.IsNotEmpty(virtualMachinesType.Aliases);
            Assert.AreEqual("Microsoft.Compute/licenseType", virtualMachinesType.Aliases[0].Name);
            Assert.AreEqual("properties.licenseType", virtualMachinesType.Aliases[0].Paths[0].Path);

            computeProvider = (await ProvidersOperations.GetAsync(resourceProviderNamespace: computeNamespace, expand: "resourceTypes/aliases")).Value;

            Assert.IsNotEmpty(computeProvider.ResourceTypes);
            virtualMachinesType = computeProvider.ResourceTypes.First(
                resourceType => string.Equals(resourceType.ResourceType, "virtualMachines", StringComparison.OrdinalIgnoreCase));

            Assert.IsNotEmpty(virtualMachinesType.Aliases);
            Assert.AreEqual("Microsoft.Compute/licenseType", virtualMachinesType.Aliases[0].Name);
            Assert.AreEqual("properties.licenseType", virtualMachinesType.Aliases[0].Paths[0].Path);
        }
        public async Task VerifyProviderRegister()
        {
            await ProvidersOperations.RegisterAsync(ProviderName);

            var provider = (await ProvidersOperations.GetAsync(ProviderName)).Value;

            Assert.True(provider.RegistrationState == "Registered" ||
                        provider.RegistrationState == "Registering");
        }
        public async Task VerifyProviderUnregister()
        {
            var registerResult = await ProvidersOperations.RegisterAsync(ProviderName);

            var provider = (await ProvidersOperations.GetAsync(ProviderName)).Value;

            Assert.True(provider.RegistrationState == "Registered" ||
                        provider.RegistrationState == "Registering");

            var unregisterResult = await ProvidersOperations.UnregisterAsync(ProviderName);

            provider = (await ProvidersOperations.GetAsync(ProviderName)).Value;
            Assert.True(provider.RegistrationState == "NotRegistered" ||
                        provider.RegistrationState == "Unregistering",
                        "RegistrationState is expected NotRegistered or Unregistering. Actual value " +
                        provider.RegistrationState);
        }
        public async Task ProviderGetValidateMessage()
        {
            var reg = await ProvidersOperations.RegisterAsync(ProviderName);

            Assert.NotNull(reg);

            var result = (await ProvidersOperations.GetAsync(ProviderName)).Value;

            // Validate result
            Assert.NotNull(result);
            Assert.IsNotEmpty(result.Id);
            Assert.AreEqual(ProviderName, result.Namespace);
            Assert.True("Registered" == result.RegistrationState ||
                        "Registering" == result.RegistrationState,
                        string.Format("Provider registration state was not 'Registered' or 'Registering', instead it was '{0}'", result.RegistrationState));
            Assert.IsNotEmpty(result.ResourceTypes);
            Assert.IsNotEmpty(result.ResourceTypes[0].Locations);
        }
示例#5
0
        protected async Task <string> GetFirstUsableLocationAsync(ProvidersOperations providersClient, string resourceProviderNamespace, string resourceType)
        {
            var provider = (await providersClient.GetAsync(resourceProviderNamespace)).Value;

            return(provider.ResourceTypes.Where(
                       (resType) =>
            {
                if (resType.ResourceType == resourceType)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
                       ).First().Locations.FirstOrDefault());
        }
示例#6
0
        /// <summary>
        /// Get default resource location for a given resource type.
        /// Once all tests are moved away from depreciated version of Resource Manager, this method should be removed
        /// and "using Microsoft.Azure.Management.Resources" should be changed to "using Microsoft.Azure.Management.ResourceManager"
        /// </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(ResourcesManagementClient client, ProvidersOperations providersOperations, string resourceType, FeaturesInfo.Type feature = FeaturesInfo.Type.Default)
        {
            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];
            Response <Provider> provider     = await providersOperations.GetAsync(providerName);

            foreach (var resource in provider.Value.ResourceTypes)
            {
                if (string.Equals(resource.ResourceType, parts[1], StringComparison.OrdinalIgnoreCase))
                {
                    return(resource.Locations.FirstOrDefault(supportedLocations.Contains));
                }
            }

            return(null);
        }
示例#7
0
        protected async Task Initialize()
        {
            var resourceManagementClient = GetResourceManagementClient();

            ResourcesClient         = resourceManagementClient.Resources;
            ResourceGroupsClient    = resourceManagementClient.ResourceGroups;
            ResourceProvidersClient = resourceManagementClient.Providers;

            var keyVaultManagementClient = GetKeyVaultManagementClient();

            VaultsClient = keyVaultManagementClient.Vaults;

            if (Mode == RecordedTestMode.Playback)
            {
                this.ObjectId = Recording.GetVariable(ObjectIdKey, string.Empty);
            }
            else if (Mode == RecordedTestMode.Record)
            {
                var spClient             = new RbacManagementClient(TestEnvironment.TenantId, TestEnvironment.Credential).ServicePrincipals;
                var servicePrincipalList = spClient.ListAsync($"appId eq '{TestEnvironment.ClientId}'");
                await foreach (var servicePrincipal in servicePrincipalList)
                {
                    this.ObjectId = servicePrincipal.ObjectId;
                    Recording.GetVariable(ObjectIdKey, this.ObjectId);
                    break;
                }
            }
            var provider = (await ResourceProvidersClient.GetAsync("Microsoft.KeyVault")).Value;

            this.Location = provider.ResourceTypes.Where(
                (resType) =>
            {
                if (resType.ResourceType == "vaults")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
                ).First().Locations.FirstOrDefault();

            ResGroupName = Recording.GenerateAssetName("sdktestrg");
            await ResourceGroupsClient.CreateOrUpdateAsync(ResGroupName, new Management.Resources.Models.ResourceGroup(Location));

            VaultName = Recording.GenerateAssetName("sdktestvault");

            TenantIdGuid = new Guid(TestEnvironment.TenantId);
            Tags         = new Dictionary <string, string> {
                { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" }
            };

            var permissions = new Permissions
            {
                Keys         = new KeyPermissions[] { new KeyPermissions("all") },
                Secrets      = new SecretPermissions[] { new SecretPermissions("all") },
                Certificates = new CertificatePermissions[] { new CertificatePermissions("all") },
                Storage      = new StoragePermissions[] { new StoragePermissions("all") },
            };

            AccessPolicy = new AccessPolicyEntry(TenantIdGuid, ObjectId, permissions);

            IList <IPRule> ipRules = new List <IPRule>();

            ipRules.Add(new IPRule("1.2.3.4/32"));
            ipRules.Add(new IPRule("1.0.0.0/25"));

            VaultProperties = new VaultProperties(TenantIdGuid, new Sku(SkuName.Standard));


            VaultProperties.EnabledForDeployment         = true;
            VaultProperties.EnabledForDiskEncryption     = true;
            VaultProperties.EnabledForTemplateDeployment = true;
            VaultProperties.EnableSoftDelete             = true;
            VaultProperties.VaultUri    = "";
            VaultProperties.NetworkAcls = new NetworkRuleSet()
            {
                Bypass = "******", DefaultAction = "Allow", IpRules = ipRules, VirtualNetworkRules = null
            };
            VaultProperties.AccessPolicies = new[] { AccessPolicy };
        }