Skip to content

Commit 6071f19

Browse files
authored
Merge pull request #37 from Azure/test-controller
Common test controller framework
2 parents 6557ed7 + a1331a5 commit 6071f19

17 files changed

+753
-35
lines changed

Azure.PowerShell.Common.Netcore.sln

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Compute.Test.Netcore", "src
4343
EndProject
4444
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Strategies.Test.Netcore", "src\Strategies.Test\Strategies.Test.Netcore.csproj", "{6756A7F2-1141-4065-BA23-0C555D2A2BC3}"
4545
EndProject
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFx.Netcore", "src\TestFx\TestFx.Netcore.csproj", "{1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}"
47+
EndProject
4648
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Authentication.Test.Netcore", "src\Authentication.Test\Authentication.Test.Netcore.csproj", "{78D9B754-6A18-4125-80CC-63437BDE3244}"
4749
EndProject
4850
Global
@@ -127,6 +129,10 @@ Global
127129
{6756A7F2-1141-4065-BA23-0C555D2A2BC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
128130
{6756A7F2-1141-4065-BA23-0C555D2A2BC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
129131
{6756A7F2-1141-4065-BA23-0C555D2A2BC3}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Release|Any CPU.Build.0 = Release|Any CPU
130136
{78D9B754-6A18-4125-80CC-63437BDE3244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131137
{78D9B754-6A18-4125-80CC-63437BDE3244}.Debug|Any CPU.Build.0 = Debug|Any CPU
132138
{78D9B754-6A18-4125-80CC-63437BDE3244}.Release|Any CPU.ActiveCfg = Release|Any CPU

Azure.PowerShell.Common.sln

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strategies.Test", "src\Stra
5151
EndProject
5252
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScenarioTest", "src\ScenarioTest\ScenarioTest.csproj", "{C1BDA476-A5CC-4394-914D-48B0EC31A710}"
5353
EndProject
54+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestFx", "src\TestFx\TestFx.csproj", "{8C625DE3-0067-454A-AF2C-EFD672EEB31A}"
55+
EndProject
5456
Global
5557
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5658
Debug|Any CPU = Debug|Any CPU
@@ -149,6 +151,10 @@ Global
149151
{C1BDA476-A5CC-4394-914D-48B0EC31A710}.Debug|Any CPU.Build.0 = Debug|Any CPU
150152
{C1BDA476-A5CC-4394-914D-48B0EC31A710}.Release|Any CPU.ActiveCfg = Release|Any CPU
151153
{C1BDA476-A5CC-4394-914D-48B0EC31A710}.Release|Any CPU.Build.0 = Release|Any CPU
154+
{8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155+
{8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Debug|Any CPU.Build.0 = Debug|Any CPU
156+
{8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Release|Any CPU.ActiveCfg = Release|Any CPU
157+
{8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Release|Any CPU.Build.0 = Release|Any CPU
152158
EndGlobalSection
153159
GlobalSection(SolutionProperties) = preSolution
154160
HideSolutionNode = FALSE

build/sign.proj

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<ItemGroup>
2424
<UnsignedFiles Include="$(OutputDir)net452\Microsoft.Azure.Commands*.dll" />
2525
<UnsignedFiles Include="$(OutputDir)net452\Microsoft.WindowsAzure.Commands*.dll" />
26+
<UnsignedFiles Include="$(OutputDir)net452\Microsoft.Azure.PowerShell*.dll" Exclude="$(OutputDir)net452\Microsoft.Azure.PowerShell*.Test.dll" />
2627
</ItemGroup>
2728
</Target>
2829

src/Aks/Aks.Netcore.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<Import Project="$(ProjectDir)..\Dependencies.Netcore.targets" />
4-
5-
<PropertyGroup>
4+
5+
<PropertyGroup>
66
<TargetFramework>netstandard2.0</TargetFramework>
77
<AssemblyName>Microsoft.Azure.PowerShell.Aks</AssemblyName>
88
<RootNamespace>Microsoft.Azure.Commands.Common.Aks</RootNamespace>

src/Dependencies.Test.targets

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
</PropertyGroup>
66

77
<Import Project="$(MSBuildThisFileDirectory)Dependencies.targets" />
8-
<Import Project="$(PackagesDirectory)MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('$(PackagesDirectory)MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props') and '$(ServiceManagementDependencies)' == 'true'" />
9-
<Import Project="$(PackagesDirectory)xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('$(PackagesDirectory)xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
10-
<Import Project="$(PackagesDirectory)xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props" Condition="Exists('$(PackagesDirectory)xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" />
8+
<Import Project="$(PackagesDirectory)MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('$(PackagesDirectory)MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props') and '$(ServiceManagementDependencies)' == 'true' and '$(UseTestImports)' != 'false'" />
9+
<Import Project="$(PackagesDirectory)xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('$(PackagesDirectory)xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props') and '$(UseTestImports)' != 'false'" />
10+
<Import Project="$(PackagesDirectory)xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props" Condition="Exists('$(PackagesDirectory)xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props') and '$(UseTestImports)' != 'false'" />
1111

1212
<ItemGroup>
1313
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">

src/ScenarioTest.ResourceManager/EnvironmentSetupHelper.cs

+25-30
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,7 @@ public void SetupModulesFromCommon(AzureModule mode, params string[] modules)
585585

586586
public void SetupModules(params string[] modules)
587587
{
588-
this.modules = new List<string>();
589-
this.modules.Add("Assert.ps1");
590-
this.modules.Add("Common.ps1");
588+
this.modules = new List<string> {"Assert.ps1", "Common.ps1"};
591589
this.modules.AddRange(modules);
592590
}
593591

@@ -597,14 +595,18 @@ public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
597595
// permissive record matcher.
598596
if (HttpMockServer.Matcher == null || HttpMockServer.Matcher.GetType() == typeof(SimpleRecordMatcher))
599597
{
600-
Dictionary<string, string> d = new Dictionary<string, string>();
601-
d.Add("Microsoft.Resources", null);
602-
d.Add("Microsoft.Features", null);
603-
d.Add("Microsoft.Authorization", null);
604-
d.Add("Microsoft.Compute", null);
605-
d.Add("Microsoft.KeyVault", null);
606-
var providersToIgnore = new Dictionary<string, string>();
607-
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
598+
var d = new Dictionary<string, string>
599+
{
600+
{"Microsoft.Resources", null},
601+
{"Microsoft.Features", null},
602+
{"Microsoft.Authorization", null},
603+
{"Microsoft.Compute", null},
604+
{"Microsoft.KeyVault", null}
605+
};
606+
var providersToIgnore = new Dictionary<string, string>
607+
{
608+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}
609+
};
608610
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);
609611
}
610612

@@ -613,26 +615,18 @@ public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
613615
SetupPowerShellModules(powershell);
614616

615617
Collection<PSObject> output = null;
616-
for (int i = 0; i < scripts.Length; ++i)
618+
foreach (var script in scripts)
617619
{
618-
if (TracingInterceptor != null)
619-
{
620-
TracingInterceptor.Information(scripts[i]);
621-
}
622-
powershell.AddScript(scripts[i]);
620+
TracingInterceptor?.Information(script);
621+
powershell.AddScript(script);
623622
}
624623
try
625624
{
626625
output = powershell.Invoke();
627626
if (powershell.Streams.Error.Count > 0)
628627
{
629628
throw new RuntimeException(
630-
string.Format(
631-
"Test failed due to a non-empty error stream. First error: {0}{1}",
632-
PowerShellExtensions.FormatErrorRecord(powershell.Streams.Error[0]),
633-
powershell.Streams.Error.Count > 0
634-
? "Check the error stream in the test log for additional errors."
635-
: ""));
629+
$"Test failed due to a non-empty error stream. First error: {PowerShellExtensions.FormatErrorRecord(powershell.Streams.Error[0])}{(powershell.Streams.Error.Count > 0 ? "Check the error stream in the test log for additional errors." : "")}");
636630
}
637631

638632
return output;
@@ -660,13 +654,14 @@ private void SetupPowerShellModules(System.Management.Automation.PowerShell powe
660654
}
661655
#endif
662656
powershell.AddScript("$error.clear()");
663-
powershell.AddScript(string.Format("Write-Debug \"current directory: {0}\"", System.AppDomain.CurrentDomain.BaseDirectory));
664-
powershell.AddScript(string.Format("Write-Debug \"current executing assembly: {0}\"", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
665-
powershell.AddScript(string.Format("cd \"{0}\"", System.AppDomain.CurrentDomain.BaseDirectory));
657+
powershell.AddScript($"Write-Debug \"current directory: {System.AppDomain.CurrentDomain.BaseDirectory}\"");
658+
powershell.AddScript(
659+
$"Write-Debug \"current executing assembly: {Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\"");
660+
powershell.AddScript($"cd \"{System.AppDomain.CurrentDomain.BaseDirectory}\"");
666661

667-
foreach (string moduleName in modules)
662+
foreach (var moduleName in modules)
668663
{
669-
powershell.AddScript(string.Format("Import-Module \"{0}\"", moduleName.AsAbsoluteLocation()));
664+
powershell.AddScript($"Import-Module \"{moduleName.AsAbsoluteLocation()}\"");
670665
if (moduleName.EndsWith(".psd1"))
671666
{
672667
#if NETSTANDARD
@@ -682,8 +677,8 @@ private void SetupPowerShellModules(System.Management.Automation.PowerShell powe
682677

683678
powershell.AddScript("Disable-AzureRmDataCollection -ErrorAction Ignore");
684679
powershell.AddScript(
685-
string.Format("set-location \"{0}\"", System.AppDomain.CurrentDomain.BaseDirectory));
686-
powershell.AddScript(string.Format(@"$TestOutputRoot='{0}'", System.AppDomain.CurrentDomain.BaseDirectory));
680+
$"set-location \"{System.AppDomain.CurrentDomain.BaseDirectory}\"");
681+
powershell.AddScript($@"$TestOutputRoot='{System.AppDomain.CurrentDomain.BaseDirectory}'");
687682
powershell.AddScript("$VerbosePreference='Continue'");
688683
powershell.AddScript("$DebugPreference='Continue'");
689684
powershell.AddScript("$ErrorActionPreference='Stop'");

src/ScenarioTest.ResourceManager/ScenarioTest.ResourceManager.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<UseTestImports>false</UseTestImports>
5+
</PropertyGroup>
36
<Import Project="$(ProjectDir)..\Dependencies.Test.targets" />
47
<PropertyGroup>
58
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

src/ScenarioTest/ScenarioTest.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<ServiceManagementDependencies>true</ServiceManagementDependencies>
5+
<UseTestImports>false</UseTestImports>
56
</PropertyGroup>
67
<Import Project="$(ProjectDir)..\Dependencies.Test.targets" />
78
<PropertyGroup>

src/TestFx/ITestRunner.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
namespace Microsoft.Azure.Commands.TestFx
16+
{
17+
public interface ITestRunner
18+
{
19+
void RunTestScript(params string[] scripts);
20+
}
21+
}

src/TestFx/ITestRunnerFactory.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
19+
namespace Microsoft.Azure.Commands.TestFx
20+
{
21+
public interface ITestRunnerFactory
22+
{
23+
ITestRunner Build();
24+
ITestRunnerFactory WithProjectSubfolderForTests(string folderName);
25+
ITestRunnerFactory WithCommonPsScripts(string[] psScriptList);
26+
ITestRunnerFactory WithNewPsScriptFilename(string psScriptName);
27+
ITestRunnerFactory WithExtraRmModules(Func<EnvironmentSetupHelper, string[]> buildModuleList);
28+
ITestRunnerFactory WithNewRmModules(Func<EnvironmentSetupHelper, string[]> buildModuleList);
29+
ITestRunnerFactory WithExtraUserAgentsToIgnore(Dictionary<string, string> userAgentsToIgnore);
30+
ITestRunnerFactory WithRecordMatcher(RecordMatcherDelegate recordMatcher);
31+
}
32+
}

src/TestFx/Properties/AssemblyInfo.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("Microsoft Azure PowerShell TestFx")]
8+
[assembly: AssemblyDescription("Microsoft Azure PowerShell TestFx library. Only for use with the Azure PowerShell runtime. Not intended for general development use.")]
9+
[assembly: AssemblyProduct("Microsoft Azure PowerShell")]
10+
[assembly: AssemblyCompany("Microsoft Corporation")]
11+
[assembly: AssemblyCopyright("Copyright © Microsoft Corporation")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("8c625de3-0067-454a-af2c-efd672eeb31a")]
20+
21+
// Version information for an assembly consists of the following four values:
22+
//
23+
// Major Version
24+
// Minor Version
25+
// Build Number
26+
// Revision
27+
//
28+
// You can specify all the values or you can default the Build and Revision Numbers
29+
// by using the '*' as shown below:
30+
// [assembly: AssemblyVersion("1.0.*")]
31+
[assembly: AssemblyVersion("1.0.0.0")]
32+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)