示例#1
0
        public async Task CreateLargeWebDeploymentTemplateWorks()
        {
            string resourceName   = Recording.GenerateAssetName("csmr");
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(GoodWebsiteTemplateUri),
                Parameters   = ("{'repoURL': {'value': 'https://github.com/devigned/az-roadshow-oss.git'}, 'siteName': {'value': '" + resourceName + "'}, 'location': {'value': 'westus'}, 'sku': {'value': 'F1'}}").Replace("'", "\"")
            }
                             );

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationSouthCentralUS));

            await DeploymentsOperations.StartCreateOrUpdateAsync(groupName, deploymentName, parameters);

            // Wait until deployment completes
            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(30 * 1000);
            }
            var operations = await DeploymentOperations.ListAsync(groupName, deploymentName, null).ToEnumerableAsync();

            Assert.True(operations.Any());
        }
        public async Task WhatIf_BlankTemplate_ReturnsNoChange()
        {
            // Arrange.
            var deploymentWhatIf = new DeploymentWhatIf(
                new DeploymentWhatIfProperties(DeploymentMode.Incremental)
            {
                Template       = BlankTemplate,
                WhatIfSettings = new DeploymentWhatIfSettings()
                {
                    ResultFormat = WhatIfResultFormat.FullResourcePayloads
                }
            }
                );

            string resourceGroupName = NewResourceGroupName();
            string deploymentName    = NewDeploymentName();

            var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, ResourceGroup)).Value;

            // Act.
            var rawResult = await DeploymentsOperations.StartWhatIfAsync(resourceGroupName, deploymentName, deploymentWhatIf);

            var result = (await WaitForCompletionAsync(rawResult)).Value;

            // Assert.
            Assert.AreEqual("Succeeded", result.Status);
            Assert.NotNull(result.Changes);
            Assert.IsEmpty(result.Changes);
        }
示例#3
0
        public async Task ValidateBadDeployment()
        {
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            var    parameters     = new Deployment
                                    (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(BadTemplateUri),
                Parameters   = @"{ 'siteName': {'value': 'mctest0101'},'hostingPlanName': {'value': 'mctest0101'},'siteMode': {'value': 'Limited'},'computeMode': {'value': 'Shared'},'siteLocation': {'value': 'North Europe'},'sku': {'value': 'Free'},'workerSize': {'value': '0'}}".Replace("'", "\"")
            }
                                    );

            // TODO
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            try
            {
                var rawResult = await DeploymentsOperations.StartValidateAsync(groupName, deploymentName, parameters);

                var result = (await WaitForCompletionAsync(rawResult)).Value;
                Assert.NotNull(result);
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message.Contains("InvalidTemplate"));
            }
        }
示例#4
0
        public async Task CreateDeploymentWithStringTemplateAndParameters()
        {
            var templateString  = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "simple-storage-account.json"));
            var parameterString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "simple-storage-account-parameters.json"));

            JsonElement jsonParameter = JsonSerializer.Deserialize <JsonElement>(parameterString);

            if (!jsonParameter.TryGetProperty("parameters", out JsonElement parameter))
            {
                parameter = jsonParameter;
            }

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template       = templateString,
                ParametersJson = parameter
            }
                             );

            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            var rawResult = await DeploymentsOperations.StartCreateOrUpdateAsync(groupName, deploymentName, parameters);

            await WaitForCompletionAsync(rawResult);

            var deployment = (await DeploymentsOperations.GetAsync(groupName, deploymentName)).Value;

            Assert.AreEqual("Succeeded", deployment.Properties.ProvisioningState);
        }
        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);
        }
示例#7
0
        public async Task ValidateGoodDeployment()
        {
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            string resourceName   = Recording.GenerateAssetName("csres");

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(GoodWebsiteTemplateUri),
                Parameters   = (@"{'repoURL': {'value': 'https://github.com/devigned/az-roadshow-oss.git'}, 'siteName': {'value': '" + resourceName + "'}, 'location': {'value': 'westus'}, 'sku': {'value': 'F1'}}").Replace("'", "\"")
            }
                             );

            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            //Action
            var rawValidationResult = await DeploymentsOperations.StartValidateAsync(groupName, deploymentName, parameters);

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

            //Assert
            Assert.Null(validationResult.Error);
            Assert.NotNull(validationResult.Properties);
            Assert.NotNull(validationResult.Properties.Providers);
            Assert.AreEqual(1, validationResult.Properties.Providers.Count);
            Assert.AreEqual("Microsoft.Web", validationResult.Properties.Providers[0].Namespace);
        }
示例#8
0
        public async Task DeploymentWithScope_AtManagementGroup()
        {
            string groupId        = "tag-mg1";
            string deploymentName = Recording.GenerateAssetName("csharpsdktest");
            string accountName    = Recording.GenerateAssetName("tagsa");
            var    templateString =
                File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "management_group_level_template.json"));

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

            var managementGroupScope = $"//providers/Microsoft.Management/managementGroups/{groupId}";

            //Validate
            var rawValidationResult = await DeploymentsOperations.StartValidateAtScopeAsync(scope : managementGroupScope, deploymentName : deploymentName, parameters : parameters);

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

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

            //Put deployment
            var deploymentResult = await DeploymentsOperations.StartCreateOrUpdateAtScopeAsync(scope : managementGroupScope, deploymentName : deploymentName, parameters : parameters);

            await WaitForCompletionAsync(deploymentResult);

            var deployment = (await DeploymentsOperations.GetAtScopeAsync(scope: managementGroupScope, deploymentName: deploymentName)).Value;

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

            var deploymentOperations = await DeploymentOperations.ListAtScopeAsync(scope : managementGroupScope, deploymentName : deploymentName).ToEnumerableAsync();

            Assert.AreEqual(4, deploymentOperations.Count());
        }
示例#9
0
        public async Task CreateDeploymentAndValidateProperties()
        {
            string resourceName = Recording.GenerateAssetName("csmr");

            var parameters = new Deployment
                             (
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                TemplateLink = new TemplateLink(GoodWebsiteTemplateUri),
                Parameters   =
                    (@"{'repoURL': {'value': 'https://github.com/devigned/az-roadshow-oss.git'}, 'siteName': {'value': '" + resourceName + "'}, 'location': {'value': 'westus'}, 'sku': {'value': 'F1'}}").Replace("'", "\"")
            }
                             )
            {
                Tags = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" }
                }
            };
            string groupName      = Recording.GenerateAssetName("csmrg");
            string deploymentName = Recording.GenerateAssetName("csmd");
            await ResourceGroupsOperations.CreateOrUpdateAsync(groupName, new ResourceGroup(LiveDeploymentTests.LocationWestEurope));

            var rawResult = await DeploymentsOperations.StartCreateOrUpdateAsync(groupName, deploymentName, parameters);

            var deploymentCreateResult = (await WaitForCompletionAsync(rawResult)).Value;

            Assert.NotNull(deploymentCreateResult.Id);
            Assert.AreEqual(deploymentName, deploymentCreateResult.Name);

            if (Mode == RecordedTestMode.Record)
            {
                Thread.Sleep(1 * 1000);
            }

            var deploymentListResult = await DeploymentsOperations.ListByResourceGroupAsync(groupName, null).ToEnumerableAsync();

            var deploymentGetResult = (await DeploymentsOperations.GetAsync(groupName, deploymentName)).Value;

            Assert.IsNotEmpty(deploymentListResult);
            Assert.AreEqual(deploymentName, deploymentGetResult.Name);
            Assert.AreEqual(deploymentName, deploymentListResult.First().Name);
            Assert.AreEqual(GoodWebsiteTemplateUri, deploymentGetResult.Properties.TemplateLink.Uri);
            Assert.AreEqual(GoodWebsiteTemplateUri, deploymentListResult.First().Properties.TemplateLink.Uri);
            Assert.NotNull(deploymentGetResult.Properties.ProvisioningState);
            Assert.NotNull(deploymentListResult.First().Properties.ProvisioningState);
            Assert.NotNull(deploymentGetResult.Properties.CorrelationId);
            Assert.NotNull(deploymentListResult.First().Properties.CorrelationId);
            Assert.NotNull(deploymentListResult.First().Tags);
            Assert.True(deploymentListResult.First().Tags.ContainsKey("tagKey1"));
        }
示例#10
0
        public async Task DeploymentWithScope_AtSubscription()
        {
            string groupName      = "SDK-test";
            string deploymentName = Recording.GenerateAssetName("csmd");
            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"));

            var subscriptionScope = $"//subscriptions/{TestEnvironment.SubscriptionId}";

            //Validate
            var rawValidationResult = await DeploymentsOperations.StartValidateAtScopeAsync(scope : subscriptionScope, deploymentName : deploymentName, parameters : parameters);

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

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

            //Put deployment
            var deploymentResult = await DeploymentsOperations.StartCreateOrUpdateAtScopeAsync(scope : subscriptionScope, deploymentName : deploymentName, parameters : parameters);

            await WaitForCompletionAsync(deploymentResult);

            var deployment = (await DeploymentsOperations.GetAtScopeAsync(scope: subscriptionScope, deploymentName: deploymentName)).Value;

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

            var deploymentOperations = await DeploymentOperations.ListAtScopeAsync(scope : subscriptionScope, deploymentName : deploymentName).ToEnumerableAsync();

            Assert.AreEqual(4, deploymentOperations.Count());
        }
        public async Task WhatIf_ResourceIdOnlyMode_ReturnsChangesWithResourceIdsOnly()
        {
            // Arrange.
            JsonElement jsonParameter = JsonSerializer.Deserialize <JsonElement>(ResourceGroupTemplateParameters);

            if (!jsonParameter.TryGetProperty("parameters", out JsonElement parameter))
            {
                parameter = jsonParameter;
            }

            var deploymentWhatIf = new DeploymentWhatIf(
                new DeploymentWhatIfProperties(DeploymentMode.Incremental)
            {
                Template       = ResourceGroupTemplate,
                ParametersJson = parameter,
                WhatIfSettings = new DeploymentWhatIfSettings()
                {
                    ResultFormat = WhatIfResultFormat.ResourceIdOnly
                }
            }
                );

            string resourceGroupName = NewResourceGroupName();
            string deploymentName    = NewDeploymentName();

            var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, ResourceGroup)).Value;

            // Act.
            var rawResult = await DeploymentsOperations.StartWhatIfAsync(resourceGroupName, deploymentName, 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.AreEqual(ChangeType.Create, change.ChangeType);
                Assert.Null(change.Before);
                Assert.Null(change.After);
                Assert.Null(change.Delta);
            }
        }
示例#12
0
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Services           = new ServicesOperations(this);
     ConfigServers      = new ConfigServersOperations(this);
     MonitoringSettings = new MonitoringSettingsOperations(this);
     Apps            = new AppsOperations(this);
     Bindings        = new BindingsOperations(this);
     Certificates    = new CertificatesOperations(this);
     CustomDomains   = new CustomDomainsOperations(this);
     Deployments     = new DeploymentsOperations(this);
     Operations      = new Operations(this);
     RuntimeVersions = new RuntimeVersionsOperations(this);
     Skus            = new SkusOperations(this);
     BaseUri         = new System.Uri("https://management.azure.com");
     ApiVersion      = "2020-11-01-preview";
     AcceptLanguage  = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
示例#13
0
        public async Task TenantLevelDeployment()
        {
            string deploymentName = Recording.GenerateAssetName("csharpsdktest");
            var    templateString = File.ReadAllText(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ScenarioTests", "tenant_level_template.json"));

            var parameters = new ScopedDeployment
                             (
                "East US 2",
                new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template   = templateString,
                Parameters = "{'managementGroupId': {'value': 'tiano-mgtest01'}}".Replace("'", "\"")
            }
                             )
            {
                Tags = new Dictionary <string, string> {
                    { "tagKey1", "tagValue1" }
                }
            };

            //Validate
            var rawValidationResult = await DeploymentsOperations.StartValidateAtTenantScopeAsync(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 deploymentResult = await DeploymentsOperations.StartCreateOrUpdateAtTenantScopeAsync(deploymentName, parameters);

            await WaitForCompletionAsync(deploymentResult);

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

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

            var deploymentOperations = await DeploymentOperations.ListAtTenantScopeAsync(deploymentName).ToEnumerableAsync();

            Assert.AreEqual(4, deploymentOperations.Count());
        }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Operations            = new Operations(this);
     Deployments           = new DeploymentsOperations(this);
     Providers             = new ProvidersOperations(this);
     ProviderResourceTypes = new ProviderResourceTypesOperations(this);
     Resources             = new ResourcesOperations(this);
     ResourceGroups        = new ResourceGroupsOperations(this);
     Tags = new TagsOperations(this);
     DeploymentOperations = new DeploymentOperations(this);
     BaseUri        = new System.Uri("https://management.azure.com");
     ApiVersion     = "2020-10-01";
     AcceptLanguage = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new TransformationJsonConverter());
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
示例#15
0
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Accounts                   = new AccountsOperations(this);
     DeletedAccounts            = new DeletedAccountsOperations(this);
     ResourceSkus               = new ResourceSkusOperations(this);
     Operations                 = new Operations(this);
     CommitmentTiers            = new CommitmentTiersOperations(this);
     PrivateEndpointConnections = new PrivateEndpointConnectionsOperations(this);
     PrivateLinkResources       = new PrivateLinkResourcesOperations(this);
     Deployments                = new DeploymentsOperations(this);
     CommitmentPlans            = new CommitmentPlansOperations(this);
     BaseUri        = new System.Uri("https://management.azure.com");
     ApiVersion     = "2022-03-01";
     AcceptLanguage = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     CustomInitialize();
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
        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);
            }
        }
 /// <summary>
 /// Initializes client properties.
 /// </summary>
 private void Initialize()
 {
     Services              = new ServicesOperations(this);
     ConfigServers         = new ConfigServersOperations(this);
     ConfigurationServices = new ConfigurationServicesOperations(this);
     ServiceRegistries     = new ServiceRegistriesOperations(this);
     BuildService          = new BuildServiceOperations(this);
     BuildpackBinding      = new BuildpackBindingOperations(this);
     BuildServiceBuilder   = new BuildServiceBuilderOperations(this);
     BuildServiceAgentPool = new BuildServiceAgentPoolOperations(this);
     MonitoringSettings    = new MonitoringSettingsOperations(this);
     Apps                             = new AppsOperations(this);
     Bindings                         = new BindingsOperations(this);
     Storages                         = new StoragesOperations(this);
     Certificates                     = new CertificatesOperations(this);
     CustomDomains                    = new CustomDomainsOperations(this);
     Deployments                      = new DeploymentsOperations(this);
     Operations                       = new Operations(this);
     RuntimeVersions                  = new RuntimeVersionsOperations(this);
     Skus                             = new SkusOperations(this);
     Gateways                         = new GatewaysOperations(this);
     GatewayRouteConfigs              = new GatewayRouteConfigsOperations(this);
     GatewayCustomDomains             = new GatewayCustomDomainsOperations(this);
     ApiPortals                       = new ApiPortalsOperations(this);
     ApiPortalCustomDomains           = new ApiPortalCustomDomainsOperations(this);
     BaseUri                          = new System.Uri("https://management.azure.com");
     ApiVersion                       = "2022-01-01-preview";
     AcceptLanguage                   = "en-US";
     LongRunningOperationRetryTimeout = 30;
     GenerateClientRequestId          = true;
     SerializationSettings            = new JsonSerializerSettings
     {
         Formatting            = Newtonsoft.Json.Formatting.Indented,
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     DeserializationSettings = new JsonSerializerSettings
     {
         DateFormatHandling    = Newtonsoft.Json.DateFormatHandling.IsoDateFormat,
         DateTimeZoneHandling  = Newtonsoft.Json.DateTimeZoneHandling.Utc,
         NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
         ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
         ContractResolver      = new ReadOnlyJsonContractResolver(),
         Converters            = new List <JsonConverter>
         {
             new Iso8601TimeSpanConverter()
         }
     };
     SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter <CustomPersistentDiskProperties>("type"));
     DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter <CustomPersistentDiskProperties>("type"));
     SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter <CertificateProperties>("type"));
     DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter <CertificateProperties>("type"));
     SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter <StorageProperties>("storageType"));
     DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter <StorageProperties>("storageType"));
     SerializationSettings.Converters.Add(new PolymorphicSerializeJsonConverter <UserSourceInfo>("type"));
     DeserializationSettings.Converters.Add(new PolymorphicDeserializeJsonConverter <UserSourceInfo>("type"));
     CustomInitialize();
     DeserializationSettings.Converters.Add(new CloudErrorJsonConverter());
 }
        public async Task WhatIf_ModifyResources_ReturnsModifyChanges()
        {
            // Arrange.
            JsonElement jsonParameter = JsonSerializer.Deserialize <JsonElement>(ResourceGroupTemplateParameters);

            if (!jsonParameter.TryGetProperty("parameters", out JsonElement parameter))
            {
                parameter = jsonParameter;
            }

            var deployment = new Deployment(new DeploymentProperties(DeploymentMode.Incremental)
            {
                Template       = ResourceGroupTemplate,
                ParametersJson = parameter
            });

            // Modify account type: Standard_LRS => Standard_GRS.
            var deploymentWhatIf = new DeploymentWhatIf(
                new DeploymentWhatIfProperties(DeploymentMode.Incremental)
            {
                Template       = ResourceGroupTemplateGRS,
                ParametersJson = parameter,
                WhatIfSettings = new DeploymentWhatIfSettings()
                {
                    ResultFormat = WhatIfResultFormat.FullResourcePayloads
                }
            }
                );

            string resourceGroupName = NewResourceGroupName();

            var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, ResourceGroup)).Value;
            var deploy        = await DeploymentsOperations.StartCreateOrUpdateAsync(resourceGroupName, NewDeploymentName(), deployment);

            await WaitForCompletionAsync(deploy);

            // Act.
            var rawResult = await DeploymentsOperations.StartWhatIfAsync(resourceGroupName, NewDeploymentName(), deploymentWhatIf);

            var result = (await WaitForCompletionAsync(rawResult)).Value;

            // Assert.
            Assert.AreEqual("Succeeded", result.Status);
            Assert.NotNull(result.Changes);
            Assert.IsNotEmpty(result.Changes);

            WhatIfChange storageAccountChange = result.Changes.FirstOrDefault(change =>
                                                                              change.ResourceId.EndsWith("Microsoft.Storage/storageAccounts/ramokaSATestAnother1"));

            Assert.NotNull(storageAccountChange);
            Assert.AreEqual(ChangeType.Modify, storageAccountChange.ChangeType);

            Assert.NotNull(storageAccountChange.Delta);
            Assert.IsNotEmpty(storageAccountChange.Delta);

            WhatIfPropertyChange accountTypeChange = storageAccountChange.Delta
                                                     .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.accountType"));

            Assert.NotNull(accountTypeChange);
            Assert.AreEqual("Standard_LRS", accountTypeChange.Before);
            Assert.AreEqual("Standard_GRS", accountTypeChange.After);
        }