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

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

            ResourceGroupResource rg         = lro.Value;
            string applicationDefinitionName = Recording.GenerateAssetName("appDef-G-");
            ArmApplicationDefinitionData     applicationDefinitionData = CreateApplicationDefinitionData(applicationDefinitionName);
            ArmApplicationDefinitionResource applicationDefinition     = (await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, applicationDefinitionData)).Value;
            ArmApplicationDefinitionResource getApplicationDefinition  = await rg.GetArmApplicationDefinitions().GetAsync(applicationDefinitionName);

            AssertValidApplicationDefinition(applicationDefinition, getApplicationDefinition);
        }
        public async Task ListBySubscription()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            string            rgName = Recording.GenerateAssetName("testRg-3-");
            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-L-");
            ArmApplicationDefinitionData     appDefData = CreateApplicationDefinitionData(appDefName);
            ArmApplicationDefinitionResource appDef     = (await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, appDefName, appDefData)).Value;
            string             appName         = Recording.GenerateAssetName("application-L-");
            ArmApplicationData applicationData = CreateApplicationData(appDef.Id, new ResourceIdentifier(subscription.Id + Recording.GenerateAssetName("/resourceGroups/managed-3-")), Recording.GenerateAssetName("s3"));

            _ = await rg.GetArmApplications().CreateOrUpdateAsync(WaitUntil.Completed, appName, applicationData);

            int count = 0;

            await foreach (var tempApplication in subscription.GetArmApplicationsAsync())
            {
                if (tempApplication.Data.ApplicationDefinitionId == appDef.Id)
                {
                    count++;
                }
            }
            Assert.AreEqual(count, 1);
        }
        public async Task CreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

            ResourceGroupResource rg         = lro.Value;
            string applicationDefinitionName = Recording.GenerateAssetName("appDef-C-");
            ArmApplicationDefinitionData     applicationDefinitionData = CreateApplicationDefinitionData(applicationDefinitionName);
            ArmApplicationDefinitionResource applicationDefinition     = (await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, applicationDefinitionData)).Value;

            Assert.AreEqual(applicationDefinitionName, applicationDefinition.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, null, applicationDefinitionData));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, null));
        }
Exemple #4
0
        public async Task CreateApplicationDefinitions()
        {
            #region Snippet:Managing_ApplicationDefinitions_CreateAnApplicationDefinition
            // First we need to get the application definition collection from the resource group
            ArmApplicationDefinitionCollection applicationDefinitionCollection = resourceGroup.GetArmApplicationDefinitions();
            // Use the same location as the resource group
            string applicationDefinitionName = "myApplicationDefinition";
            var    input = new ArmApplicationDefinitionData(resourceGroup.Data.Location, ArmApplicationLockLevel.None)
            {
                DisplayName    = applicationDefinitionName,
                Description    = $"{applicationDefinitionName} description",
                PackageFileUri = new Uri("https://raw.githubusercontent.com/Azure/azure-managedapp-samples/master/Managed%20Application%20Sample%20Packages/201-managed-storage-account/managedstorage.zip")
            };
            ArmOperation <ArmApplicationDefinitionResource> lro = await applicationDefinitionCollection.CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, input);

            ArmApplicationDefinitionResource applicationDefinition = lro.Value;
            #endregion Snippet:Managing_ApplicationDefinitions_CreateAnApplicationDefinition
        }
        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 applicationDefinitionName = Recording.GenerateAssetName("appDef-L-");
            ArmApplicationDefinitionData applicationDefinitionData = CreateApplicationDefinitionData(applicationDefinitionName);

            _ = await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, applicationDefinitionData);

            int count = 0;

            await foreach (var tempApplicationDefinition in rg.GetArmApplicationDefinitions().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
        public async Task Delete()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

            ResourceGroupResource rg         = lro.Value;
            string applicationDefinitionName = Recording.GenerateAssetName("appDef-C-");
            ArmApplicationDefinitionData     applicationDefinitionData = CreateApplicationDefinitionData(applicationDefinitionName);
            ArmApplicationDefinitionResource applicationDefinition     = (await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, applicationDefinitionData)).Value;
            await applicationDefinition.DeleteAsync(WaitUntil.Completed);

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

            Assert.AreEqual(404, ex.Status);
        }
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            string            rgName = Recording.GenerateAssetName("testRg-4-");
            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-G-");
            ArmApplicationDefinitionData     appDefData = CreateApplicationDefinitionData(appDefName);
            ArmApplicationDefinitionResource appDef     = (await rg.GetArmApplicationDefinitions().CreateOrUpdateAsync(WaitUntil.Completed, appDefName, appDefData)).Value;
            string                 appName         = Recording.GenerateAssetName("application-G-");
            ArmApplicationData     applicationData = CreateApplicationData(appDef.Id, new ResourceIdentifier(subscription.Id + Recording.GenerateAssetName("/resourceGroups/managed-4-")), Recording.GenerateAssetName("s4"));
            ArmApplicationResource application     = (await rg.GetArmApplications().CreateOrUpdateAsync(WaitUntil.Completed, appName, applicationData)).Value;
            ArmApplicationResource getApplication  = await rg.GetArmApplications().GetAsync(appName);

            AssertValidApplication(application, getApplication);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetArmApplications().GetAsync(null));
        }