Example #1
0
        public async Task SubscriptionLevelDeployment()
        {
            string groupName      = "SDK-test";
            string deploymentName = Recording.GenerateAssetName("csmd");
            string resourceName   = Recording.GenerateAssetName("csmr");
            var    templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "subscription_level_template.json"));

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template   = templateString,
                Parameters = "{'storageAccountName': {'value': 'armbuilddemo1803'}}".Replace("'", "\"")
            }
                             )
            {
                Location = "WestUS",
                Tags     = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" }
                }
            };

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup("WestUS"));

            //Validate
            var rawValidationResult = await DeploymentsOperations.StartValidateAtSubscriptionScopeAsync(deploymentName, parameters);

            var validationResult = (await WaitForCompletionAsync(rawValidationResult)).Value;

            //Assert
            Assert.Null(validationResult.Error);
            Assert.NotNull(validationResult.Properties);
            Assert.NotNull(validationResult.Properties.Providers);

            //Put deployment
            var rawDeploymentResult = await DeploymentsOperations.StartCreateOrUpdateAtSubscriptionScopeAsync(deploymentName, parameters);

            await WaitForCompletionAsync(rawDeploymentResult);

            var deployment = (await DeploymentsOperations.GetAtSubscriptionScopeAsync(deploymentName)).Value;

            Assert.AreEqual("Succeeded", deployment.Properties.ProvisioningState);
            Assert.NotNull(deployment.Tags);
            Assert.True(deployment.Tags.ContainsKey("tagKey1"));
        }