Skip to content

huangpf PR: dev <- Azure:dev #604

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 3 commits into from
Sep 1, 2016
Merged
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 @@ -17,7 +17,8 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<NuGetPackageImportStamp>653414c6</NuGetPackageImportStamp>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -64,18 +65,23 @@
<Reference Include="Microsoft.Azure.Graph.RBAC">
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.3.2.0-preview\lib\net45\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.1.0.0\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
<Reference Include="Microsoft.Azure.KeyVault, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.2.0.1-preview\lib\net45\Microsoft.Azure.KeyVault.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault.WebKey, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.KeyVault.WebKey.2.0.0-preview\lib\net45\Microsoft.Azure.KeyVault.WebKey.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.Authorization">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Common.NetFramework">
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.KeyVault, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.1.0.1\lib\net40\Microsoft.Azure.Management.KeyVault.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.KeyVault, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.KeyVault.2.0.0-preview\lib\net45\Microsoft.Azure.Management.KeyVault.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down Expand Up @@ -148,6 +154,8 @@
<HintPath>..\..\..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
Expand Down Expand Up @@ -200,16 +208,15 @@
<None Include="Scripts\Common.ps1" />
<None Include="Scripts\ControlPlane\Common.ps1" />
<None Include="Scripts\ControlPlane\KeyVaultManagementTests.ps1">
<Link>ScenarioTests\KeyVaultManagementTests.ps1</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Scripts\ControlPlane\KeyVaultManagementTests.ps1" />
<None Include="Scripts\proddata\byoktest.byok" />
<None Include="Scripts\proddata\byoktest1024.byok" />
<None Include="Scripts\proddata\pfxtest.pfx" />
<None Include="Scripts\proddata\pfxtest1024.pfx" />
<None Include="Scripts\RunKeyVaultTests.ps1" />
<None Include="Scripts\RunUITests.ps1" />
<None Include="Scripts\VaultCertificateTests.ps1" />
<None Include="Scripts\VaultKeyTests.ps1" />
<None Include="Scripts\VaultManagementTests.ps1" />
<None Include="Scripts\VaultSecretTests.ps1" />
Expand Down Expand Up @@ -335,11 +342,19 @@
<EmbeddedResource Include="Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="Scripts\readme.txt" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function Get-VaultName

<#
.SYNOPSIS
Gets the location for the Website. Default to West US if none found.
Gets the location for the Vault. Default to West US if none found.
#>
function Get-Location
{
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetCurrentMode() -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
{
$namespace = "Microsoft.KeyVault"
$type = "vaults"
Expand All @@ -60,7 +60,7 @@ Gets the default location for a provider
#>
function Get-ProviderLocation($provider)
{
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetCurrentMode() -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
{
$namespace = $provider.Split("/")[0]
if($provider.Contains("/"))
Expand Down Expand Up @@ -89,7 +89,7 @@ Cleans the created resource groups
#>
function Clean-ResourceGroup($rgname)
{
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback) {
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetCurrentMode() -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback) {
Remove-AzureRmResourceGroup -Name $rgname -Force
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void SetupEnvironment()

private string GetTenantId(TestEnvironment environment)
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
HttpMockServer.Variables["TenantId"] = environment.AuthorizationContext.TenantId;
return environment.AuthorizationContext.TenantId;
Expand All @@ -84,7 +84,7 @@ private string GetTenantId(TestEnvironment environment)

private string GetUser(TestEnvironment environment)
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
HttpMockServer.Variables["User"] = environment.AuthorizationContext.UserId;
return environment.AuthorizationContext.UserId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
using Microsoft.Azure.Management.Authorization;
using Microsoft.Azure.Management.KeyVault;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.ServiceManagemenet.Common.Models;
using Microsoft.Azure.Subscriptions;
using Microsoft.Azure.Test;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LegacyTest = Microsoft.Azure.Test;

namespace Microsoft.Azure.Commands.KeyVault.Test
{
Expand All @@ -38,10 +40,11 @@ namespace Microsoft.Azure.Commands.KeyVault.Test
public class KeyVaultManagementController
{

private CSMTestEnvironmentFactory csmTestFactory;
private LegacyTest.CSMTestEnvironmentFactory csmTestFactory;
private KeyVaultEnvSetupHelper helper;
private const string TenantIdKey = "TenantId";
private const string DomainKey = "Domain";
private const string SubscriptionIdKey = "SubscriptionId";

public ResourceManagementClient ResourceManagementClient { get; private set; }

Expand Down Expand Up @@ -70,11 +73,13 @@ public KeyVaultManagementController()
helper = new KeyVaultEnvSetupHelper();
}

public void RunPsTest(params string[] scripts)
public void RunPsTest(XunitTracingInterceptor logger, params string[] scripts)
{
var callingClassType = TestUtilities.GetCallingClass(2);
var mockName = TestUtilities.GetCurrentMethodName(2);

logger.Information(string.Format("Test method entered: {0}.{1}", callingClassType, mockName));
helper.TracingInterceptor = logger;
RunPsTestWorkflow(
() => scripts,
// no custom initializer
Expand All @@ -83,12 +88,13 @@ public void RunPsTest(params string[] scripts)
null,
callingClassType,
mockName);
logger.Information(string.Format("Test method finished: {0}.{1}", callingClassType, mockName));
}


public void RunPsTestWorkflow(
Func<string[]> scriptBuilder,
Action<CSMTestEnvironmentFactory> initialize,
Action<LegacyTest.CSMTestEnvironmentFactory> initialize,
Action cleanup,
string callingClassType,
string mockName)
Expand All @@ -104,7 +110,7 @@ public void RunPsTestWorkflow(
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
using (MockContext context = MockContext.Start(callingClassType, mockName))
{
this.csmTestFactory = new CSMTestEnvironmentFactory();
this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory();

if (initialize != null)
{
Expand All @@ -120,7 +126,7 @@ public void RunPsTestWorkflow(
.Last();
helper.SetupModules(AzureModule.AzureResourceManager,
"ScenarioTests\\Common.ps1",
"ScenarioTests\\" + callingClassName + ".ps1",
"Scripts\\ControlPlane\\" + callingClassName + ".ps1",
helper.RMProfileModule,
helper.RMResourceModule,
helper.GetRMModulePath("AzureRM.KeyVault.psd1"));
Expand Down Expand Up @@ -154,7 +160,7 @@ private void SetupManagementClients(MockContext context)
GalleryClient = GetGalleryClient();
AuthorizationManagementClient = GetAuthorizationManagementClient();
GraphClient = GetGraphClient(context);
KeyVaultManagementClient = GetKeyVaultManagementClient();
KeyVaultManagementClient = GetKeyVaultManagementClient(context);
helper.SetupManagementClients(ResourceManagementClient,
SubscriptionClient,
KeyVaultManagementClient,
Expand All @@ -167,26 +173,26 @@ private void SetupManagementClients(MockContext context)

private AuthorizationManagementClient GetAuthorizationManagementClient()
{
return TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
return LegacyTest.TestBase.GetServiceClient<AuthorizationManagementClient>(this.csmTestFactory);
}

private ResourceManagementClient GetResourceManagementClient()
{
return TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
return LegacyTest.TestBase.GetServiceClient<ResourceManagementClient>(this.csmTestFactory);
}

private KeyVaultManagementClient GetKeyVaultManagementClient()
private KeyVaultManagementClient GetKeyVaultManagementClient(MockContext context)
{
return TestBase.GetServiceClient<KeyVaultManagementClient>(this.csmTestFactory);
return context.GetServiceClient<KeyVaultManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
}
private SubscriptionClient GetSubscriptionClient()
{
return TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
return LegacyTest.TestBase.GetServiceClient<SubscriptionClient>(this.csmTestFactory);
}

private GalleryClient GetGalleryClient()
{
return TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
return LegacyTest.TestBase.GetServiceClient<GalleryClient>(this.csmTestFactory);
}

private GraphRbacManagementClient GetGraphClient(MockContext context)
Expand All @@ -207,19 +213,27 @@ private GraphRbacManagementClient GetGraphClient(MockContext context)
if (HttpMockServer.Variables.ContainsKey(TenantIdKey))
{
tenantId = HttpMockServer.Variables[TenantIdKey];
AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = new Guid(tenantId);
}
if (HttpMockServer.Variables.ContainsKey(DomainKey))
{
UserDomain = HttpMockServer.Variables[DomainKey];
AzureRmProfileProvider.Instance.Profile.Context.Tenant.Domain = UserDomain;
}

if (HttpMockServer.Variables.ContainsKey(SubscriptionIdKey))
{
AzureRmProfileProvider.Instance.Profile.Context.Subscription.Id = new Guid(HttpMockServer.Variables[SubscriptionIdKey]);
}
}

var client = context.GetGraphServiceClient<GraphRbacManagementClient>(environment);
client.TenantID = tenantId;
return client;
if (AzureRmProfileProvider.Instance != null &&
AzureRmProfileProvider.Instance.Profile != null &&
AzureRmProfileProvider.Instance.Profile.Context != null &&
AzureRmProfileProvider.Instance.Profile.Context.Tenant != null)
{
AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = Guid.Parse(client.TenantID);
}
return client;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

using Microsoft.Azure.Graph.RBAC;
using Microsoft.Azure.Graph.RBAC.Models;
using Microsoft.Azure.ServiceManagemenet.Common.Models;
using Microsoft.Azure.Test;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.KeyVault.Test.ScenarioTests
{
Expand All @@ -38,7 +40,7 @@ public KeyVaultManagementTests(KeyVaultTestFixture fixture)

private void Initialize()
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
HttpMockServer.Variables["ResourceGroupName"] = _data.resourceGroupName;
HttpMockServer.Variables["Location"] = _data.location;
Expand Down Expand Up @@ -631,7 +633,7 @@ public void TestCreateDeleteVaultWithPiping()
#region Helper Methods
private string GetUser(TestEnvironment environment)
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
HttpMockServer.Variables["User"] = environment.AuthorizationContext.UserId;
return environment.AuthorizationContext.UserId;
Expand All @@ -644,7 +646,7 @@ private string GetUser(TestEnvironment environment)

private string GetUserObjectId(KeyVaultManagementController controllerAdmin, string upn)
{
if (HttpMockServer.Mode == HttpRecorderMode.Record)
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
var user = controllerAdmin.GraphClient.Users.Get(upn);
HttpMockServer.Variables["ObjectId"] = user.ObjectId;
Expand All @@ -661,7 +663,7 @@ private Guid GetApplicationId(TestEnvironment environment, int appNum)
if (appNum < 0)
throw new ArgumentException("Invalid appNum");
string variableName = "AppId" + appNum;
if (HttpMockServer.Mode == HttpRecorderMode.Record)
if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
{
Guid appId = Guid.NewGuid();
HttpMockServer.Variables[variableName] = appId.ToString();
Expand Down
Loading