Skip to content

, #396

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 6 commits into from
Feb 9, 2016
Merged

, #396

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 @@ -167,6 +167,7 @@
<Compile Include="ScenarioTests\ComputeCloudExceptionTests.cs" />
<Compile Include="ScenarioTests\DiagnosticsExtensionTests.cs" />
<Compile Include="ScenarioTests\DscExtensionTests.cs" />
<Compile Include="ScenarioTests\RunnerTests.cs" />
<Compile Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.cs" />
<Compile Include="ScenarioTests\VMDynamicTests.cs" />
<Compile Include="ScenarioTests\VirtualMachineProfileTests.cs" />
Expand Down Expand Up @@ -237,6 +238,9 @@
<None Include="ScenarioTests\Generated\VirtualMachineDynamicTest3.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\RunnerTests.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;

namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
{
public class RunnerTests
{
[Fact]
public void ExecuteRunnerTests()
{
var mode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
var csmAuth = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION");

if (mode == null || csmAuth == null || mode.ToLower() != "record")
{
return;
}

Assert.False(string.IsNullOrEmpty(csmAuth));
Assert.True(csmAuth.Contains("AADTenant"));

var envDictionary = TestUtilities.ParseConnectionString(csmAuth);
var testEnv = new TestEnvironment(envDictionary);
Assert.NotNull(testEnv.Tenant);
Assert.NotNull(testEnv.SubscriptionId);
Assert.NotNull(testEnv.ClientId);
Assert.True(envDictionary.ContainsKey("ApplicationSecret"));

var authenticationContext = new AuthenticationContext("https://login.windows.net/" + testEnv.Tenant);
var credential = new ClientCredential(testEnv.ClientId, envDictionary["ApplicationSecret"]);

var result = authenticationContext.AcquireToken("https://management.core.windows.net/", clientCredential: credential);
Assert.NotNull(result.AccessToken);
envDictionary["RawToken"] = result.AccessToken;

FixCSMAuthEnvVariable(envDictionary);

Console.WriteLine(Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"));

var testFile = File.ReadAllLines("ScenarioTests\\RunnerTests.csv");
foreach (var line in testFile)
{
var tokens = line.Split(';');
var className = tokens[0];
var type = Type.GetType(className);
var constructorInfo = type.GetConstructor(Type.EmptyTypes);
for (int i = 1; i < tokens.Length; i++)
{
var method = tokens[i];
var testClassInstance = constructorInfo.Invoke(new object[] {});
var testMethod = type.GetMethod(method);

testMethod.Invoke(testClassInstance, new object[] {});
}
}
}

private void FixCSMAuthEnvVariable(IDictionary<string, string> envDictionary)
{
var str = string.Empty;
foreach (var entry in envDictionary)
{
if (entry.Key != "AADClientId" && entry.Key != "ApplicationSecret")
{
str += string.Format("{0}={1};", entry.Key, entry.Value);
}
}

Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", str);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AvailabilitySetTests;TestAvailabilitySet
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.ComputeCloudExceptionTests;RunComputeCloudExceptionTests
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests;TestLinuxVirtualMachine
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineProfileTests;TestVirtualMachineProfile
Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VMDynamicTests;RunVMDynamicTests