public async Task WhatIfAtSubscriptionScope_ModifyResources_ReturnsModifyChanges() { // Arrange. var deployment = new Deployment( new DeploymentProperties(DeploymentMode.Incremental) { Template = SubscriptionTemplate, Parameters = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\"") }) { Location = "westus2" }; var deploymentWhatIf = new DeploymentWhatIf( new DeploymentWhatIfProperties(DeploymentMode.Incremental) { Template = SubscriptionTemplateWestEurope, Parameters = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\""), WhatIfSettings = new DeploymentWhatIfSettings() { ResultFormat = WhatIfResultFormat.FullResourcePayloads } } ) { Location = "westus2" }; var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync("SDK-test", ResourceGroup)).Value; var deploy = await DeploymentsOperations.StartCreateOrUpdateAtSubscriptionScopeAsync(NewDeploymentName(), deployment); await WaitForCompletionAsync(deploy); // Act. var rawResult = await DeploymentsOperations.StartWhatIfAtSubscriptionScopeAsync(NewDeploymentName(), deploymentWhatIf); var result = (await WaitForCompletionAsync(rawResult)).Value; // Assert. Assert.AreEqual("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.IsNotEmpty(result.Changes); WhatIfChange policyChange = result.Changes.FirstOrDefault(change => change.ResourceId.EndsWith("Microsoft.Authorization/policyDefinitions/policy2")); Assert.NotNull(policyChange); Assert.True(policyChange.ChangeType == ChangeType.Deploy || policyChange.ChangeType == ChangeType.Modify); Assert.NotNull(policyChange.Delta); Assert.IsNotEmpty(policyChange.Delta); WhatIfPropertyChange policyRuleChange = policyChange.Delta .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.policyRule.if.equals")); Assert.NotNull(policyRuleChange); Assert.AreEqual(PropertyChangeType.Modify, policyRuleChange.PropertyChangeType); Assert.AreEqual("northeurope", policyRuleChange.Before); Assert.AreEqual("westeurope", policyRuleChange.After); }
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")); }