public async Task Delete()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            string            rgName = Recording.GenerateAssetName("testRg-5-");
            ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2);
            var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData);

            ResourceGroupResource rg = lro.Value;
            string appDefName        = Recording.GenerateAssetName("appDef-D-");
            ArmApplicationDefinitionData     appDefData = CreateApplicationDefinitionData(appDefName);
            ArmApplicationDefinitionResource appDef     = (await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, appDefName, appDefData)).Value;
            string                 appName         = Recording.GenerateAssetName("application-D-");
            ArmApplicationData     applicationData = CreateApplicationData(appDef.Id, new ResourceIdentifier(subscription.Id + Recording.GenerateAssetName("/resourceGroups/managed-5-")), Recording.GenerateAssetName("s5"));
            ArmApplicationResource application     = (await rg.GetArmApplications().CreateOrUpdateAsync(WaitUntil.Completed, appName, applicationData)).Value;
            await application.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await application.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
Exemplo n.º 2
0
        private async Task <ArmOperation <VirtualNetworkResource> > createVirtualNetwork()
        {
            var vnetName = Recording.GenerateAssetName("vnet-");
            var vnet     = new VirtualNetworkData()
            {
                Location = Location,
                Subnets  = { new SubnetData()
                             {
                                 Name          = "default",
                                 AddressPrefix = "10.0.1.0/24",
                                 PrivateEndpointNetworkPolicies = VirtualNetworkPrivateEndpointNetworkPolicies.Disabled
                             } }
            };

            vnet.AddressPrefixes.Add("10.0.0.0/16");
            vnet.DhcpOptionsDnsServers.Add("10.1.1.1");
            vnet.DhcpOptionsDnsServers.Add("10.1.2.4");
            VirtualNetworkCollection networks = ResourceGroupResource.GetVirtualNetworks();

            return(await networks.CreateOrUpdateAsync(WaitUntil.Completed, vnetName, vnet));
        }
        public async Task Delete()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          cdnProfileName = Recording.GenerateAssetName("profile-");
            ProfileResource cdnProfile     = await CreateCdnProfile(rg, cdnProfileName, CdnSkuName.StandardMicrosoft);

            string cdnEndpointName          = Recording.GenerateAssetName("endpoint-");
            CdnEndpointResource cdnEndpoint = await CreateCdnEndpoint(cdnProfile, cdnEndpointName);

            string cdnOriginGroupName             = Recording.GenerateAssetName("origingroup-");
            CdnOriginGroupResource cdnOriginGroup = await CreateCdnOriginGroup(cdnEndpoint, cdnOriginGroupName, cdnEndpoint.Data.Origins[0].Name);

            await cdnOriginGroup.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await cdnOriginGroup.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
        public async Task CreateAvailabilitySet()
        {
            // First, initialize the ArmClient and get the default subscription
            ArmClient armClient = new ArmClient(new DefaultAzureCredential());
            // Now we get a ResourceGroupResource collection for that subscription
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
            ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

            // With the collection, we can create a new resource group with an specific name
            string rgName = "myRgName";
            AzureLocation location = AzureLocation.WestUS2;
            ArmOperation<ResourceGroupResource> rgLro = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location));
            ResourceGroupResource resourceGroup = rgLro.Value;
            #region Snippet:Managing_Availability_Set_CreateAnAvailabilitySet
            AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
            string availabilitySetName = "myAvailabilitySet";
            AvailabilitySetData input = new AvailabilitySetData(location);
            ArmOperation<AvailabilitySetResource> lro = await availabilitySetCollection.CreateOrUpdateAsync(WaitUntil.Completed, availabilitySetName, input);
            AvailabilitySetResource availabilitySet = lro.Value;
            #endregion Snippet:Managing_Availability_Set_CreateAnAvailabilitySet
        }
Exemplo n.º 5
0
        public async Task Delete()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-");
            AfdOriginGroupResource afdOriginGroupInstance = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName);

            string            afdOriginName     = Recording.GenerateAssetName("AFDOrigin-");
            AfdOriginResource afdOriginInstance = await CreateAfdOrigin(afdOriginGroupInstance, afdOriginName);

            await afdOriginInstance.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await afdOriginInstance.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
Exemplo n.º 6
0
        public async Task Update()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfile     = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdEndpointName = Recording.GenerateAssetName("AFDEndpoint-");
            FrontDoorEndpointResource afdEndpointInstance = await CreateAfdEndpoint(afdProfile, afdEndpointName);

            FrontDoorEndpointPatch updateOptions = new FrontDoorEndpointPatch();

            updateOptions.Tags.Add("newTag", "newValue");
            var lro = await afdEndpointInstance.UpdateAsync(WaitUntil.Completed, updateOptions);

            FrontDoorEndpointResource updatedAfdEndpointInstance = lro.Value;

            ResourceDataHelper.AssertAfdEndpointUpdate(updatedAfdEndpointInstance, updateOptions);
        }
Exemplo n.º 7
0
 public async Task ManageAvailabilitySetOld()
 {
     #region Snippet:Readme_ManageAvailabilitySetOld
     ResourceIdentifier id = new ResourceIdentifier("/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/workshop2021-rg/providers/Microsoft.Compute/availabilitySets/ws2021availSet");
     // We construct a new client to work with
     ArmClient client = new ArmClient(new DefaultAzureCredential());
     // Next we get the collection of subscriptions
     SubscriptionCollection subscriptions = client.GetSubscriptions();
     // Next we get the specific subscription this resource belongs to
     SubscriptionResource subscription = await subscriptions.GetAsync(id.SubscriptionId);
     // Next we get the collection of resource groups that belong to that subscription
     ResourceGroupCollection resourceGroups = subscription.GetResourceGroups();
     // Next we get the specific resource group this resource belongs to
     ResourceGroupResource resourceGroup = await resourceGroups.GetAsync(id.ResourceGroupName);
     // Next we get the collection of availability sets that belong to that resource group
     AvailabilitySetCollection availabilitySets = resourceGroup.GetAvailabilitySets();
     // Finally we get the resource itself
     // Note: for this last step in this example, Azure.ResourceManager.Compute is needed
     AvailabilitySetResource availabilitySet = await availabilitySets.GetAsync(id.Name);
     #endregion Snippet:Readme_ManageAvailabilitySetOld
 }
        public async Task EnableAndDisable()
        {
            //In this test, the CName mapping from custom domain "customdomaintest-5.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = Recording.GenerateAssetName("customDomain-");
            string hostName            = "customdomaintest-5.azuretest.net";
            CdnCustomDomainResource cdnCustomDomain = await CreateCdnCustomDomain(cdnEndpoint, cdnCustomDomainName, hostName);

            Assert.ThrowsAsync <RequestFailedException>(async() => await cdnCustomDomain.DisableCustomHttpsAsync(WaitUntil.Completed));
            CdnManagedHttpsOptions customDomainHttpsOptions = new CdnManagedHttpsOptions(ProtocolType.ServerNameIndication, new CdnCertificateSourceParameters(CdnCertificateSourceParametersOdataType.MicrosoftAzureCdnModelsCdnCertificateSourceParameters, CertificateType.Dedicated));

            Assert.DoesNotThrowAsync(async() => await cdnCustomDomain.EnableCustomHttpsAsync(WaitUntil.Completed, customDomainHttpsOptions));
            Assert.DoesNotThrowAsync(async() => await cdnCustomDomain.DisableCustomHttpsAsync(WaitUntil.Completed));
        }
        [LiveOnly] // Playback error: Fast polling interval of 00:00:00 detected in playback mode. Please use the default WaitForCompletion(). The test framework would automatically reduce the interval in playback.
        public async Task StartDelete()
        {
            var rgOp = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
            ResourceGroupResource rg = rgOp.Value;
            var             createOp = InstrumentOperation(await StartCreateGenericAvailabilitySetAsync(rg.Id));
            GenericResource aset     = await createOp.WaitForCompletionAsync();

            Assert.DoesNotThrowAsync(async() =>
            {
                var deleteOp = await aset.DeleteAsync(WaitUntil.Started);
                _            = await deleteOp.WaitForCompletionResponseAsync();
            });

            var fakeId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1";

            Assert.ThrowsAsync <RequestFailedException>(async() =>
            {
                var createOp = await StartCreateGenericAvailabilitySetAsync(new ResourceIdentifier(fakeId));
                _            = await createOp.WaitForCompletionAsync();
            });
        }
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdOriginGroupName = Recording.GenerateAssetName("AFDOriginGroup-");

            _ = await CreateAfdOriginGroup(afdProfileResource, afdOriginGroupName);

            int count = 0;

            await foreach (var tempAfdOriginGroup in afdProfileResource.GetAfdOriginGroups().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
        public async Task GetAllAvailabilitySets()
        {
            #region Snippet:Managing_Availability_Set_GetAllAvailabilitySets
            // First, initialize the ArmClient and get the default subscription
            ArmClient armClient = new ArmClient(new DefaultAzureCredential());
            // Now we get a ResourceGroupResource collection for that subscription
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();
            ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

            string rgName = "myRgName";
            ResourceGroupResource resourceGroup = await rgCollection.GetAsync(rgName);
            // First, we get the availability set collection from the resource group
            AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
            // With GetAllAsync(), we can get a list of the availability sets in the collection
            AsyncPageable<AvailabilitySetResource> response = availabilitySetCollection.GetAllAsync();
            await foreach (AvailabilitySetResource availabilitySet in response)
            {
                Console.WriteLine(availabilitySet.Data.Name);
            }
            #endregion Snippet:Managing_Availability_Set_GetAllAvailabilitySets
        }
Exemplo n.º 12
0
        public async Task UpdateAccountIdentityFromSystemToNone()
        {
            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts();

            string accountName = await CreateValidAccountNameAsync(namePrefix);

            var identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned);
            var param    = GetDefaultStorageAccountParameters(sku: new StorageSku(StorageSkuName.StandardLRS), identity: identity);
            StorageAccountResource account1 = (await storageAccountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, param)).Value;

            Assert.AreEqual(accountName, account1.Id.Name);
            VerifyAccountProperties(account1, false);
            Assert.AreEqual(ManagedServiceIdentityType.SystemAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.IsEmpty(account1.Data.Identity.UserAssignedIdentities);
            Assert.NotNull(account1.Data.Identity.PrincipalId);
            Assert.NotNull(account1.Data.Identity.TenantId);

            var noneIdentity = new ManagedServiceIdentity(ManagedServiceIdentityType.None);
            StorageAccountPatch parameters = new StorageAccountPatch()
            {
                Identity = noneIdentity
            };

            account1 = await account1.UpdateAsync(parameters);

            Assert.AreEqual(ManagedServiceIdentityType.None, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.IsEmpty(account1.Data.Identity.UserAssignedIdentities);
            Assert.Null(account1.Data.Identity.PrincipalId);
            Assert.Null(account1.Data.Identity.TenantId);

            // validate
            StorageAccountResource account2 = await storageAccountCollection.GetAsync(accountName);

            Assert.AreEqual(ManagedServiceIdentityType.None, account2.Data.Identity.ManagedServiceIdentityType);
            Assert.IsEmpty(account2.Data.Identity.UserAssignedIdentities);
            Assert.Null(account2.Data.Identity.PrincipalId);
            Assert.Null(account2.Data.Identity.TenantId);
        }
        public async Task CreateGetUpdateDeleteCluster()
        {
            //create a cluster
            _resourceGroup = await CreateResourceGroupAsync();

            string clusterName = Recording.GenerateAssetName("cluster");
            EventHubClusterCollection clusterCollection = _resourceGroup.GetEventHubClusters();
            EventHubClusterData       parameter         = new EventHubClusterData(AzureLocation.EastUS2);
            EventHubClusterResource   cluster           = (await clusterCollection.CreateOrUpdateAsync(WaitUntil.Completed, clusterName, parameter)).Value;

            Assert.NotNull(cluster);
            Assert.AreEqual(cluster.Data.Name, clusterName);

            //get the cluster
            cluster = await clusterCollection.GetAsync(clusterName);

            Assert.NotNull(cluster);
            Assert.AreEqual(cluster.Data.Name, clusterName);

            //get the namespace under cluster
            SubResource subResource = null;

            await foreach (var namespaceId in cluster.GetNamespacesAsync())
            {
                subResource = namespaceId;
                break;
            }

            Assert.NotNull(subResource);

            //update the cluster
            cluster.Data.Tags.Add("key", "value");
            cluster = (await cluster.UpdateAsync(WaitUntil.Completed, cluster.Data)).Value;
            Assert.AreEqual(cluster.Data.Tags["key"], "value");

            //delete the cluster
            await cluster.DeleteAsync(WaitUntil.Completed);

            Assert.IsFalse(await clusterCollection.ExistsAsync(clusterName));
        }
Exemplo n.º 14
0
        public async Task GetNamespacesInSubscription()
        {
            //create two namespaces in two resourcegroups
            string namespaceName1 = await CreateValidNamespaceName("testnamespacemgmt1");

            string namespaceName2 = await CreateValidNamespaceName("testnamespacemgmt2");

            _resourceGroup = await CreateResourceGroupAsync();

            ResourceGroupResource resourceGroup = await CreateResourceGroupAsync();

            EventHubNamespaceCollection namespaceCollection1 = _resourceGroup.GetEventHubNamespaces();
            EventHubNamespaceCollection namespaceCollection2 = resourceGroup.GetEventHubNamespaces();

            _ = (await namespaceCollection1.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new EventHubNamespaceData(DefaultLocation))).Value;
            _ = (await namespaceCollection2.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new EventHubNamespaceData(DefaultLocation))).Value;
            int count = 0;
            EventHubNamespaceResource namespace1 = null;
            EventHubNamespaceResource namespace2 = null;

            //validate
            await foreach (EventHubNamespaceResource eventHubNamespace in DefaultSubscription.GetEventHubNamespacesAsync())
            {
                count++;
                if (eventHubNamespace.Id.Name == namespaceName1)
                {
                    namespace1 = eventHubNamespace;
                }
                if (eventHubNamespace.Id.Name == namespaceName2)
                {
                    namespace2 = eventHubNamespace;
                }
            }
            VerifyNamespaceProperties(namespace1, true);
            VerifyNamespaceProperties(namespace2, true);
            Assert.AreEqual(namespace1.Id.ResourceGroupName, _resourceGroup.Id.Name);
            Assert.AreEqual(namespace2.Id.ResourceGroupName, resourceGroup.Id.Name);

            await namespace2.DeleteAsync(WaitUntil.Completed);
        }
Exemplo n.º 15
0
        public async Task GetResourceUsage()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string             afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            AfdRuleSetResource afdRuleSet     = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

            int count = 0;

            await foreach (var tempUsage in afdRuleSet.GetResourceUsagesAsync())
            {
                count++;
                Assert.AreEqual(tempUsage.Unit, UsageUnit.Count);
                Assert.AreEqual(tempUsage.CurrentValue, 0);
            }
            Assert.AreEqual(count, 1);
        }
        public async Task ValidateCustomDomain()
        {
            //A CName mapping needs to be created in advance to validate custom domain.
            //In this test is "customdomainrecord.azuretest.net" maps to "testEndpoint4dotnetsdk.azureedge.net"
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            ValidateCustomDomainInput  validateCustomDomainInput1 = new ValidateCustomDomainInput("customdomainrecord.azuretest.net");
            ValidateCustomDomainOutput validateResult             = await cdnEndpoint.ValidateCustomDomainAsync(validateCustomDomainInput1);

            Assert.True(validateResult.CustomDomainValidated);
            ValidateCustomDomainInput validateCustomDomainInput2 = new ValidateCustomDomainInput("customdomainvirtual.azuretest.net");

            validateResult = await cdnEndpoint.ValidateCustomDomainAsync(validateCustomDomainInput2);

            Assert.False(validateResult.CustomDomainValidated);
        }
        public async Task CreateNamespaceWithZoneRedundant()
        {
            IgnoreTestInLiveMode();
            //create namespace and wait for completion
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            var parameters = new ServiceBusNamespaceData(DefaultLocation)
            {
                Sku = new ServiceBusSku(ServiceBusSkuName.Premium)
                {
                    Tier = ServiceBusSkuTier.Premium
                },
                ZoneRedundant = true
            };
            ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, parameters)).Value;

            VerifyNamespaceProperties(serviceBusNamespace, false);
            Assert.IsTrue(serviceBusNamespace.Data.ZoneRedundant);
        }
        public async Task GetNamespacesInSubscription()
        {
            IgnoreTestInLiveMode();
            //create two namespaces in two resourcegroups
            string namespaceName1 = await CreateValidNamespaceName(namespacePrefix);

            _resourceGroup = await CreateResourceGroupAsync();

            ResourceGroupResource resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection1 = _resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespaceCollection namespaceCollection2 = resourceGroup.GetServiceBusNamespaces();

            _ = (await namespaceCollection1.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName1, new ServiceBusNamespaceData(DefaultLocation))).Value;
            string namespaceName2 = await CreateValidNamespaceName(namespacePrefix);

            _ = (await namespaceCollection2.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName2, new ServiceBusNamespaceData(DefaultLocation))).Value;
            int count = 0;
            ServiceBusNamespaceResource namespace1 = null;
            ServiceBusNamespaceResource namespace2 = null;

            //validate
            await foreach (ServiceBusNamespaceResource serviceBusNamespace in DefaultSubscription.GetServiceBusNamespacesAsync())
            {
                count++;
                if (serviceBusNamespace.Id.Name == namespaceName1)
                {
                    namespace1 = serviceBusNamespace;
                }
                if (serviceBusNamespace.Id.Name == namespaceName2)
                {
                    namespace2 = serviceBusNamespace;
                }
            }
            VerifyNamespaceProperties(namespace1, true);
            VerifyNamespaceProperties(namespace2, true);
            Assert.AreEqual(namespace1.Id.ResourceGroupName, _resourceGroup.Id.Name);
            Assert.AreEqual(namespace2.Id.ResourceGroupName, resourceGroup.Id.Name);
        }
        public async Task WhatIfAtResourceGroup()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            string            rgName = Recording.GenerateAssetName("testRg-5-");
            ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2);
            var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData);

            ResourceGroupResource rg = lro.Value;
            ResourceIdentifier    deploymentResourceIdentifier = ArmDeploymentResource.CreateResourceIdentifier(rg.Id, "testDeploymentWhatIf");
            ArmDeploymentResource deployment = Client.GetArmDeploymentResource(deploymentResourceIdentifier);
            var deploymentWhatIf             = new ArmDeploymentWhatIfContent(new ArmDeploymentWhatIfProperties(ArmDeploymentMode.Incremental)
            {
                Template   = CreateDeploymentPropertiesUsingString().Template,
                Parameters = CreateDeploymentPropertiesUsingJsonElement().Parameters
            });
            WhatIfOperationResult whatIfOperationResult = (await deployment.WhatIfAsync(WaitUntil.Completed, deploymentWhatIf)).Value;

            Assert.AreEqual(whatIfOperationResult.Status, "Succeeded");
            Assert.AreEqual(whatIfOperationResult.Changes.Count, 1);
            Assert.AreEqual(whatIfOperationResult.Changes[0].ChangeType, WhatIfChangeType.Create);
        }
Exemplo n.º 20
0
        public async Task StartCreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);

            string rgName = Recording.GenerateAssetName("testRg-");
            var    rgOp   = await subscription.GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(rgName, WaitUntil.Started);

            ResourceGroupResource rg = await rgOp.WaitForCompletionAsync();

            Assert.AreEqual(rgName, rg.Data.Name);

            Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                var rgOp = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Started, null, new ResourceGroupData(AzureLocation.WestUS2));
                _        = await rgOp.WaitForCompletionAsync();
            });
            Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                var rgOp = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Started, rgName, null);
                _        = await rgOp.WaitForCompletionAsync();
            });
        }
        public async Task EnableAndDisable()
        {
            //In this test, the CName mapping from custom domain "customdomaintest5.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = "customdomaintest5-azuretest-net";
            var    lro = await cdnEndpoint.GetCdnCustomDomains().GetAsync(cdnCustomDomainName);

            CdnCustomDomainResource cdnCustomDomain = lro.Value;

            Assert.ThrowsAsync <RequestFailedException>(async() => await cdnCustomDomain.DisableCustomHttpsAsync());
            CdnManagedHttpsOptions  customDomainHttpsOptions = new CdnManagedHttpsOptions(ProtocolType.ServerNameIndication, new CdnCertificateSourceParameters(CdnCertificateSourceParametersTypeName.CdnCertificateSourceParameters, CertificateType.Dedicated));
            CdnCustomDomainResource enabledCdnCustomDomain   = await cdnCustomDomain.EnableCustomHttpsAsync(customDomainHttpsOptions);

            Assert.AreEqual(enabledCdnCustomDomain.Data.CustomHttpsProvisioningState, CustomHttpsProvisioningState.Enabling);
        }
Exemplo n.º 22
0
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdCustomDomainName = Recording.GenerateAssetName("AFDCustomDomain-");
            string afdHostName         = "customdomain4afd-2.azuretest.net";

            _ = await CreateAfdCustomDomain(afdProfile, afdCustomDomainName, afdHostName);

            int count = 0;

            await foreach (var tempAfdCustomDomain in afdProfile.GetAfdCustomDomains().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
        public async Task AddTagToAvailabilitySet()
        {
            #region Snippet:Managing_Availability_Set_AddTagAvailabilitySet
            // First, initialize the ArmClient and get the default subscription
            ArmClient armClient = new ArmClient(new DefaultAzureCredential());
            // Now we get a ResourceGroupResource collection for that subscription
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();

            ResourceGroupCollection rgCollection = subscription.GetResourceGroups();

            string rgName = "myRgName";
            ResourceGroupResource resourceGroup = await rgCollection.GetAsync(rgName);

            AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets();
            string availabilitySetName = "myAvailabilitySet";
            AvailabilitySetResource availabilitySet = await availabilitySetCollection.GetAsync(availabilitySetName);

            // add a tag on this availabilitySet
            AvailabilitySetResource updatedAvailabilitySet = await availabilitySet.AddTagAsync("key", "value");

            #endregion Snippet:Managing_Availability_Set_AddTagAvailabilitySet
        }
        public async Task GetWafLogAnalyticsMetrics()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource afdProfile = await rg.GetProfiles().GetAsync("testAFDPremiumProfile");

            List <WafMetric> metric = new List <WafMetric>()
            {
                WafMetric.ClientRequestCount
            };
            DateTimeOffset     dateTimeBegin     = new DateTimeOffset(2021, 9, 23, 0, 0, 0, TimeSpan.Zero);
            DateTimeOffset     dateTimeEnd       = new DateTimeOffset(2021, 9, 25, 0, 0, 0, TimeSpan.Zero);
            WafMetricsResponse wafMtricsResponse = await afdProfile.GetWafLogAnalyticsMetricsAsync(metric, dateTimeBegin, dateTimeEnd, WafGranularity.PT5M);

            Assert.AreEqual(wafMtricsResponse.Granularity, WafMetricsResponseGranularity.PT5M);
            Assert.AreEqual(wafMtricsResponse.Series.Count, 1);
            Assert.AreEqual(wafMtricsResponse.Series[0].Metric, WafMetric.ClientRequestCount.ToString());
            Assert.AreEqual(wafMtricsResponse.Series[0].Unit, WafMetricsResponseSeriesItemUnit.Count);
            Assert.AreEqual(wafMtricsResponse.Series[0].Data.Count, 0);
        }
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            string            rgName = Recording.GenerateAssetName("testRg-2-");
            ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2);
            var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData);

            ResourceGroupResource rg = lro.Value;
            string deployName        = Recording.GenerateAssetName("deployEx-L-");
            var    deploymentData    = CreateDeploymentData(CreateDeploymentProperties());

            _ = await rg.GetArmDeployments().CreateOrUpdateAsync(WaitUntil.Completed, deployName, deploymentData);

            int count = 0;

            await foreach (var tempDeployment in rg.GetArmDeployments().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
Exemplo n.º 26
0
        public async Task CreateAccountWithSystemAndUserAssignedIdentity()
        {
            _resourceGroup = await CreateResourceGroupAsync();

            StorageAccountCollection storageAccountCollection = _resourceGroup.GetStorageAccounts();

            string accountName = await CreateValidAccountNameAsync(namePrefix);

            var identity             = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssignedUserAssigned);
            var userAssignedIdentity = await CreateUserAssignedIdentityAsync();

            identity.UserAssignedIdentities.Add(userAssignedIdentity.Id, new UserAssignedIdentity());
            var param = GetDefaultStorageAccountParameters(sku: new StorageSku(StorageSkuName.StandardLRS), identity: identity);
            StorageAccountResource account1 = (await storageAccountCollection.CreateOrUpdateAsync(WaitUntil.Completed, accountName, param)).Value;

            Assert.AreEqual(accountName, account1.Id.Name);
            VerifyAccountProperties(account1, false);
            Assert.AreEqual(ManagedServiceIdentityType.SystemAssignedUserAssigned, account1.Data.Identity.ManagedServiceIdentityType);
            Assert.AreEqual(account1.Data.Identity.UserAssignedIdentities.Count, 1);
            Assert.NotNull(account1.Data.Identity.PrincipalId);
            Assert.NotNull(account1.Data.Identity.UserAssignedIdentities[userAssignedIdentity.Id].PrincipalId);
        }
Exemplo n.º 27
0
        public async Task createNamespace()
        {
            #region Snippet:Managing_ServiceBusQueues_DefaultSubscription
            ArmClient            armClient    = new ArmClient(new DefaultAzureCredential());
            SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync();

            #endregion
            #region Snippet:Managing_ServiceBusQueues_CreateResourceGroup
            string        rgName   = "myRgName";
            AzureLocation location = AzureLocation.WestUS2;
            ArmOperation <ResourceGroupResource> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location));

            ResourceGroupResource resourceGroup = operation.Value;
            #endregion
            #region Snippet:Managing_ServiceBusQueues_CreateNamespace
            string namespaceName = "myNamespace";
            ServiceBusNamespaceCollection namespaceCollection       = resourceGroup.GetServiceBusNamespaces();
            ServiceBusNamespaceResource   serviceBusNamespace       = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(location))).Value;
            ServiceBusQueueCollection     serviceBusQueueCollection = serviceBusNamespace.GetServiceBusQueues();
            #endregion
            this.serviceBusQueueCollection = serviceBusQueueCollection;
        }
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);

            var rg1Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("testrg"), new ResourceGroupData(AzureLocation.WestUS2));

            ResourceGroupResource rg1 = rg1Op.Value;
            ResourceGroupResource rg2 = await rg1.GetAsync();

            Assert.AreEqual(rg1.Data.Name, rg2.Data.Name);
            Assert.AreEqual(rg1.Data.Id, rg2.Data.Id);
            Assert.AreEqual(rg1.Data.ResourceType, rg2.Data.ResourceType);
            Assert.AreEqual(rg1.Data.Properties.ProvisioningState, rg2.Data.Properties.ProvisioningState);
            Assert.AreEqual(rg1.Data.Location, rg2.Data.Location);
            Assert.AreEqual(rg1.Data.ManagedBy, rg2.Data.ManagedBy);
            Assert.AreEqual(rg1.Data.Tags, rg2.Data.Tags);

            ResourceIdentifier fakeId = new ResourceIdentifier(rg1.Data.Id.ToString() + "x");
            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await Client.GetResourceGroupResource(new ResourceIdentifier(fakeId)).GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
        public async Task CreateOrUpdate()
        {
            TenantResource tenant = await Client.GetTenants().GetAllAsync().FirstOrDefaultAsync(_ => true);

            SubscriptionResource subscription = await tenant.GetSubscriptions().GetAllAsync().FirstOrDefaultAsync(_ => true);

            string rgName            = Recording.GenerateAssetName("testRg-");
            ResourceGroupResource rg = await CreateResourceGroup(subscription, rgName);

            string          vnName1 = Recording.GenerateAssetName("testVn-");
            string          vnName2 = Recording.GenerateAssetName("testVn-");
            GenericResource vn1     = await CreateGenericVirtualNetwork(subscription, rg, vnName1);

            GenericResource vn2 = await CreateGenericVirtualNetwork(subscription, rg, vnName2);

            string resourceLinkName           = Recording.GenerateAssetName("link-");
            ResourceLinkResource resourceLink = await CreateResourceLink(tenant, vn1, vn2, resourceLinkName);

            Assert.AreEqual(resourceLinkName, resourceLink.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await tenant.GetResourceLinks(null).CreateOrUpdateAsync(WaitUntil.Completed, null));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await tenant.GetResourceLinks(rg.Id).CreateOrUpdateAsync(WaitUntil.Completed, null));
        }
        public async Task Delete()
        {
            //In this test, the CName mapping from custom domain "customdomaintest4.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            //The CName mapping needs to be deleted before deleting the custom domain.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = "customdomaintest4-azuretest-net";
            var    lro = await cdnEndpoint.GetCdnCustomDomains().GetAsync(cdnCustomDomainName);

            CdnCustomDomainResource cdnCustomDomain = lro.Value;
            await cdnCustomDomain.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await cdnCustomDomain.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }