Skip to content

Commit 8ae38ce

Browse files
committed
Merge pull request #396 from AzureRT/dev
,
2 parents 31111f4 + 39d97c2 commit 8ae38ce

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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 == null || csmAuth == null || 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+
var result = authenticationContext.AcquireToken("https://management.core.windows.net/", clientCredential: credential);
37+
Assert.NotNull(result.AccessToken);
38+
envDictionary["RawToken"] = result.AccessToken;
39+
40+
FixCSMAuthEnvVariable(envDictionary);
41+
42+
Console.WriteLine(Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"));
43+
44+
var testFile = File.ReadAllLines("ScenarioTests\\RunnerTests.csv");
45+
foreach (var line in testFile)
46+
{
47+
var tokens = line.Split(';');
48+
var className = tokens[0];
49+
var type = Type.GetType(className);
50+
var constructorInfo = type.GetConstructor(Type.EmptyTypes);
51+
for (int i = 1; i < tokens.Length; i++)
52+
{
53+
var method = tokens[i];
54+
var testClassInstance = constructorInfo.Invoke(new object[] {});
55+
var testMethod = type.GetMethod(method);
56+
57+
testMethod.Invoke(testClassInstance, new object[] {});
58+
}
59+
}
60+
}
61+
62+
private void FixCSMAuthEnvVariable(IDictionary<string, string> envDictionary)
63+
{
64+
var str = string.Empty;
65+
foreach (var entry in envDictionary)
66+
{
67+
if (entry.Key != "AADClientId" && entry.Key != "ApplicationSecret")
68+
{
69+
str += string.Format("{0}={1};", entry.Key, entry.Value);
70+
}
71+
}
72+
73+
Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", str);
74+
}
75+
}
76+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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
5+
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VMDynamicTests;RunVMDynamicTests

0 commit comments

Comments
 (0)