public void WhatIfAtTenantScope_FullResourcePayloadMode_ReturnsChangesWithPayloads() { using (MockContext context = MockContext.Start(this.GetType())) { // Arrange. ResourceManagementClient client = this.GetResourceManagementClient(context); var deploymentWhatIf = new ScopedDeploymentWhatIf { Location = "westus", Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Incremental, Template = TenantTemplate, WhatIfSettings = new DeploymentWhatIfSettings(WhatIfResultFormat.FullResourcePayloads) } }; // Act. WhatIfOperationResult result = client.Deployments .WhatIfAtTenantScope(NewDeploymentName(), deploymentWhatIf); // Assert. Assert.Equal("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.NotEmpty(result.Changes); result.Changes.ForEach(change => { Assert.NotNull(change.ResourceId); Assert.NotEmpty(change.ResourceId); Assert.True(change.Before != null || change.After != null); }); } }
public void WhatIfAtTenantScope_BlankTemplate_ReturnsNoChange() { using (MockContext context = MockContext.Start(this.GetType())) { // Arrange. ResourceManagementClient client = this.GetResourceManagementClient(context); var deploymentWhatIf = new ScopedDeploymentWhatIf { Location = "westus", Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Incremental, Template = BlankTemplate, WhatIfSettings = new DeploymentWhatIfSettings(WhatIfResultFormat.ResourceIdOnly) } }; // Act. WhatIfOperationResult result = client.Deployments .WhatIfAtTenantScope(NewDeploymentName(), deploymentWhatIf); // Assert. Assert.Equal("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.Empty(result.Changes); } }
public void WhatIfAtTenantScope_SendingRequest_SerializesPayload() { // Arrange. var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var deploymentWhatIf = new ScopedDeploymentWhatIf { Location = "westus", Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Complete, TemplateLink = new TemplateLink { Uri = "https://example.com", ContentVersion = "1.0.0.0" }, ParametersLink = new ParametersLink { Uri = "https://example.com/parameters", ContentVersion = "1.0.0.0" }, Template = JObject.Parse("{ '$schema': 'fake' }"), Parameters = new Dictionary <string, object> { ["param1"] = "foo", ["param2"] = new Dictionary <string, object> { ["param2_1"] = 123, ["param2_2"] = "bar" } } } }; using (ResourceManagementClient client = CreateResourceManagementClient(handler)) { // Act. client.Deployments.WhatIfAtTenantScope("test-tenant-deploy", deploymentWhatIf); } // Assert. JObject resultJson = JObject.Parse(handler.Request); Assert.Equal("westus", resultJson["location"]); Assert.Equal("Complete", resultJson["properties"]["mode"]); Assert.Equal("https://example.com", resultJson["properties"]["templateLink"]["uri"]); Assert.Equal("1.0.0.0", resultJson["properties"]["templateLink"]["contentVersion"]); Assert.Equal("https://example.com/parameters", resultJson["properties"]["parametersLink"]["uri"]); Assert.Equal("1.0.0.0", resultJson["properties"]["parametersLink"]["contentVersion"]); Assert.Equal(JObject.Parse("{ '$schema': 'fake' }"), resultJson["properties"]["template"]); Assert.Equal("foo", resultJson["properties"]["parameters"]["param1"]); Assert.Equal(123, resultJson["properties"]["parameters"]["param2"]["param2_1"]); Assert.Equal("bar", resultJson["properties"]["parameters"]["param2"]["param2_2"]); }
public void WhatIfAtTenantScope_ReceivingResponse_DeserializesResult() { // Arrange. var deploymentWhatIf = new ScopedDeploymentWhatIf("westus", new DeploymentWhatIfProperties()); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(@"{ 'status': 'Succeeded', 'properties': { 'changes': [ { 'resourceId': '/providers/Microsoft.Management/managementGroups/myManagementGroup', 'changeType': 'Create', 'after': { 'apiVersion': '2018-03-01', 'id': '/providers/Microsoft.Management/managementGroups/myManagementGroup', 'type': 'Microsoft.Management/managementGroup', 'name': 'myManagementGroup' } } ] } }") }; var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK }; using (ResourceManagementClient client = CreateResourceManagementClient(handler)) { // Act. WhatIfOperationResult result = client.Deployments.WhatIfAtTenantScope("test-tenent-deploy", deploymentWhatIf); // Assert. Assert.Equal("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.Equal(1, result.Changes.Count); WhatIfChange change = result.Changes[0]; Assert.Equal(ChangeType.Create, change.ChangeType); Assert.Null(change.Before); Assert.Null(change.Delta); Assert.NotNull(change.After); Assert.Equal("myManagementGroup", JToken.FromObject(change.After)["name"]); } }
public void WhatIfAtTenantScope_SendingRequestWithStrings_SerializesPayload(string parameterContent) { // Arrange. var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; string templateContent = @"{ '$schema': 'http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#', 'contentVersion': '1.0.0.0', 'parameters': { 'roleDefName': { 'type': 'string' } }, 'resources': [ ], 'outputs': {} }"; var deploymentWhatIf = new ScopedDeploymentWhatIf { Location = "westus", Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Incremental, Template = templateContent, Parameters = parameterContent } }; using (ResourceManagementClient client = CreateResourceManagementClient(handler)) { // Act. client.Deployments.WhatIfAtTenantScope("test-tenant-deploy", deploymentWhatIf); } // Assert. JObject resultJson = JObject.Parse(handler.Request); Assert.Equal("Incremental", resultJson["properties"]["mode"]); Assert.Equal("1.0.0.0", resultJson["properties"]["template"]["contentVersion"]); Assert.Equal("myCustomRole", resultJson["properties"]["parameters"]["roleDefName"]["value"]); }
public void WhatIfAtTenantScope_SendingRequest_SetsHeaders() { // Arrange. var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; var deploymentWhatIf = new ScopedDeploymentWhatIf("westus", new DeploymentWhatIfProperties()); using (ResourceManagementClient client = CreateResourceManagementClient(handler)) { // Act. client.Deployments.WhatIfAtTenantScope("test-tenant-deploy", deploymentWhatIf); } // Assert. Assert.Equal("application/json; charset=utf-8", handler.ContentHeaders.GetValues("Content-Type").First()); Assert.Equal(HttpMethod.Post, handler.Method); Assert.NotNull(handler.RequestHeaders.GetValues("Authorization")); }
public void WhatIfAtManagementGroupScope_ResourceIdOnlyMode_ReturnsChangesWithResourceIdsOnly() { using (MockContext context = MockContext.Start(this.GetType())) { // Arrange. ResourceManagementClient client = this.GetResourceManagementClient(context); var deploymentWhatIf = new ScopedDeploymentWhatIf { Location = "westus", Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Incremental, Template = ManagementGroupTemplate, Parameters = ManagementGroupTemplateParameters, WhatIfSettings = new DeploymentWhatIfSettings(WhatIfResultFormat.ResourceIdOnly) } }; // Act. WhatIfOperationResult result = client.Deployments .WhatIfAtManagementGroupScope("tag-mg-sdk", NewDeploymentName(), deploymentWhatIf); // Assert. Assert.Equal("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.NotEmpty(result.Changes); result.Changes.ForEach(change => { Assert.NotNull(change.ResourceId); Assert.NotEmpty(change.ResourceId); Assert.True(change.ChangeType == ChangeType.Deploy || change.ChangeType == ChangeType.Create); Assert.Null(change.Before); Assert.Null(change.After); Assert.Null(change.Delta); }); } }
public static string SerializeScopedDeploymentWhatIf(ScopedDeploymentWhatIf deploymentWhatIf, JsonSerializerSettings settings) { CheckSerializationForDeploymentProperties(deploymentWhatIf.Properties); return(Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(deploymentWhatIf, settings)); }