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 void CreatesNewPSResourceGroupDeploymentWithUserTemplate() { PSCreateResourceGroupDeploymentParameters expectedParameters = new PSCreateResourceGroupDeploymentParameters() { TemplateFile = templateFile, DeploymentName = deploymentName, }; PSCreateResourceGroupDeploymentParameters actualParameters = new PSCreateResourceGroupDeploymentParameters(); 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.ToString(), ResourceGroupName = resourceGroupName, TemplateLink = new TemplateLink() { ContentVersion = "1.0", Uri = "http://mytemplate.com" }, Timestamp = new DateTime(2014, 2, 13) }; resourcesClientMock.Setup(f => f.ExecuteDeployment( It.IsAny<PSCreateResourceGroupDeploymentParameters>())) .Returns(expected) .Callback((PSCreateResourceGroupDeploymentParameters p) => { actualParameters = p; }); cmdlet.ResourceGroupName = resourceGroupName; cmdlet.Name = expectedParameters.DeploymentName; cmdlet.TemplateFile = expectedParameters.TemplateFile; cmdlet.ExecuteCmdlet(); Assert.Equal(expectedParameters.DeploymentName, actualParameters.DeploymentName); Assert.Equal(expectedParameters.TemplateFile, actualParameters.TemplateFile); Assert.NotNull(actualParameters.TemplateParameterObject); 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.Value; deploymentObject.ProvisioningState = properties.ProvisioningState; deploymentObject.TemplateLink = properties.TemplateLink; deploymentObject.Timestamp = properties.Timestamp == null ? default(DateTime) : properties.Timestamp.Value; deploymentObject.CorrelationId = properties.CorrelationId; if(properties.DebugSetting != null && !string.IsNullOrEmpty(properties.DebugSetting.DetailLevel)) { deploymentObject.DeploymentDebugLogLevel = properties.DebugSetting.DetailLevel; } if (properties.Outputs != null) { Dictionary<string, DeploymentVariable> outputs = JsonConvert.DeserializeObject<Dictionary<string, DeploymentVariable>>(properties.Outputs.ToString()); deploymentObject.Outputs = outputs; } if (properties.Parameters != null) { Dictionary<string, DeploymentVariable> parameters = JsonConvert.DeserializeObject<Dictionary<string, DeploymentVariable>>(properties.Parameters.ToString()); deploymentObject.Parameters = parameters; } if (properties.TemplateLink != null) { deploymentObject.TemplateLinkString = ConstructTemplateLinkView(properties.TemplateLink); } } return deploymentObject; }