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);
        }
        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);
            }
        }
        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);
        }