Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -878,96 +878,6 @@ public void GetResourceWithIncorrectTypeThrowsException()
Assert.Throws<ArgumentException>(() => resourcesClient.FilterPSResources(parameters));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void NewResourceGroupFailsWithInvalidDeployment()
{
Uri templateUri = new Uri("http://templateuri.microsoft.com");
Deployment deploymentFromGet = new Deployment();
Deployment deploymentFromValidate = new Deployment();
CreatePSResourceGroupParameters parameters = new CreatePSResourceGroupParameters()
{
ResourceGroupName = resourceGroupName,
Location = resourceGroupLocation,
DeploymentName = deploymentName,
TemplateFile = templateFile,
StorageAccountName = storageAccountName,
ConfirmAction = ConfirmAction
};
resourceGroupMock.Setup(f => f.CheckExistenceAsync(parameters.ResourceGroupName, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new ResourceGroupExistsResult
{
Exists = false
}));

resourceGroupMock.Setup(f => f.CreateOrUpdateAsync(
parameters.ResourceGroupName,
It.IsAny<ResourceGroup>(),
new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new ResourceGroupCreateOrUpdateResult
{
ResourceGroup = new ResourceGroupExtended() { Name = parameters.ResourceGroupName, Location = parameters.Location }
}));
resourceGroupMock.Setup(f => f.GetAsync(resourceGroupName, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new ResourceGroupGetResult
{
ResourceGroup = new ResourceGroupExtended() { Location = resourceGroupLocation }
}));
deploymentsMock.Setup(f => f.CreateOrUpdateAsync(resourceGroupName, deploymentName, It.IsAny<Deployment>(), new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new DeploymentOperationsCreateResult
{
RequestId = requestId
}))
.Callback((string name, string dName, Deployment bDeploy, CancellationToken token) => { deploymentFromGet = bDeploy; });
deploymentsMock.Setup(f => f.GetAsync(resourceGroupName, deploymentName, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new DeploymentGetResult
{
Deployment = new DeploymentExtended()
{
Name = deploymentName,
Properties = new DeploymentPropertiesExtended()
{
Mode = DeploymentMode.Incremental,
ProvisioningState = ProvisioningState.Succeeded
},
}
}));
deploymentsMock.Setup(f => f.ValidateAsync(resourceGroupName, It.IsAny<string>(), It.IsAny<Deployment>(), new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new DeploymentValidateResponse
{
Error = new ResourceManagementErrorWithDetails()
{
Code = "404",
Message = "Awesome error message",
Target = "Bad deployment"
}
}))
.Callback((string rg, string dn, Deployment d, CancellationToken c) => { deploymentFromValidate = d; });
SetupListForResourceGroupAsync(parameters.ResourceGroupName, new List<GenericResourceExtended>() { new GenericResourceExtended() { Name = "website" } });
deploymentOperationsMock.Setup(f => f.ListAsync(resourceGroupName, deploymentName, null, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => new DeploymentOperationsListResult
{
Operations = new List<DeploymentOperation>()
{
new DeploymentOperation()
{
OperationId = Guid.NewGuid().ToString(),
Properties = new DeploymentOperationProperties()
{
ProvisioningState = ProvisioningState.Succeeded,
TargetResource = new TargetResource()
{
ResourceName = resourceName,
ResourceType = "Microsoft.Website"
}
}
}
}
}));

Assert.Throws<ArgumentException>(() => resourcesClient.CreatePSResourceGroup(parameters));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestTemplateShowsErrorMessage()
Expand Down Expand Up @@ -1304,9 +1214,6 @@ public void NewResourceGroupWithDeploymentSucceeds()
Assert.Equal(DeploymentMode.Incremental, deploymentFromGet.Properties.Mode);
Assert.NotNull(deploymentFromGet.Properties.Template);

Assert.Equal(DeploymentMode.Incremental, deploymentFromValidate.Properties.Mode);
Assert.NotNull(deploymentFromValidate.Properties.Template);

progressLoggerMock.Verify(
f => f(string.Format("Resource {0} '{1}' provisioning status is {2}",
"Microsoft.Website",
Expand Down Expand Up @@ -1417,8 +1324,6 @@ public void CreatesResourceGroupWithDeploymentFromTemplateParameterObject()
// Skip: Test produces different outputs since hashtable order is not guaranteed.
//EqualsIgnoreWhitespace(File.ReadAllText(templateParameterFile), deploymentFromGet.Parameters);

Assert.Equal(DeploymentMode.Incremental, deploymentFromValidate.Properties.Mode);
Assert.NotNull(deploymentFromValidate.Properties.Template);
// Skip: Test produces different outputs since hashtable order is not guaranteed.
//EqualsIgnoreWhitespace(File.ReadAllText(templateParameterFile), deploymentFromValidate.Parameters);

Expand Down Expand Up @@ -1524,9 +1429,6 @@ public void ShowsFailureErrorWhenResourceGroupWithDeploymentFails()
Assert.Equal(DeploymentMode.Incremental, deploymentFromGet.Properties.Mode);
Assert.NotNull(deploymentFromGet.Properties.Template);

Assert.Equal(DeploymentMode.Incremental, deploymentFromValidate.Properties.Mode);
Assert.NotNull(deploymentFromValidate.Properties.Template);

errorLoggerMock.Verify(
f => f(string.Format("Resource {0} '{1}' failed with message '{2}'",
"Microsoft.Website",
Expand Down Expand Up @@ -1632,9 +1534,6 @@ public void ExtractsErrorMessageFromFailedDeploymentOperation()
Assert.Equal(DeploymentMode.Incremental, deploymentFromGet.Properties.Mode);
Assert.NotNull(deploymentFromGet.Properties.Template);

Assert.Equal(DeploymentMode.Incremental, deploymentFromValidate.Properties.Mode);
Assert.NotNull(deploymentFromValidate.Properties.Template);

errorLoggerMock.Verify(
f => f(string.Format("Resource {0} '{1}' failed with message '{2}'",
"Microsoft.Website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,6 @@ public virtual PSResourceGroupDeployment ExecuteDeployment(CreatePSResourceGroup
{
parameters.DeploymentName = GenerateDeploymentName(parameters);
Deployment deployment = CreateBasicDeployment(parameters, parameters.DeploymentMode);
TemplateValidationInfo validationInfo = CheckBasicDeploymentErrors(parameters.ResourceGroupName, parameters.DeploymentName, deployment);

if (validationInfo.Errors.Count != 0)
{
int counter = 1;
string errorFormat = "Error {0}: Code={1}; Message={2}\r\n";
StringBuilder errorsString = new StringBuilder();
validationInfo.Errors.ForEach(e => errorsString.AppendFormat(errorFormat, counter++, e.Code, e.Message));
throw new ArgumentException(errorsString.ToString());
}
else
{
WriteVerbose(ProjectResources.TemplateValid);
}

if (!string.IsNullOrEmpty(parameters.StorageAccountName))
{
Expand Down