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 WhatIfAtSubscriptionScope_BlankTemplate_ReturnsNoChange() { // Arrange. var deploymentWhatIf = new DeploymentWhatIf( new DeploymentWhatIfProperties(DeploymentMode.Incremental) { Template = BlankTemplate, WhatIfSettings = new DeploymentWhatIfSettings() { ResultFormat = WhatIfResultFormat.ResourceIdOnly } } ) { Location = "westus" }; // 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.IsEmpty(result.Changes); }
public async Task WhatIfAtSubscriptionScope_CreateResources_ReturnsCreateChanges() { // Arrange. var deploymentWhatIf = new DeploymentWhatIf( new DeploymentWhatIfProperties(DeploymentMode.Incremental) { Template = SubscriptionTemplate, Parameters = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\""), WhatIfSettings = new DeploymentWhatIfSettings() { ResultFormat = WhatIfResultFormat.ResourceIdOnly } } ) { Location = "westus2" }; // Use resource group name from the template. var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync("SDK-test", ResourceGroup)).Value; // 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); foreach (var change in result.Changes) { if (change.ResourceId.EndsWith("SDK-test")) { Assert.AreEqual(ChangeType.Ignore, change.ChangeType); } else { Assert.True(change.ChangeType == ChangeType.Deploy || change.ChangeType == ChangeType.Create); } } }
public async Task WhatIfAtSubscriptionScope_ResourceIdOnlyMode_ReturnsChangesWithResourceIdsOnly() { // Arrange. var deploymentWhatIf = new DeploymentWhatIf( new DeploymentWhatIfProperties(DeploymentMode.Incremental) { Template = SubscriptionTemplate, WhatIfSettings = new DeploymentWhatIfSettings() { ResultFormat = WhatIfResultFormat.ResourceIdOnly } } ) { Location = "westus" }; // 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); foreach (var change in result.Changes) { Assert.NotNull(change.ResourceId); Assert.IsNotEmpty(change.ResourceId); Assert.True(change.ChangeType == ChangeType.Deploy || change.ChangeType == ChangeType.Create); Assert.Null(change.Before); Assert.Null(change.After); Assert.Null(change.Delta); } }