public void GetsResourcesGroupDeployments()
        {
            List<PSResourceGroupDeployment> result = new List<PSResourceGroupDeployment>();
            PSResourceGroupDeployment expected = new PSResourceGroupDeployment()
            {
                DeploymentName = deploymentName,
                CorrelationId = "123",
                ResourceGroupName = resourceGroupName,
                Mode = DeploymentMode.Incremental
            };
            FilterResourceGroupDeploymentOptions options = new FilterResourceGroupDeploymentOptions()
            {
                ResourceGroupName = resourceGroupName
            };
            FilterResourceGroupDeploymentOptions actual = new FilterResourceGroupDeploymentOptions();
            result.Add(expected);
            resourcesClientMock.Setup(f => f.FilterResourceGroupDeployments(It.IsAny<FilterResourceGroupDeploymentOptions>()))
                .Returns(result)
                .Callback((FilterResourceGroupDeploymentOptions o) => { actual = o; });

            cmdlet.ResourceGroupName = resourceGroupName;

            cmdlet.ExecuteCmdlet();

            commandRuntimeMock.Verify(f => f.WriteObject(result, true), Times.Once());
            Assert.Equal(options.DeploymentName, actual.DeploymentName);
            Assert.Equal(options.ExcludedProvisioningStates, actual.ExcludedProvisioningStates);
            Assert.Equal(options.ProvisioningStates, actual.ProvisioningStates);
            Assert.Equal(options.ResourceGroupName, actual.ResourceGroupName);
        }
        public static PSResourceGroupDeployment ToPSResourceGroupDeployment(this DeploymentExtended result, string resourceGroup)
        {
            PSResourceGroupDeployment deployment = new PSResourceGroupDeployment();

            if (result != null)
            {
                deployment = CreatePSResourceGroupDeployment(result.Name, resourceGroup, result.Properties);
            }

            return deployment;
        }
        public static PSResourceGroupDeployment ToPSResourceGroupDeployment(this DeploymentOperationsCreateResult result)
        {
            PSResourceGroupDeployment deployment = new PSResourceGroupDeployment();

            if (result != null)
            {
                deployment = CreatePSResourceGroupDeployment(result.Name, result.ResourceGroup, result.Properties);
            }

            return deployment;
        }
        public static PSResourceGroupDeployment ToPSResourceGroupDeployment(this DeploymentExtended result, string resourceGroup)
        {
            var deployment = new PSResourceGroupDeployment();

            if (result != null)
            {
                deployment = CreatePSResourceGroupDeployment(result.Name, resourceGroup, result.Properties);
            }

            return(deployment);
        }
        public static PSResourceGroupDeployment ToPSResourceGroupDeployment(this DeploymentOperationsCreateResult result)
        {
            PSResourceGroupDeployment deployment = new PSResourceGroupDeployment();

            if (result != null)
            {
                deployment = CreatePSResourceGroupDeployment(result.Name, result.ResourceGroup, result.Properties);
            }

            return(deployment);
        }
        public static PSResourceGroupDeployment ToPSResourceGroupDeployment(this DeploymentGetResult result, string resourceGroup)
        {
            PSResourceGroupDeployment deployment = new PSResourceGroupDeployment();

            if (result != null)
            {
                deployment = CreatePSResourceGroupDeployment(result.Deployment.DeploymentName, resourceGroup, result.Deployment.Properties);
            }

            return(deployment);
        }
        private static PSResourceGroupDeployment CreatePSResourceGroupDeployment(
            string name,
            string resourceGroup,
            DeploymentPropertiesExtended properties)
        {
            var deploymentObject = new PSResourceGroupDeployment
            {
                DeploymentName = name, ResourceGroupName = resourceGroup
            };

            if (properties == null)
            {
                return(deploymentObject);
            }

            deploymentObject.Mode              = properties.Mode();
            deploymentObject.Timestamp         = properties.Timestamp();
            deploymentObject.ProvisioningState = properties.ProvisioningState;
            deploymentObject.TemplateLink      = properties.TemplateLink;
            deploymentObject.CorrelationId     = properties.CorrelationId;
            deploymentObject.OnErrorDeployment = properties.OnErrorDeployment;

            if (properties.DebugSetting() != null && !string.IsNullOrEmpty(properties.DebugSetting().DetailLevel()))
            {
                deploymentObject.DeploymentDebugLogLevel = properties.DebugSetting().DetailLevel();
            }

            if (properties.Outputs != null && !string.IsNullOrEmpty(properties.Outputs.ToString()))
            {
                var outputs = JsonConvert.DeserializeObject <Dictionary <string, DeploymentVariable> >(properties.Outputs.ToString());
                deploymentObject.Outputs = outputs;
            }

            if (properties.Parameters != null && !string.IsNullOrEmpty(properties.Parameters.ToString()))
            {
                var parameters = JsonConvert.DeserializeObject <Dictionary <string, DeploymentVariable> >(properties.Parameters.ToString());
                deploymentObject.Parameters = parameters;
            }

            if (properties.TemplateLink != null)
            {
                deploymentObject.TemplateLinkString = ConstructTemplateLinkView(properties.TemplateLink);
            }

            return(deploymentObject);
        }
        private static PSResourceGroupDeployment CreatePSResourceGroupDeployment(
            string name,
            string gesourceGroup,
            DeploymentPropertiesExtended properties)
        {
            PSResourceGroupDeployment deploymentObject = new PSResourceGroupDeployment();

            deploymentObject.DeploymentName    = name;
            deploymentObject.ResourceGroupName = gesourceGroup;

            if (properties != null)
            {
                deploymentObject.Mode = properties.Mode;
                deploymentObject.ProvisioningState = properties.ProvisioningState;
                deploymentObject.TemplateLink      = properties.TemplateLink;
                deploymentObject.Timestamp         = properties.Timestamp;
                deploymentObject.CorrelationId     = properties.CorrelationId;

                if (properties.DebugSettingResponse != null && !string.IsNullOrEmpty(properties.DebugSettingResponse.DeploymentDebugDetailLevel))
                {
                    deploymentObject.DeploymentDebugLogLevel = properties.DebugSettingResponse.DeploymentDebugDetailLevel;
                }

                if (!string.IsNullOrEmpty(properties.Outputs))
                {
                    Dictionary <string, DeploymentVariable> outputs = JsonConvert.DeserializeObject <Dictionary <string, DeploymentVariable> >(properties.Outputs);
                    deploymentObject.Outputs = outputs;
                }

                if (!string.IsNullOrEmpty(properties.Parameters))
                {
                    Dictionary <string, DeploymentVariable> parameters = JsonConvert.DeserializeObject <Dictionary <string, DeploymentVariable> >(properties.Parameters);
                    deploymentObject.Parameters = parameters;
                }

                if (properties.TemplateLink != null)
                {
                    deploymentObject.TemplateLinkString = ConstructTemplateLinkView(properties.TemplateLink);
                }
            }

            return(deploymentObject);
        }
        private static PSResourceGroupDeployment CreatePSResourceGroupDeployment(
            string name,
            string gesourceGroup,
            DeploymentProperties properties)
        {
            Dictionary <string, DeploymentVariable> outputs    = new Dictionary <string, DeploymentVariable>();
            Dictionary <string, DeploymentVariable> parameters = new Dictionary <string, DeploymentVariable>();
            PSResourceGroupDeployment deploymentObject         = new PSResourceGroupDeployment();

            deploymentObject.DeploymentName    = name;
            deploymentObject.ResourceGroupName = gesourceGroup;

            if (properties != null)
            {
                deploymentObject.Mode = properties.Mode;
                deploymentObject.ProvisioningState = properties.ProvisioningState;
                deploymentObject.TemplateLink      = properties.TemplateLink;
                deploymentObject.Timestamp         = properties.Timestamp;
                deploymentObject.CorrelationId     = properties.CorrelationId;

                if (!string.IsNullOrEmpty(properties.Outputs))
                {
                    outputs = JsonConvert.DeserializeObject <Dictionary <string, DeploymentVariable> >(properties.Outputs);
                    deploymentObject.Outputs       = outputs;
                    deploymentObject.OutputsString = ToString(outputs);
                }

                if (!string.IsNullOrEmpty(properties.Parameters))
                {
                    parameters = JsonConvert.DeserializeObject <Dictionary <string, DeploymentVariable> >(properties.Parameters);
                    deploymentObject.Parameters       = parameters;
                    deploymentObject.ParametersString = ToString(parameters);
                }

                if (properties.TemplateLink != null)
                {
                    deploymentObject.TemplateLinkString = ToString(properties.TemplateLink);
                }
            }

            return(deploymentObject);
        }
        public void CreatesNewPSResourceGroupDeploymentWithUserTemplate()
        {
            CreatePSResourceGroupDeploymentParameters expectedParameters = new CreatePSResourceGroupDeploymentParameters()
            {
                TemplateFile = templateFile,
                DeploymentName = deploymentName,
                StorageAccountName = storageAccountName,
                TemplateVersion = "1.0"
            };
            CreatePSResourceGroupDeploymentParameters actualParameters = new CreatePSResourceGroupDeploymentParameters();
            PSResourceGroupDeployment expected = new PSResourceGroupDeployment()
            {
                Mode = DeploymentMode.Incremental,
                DeploymentName = deploymentName,
                CorrelationId = "123",
                Outputs = new Dictionary<string, DeploymentVariable>()
                {
                    { "Variable1", new DeploymentVariable() { Value = "true", Type = "bool" } },
                    { "Variable2", new DeploymentVariable() { Value = "10", Type = "int" } },
                    { "Variable3", new DeploymentVariable() { Value = "hello world", Type = "string" } }
                },
                Parameters = new Dictionary<string, DeploymentVariable>()
                {
                    { "Parameter1", new DeploymentVariable() { Value = "true", Type = "bool" } },
                    { "Parameter2", new DeploymentVariable() { Value = "10", Type = "int" } },
                    { "Parameter3", new DeploymentVariable() { Value = "hello world", Type = "string" } }
                },
                ProvisioningState = ProvisioningState.Succeeded,
                ResourceGroupName = resourceGroupName,
                TemplateLink = new TemplateLink()
                {
                    ContentVersion = "1.0",
                    Uri = new Uri("http://mytemplate.com")
                },
                Timestamp = new DateTime(2014, 2, 13)
            };
            resourcesClientMock.Setup(f => f.ExecuteDeployment(
                It.IsAny<CreatePSResourceGroupDeploymentParameters>()))
                .Returns(expected)
                .Callback((CreatePSResourceGroupDeploymentParameters p) => { actualParameters = p; });

            cmdlet.ResourceGroupName = resourceGroupName;
            cmdlet.Name = expectedParameters.DeploymentName;
            cmdlet.TemplateFile = expectedParameters.TemplateFile;
            cmdlet.TemplateVersion = expectedParameters.TemplateVersion;

            cmdlet.ExecuteCmdlet();

            Assert.Equal(expectedParameters.DeploymentName, actualParameters.DeploymentName);
            Assert.Equal(expectedParameters.GalleryTemplateIdentity, actualParameters.GalleryTemplateIdentity);
            Assert.Equal(expectedParameters.TemplateFile, actualParameters.TemplateFile);
            Assert.NotNull(actualParameters.TemplateParameterObject);
            Assert.Equal(expectedParameters.TemplateVersion, actualParameters.TemplateVersion);

            commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
        }
        private static PSResourceGroupDeployment CreatePSResourceGroupDeployment(
            string name,
            string gesourceGroup,
            DeploymentPropertiesExtended properties)
        {
            PSResourceGroupDeployment deploymentObject = new PSResourceGroupDeployment();

            deploymentObject.DeploymentName = name;
            deploymentObject.ResourceGroupName = gesourceGroup;

            if (properties != null)
            {
                deploymentObject.Mode = properties.Mode;
                deploymentObject.ProvisioningState = properties.ProvisioningState;
                deploymentObject.TemplateLink = properties.TemplateLink;
                deploymentObject.Timestamp = properties.Timestamp;
                deploymentObject.CorrelationId = properties.CorrelationId;

                if(properties.DebugSettingResponse != null && !string.IsNullOrEmpty(properties.DebugSettingResponse.DeploymentDebugDetailLevel))
                {
                    deploymentObject.DeploymentDebugLogLevel = properties.DebugSettingResponse.DeploymentDebugDetailLevel;
                }

                if (!string.IsNullOrEmpty(properties.Outputs))
                {
                    Dictionary<string, DeploymentVariable> outputs = JsonConvert.DeserializeObject<Dictionary<string, DeploymentVariable>>(properties.Outputs);
                    deploymentObject.Outputs = outputs;
                }

                if (!string.IsNullOrEmpty(properties.Parameters))
                {
                    Dictionary<string, DeploymentVariable> parameters = JsonConvert.DeserializeObject<Dictionary<string, DeploymentVariable>>(properties.Parameters);
                    deploymentObject.Parameters = parameters;
                }

                if (properties.TemplateLink != null)
                {
                    deploymentObject.TemplateLinkString = ConstructTemplateLinkView(properties.TemplateLink);
                }
            }

            return deploymentObject;
        }
        private static PSResourceGroupDeployment CreatePSResourceGroupDeployment(
            string name,
            string gesourceGroup,
            DeploymentProperties properties)
        {
            Dictionary<string, DeploymentVariable> outputs = new Dictionary<string, DeploymentVariable>();
            Dictionary<string, DeploymentVariable> parameters = new Dictionary<string, DeploymentVariable>();
            PSResourceGroupDeployment deploymentObject = new PSResourceGroupDeployment();

            deploymentObject.DeploymentName = name;
            deploymentObject.ResourceGroupName = gesourceGroup;

            if (properties != null)
            {
                deploymentObject.Mode = properties.Mode;
                deploymentObject.ProvisioningState = properties.ProvisioningState;
                deploymentObject.TemplateLink = properties.TemplateLink;
                deploymentObject.Timestamp = properties.Timestamp;
                deploymentObject.CorrelationId = properties.CorrelationId;

                if (!string.IsNullOrEmpty(properties.Outputs))
                {
                    outputs = JsonConvert.DeserializeObject<Dictionary<string, DeploymentVariable>>(properties.Outputs);
                    deploymentObject.Outputs = outputs;
                    deploymentObject.OutputsString = ToString(outputs);
                }

                if (!string.IsNullOrEmpty(properties.Parameters))
                {
                    parameters = JsonConvert.DeserializeObject<Dictionary<string, DeploymentVariable>>(properties.Parameters);
                    deploymentObject.Parameters = parameters;
                    deploymentObject.ParametersString = ToString(parameters);
                }

                if (properties.TemplateLink != null)
                {
                    deploymentObject.TemplateLinkString = ToString(properties.TemplateLink);
                }
            }

            return deploymentObject;
        }