Skip to content

Commit 2135339

Browse files
committed
Merge pull request #1 from markcowl/release-1.3.0
Fix for missing deployment validation records in some sql tests
2 parents 2e04609 + 369ed1d commit 2135339

File tree

10 files changed

+155
-8
lines changed

10 files changed

+155
-8
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Commands.ScenarioTests.ResourceManager.Common.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
<Reference Include="Microsoft.WindowsAzure.Management">
9393
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
9494
</Reference>
95+
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
96+
<HintPath>..\..\..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
97+
<Private>True</Private>
98+
</Reference>
9599
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
96100
<SpecificVersion>False</SpecificVersion>
97101
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -139,6 +143,7 @@
139143
<Compile Include="EnvironmentSetupHelper.cs" />
140144
<Compile Include="Mocks\MockClientFactory.cs" />
141145
<Compile Include="Mocks\MockCommandRuntime.cs" />
146+
<Compile Include="Mocks\MockDeploymentClientFactory.cs" />
142147
<Compile Include="PermissiveRecordMatcherWithApiExclusion.cs" />
143148
<Compile Include="ProfileClient.cs" />
144149
<Compile Include="PSCmdletExtensions.cs" />

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Mocks/MockClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public TClient CreateCustomClient<TClient>(params object[] parameters) where TCl
115115
}
116116
else
117117
{
118-
if (!MoqClients)
118+
if (!MoqClients && !client.GetType().Namespace.Contains("Castle."))
119119
{
120120
// Use the WithHandler method to create an extra reference to the http client
121121
// this will prevent the httpClient from being disposed in a long-running test using
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Net;
19+
using System.Net.Http;
20+
using System.Text;
21+
using System.Threading;
22+
using System.Threading.Tasks;
23+
using Hyak.Common.TransientFaultHandling;
24+
using Microsoft.Azure.Management.Resources;
25+
using Microsoft.Azure.Management.Resources.Models;
26+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
27+
using Moq;
28+
29+
namespace Microsoft.Azure.Commands.ScenarioTest.Mocks
30+
{
31+
public class MockDeploymentClientFactory
32+
{
33+
public static ResourceManagementClient GetResourceClient(ResourceManagementClient wrapped)
34+
{
35+
var deployment = new Mock<IDeploymentOperations>();
36+
deployment.Setup(d => d.ValidateAsync(It.IsAny<string>(), It.IsAny<string>(),
37+
It.IsAny<Deployment>(), It.IsAny<CancellationToken>())).Returns(
38+
(string resourceGroupName, string deploymentName, Deployment props, CancellationToken token) =>
39+
Task.FromResult(new DeploymentValidateResponse
40+
{
41+
Error = null,
42+
IsValid = true,
43+
Properties = new DeploymentPropertiesExtended
44+
{
45+
CorrelationId = Guid.NewGuid().ToString(),
46+
DebugSetting = props.Properties.DebugSetting,
47+
DebugSettingResponse = props.Properties.DebugSetting,
48+
Dependencies = new List<Dependency>(),
49+
Duration = TimeSpan.FromSeconds(1),
50+
Mode = props.Properties.Mode,
51+
Outputs = string.Empty,
52+
Parameters = props.Properties.Parameters,
53+
ParametersLink = props.Properties.ParametersLink,
54+
Providers = new List<Provider>
55+
{
56+
new Provider
57+
{
58+
Id = Guid.NewGuid().ToString(),
59+
Namespace = "Microsoft.Compute",
60+
RegistrationState = "Registered",
61+
RequestId = Guid.NewGuid().ToString(),
62+
ResourceTypes = null,
63+
StatusCode = HttpStatusCode.OK
64+
}
65+
}
66+
67+
},
68+
RequestId = Guid.NewGuid().ToString(),
69+
StatusCode = HttpStatusCode.OK
70+
}));
71+
deployment.Setup(
72+
d => d.BeginDeletingAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
73+
.Returns(
74+
(string resourceGroupName, string deploymentName, CancellationToken token) =>
75+
wrapped.Deployments.BeginDeletingAsync(resourceGroupName, deploymentName, token));
76+
deployment.Setup(
77+
d => d.CancelAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
78+
.Returns(
79+
(string resourceGroupName, string deploymentName, CancellationToken token) =>
80+
wrapped.Deployments.CancelAsync(resourceGroupName, deploymentName, token));
81+
deployment.Setup(
82+
d => d.CheckExistenceAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
83+
.Returns(
84+
(string resourceGroupName, string deploymentName, CancellationToken token) =>
85+
wrapped.Deployments.CheckExistenceAsync(resourceGroupName, deploymentName, token));
86+
deployment.Setup(
87+
d =>
88+
d.CreateOrUpdateAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Deployment>(),
89+
It.IsAny<CancellationToken>()))
90+
.Returns(
91+
(string resourceGroupName, string deploymentName, Deployment depl, CancellationToken token) =>
92+
wrapped.Deployments.CreateOrUpdateAsync(resourceGroupName, deploymentName, depl, token));
93+
deployment.Setup(
94+
d => d.DeleteAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
95+
.Returns(
96+
(string resourceGroupName, string deploymentName, CancellationToken token) =>
97+
wrapped.Deployments.DeleteAsync(resourceGroupName, deploymentName, token));
98+
deployment.Setup(
99+
d => d.GetAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
100+
.Returns(
101+
(string resourceGroupName, string deploymentName, CancellationToken token) =>
102+
wrapped.Deployments.GetAsync(resourceGroupName, deploymentName, token));
103+
deployment.Setup(
104+
d =>
105+
d.ListAsync(It.IsAny<string>(), It.IsAny<DeploymentListParameters>(),
106+
It.IsAny<CancellationToken>()))
107+
.Returns(
108+
(string resourceGroupName, DeploymentListParameters list, CancellationToken token) =>
109+
wrapped.Deployments.ListAsync(resourceGroupName, list, token));
110+
deployment.Setup(
111+
d => d.ListNextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
112+
.Returns(
113+
(string nextLink, CancellationToken token) =>
114+
wrapped.Deployments.ListNextAsync(nextLink, token));
115+
var mockResource = new Mock<ResourceManagementClient>();
116+
mockResource.SetupGet(r => r.Deployments).Returns(deployment.Object);
117+
mockResource.SetupGet(r => r.Resources).Returns(wrapped.Resources);
118+
mockResource.SetupGet(r => r.DeploymentOperations).Returns(wrapped.DeploymentOperations);
119+
mockResource.SetupGet(r => r.ProviderOperationsMetadata).Returns(wrapped.ProviderOperationsMetadata);
120+
mockResource.SetupGet(r => r.Providers).Returns(wrapped.Providers);
121+
mockResource.SetupGet(r => r.ResourceGroups).Returns(wrapped.ResourceGroups);
122+
mockResource.SetupGet(r => r.ResourceProviderOperationDetails)
123+
.Returns(wrapped.ResourceProviderOperationDetails);
124+
mockResource.SetupGet(r => r.Tags).Returns(wrapped.Tags);
125+
126+
return mockResource.Object;
127+
}
128+
}
129+
}

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<package id="Microsoft.Rest.ClientRuntime" version="2.1.0" targetFramework="net45" />
1515
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.0.1-preview" targetFramework="net45" />
1616
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
17+
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
1718
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
1819
<package id="xunit" version="2.1.0" targetFramework="net45" />
1920
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<SpecificVersion>False</SpecificVersion>
6666
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.9.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
6767
</Reference>
68-
<Reference Include="Microsoft.Azure.Management.Authorization">
68+
<Reference Include="Microsoft.Azure.Management.Authorization, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6969
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
7070
<Private>True</Private>
7171
</Reference>

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/AuditingTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Common.Authentication;
16+
using Microsoft.Azure.Commands.ScenarioTest.Mocks;
1517
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
1618
using Microsoft.Azure.Test;
1719
using Microsoft.Azure.Test.HttpRecorder;
20+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
1821
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1922
using Xunit;
2023

@@ -27,7 +30,8 @@ protected override void SetupManagementClients()
2730
var sqlCSMClient = GetSqlClient();
2831
var storageClient = GetStorageClient();
2932
var storageV2Client = GetStorageV2Client();
30-
var resourcesClient = GetResourcesClient();
33+
//TODO, Remove the MockDeploymentFactory call when the test is re-recorded
34+
var resourcesClient = MockDeploymentClientFactory.GetResourceClient(GetResourcesClient());
3135
var authorizationClient = GetAuthorizationManagementClient();
3236
helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, storageV2Client, resourcesClient, authorizationClient);
3337
}

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/SqlTestsBase.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
using Microsoft.Azure.Commands.Common.Authentication;
2727
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2828
using Microsoft.Azure.Commands.ResourceManager.Common;
29+
using Microsoft.Azure.Commands.ScenarioTest.Mocks;
2930
using Microsoft.WindowsAzure.Commands.Common;
31+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
3032

3133

3234
namespace Microsoft.Azure.Commands.ScenarioTest.SqlTests
@@ -49,7 +51,8 @@ protected virtual void SetupManagementClients()
4951
{
5052
var sqlCSMClient = GetSqlClient(); // to interact with the security endpoints
5153
var storageClient = GetStorageClient();
52-
var resourcesClient = GetResourcesClient();
54+
//TODO, Remove the MockDeploymentFactory call when the test is re-recorded
55+
var resourcesClient = MockDeploymentClientFactory.GetResourceClient(GetResourcesClient());
5356
var authorizationClient = GetAuthorizationManagementClient();
5457
var graphClient = GetGraphClient();
5558
helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, resourcesClient, authorizationClient, graphClient);

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/ThreatDetectionTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Azure.Commands.Common.Authentication;
16+
using Microsoft.Azure.Commands.ScenarioTest.Mocks;
1517
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
18+
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
1619
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1720
using Xunit;
1821

@@ -25,7 +28,8 @@ protected override void SetupManagementClients()
2528
var sqlCSMClient = GetSqlClient();
2629
var storageClient = GetStorageClient();
2730
var storageV2Client = GetStorageV2Client();
28-
var resourcesClient = GetResourcesClient();
31+
//TODO, Remove the MockDeploymentFactory call when the test is re-recorded
32+
var resourcesClient = MockDeploymentClientFactory.GetResourceClient(GetResourcesClient());
2933
var authorizationClient = GetAuthorizationManagementClient();
3034
helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, storageV2Client, resourcesClient,
3135
authorizationClient);

src/ResourceManager/Sql/Commands.Sql.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<package id="Microsoft.Azure.Gallery" version="2.6.2-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Graph.RBAC" version="1.9.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
9-
<package id="Microsoft.Azure.Management.Authorization" version="1.0.0" targetFramework="net45" />
9+
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.Resources" version="2.19.0-preview" targetFramework="net45" />
1111
<package id="Microsoft.Azure.Management.Sql" version="0.44.0-prerelease" targetFramework="net45" />
1212
<package id="Microsoft.Azure.Management.Storage" version="2.4.0-preview" targetFramework="net45" />

tools/StaticAnalysis/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public static void Main(string[] args)
4444
var directories = new List<string>
4545
{
4646
Path.Combine(installDir, @"ResourceManager\AzureResourceManager\"),
47-
Path.Combine(installDir, @"ServiceManagement\Azure\")
48-
};
47+
Path.Combine(installDir, @"ServiceManagement\Azure\"),
48+
Path.Combine(installDir, @"Storage\")
49+
};
4950

5051
var reportsDirectory = Directory.GetCurrentDirectory();
5152
bool logReportsDirectoryWarning = true;

0 commit comments

Comments
 (0)