Skip to content

Commit

Permalink
Merge pull request #1037 from vivsriaus/DeploymentUpdates
Browse files Browse the repository at this point in the history
Updates to template deployment cmdlets
  • Loading branch information
ogail committed Oct 2, 2015
2 parents 211ba0d + 0ba6aa8 commit b30b857
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 467 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<Compile Include="ScenarioTests\ResourceTests.cs" />
<Compile Include="ScenarioTests\RoleAssignmentTests.cs" />
<Compile Include="ScenarioTests\RoleDefinitionTests.cs" />
<Compile Include="Templates\TestAzureResourceGroupTemplateCommandTests.cs" />
<Compile Include="ResourceGroupDeployments\TestAzureResourceGroupDeploymentCommandTests.cs" />
<Compile Include="Models.ResourceGroups\ResourceClientTests.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public void CreatesNewPSResourceGroupDeploymentWithUserTemplate()
{
TemplateFile = templateFile,
DeploymentName = deploymentName,
StorageAccountName = storageAccountName,
TemplateVersion = "1.0"
};
CreatePSResourceGroupDeploymentParameters actualParameters = new CreatePSResourceGroupDeploymentParameters();
PSResourceGroupDeployment expected = new PSResourceGroupDeployment()
Expand Down Expand Up @@ -97,75 +95,12 @@ public void CreatesNewPSResourceGroupDeploymentWithUserTemplate()
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());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CreatesNewPSResourceGroupDeploymentWithGalleryTemplate()
{
CreatePSResourceGroupDeploymentParameters expectedParameters = new CreatePSResourceGroupDeploymentParameters()
{
GalleryTemplateIdentity = "sqlServer",
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.GalleryTemplateIdentity = expectedParameters.GalleryTemplateIdentity;
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);
Assert.Equal(null, actualParameters.StorageAccountName);

commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

namespace Microsoft.Azure.Commands.Resources.Test.Resources
{
public class TestAzureResourceGroupTemplateCommandTests
public class TestAzureResourceGroupDeploymentCommandTests
{
private TestAzureResourceGroupTemplateCommand cmdlet;
private TestAzureResourceGroupDeploymentCommand cmdlet;

private Mock<ResourcesClient> resourcesClientMock;

Expand All @@ -35,13 +35,11 @@ public class TestAzureResourceGroupTemplateCommandTests

private string templateFile = @"Resources\sampleTemplateFile.json";

private string storageAccountName = "myStorageAccount";

public TestAzureResourceGroupTemplateCommandTests()
public TestAzureResourceGroupDeploymentCommandTests()
{
resourcesClientMock = new Mock<ResourcesClient>();
commandRuntimeMock = new Mock<ICommandRuntime>();
cmdlet = new TestAzureResourceGroupTemplateCommand()
cmdlet = new TestAzureResourceGroupDeploymentCommand()
{
CommandRuntime = commandRuntimeMock.Object,
ResourcesClient = resourcesClientMock.Object
Expand All @@ -53,9 +51,7 @@ public void ValidatesPSResourceGroupDeploymentWithUserTemplate()
{
ValidatePSResourceGroupDeploymentParameters expectedParameters = new ValidatePSResourceGroupDeploymentParameters()
{
TemplateFile = templateFile,
StorageAccountName = storageAccountName,
TemplateVersion = "1.0"
TemplateFile = templateFile
};
ValidatePSResourceGroupDeploymentParameters actualParameters = new ValidatePSResourceGroupDeploymentParameters();
List<PSResourceManagerError> expected = new List<PSResourceManagerError>()
Expand Down Expand Up @@ -83,63 +79,11 @@ public void ValidatesPSResourceGroupDeploymentWithUserTemplate()

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

cmdlet.ExecuteCmdlet();

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

commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
}

[Fact]
public void ValidatesPSResourceGroupDeploymentWithGalleryTemplate()
{
ValidatePSResourceGroupDeploymentParameters expectedParameters = new ValidatePSResourceGroupDeploymentParameters()
{
GalleryTemplateIdentity = "sqlServer",
StorageAccountName = storageAccountName,
TemplateVersion = "1.0"
};
ValidatePSResourceGroupDeploymentParameters actualParameters = new ValidatePSResourceGroupDeploymentParameters();
List<PSResourceManagerError> expected = new List<PSResourceManagerError>()
{
new PSResourceManagerError()
{
Code = "202",
Message = "bad input",
},
new PSResourceManagerError()
{
Code = "203",
Message = "bad input 2",
},
new PSResourceManagerError()
{
Code = "203",
Message = "bad input 3",
}
};
resourcesClientMock.Setup(f => f.ValidatePSResourceGroupDeployment(
It.IsAny<ValidatePSResourceGroupDeploymentParameters>(), DeploymentMode.Incremental))
.Returns(expected)
.Callback((ValidatePSResourceGroupDeploymentParameters p, DeploymentMode m) => { actualParameters = p; m = DeploymentMode.Incremental; });

cmdlet.ResourceGroupName = resourceGroupName;
cmdlet.GalleryTemplateIdentity = expectedParameters.GalleryTemplateIdentity;
cmdlet.TemplateVersion = expectedParameters.TemplateVersion;

cmdlet.ExecuteCmdlet();

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

commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public void CreatesNewPSResourceGroupWithUserTemplate()
Location = resourceGroupLocation,
TemplateFile = templateFile,
DeploymentName = deploymentName,
StorageAccountName = storageAccountName,
TemplateVersion = "1.0",
Tag = tags
};
CreatePSResourceGroupParameters actualParameters = new CreatePSResourceGroupParameters();
Expand All @@ -93,66 +91,18 @@ public void CreatesNewPSResourceGroupWithUserTemplate()
cmdlet.Location = expectedParameters.Location;
cmdlet.TemplateFile = expectedParameters.TemplateFile;
cmdlet.DeploymentName = expectedParameters.DeploymentName;
cmdlet.TemplateVersion = expectedParameters.TemplateVersion;
cmdlet.Tag = expectedParameters.Tag;

cmdlet.ExecuteCmdlet();

Assert.Equal(expectedParameters.ResourceGroupName, actualParameters.ResourceGroupName);
Assert.Equal(expectedParameters.Location, actualParameters.Location);
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);
Assert.Equal(null, actualParameters.StorageAccountName);
Assert.Equal(expectedParameters.Tag, actualParameters.Tag);

commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CreatesNewPSResourceGroupWithGalleryTemplate()
{
CreatePSResourceGroupParameters expectedParameters = new CreatePSResourceGroupParameters()
{
ResourceGroupName = resourceGroupName,
Location = resourceGroupLocation,
GalleryTemplateIdentity = "sqlServer",
DeploymentName = deploymentName,
StorageAccountName = storageAccountName,
TemplateVersion = "1.0"
};
CreatePSResourceGroupParameters actualParameters = new CreatePSResourceGroupParameters();
PSResourceGroup expected = new PSResourceGroup()
{
Location = expectedParameters.Location,
ResourceGroupName = expectedParameters.ResourceGroupName,
Resources = new List<PSResource>() { new PSResource() { Name = "resource1" } }
};
resourcesClientMock.Setup(f => f.CreatePSResourceGroup(It.IsAny<CreatePSResourceGroupParameters>()))
.Returns(expected)
.Callback((CreatePSResourceGroupParameters p) => { actualParameters = p; });

cmdlet.Name = expectedParameters.ResourceGroupName;
cmdlet.Location = expectedParameters.Location;
cmdlet.GalleryTemplateIdentity = expectedParameters.GalleryTemplateIdentity;
cmdlet.DeploymentName = expectedParameters.DeploymentName;
cmdlet.TemplateVersion = expectedParameters.TemplateVersion;

cmdlet.ExecuteCmdlet();

Assert.Equal(expectedParameters.ResourceGroupName, actualParameters.ResourceGroupName);
Assert.Equal(expectedParameters.Location, actualParameters.Location);
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);
Assert.Equal(null, actualParameters.StorageAccountName);

commandRuntimeMock.Verify(f => f.WriteObject(expected), Times.Once());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
<Compile Include="RoleDefinitions\NewAzureRoleDefinitionCommand.cs" />
<Compile Include="RoleDefinitions\SetAzureRoleDefinitionCommand.cs" />
<Compile Include="RoleDefinitions\RemoveAzureRoleDefinitionCommand.cs" />
<Compile Include="Templates\TestAzureResourceGroupTemplateCommand.cs" />
<Compile Include="ResourceGroupDeployments\TestAzureResourceGroupDeploymentCommand.cs" />
<Compile Include="Models.ResourceGroups\CreatePSResourceParameters.cs" />
<Compile Include="Models.ResourceGroups\PSResource.cs" />
<Compile Include="Models.ResourceGroups\DeploymentVariable.cs" />
Expand Down
Loading

0 comments on commit b30b857

Please sign in to comment.