Skip to content

Call validate when submitting deployments #2013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 25, 2016
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 @@ -92,6 +92,10 @@
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -139,6 +143,7 @@
<Compile Include="EnvironmentSetupHelper.cs" />
<Compile Include="Mocks\MockClientFactory.cs" />
<Compile Include="Mocks\MockCommandRuntime.cs" />
<Compile Include="Mocks\MockDeploymentClientFactory.cs" />
<Compile Include="PermissiveRecordMatcherWithApiExclusion.cs" />
<Compile Include="ProfileClient.cs" />
<Compile Include="PSCmdletExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public TClient CreateCustomClient<TClient>(params object[] parameters) where TCl
}
else
{
if (!MoqClients)
if (!MoqClients && !client.GetType().Namespace.Contains("Castle."))
{
// Use the WithHandler method to create an extra reference to the http client
// this will prevent the httpClient from being disposed in a long-running test using
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Hyak.Common.TransientFaultHandling;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Moq;

namespace Microsoft.Azure.Commands.ScenarioTest.Mocks
{
public class MockDeploymentClientFactory
{
public static ResourceManagementClient GetResourceClient(ResourceManagementClient wrapped)
{
var deployment = new Mock<IDeploymentOperations>();
deployment.Setup(d => d.ValidateAsync(It.IsAny<string>(), It.IsAny<string>(),
It.IsAny<Deployment>(), It.IsAny<CancellationToken>())).Returns(
(string resourceGroupName, string deploymentName, Deployment props, CancellationToken token) =>
Task.FromResult(new DeploymentValidateResponse
{
Error = null,
IsValid = true,
Properties = new DeploymentPropertiesExtended
{
CorrelationId = Guid.NewGuid().ToString(),
DebugSetting = props.Properties.DebugSetting,
DebugSettingResponse = props.Properties.DebugSetting,
Dependencies = new List<Dependency>(),
Duration = TimeSpan.FromSeconds(1),
Mode = props.Properties.Mode,
Outputs = string.Empty,
Parameters = props.Properties.Parameters,
ParametersLink = props.Properties.ParametersLink,
Providers = new List<Provider>
{
new Provider
{
Id = Guid.NewGuid().ToString(),
Namespace = "Microsoft.Compute",
RegistrationState = "Registered",
RequestId = Guid.NewGuid().ToString(),
ResourceTypes = null,
StatusCode = HttpStatusCode.OK
}
}

},
RequestId = Guid.NewGuid().ToString(),
StatusCode = HttpStatusCode.OK
}));
deployment.Setup(
d => d.BeginDeletingAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, string deploymentName, CancellationToken token) =>
wrapped.Deployments.BeginDeletingAsync(resourceGroupName, deploymentName, token));
deployment.Setup(
d => d.CancelAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, string deploymentName, CancellationToken token) =>
wrapped.Deployments.CancelAsync(resourceGroupName, deploymentName, token));
deployment.Setup(
d => d.CheckExistenceAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, string deploymentName, CancellationToken token) =>
wrapped.Deployments.CheckExistenceAsync(resourceGroupName, deploymentName, token));
deployment.Setup(
d =>
d.CreateOrUpdateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Deployment>(),
It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, string deploymentName, Deployment depl, CancellationToken token) =>
wrapped.Deployments.CreateOrUpdateAsync(resourceGroupName, deploymentName, depl, token));
deployment.Setup(
d => d.DeleteAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, string deploymentName, CancellationToken token) =>
wrapped.Deployments.DeleteAsync(resourceGroupName, deploymentName, token));
deployment.Setup(
d => d.GetAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, string deploymentName, CancellationToken token) =>
wrapped.Deployments.GetAsync(resourceGroupName, deploymentName, token));
deployment.Setup(
d =>
d.ListAsync(It.IsAny<string>(), It.IsAny<DeploymentListParameters>(),
It.IsAny<CancellationToken>()))
.Returns(
(string resourceGroupName, DeploymentListParameters list, CancellationToken token) =>
wrapped.Deployments.ListAsync(resourceGroupName, list, token));
deployment.Setup(
d => d.ListNextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(
(string nextLink, CancellationToken token) =>
wrapped.Deployments.ListNextAsync(nextLink, token));
var mockResource = new Mock<ResourceManagementClient>();
mockResource.SetupGet(r => r.Deployments).Returns(deployment.Object);
mockResource.SetupGet(r => r.Resources).Returns(wrapped.Resources);
mockResource.SetupGet(r => r.DeploymentOperations).Returns(wrapped.DeploymentOperations);
mockResource.SetupGet(r => r.ProviderOperationsMetadata).Returns(wrapped.ProviderOperationsMetadata);
mockResource.SetupGet(r => r.Providers).Returns(wrapped.Providers);
mockResource.SetupGet(r => r.ResourceGroups).Returns(wrapped.ResourceGroups);
mockResource.SetupGet(r => r.ResourceProviderOperationDetails)
.Returns(wrapped.ResourceProviderOperationDetails);
mockResource.SetupGet(r => r.Tags).Returns(wrapped.Tags);

return mockResource.Object;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<package id="Microsoft.Rest.ClientRuntime" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.0.1-preview" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ function Test-NewDeploymentFromTemplateFile
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$location = Get-ProviderLocation "Microsoft.Web/sites"
$rglocation = "EastUS"

try
{
Expand Down Expand Up @@ -77,8 +76,7 @@ function Test-NestedDeploymentFromTemplateFile
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$location = Get-ProviderLocation "Microsoft.Web/sites"
$rglocation = "EastUS"

try
{
Expand Down Expand Up @@ -112,8 +110,7 @@ function Test-SaveDeploymentTemplateFile
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$location = Get-ProviderLocation "Microsoft.Web/sites"
$rglocation = "EastUS"

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ function Test-RemoveDeployment
# Setup
$deploymentName = "Test"
$templateUri = "https://gallery.azure.com/artifact/20140901/Microsoft.ResourceGroup.1.0.0/DeploymentTemplates/Template.json"
$rgName = "TestSDK"
$rgName = "TestSDK0123"

try
{
# Test
New-AzureRmResourceGroup -Name $rgName -Location "west us"
New-AzureRmResourceGroup -Name $rgName -Location "East US"
$deployment = New-AzureRmResourceGroupDeployment -ResourceGroupName $rgName -Name $deploymentName -TemplateUri $templateUri
Assert-True { Remove-AzureRmResourceGroupDeployment -ResourceGroupName $deployment.ResourceGroupName -Name $deployment.DeploymentName -Force }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function Test-GetResourceWithCollection
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$rglocation = "East US"
$apiversion = "2015-08-01"
$resourceType = "Providers.Test/statefulResources"

Expand Down
Loading