Skip to content

Commit 5aa7a89

Browse files
committed
Adding RunnerTests.cs to run Azure Tests in Record mode
1 parent bf33468 commit 5aa7a89

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<Compile Include="ScenarioTests\ComputeCloudExceptionTests.cs" />
168168
<Compile Include="ScenarioTests\DiagnosticsExtensionTests.cs" />
169169
<Compile Include="ScenarioTests\DscExtensionTests.cs" />
170+
<Compile Include="ScenarioTests\RunnerTests.cs" />
170171
<Compile Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.cs" />
171172
<Compile Include="ScenarioTests\VMDynamicTests.cs" />
172173
<Compile Include="ScenarioTests\VirtualMachineProfileTests.cs" />
@@ -237,6 +238,9 @@
237238
<None Include="ScenarioTests\Generated\VirtualMachineDynamicTest3.ps1">
238239
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
239240
</None>
241+
<None Include="ScenarioTests\RunnerTests.csv">
242+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
243+
</None>
240244
<None Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.ps1">
241245
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
242246
</None>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
5+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
6+
using Xunit;
7+
8+
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
9+
{
10+
public class RunnerTests
11+
{
12+
[Fact]
13+
public void ExecuteRunnerTests()
14+
{
15+
var mode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
16+
var csmAuth = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION");
17+
18+
if (mode.ToLower() != "record")
19+
{
20+
return;
21+
}
22+
23+
Assert.False(string.IsNullOrEmpty(csmAuth));
24+
Assert.True(csmAuth.Contains("AADTenant"));
25+
26+
var envDictionary = TestUtilities.ParseConnectionString(csmAuth);
27+
var testEnv = new TestEnvironment(envDictionary);
28+
Assert.NotNull(testEnv.Tenant);
29+
Assert.NotNull(testEnv.SubscriptionId);
30+
Assert.NotNull(testEnv.ClientId);
31+
Assert.True(envDictionary.ContainsKey("ApplicationSecret"));
32+
33+
var authenticationContext = new AuthenticationContext("https://login.windows.net/" + testEnv.Tenant);
34+
var credential = new ClientCredential(testEnv.ClientId, envDictionary["ApplicationSecret"]);
35+
36+
37+
var result = authenticationContext.AcquireToken("https://management.core.windows.net/", clientCredential: credential);
38+
Assert.NotNull(result.AccessToken);
39+
envDictionary["RawToken"] = result.AccessToken;
40+
41+
FixCSMAuthEnvVariable(envDictionary);
42+
43+
Console.WriteLine(Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"));
44+
45+
var testFile = File.ReadAllLines("ScenarioTests\\RunnerTests.csv");
46+
foreach (var line in testFile)
47+
{
48+
var tokens = line.Split(';');
49+
var className = tokens[0];
50+
var type = Type.GetType(className);
51+
var constructorInfo = type.GetConstructor(Type.EmptyTypes);
52+
for (int i = 1; i < tokens.Length; i++)
53+
{
54+
var method = tokens[i];
55+
var testClassInstance = constructorInfo.Invoke(new object[] {});
56+
var testMethod = type.GetMethod(method);
57+
58+
testMethod.Invoke(testClassInstance, new object[] {});
59+
}
60+
}
61+
}
62+
63+
private void FixCSMAuthEnvVariable(IDictionary<string, string> envDictionary)
64+
{
65+
var str = string.Empty;
66+
foreach (var entry in envDictionary)
67+
{
68+
if (entry.Key != "AADClientId" && entry.Key != "ApplicationSecret")
69+
{
70+
str += string.Format("{0}={1};", entry.Key, entry.Value);
71+
}
72+
}
73+
74+
Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", str);
75+
}
76+
}
77+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AvailabilitySetTests;TestAvailabilitySet
2+
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.ComputeCloudExceptionTests;RunComputeCloudExceptionTests
3+
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests;TestLinuxVirtualMachine
4+
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineProfileTests;TestVirtualMachineProfile

0 commit comments

Comments
 (0)