Skip to content

Commit 4244433

Browse files
author
Hovsep
committed
Merge pull request Azure#2098 from SiddharthChatrolaMs/dev
Moving to swagger generated .net client
2 parents c12bca2 + d3c1fa6 commit 4244433

24 files changed

+1516
-2231
lines changed

src/ResourceManager/RedisCache/Commands.RedisCache.Test/Commands.RedisCache.Test.csproj

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<Private>True</Private>
5959
</Reference>
6060
<Reference Include="Microsoft.Azure.Management.Redis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Redis.1.2.0-preview\lib\net40\Microsoft.Azure.Management.Redis.dll</HintPath>
61+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Redis.2.0.0-preview\lib\net45\Microsoft.Azure.Management.Redis.dll</HintPath>
6262
<Private>True</Private>
6363
</Reference>
6464
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -69,9 +69,9 @@
6969
<SpecificVersion>False</SpecificVersion>
7070
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.5896.19355-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
7171
</Reference>
72-
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
73-
<SpecificVersion>False</SpecificVersion>
74-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.0.5896.19355-prerelease\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
72+
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
73+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.0-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
74+
<Private>True</Private>
7575
</Reference>
7676
<Reference Include="Microsoft.Data.Edm">
7777
<HintPath>..\..\..\packages\Microsoft.Data.Edm.5.6.4\lib\net40\Microsoft.Data.Edm.dll</HintPath>
@@ -97,10 +97,18 @@
9797
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.1.0\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
9898
<Private>True</Private>
9999
</Reference>
100+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
101+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.1.0\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
102+
<Private>True</Private>
103+
</Reference>
100104
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
101105
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.0.1-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
102106
<Private>True</Private>
103107
</Reference>
108+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
109+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.2.1-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll</HintPath>
110+
<Private>True</Private>
111+
</Reference>
104112
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
105113
<SpecificVersion>False</SpecificVersion>
106114
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
@@ -152,6 +160,7 @@
152160
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
153161
</Reference>
154162
<Reference Include="System.Net.Http.WebRequest" />
163+
<Reference Include="System.Runtime.Serialization" />
155164
<Reference Include="System.Spatial">
156165
<HintPath>..\..\..\packages\System.Spatial.5.6.4\lib\net40\System.Spatial.dll</HintPath>
157166
<Private>True</Private>
@@ -180,7 +189,7 @@
180189
</ItemGroup>
181190
<ItemGroup>
182191
<Compile Include="Properties\AssemblyInfo.cs" />
183-
<Compile Include="ScenarioTests\RedisCacheTestsBase.cs" />
192+
<Compile Include="ScenarioTests\RedisCacheController.cs" />
184193
<Compile Include="ScenarioTests\RedisCacheTests.cs" />
185194
</ItemGroup>
186195
<ItemGroup>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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.IO;
18+
using System.Linq;
19+
using Microsoft.Azure.Commands.Common.Authentication;
20+
using Microsoft.Azure.Management.Insights;
21+
using Microsoft.Azure.Management.Redis;
22+
using Microsoft.Azure.Management.Resources;
23+
using Microsoft.Azure.ServiceManagemenet.Common;
24+
using Microsoft.Azure.Subscriptions;
25+
using Microsoft.Azure.Test.HttpRecorder;
26+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
27+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
28+
using LegacyTest = Microsoft.Azure.Test;
29+
using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory;
30+
using TestUtilities = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities;
31+
32+
namespace Microsoft.Azure.Commands.RedisCache.Test.ScenarioTests
33+
{
34+
public class RedisCacheController
35+
{
36+
private EnvironmentSetupHelper helper;
37+
private LegacyTest.CSMTestEnvironmentFactory csmTestFactory;
38+
39+
public ResourceManagementClient ResourceManagementClient { get; private set; }
40+
41+
public InsightsManagementClient InsightsManagementClient { get; private set; }
42+
43+
public RedisManagementClient RedisManagementClient { get; private set; }
44+
45+
public RedisCacheController()
46+
{
47+
helper = new EnvironmentSetupHelper();
48+
}
49+
50+
public static RedisCacheController NewInstance
51+
{
52+
get
53+
{
54+
return new RedisCacheController();
55+
}
56+
}
57+
58+
private void SetupManagementClients(MockContext context)
59+
{
60+
RedisManagementClient = GetRedisManagementClient(context);
61+
InsightsManagementClient = GetInsightsManagementClient();
62+
ResourceManagementClient = GetResourceManagementClient();
63+
helper.SetupManagementClients(ResourceManagementClient,
64+
InsightsManagementClient,
65+
RedisManagementClient
66+
);
67+
}
68+
69+
public void RunPowerShellTest(params string[] scripts)
70+
{
71+
var callingClassType = TestUtilities.GetCallingClass(2);
72+
var mockName = TestUtilities.GetCurrentMethodName(2);
73+
74+
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
75+
using (MockContext context = MockContext.Start(callingClassType, mockName))
76+
{
77+
this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory();
78+
SetupManagementClients(context);
79+
80+
var callingClassName = callingClassType
81+
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
82+
.Last();
83+
helper.SetupEnvironment(AzureModule.AzureResourceManager);
84+
helper.SetupModules(AzureModule.AzureResourceManager,
85+
"ScenarioTests\\" + callingClassName + ".ps1",
86+
helper.RMProfileModule,
87+
helper.RMResourceModule,
88+
helper.GetRMModulePath(@"AzureRM.RedisCache.psd1"));
89+
90+
if (scripts != null)
91+
{
92+
helper.RunPowerShellTest(scripts);
93+
}
94+
}
95+
}
96+
97+
private RedisManagementClient GetRedisManagementClient(MockContext context)
98+
{
99+
return context.GetServiceClient<RedisManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
100+
}
101+
102+
private InsightsManagementClient GetInsightsManagementClient()
103+
{
104+
return LegacyTest.TestBase.GetServiceClient<InsightsManagementClient>(this.csmTestFactory);
105+
}
106+
107+
private ResourceManagementClient GetResourceManagementClient()
108+
{
109+
return LegacyTest.TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
110+
}
111+
}
112+
}

src/ResourceManager/RedisCache/Commands.RedisCache.Test/ScenarioTests/RedisCacheTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,65 +15,66 @@
1515
namespace Microsoft.Azure.Commands.RedisCache.Test.ScenarioTests
1616
{
1717
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1819
using Microsoft.Azure.Test;
1920
using Xunit;
20-
21-
public class RedisCacheTests : RedisCacheTestsBase
21+
22+
public class RedisCacheTests : RMTestBase
2223
{
2324
[Fact]
2425
[Trait(Category.AcceptanceType, Category.CheckIn)]
2526
public void TestRedisCache()
2627
{
27-
RunPowerShellTest("Test-RedisCache");
28+
RedisCacheController.NewInstance.RunPowerShellTest("Test-RedisCache");
2829
}
2930

3031
[Fact]
3132
[Trait(Category.AcceptanceType, Category.CheckIn)]
3233
public void TestSetNonExistingRedisCacheTest()
3334
{
34-
RunPowerShellTest("Test-SetNonExistingRedisCacheTest");
35+
RedisCacheController.NewInstance.RunPowerShellTest("Test-SetNonExistingRedisCacheTest");
3536
}
3637

3738
[Fact]
3839
[Trait(Category.AcceptanceType, Category.CheckIn)]
3940
public void TestRedisCachePipeline()
4041
{
41-
RunPowerShellTest("Test-RedisCachePipeline");
42+
RedisCacheController.NewInstance.RunPowerShellTest("Test-RedisCachePipeline");
4243
}
4344

4445
[Fact]
4546
[Trait(Category.AcceptanceType, Category.CheckIn)]
4647
public void TestSetRedisCacheBugFixTest()
4748
{
48-
RunPowerShellTest("Test-SetRedisCacheBugFixTest");
49+
RedisCacheController.NewInstance.RunPowerShellTest("Test-SetRedisCacheBugFixTest");
4950
}
5051

5152
[Fact]
5253
[Trait(Category.AcceptanceType, Category.CheckIn)]
5354
public void TestMaxMemoryPolicyErrorCheck()
5455
{
55-
RunPowerShellTest("Test-MaxMemoryPolicyErrorCheck");
56+
RedisCacheController.NewInstance.RunPowerShellTest("Test-MaxMemoryPolicyErrorCheck");
5657
}
5758

5859
[Fact]
5960
[Trait(Category.AcceptanceType, Category.CheckIn)]
6061
public void TestRedisCacheClustering()
6162
{
62-
RunPowerShellTest("Test-RedisCacheClustering");
63+
RedisCacheController.NewInstance.RunPowerShellTest("Test-RedisCacheClustering");
6364
}
6465

6566
[Fact]
6667
[Trait(Category.AcceptanceType, Category.CheckIn)]
6768
public void TestSetAzureRedisCacheDiagnostics()
6869
{
69-
RunPowerShellTest("Test-SetAzureRedisCacheDiagnostics");
70+
RedisCacheController.NewInstance.RunPowerShellTest("Test-SetAzureRedisCacheDiagnostics");
7071
}
7172

7273
[Fact]
7374
[Trait(Category.AcceptanceType, Category.CheckIn)]
7475
public void TestRemoveAzureRedisCacheDiagnostics()
7576
{
76-
RunPowerShellTest("Test-RemoveAzureRedisCacheDiagnostics");
77+
RedisCacheController.NewInstance.RunPowerShellTest("Test-RemoveAzureRedisCacheDiagnostics");
7778
}
7879
}
7980
}

src/ResourceManager/RedisCache/Commands.RedisCache.Test/ScenarioTests/RedisCacheTests.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Test-RedisCache
3131
# In loop to check if cache exists
3232
for ($i = 0; $i -le 60; $i++)
3333
{
34-
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(30000)
34+
Start-TestSleep 30000
3535
$cacheGet = Get-AzureRmRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName
3636
if ([string]::Compare("succeeded", $cacheGet[0].ProvisioningState, $True) -eq 0)
3737
{
@@ -187,7 +187,7 @@ function Test-RedisCachePipeline
187187
# In loop to check if cache exists
188188
for ($i = 0; $i -le 60; $i++)
189189
{
190-
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(30000)
190+
Start-TestSleep 30000
191191
$cacheGet = Get-AzureRmRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName
192192
if ([string]::Compare("succeeded", $cacheGet[0].ProvisioningState, $True) -eq 0)
193193
{
@@ -306,7 +306,7 @@ function Test-RedisCacheClustering
306306
# In loop to check if cache exists
307307
for ($i = 0; $i -le 60; $i++)
308308
{
309-
[Microsoft.WindowsAzure.Commands.Utilities.Common.TestMockSupport]::Delay(30000)
309+
Start-TestSleep 30000
310310
$cacheGet = Get-AzureRmRedisCache -ResourceGroupName $resourceGroupName -Name $cacheName
311311
if ([string]::Compare("succeeded", $cacheGet[0].ProvisioningState, $True) -eq 0)
312312
{
@@ -423,4 +423,16 @@ function Test-RemoveAzureRedisCacheDiagnostics
423423

424424
# Set Diagnostics
425425
Remove-AzureRmRedisCacheDiagnostics -ResourceGroupName $resourceGroupName -Name $cacheName -Force
426+
}
427+
428+
<#
429+
.SYNOPSIS
430+
Sleeps but only during recording.
431+
#>
432+
function Start-TestSleep($milliseconds)
433+
{
434+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
435+
{
436+
Start-Sleep -Milliseconds $milliseconds
437+
}
426438
}

src/ResourceManager/RedisCache/Commands.RedisCache.Test/ScenarioTests/RedisCacheTestsBase.cs

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)