From d589b6d9dcf9853150099c4620c455d707af6b85 Mon Sep 17 00:00:00 2001 From: vlashch Date: Mon, 20 Aug 2018 11:37:46 -0700 Subject: [PATCH 01/16] Common test controller stuff. --- Azure.PowerShell.Common.Netcore.sln | 6 + Azure.PowerShell.Common.sln | 6 + .../EnvironmentSetupHelper.cs | 55 ++-- src/TestFx/ITestRunner.cs | 21 ++ src/TestFx/ITestRunnerFactory.cs | 32 ++ src/TestFx/Properties/AssemblyInfo.cs | 32 ++ src/TestFx/TestClientFactory.cs | 144 +++++++++ src/TestFx/TestFx.Netcore.csproj | 56 ++++ src/TestFx/TestFx.csproj | 144 +++++++++ src/TestFx/TestFx.nuspec | 16 + src/TestFx/TestManager.cs | 296 ++++++++++++++++++ src/TestFx/TestRunnerBase.cs | 31 ++ src/TestFx/packages.config | 22 ++ 13 files changed, 831 insertions(+), 30 deletions(-) create mode 100644 src/TestFx/ITestRunner.cs create mode 100644 src/TestFx/ITestRunnerFactory.cs create mode 100644 src/TestFx/Properties/AssemblyInfo.cs create mode 100644 src/TestFx/TestClientFactory.cs create mode 100644 src/TestFx/TestFx.Netcore.csproj create mode 100644 src/TestFx/TestFx.csproj create mode 100644 src/TestFx/TestFx.nuspec create mode 100644 src/TestFx/TestManager.cs create mode 100644 src/TestFx/TestRunnerBase.cs create mode 100644 src/TestFx/packages.config diff --git a/Azure.PowerShell.Common.Netcore.sln b/Azure.PowerShell.Common.Netcore.sln index 78b474e3a6..7c2d359a59 100644 --- a/Azure.PowerShell.Common.Netcore.sln +++ b/Azure.PowerShell.Common.Netcore.sln @@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Compute.Test.Netcore", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Strategies.Test.Netcore", "src\Strategies.Test\Strategies.Test.Netcore.csproj", "{6756A7F2-1141-4065-BA23-0C555D2A2BC3}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFx.Netcore", "src\TestFx\TestFx.Netcore.csproj", "{1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -125,6 +127,10 @@ Global {6756A7F2-1141-4065-BA23-0C555D2A2BC3}.Debug|Any CPU.Build.0 = Debug|Any CPU {6756A7F2-1141-4065-BA23-0C555D2A2BC3}.Release|Any CPU.ActiveCfg = Release|Any CPU {6756A7F2-1141-4065-BA23-0C555D2A2BC3}.Release|Any CPU.Build.0 = Release|Any CPU + {1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E20E5A0-3353-4888-9B29-AE1A2C1C8DD0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Azure.PowerShell.Common.sln b/Azure.PowerShell.Common.sln index 5e2110e060..d8956bcafc 100644 --- a/Azure.PowerShell.Common.sln +++ b/Azure.PowerShell.Common.sln @@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Strategies.Test", "src\Stra EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScenarioTest", "src\ScenarioTest\ScenarioTest.csproj", "{C1BDA476-A5CC-4394-914D-48B0EC31A710}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestFx", "src\TestFx\TestFx.csproj", "{8C625DE3-0067-454A-AF2C-EFD672EEB31A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -149,6 +151,10 @@ Global {C1BDA476-A5CC-4394-914D-48B0EC31A710}.Debug|Any CPU.Build.0 = Debug|Any CPU {C1BDA476-A5CC-4394-914D-48B0EC31A710}.Release|Any CPU.ActiveCfg = Release|Any CPU {C1BDA476-A5CC-4394-914D-48B0EC31A710}.Release|Any CPU.Build.0 = Release|Any CPU + {8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C625DE3-0067-454A-AF2C-EFD672EEB31A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/ScenarioTest.ResourceManager/EnvironmentSetupHelper.cs b/src/ScenarioTest.ResourceManager/EnvironmentSetupHelper.cs index 41bc36aaaa..aee916b454 100644 --- a/src/ScenarioTest.ResourceManager/EnvironmentSetupHelper.cs +++ b/src/ScenarioTest.ResourceManager/EnvironmentSetupHelper.cs @@ -585,9 +585,7 @@ public void SetupModulesFromCommon(AzureModule mode, params string[] modules) public void SetupModules(params string[] modules) { - this.modules = new List(); - this.modules.Add("Assert.ps1"); - this.modules.Add("Common.ps1"); + this.modules = new List {"Assert.ps1", "Common.ps1"}; this.modules.AddRange(modules); } @@ -597,14 +595,18 @@ public virtual Collection RunPowerShellTest(params string[] scripts) // permissive record matcher. if (HttpMockServer.Matcher == null || HttpMockServer.Matcher.GetType() == typeof(SimpleRecordMatcher)) { - Dictionary d = new Dictionary(); - d.Add("Microsoft.Resources", null); - d.Add("Microsoft.Features", null); - d.Add("Microsoft.Authorization", null); - d.Add("Microsoft.Compute", null); - d.Add("Microsoft.KeyVault", null); - var providersToIgnore = new Dictionary(); - providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"); + var d = new Dictionary + { + {"Microsoft.Resources", null}, + {"Microsoft.Features", null}, + {"Microsoft.Authorization", null}, + {"Microsoft.Compute", null}, + {"Microsoft.KeyVault", null} + }; + var providersToIgnore = new Dictionary + { + {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} + }; HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore); } @@ -613,13 +615,10 @@ public virtual Collection RunPowerShellTest(params string[] scripts) SetupPowerShellModules(powershell); Collection output = null; - for (int i = 0; i < scripts.Length; ++i) + foreach (var script in scripts) { - if (TracingInterceptor != null) - { - TracingInterceptor.Information(scripts[i]); - } - powershell.AddScript(scripts[i]); + TracingInterceptor?.Information(script); + powershell.AddScript(script); } try { @@ -627,12 +626,7 @@ public virtual Collection RunPowerShellTest(params string[] scripts) if (powershell.Streams.Error.Count > 0) { throw new RuntimeException( - string.Format( - "Test failed due to a non-empty error stream. First error: {0}{1}", - PowerShellExtensions.FormatErrorRecord(powershell.Streams.Error[0]), - powershell.Streams.Error.Count > 0 - ? "Check the error stream in the test log for additional errors." - : "")); + $"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." : "")}"); } return output; @@ -660,13 +654,14 @@ private void SetupPowerShellModules(System.Management.Automation.PowerShell powe } #endif powershell.AddScript("$error.clear()"); - powershell.AddScript(string.Format("Write-Debug \"current directory: {0}\"", System.AppDomain.CurrentDomain.BaseDirectory)); - powershell.AddScript(string.Format("Write-Debug \"current executing assembly: {0}\"", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))); - powershell.AddScript(string.Format("cd \"{0}\"", System.AppDomain.CurrentDomain.BaseDirectory)); + powershell.AddScript($"Write-Debug \"current directory: {System.AppDomain.CurrentDomain.BaseDirectory}\""); + powershell.AddScript( + $"Write-Debug \"current executing assembly: {Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\""); + powershell.AddScript($"cd \"{System.AppDomain.CurrentDomain.BaseDirectory}\""); - foreach (string moduleName in modules) + foreach (var moduleName in modules) { - powershell.AddScript(string.Format("Import-Module \"{0}\"", moduleName.AsAbsoluteLocation())); + powershell.AddScript($"Import-Module \"{moduleName.AsAbsoluteLocation()}\""); if (moduleName.EndsWith(".psd1")) { #if NETSTANDARD @@ -677,8 +672,8 @@ private void SetupPowerShellModules(System.Management.Automation.PowerShell powe } powershell.AddScript( - string.Format("set-location \"{0}\"", System.AppDomain.CurrentDomain.BaseDirectory)); - powershell.AddScript(string.Format(@"$TestOutputRoot='{0}'", System.AppDomain.CurrentDomain.BaseDirectory)); + $"set-location \"{System.AppDomain.CurrentDomain.BaseDirectory}\""); + powershell.AddScript($@"$TestOutputRoot='{System.AppDomain.CurrentDomain.BaseDirectory}'"); powershell.AddScript("$VerbosePreference='Continue'"); powershell.AddScript("$DebugPreference='Continue'"); powershell.AddScript("$ErrorActionPreference='Stop'"); diff --git a/src/TestFx/ITestRunner.cs b/src/TestFx/ITestRunner.cs new file mode 100644 index 0000000000..b833046a97 --- /dev/null +++ b/src/TestFx/ITestRunner.cs @@ -0,0 +1,21 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +namespace Microsoft.Azure.Commands.TestFx +{ + public interface ITestRunner + { + void RunTestScript(params string[] scripts); + } +} diff --git a/src/TestFx/ITestRunnerFactory.cs b/src/TestFx/ITestRunnerFactory.cs new file mode 100644 index 0000000000..6de9e74085 --- /dev/null +++ b/src/TestFx/ITestRunnerFactory.cs @@ -0,0 +1,32 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using Microsoft.WindowsAzure.Commands.ScenarioTest; + +namespace Microsoft.Azure.Commands.TestFx +{ + public interface ITestRunnerFactory + { + ITestRunner Build(); + ITestRunnerFactory WithProjectSubfolderForTests(string folderName); + ITestRunnerFactory WithCommonPsScripts(string[] psScriptList); + ITestRunnerFactory WithNewPsScriptFilename(string psScriptName); + ITestRunnerFactory WithExtraRmModules(Func buildModuleList); + ITestRunnerFactory WithNewRmModules(Func buildModuleList); + ITestRunnerFactory WithExtraUserAgentsToIgnore(Dictionary userAgentsToIgnore); + ITestRunnerFactory WithBuildMatcher(BuildMatcherDelegate buildMatcher); + } +} diff --git a/src/TestFx/Properties/AssemblyInfo.cs b/src/TestFx/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..b886e27102 --- /dev/null +++ b/src/TestFx/Properties/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Microsoft Azure PowerShell TestFx")] +[assembly: AssemblyDescription("Microsoft Azure PowerShell TestFx library. Only for use with the Azure PowerShell runtime. Not intended for general development use.")] +[assembly: AssemblyProduct("Microsoft Azure PowerShell")] +[assembly: AssemblyCompany("Microsoft Corporation")] +[assembly: AssemblyCopyright("Copyright © Microsoft Corporation")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8c625de3-0067-454a-af2c-efd672eeb31a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/TestFx/TestClientFactory.cs b/src/TestFx/TestClientFactory.cs new file mode 100644 index 0000000000..9f6fac9aea --- /dev/null +++ b/src/TestFx/TestClientFactory.cs @@ -0,0 +1,144 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using Hyak.Common; +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Graph.RBAC.Version1_6; +using Microsoft.Rest; +using Microsoft.Rest.ClientRuntime.Azure.TestFramework; + +namespace Microsoft.Azure.Commands.TestFx +{ + public class TestClientFactory : IClientFactory + { + private readonly MockContext _mockContext; + + public TestClientFactory(MockContext mockContext) + { + _mockContext = mockContext ?? throw new ArgumentNullException(nameof(mockContext)); + } + + public TClient CreateArmClient(IAzureContext context, string endpoint) where TClient : Rest.ServiceClient + { + if (typeof(TClient) != typeof(GraphRbacManagementClient)) + { + return _mockContext.GetServiceClient(); + } + + var graphClient = _mockContext.GetGraphServiceClient(); + graphClient.TenantID = context.Tenant.Id; + return graphClient as TClient; + } + + public TClient CreateCustomArmClient(params object[] parameters) where TClient : Rest.ServiceClient + { + return _mockContext.GetServiceClient(); + } + + public HttpClient CreateHttpClient(string endpoint, ICredentials credentials) + { + throw new NotImplementedException(); + } + + public HttpClient CreateHttpClient(string endpoint, HttpMessageHandler effectiveHandler) + { + throw new NotImplementedException(); + } + + #region Action and Handler + + public void AddAction(IClientAction action) + { + // Do nothing + } + + public void RemoveAction(Type actionType) + { + // Do nothing + } + + public void AddHandler(T handler) where T : DelegatingHandler, ICloneable + { + // Do nothing + } + + public void RemoveHandler(Type handlerType) + { + // Do nothing + } + public DelegatingHandler[] GetCustomHandlers() + { + // Do nothing + return new DelegatingHandler[0]; + } + + #endregion + + #region UserAgent + + public HashSet UniqueUserAgents { get; set; } = new HashSet(); + + public void AddUserAgent(string productName, string productVersion) + { + UniqueUserAgents.Add(new ProductInfoHeaderValue(productName, productVersion)); + } + + public void AddUserAgent(string productName) + { + AddUserAgent(productName, string.Empty); + } + + public void RemoveUserAgent(string name) + { + UniqueUserAgents.RemoveWhere(p => string.Equals(p.Product.Name, name, StringComparison.OrdinalIgnoreCase)); + } + + public ProductInfoHeaderValue[] UserAgents => UniqueUserAgents.ToArray(); + + #endregion + + #region Hyak + + public TClient CreateClient(IAzureContext context, string endpoint) where TClient : Hyak.Common.ServiceClient + { + throw new NotImplementedException(); + } + + public TClient CreateClient(IAzureContextContainer profile, string endpoint) where TClient : Hyak.Common.ServiceClient + { + throw new NotImplementedException(); + } + + public TClient CreateClient(IAzureContextContainer profile, IAzureSubscription subscription, string endpoint) where TClient : Hyak.Common.ServiceClient + { + throw new NotImplementedException(); + } + + public TClient CreateCustomClient(params object[] parameters) where TClient : Hyak.Common.ServiceClient + { + throw new NotImplementedException(); + } + + #endregion + + } +} diff --git a/src/TestFx/TestFx.Netcore.csproj b/src/TestFx/TestFx.Netcore.csproj new file mode 100644 index 0000000000..1af285b5f4 --- /dev/null +++ b/src/TestFx/TestFx.Netcore.csproj @@ -0,0 +1,56 @@ + + + + + + netstandard2.0 + Microsoft.Azure.Commands.TestFx + Microsoft.Azure.Commands.TestFx + false + true + + false + + + + Microsoft Azure PowerShell TestFx + Microsoft Azure PowerShell TestFx library. Only for use with the Azure PowerShell runtime. Not intended for general development use. + azure;powershell;testfx + Microsoft Corporation + Copyright © Microsoft Corporation + https://aka.ms/azps-common-license + https://github.com/Azure/azure-powershell-common + $(ProjectDir)..\..\artifacts\Package\$(Configuration) + + + + false + TRACE;DEBUG;NETSTANDARD + true + + + + + true + true + MSSharedLibKey.snk + TRACE;RELEASE;NETSTANDARD;SIGN + true + + + + + + + + + + + + + + + PreserveNewest + + + \ No newline at end of file diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj new file mode 100644 index 0000000000..cb2f2297d3 --- /dev/null +++ b/src/TestFx/TestFx.csproj @@ -0,0 +1,144 @@ + + + + + + Debug + AnyCPU + {8C625DE3-0067-454A-AF2C-EFD672EEB31A} + Library + Properties + Microsoft.Azure.Commands.TestFx + Microsoft.Azure.Commands.TestFx + v4.5.2 + 512 + + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\packages\Hyak.Common.1.1.0\lib\net45\Hyak.Common.dll + + + ..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.8.1\lib\net452\Microsoft.Azure.Test.HttpRecorder.dll + + + ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + + + ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll + + + ..\..\packages\Microsoft.Rest.ClientRuntime.2.3.13\lib\net452\Microsoft.Rest.ClientRuntime.dll + + + ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.15\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll + + + ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.3.0\lib\net452\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll + + + ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.7.2\lib\net452\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll + + + ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll + + + ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll + + + ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll + + + ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + ..\..\packages\xunit.abstractions.2.0.2\lib\net35\xunit.abstractions.dll + + + ..\..\packages\xunit.assert.2.4.0\lib\netstandard1.1\xunit.assert.dll + + + ..\..\packages\xunit.extensibility.core.2.4.0\lib\net452\xunit.core.dll + + + ..\..\packages\xunit.extensibility.execution.2.4.0\lib\net452\xunit.execution.desktop.dll + + + + + + + + + + + + + Designer + + + Designer + + + + + {70527617-7598-4aef-b5bd-db9186b8184b} + Commands.Common.Authentication.Abstractions + + + {d3804b64-c0d3-48f8-82ec-1f632f833c9e} + Commands.Common.Authentication + + + {269ACF73-0A34-42DC-AB9C-4B15931A489D} + Commands.Common.Graph.RBAC + + + {69C2EB6B-CD63-480A-89A0-C489706E9299} + Commands.Common.Authentication.ResourceManager + + + {3436a126-edc9-4060-8952-9a1be34cdd95} + Commands.ScenarioTests.ResourceManager.Common + + + + + + + + + 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}. + + + + + + \ No newline at end of file diff --git a/src/TestFx/TestFx.nuspec b/src/TestFx/TestFx.nuspec new file mode 100644 index 0000000000..d26f499c24 --- /dev/null +++ b/src/TestFx/TestFx.nuspec @@ -0,0 +1,16 @@ + + + + Microsoft.Azure.PowerShell.TestFx + 1.0.0 + Microsoft Azure PowerShell TestFx + Microsoft Corporation + Microsoft Corporation + false + https://aka.ms/azps-common-license + https://github.com/Azure/azure-powershell-common + Microsoft Azure PowerShell TestFx library. Only for use with the Azure PowerShell runtime. Not intended for general development use. + Copyright © Microsoft Corporation + azure powershell testfx + + \ No newline at end of file diff --git a/src/TestFx/TestManager.cs b/src/TestFx/TestManager.cs new file mode 100644 index 0000000000..4124bff6f0 --- /dev/null +++ b/src/TestFx/TestManager.cs @@ -0,0 +1,296 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Commands.ResourceManager.Common; +using Microsoft.Azure.ServiceManagemenet.Common.Models; +using Microsoft.Azure.Test.HttpRecorder; +using Microsoft.Rest.ClientRuntime.Azure.TestFramework; +using Microsoft.WindowsAzure.Commands.ScenarioTest; +using Xunit.Abstractions; + +namespace Microsoft.Azure.Commands.TestFx +{ + public delegate IRecordMatcher BuildMatcherDelegate (bool ignoreResourcesClient, Dictionary resourceProviders, Dictionary userAgentsToIgnore); + + public class TestManager : ITestRunnerFactory, ITestRunner + { + private readonly string _callingClassName; + private string _projectSubfolderForTestsName = null; + private string _newPsScriptFilename = null; + private Dictionary _userAgentsToIgnore; + protected EnvironmentSetupHelper Helper; + protected readonly List RmModules; + protected readonly List CommonPsScripts = new List(); + + protected BuildMatcherDelegate BuildMatcher { get; set; } + + protected XunitTracingInterceptor Logger { get; set; } + + /// + /// Factory method + /// + /// + /// + /// + public static ITestRunnerFactory CreateInstance(ITestOutputHelper output, [CallerFilePath] string callerFilePath = null) + { + var callingClassName = string.IsNullOrEmpty(callerFilePath) + ? null + : Path.GetFileNameWithoutExtension(callerFilePath); + return new TestManager(callingClassName).WithTestOutputHelper(output); + } + + /// + /// ctor + /// + /// + protected TestManager(string callingClassName) + { + Helper = new EnvironmentSetupHelper(); + _callingClassName = callingClassName; + + RmModules = new List + { + Helper.RMProfileModule, + Helper.RMResourceModule, + }; + + BuildMatcher = (ignoreResourcesClient, resourceProviders, userAgentsToIgnore) => + new PermissiveRecordMatcherWithApiExclusion(ignoreResourcesClient, resourceProviders, userAgentsToIgnore); + } + + #region Builder impl + + /// + /// Sets a name of the subfolder where a test project keeps tests + /// + /// + /// self + public ITestRunnerFactory WithProjectSubfolderForTests(string folderName) + { + _projectSubfolderForTestsName = folderName ?? "ScenarioTests"; + return this; + } + + /// + /// Add helper scripts + /// + /// + /// self + public ITestRunnerFactory WithCommonPsScripts(string[] psScriptList) + { + CommonPsScripts.AddRange(psScriptList); + return this; + } + + /// + /// Overrided default script name, which by convension is the cs test class name with ps1 extension. + /// + /// + /// self + public ITestRunnerFactory WithNewPsScriptFilename(string psScriptName) + { + _newPsScriptFilename = psScriptName; + return this; + } + + /// + /// Adds extra RM modules in addition to the RMProfileModule and RMResourceModule, + /// witch are added in the constructor. + /// + /// + /// + public ITestRunnerFactory WithExtraRmModules(Func buildModuleList) + { + var moduleList = buildModuleList(Helper); + RmModules.AddRange(moduleList); + return this; + } + + /// + /// Clears default RM modules list and sets a brand new + /// + /// + /// + public ITestRunnerFactory WithNewRmModules(Func buildModuleList) + { + RmModules.Clear(); + var moduleList = buildModuleList(Helper); + RmModules.AddRange(moduleList); + return this; + } + + /// + /// Sets a new HttpMockServer.Matcher implementation. By defauls it's PermissiveRecordMatcherWithApiExclusion + /// + /// delegate + /// self + public ITestRunnerFactory WithBuildMatcher(BuildMatcherDelegate buildMatcher) + { + BuildMatcher = buildMatcher; + return this; + } + + /// + /// + /// + /// + /// Dictionary to store pairs: {user agent name, version-api to ignore}. + /// Initial pair is {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} + /// + /// self + public ITestRunnerFactory WithExtraUserAgentsToIgnore(Dictionary userAgentsToIgnore) + { + _userAgentsToIgnore = userAgentsToIgnore; + return this; + } + + public ITestRunnerFactory WithTestOutputHelper(ITestOutputHelper output) + { + Logger = new XunitTracingInterceptor(output); + XunitTracingInterceptor.AddToContext(Logger); + Helper.TracingInterceptor = Logger; + return this; + } + + public ITestRunner Build() + { + SetupSessionAndProfile(); + SetupMockServerMatcher(); + HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); + Helper.SetupModules(AzureModule.AzureResourceManager, BuildModulesList()); + return this; + } + + public void RunTestScript(params string[] scripts) + { + var sf = new StackTrace().GetFrame(1); + var className = sf.GetMethod().ReflectedType?.ToString(); + var methodName = sf.GetMethod().Name; + + using (var mockContext = MockContext.Start(className, methodName)) + { + AzureSession.Instance.ClientFactory = new TestClientFactory(mockContext); + Helper.SetupEnvironment(AzureModule.AzureResourceManager); + SetupAzureContext(); + Helper.RunPowerShellTest(scripts); + } + } + + #endregion + + #region Helpers + + protected string[] BuildModulesList() + { + if (string.IsNullOrEmpty(_callingClassName) + && string.IsNullOrEmpty(_newPsScriptFilename)) + throw new ArgumentNullException($"Both {nameof(_callingClassName)} and {nameof(_newPsScriptFilename)} are null"); + + var allScripts = CommonPsScripts; + allScripts.Add(_newPsScriptFilename ?? $"{_callingClassName}.ps1"); + + var allScriptsWithPath = _projectSubfolderForTestsName == null + ? allScripts + : allScripts.Select(s => Path.Combine(_projectSubfolderForTestsName, s)); + + var allModules = RmModules; + allModules.AddRange(allScriptsWithPath); + + return allModules.ToArray(); + } + + protected void SetupSessionAndProfile() + { + AzureSessionInitializer.InitializeAzureSession(); + AzureSession.Instance.ARMContextSaveMode = ContextSaveMode.Process; + ResourceManagerProfileProvider.InitializeResourceManagerProfile(); + if (!(AzureSession.Instance?.DataStore is MemoryDataStore)) + { + AzureSession.Instance.DataStore = new MemoryDataStore(); + } + } + + protected void SetupAzureContext() + { + const string tenantIdKey = "TenantId"; + const string domainKey = "Domain"; + const string subscriptionIdKey = "SubscriptionId"; + const string undefined = "Undefined"; + var zeroGuild = Guid.Empty.ToString(); + + string tenantId = null; + string userDomain = null; + string subscriptionId = null; + + if (HttpMockServer.Mode == HttpRecorderMode.Record) + { + var environment = TestEnvironmentFactory.GetTestEnvironment(); + tenantId = environment.Tenant; + userDomain = string.IsNullOrEmpty(environment.UserName) + ? string.Empty + : environment.UserName.Split(new[] { "@" }, StringSplitOptions.RemoveEmptyEntries).Last(); + + subscriptionId = environment.SubscriptionId; + } + else if (HttpMockServer.Mode == HttpRecorderMode.Playback) + { + tenantId = HttpMockServer.Variables.ContainsKey(tenantIdKey) + ? HttpMockServer.Variables[tenantIdKey] + : zeroGuild; + userDomain = HttpMockServer.Variables.ContainsKey(domainKey) + ? HttpMockServer.Variables[domainKey] + : "testdomain.onmicrosoft.com"; + subscriptionId = HttpMockServer.Variables.ContainsKey(subscriptionIdKey) + ? HttpMockServer.Variables[subscriptionIdKey] + : zeroGuild; + } + + AzureRmProfileProvider.Instance.Profile.DefaultContext.Tenant.Id = tenantId ?? undefined; + AzureRmProfileProvider.Instance.Profile.DefaultContext.Tenant.Directory = userDomain ?? undefined; + AzureRmProfileProvider.Instance.Profile.DefaultContext.Subscription.Id = subscriptionId ?? undefined; + } + + protected void SetupMockServerMatcher() + { + var resourceProviders = new Dictionary + { + {"Microsoft.Resources", null}, + {"Microsoft.Features", null}, + {"Microsoft.Authorization", null}, + {"Providers.Test", null}, + }; + + var userAgentsToIgnore = new Dictionary + { + {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}, + }; + + _userAgentsToIgnore?.Keys.ForEach(k=> userAgentsToIgnore.Add(k, _userAgentsToIgnore[k])); + + HttpMockServer.Matcher = BuildMatcher(true, resourceProviders, userAgentsToIgnore); + } + + #endregion + } +} diff --git a/src/TestFx/TestRunnerBase.cs b/src/TestFx/TestRunnerBase.cs new file mode 100644 index 0000000000..f1a6fa44c1 --- /dev/null +++ b/src/TestFx/TestRunnerBase.cs @@ -0,0 +1,31 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using Xunit.Abstractions; + +namespace Microsoft.Azure.Commands.TestFx +{ + public class TestRunnerBase + { + protected readonly ITestRunner TestRunner; + + protected TestRunnerBase(ITestOutputHelper output) + { + TestRunner = TestManager + .CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .Build(); + } + } +} diff --git a/src/TestFx/packages.config b/src/TestFx/packages.config new file mode 100644 index 0000000000..3fc28079be --- /dev/null +++ b/src/TestFx/packages.config @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 287eed964c0a6865e300ff5f5fdc9637a9773592 Mon Sep 17 00:00:00 2001 From: vlashch Date: Mon, 20 Aug 2018 12:15:50 -0700 Subject: [PATCH 02/16] app.config removed form project --- src/TestFx/TestFx.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index cb2f2297d3..de8f7a0864 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -100,9 +100,6 @@ - - Designer - Designer From 48d949b2aba980eabfd8dcaf9f4cc8d43c639b25 Mon Sep 17 00:00:00 2001 From: vlashch Date: Mon, 20 Aug 2018 13:14:53 -0700 Subject: [PATCH 03/16] shared lib key added --- src/TestFx/MSSharedLibKey.snk | Bin 0 -> 160 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/TestFx/MSSharedLibKey.snk diff --git a/src/TestFx/MSSharedLibKey.snk b/src/TestFx/MSSharedLibKey.snk new file mode 100644 index 0000000000000000000000000000000000000000..695f1b38774e839e5b90059bfb7f32df1dff4223 GIT binary patch literal 160 zcmV;R0AK$ABme*efB*oL000060ssI2Bme+XQ$aBR1ONa50098C{E+7Ye`kjtcRG*W zi8#m|)B?I?xgZ^2Sw5D;l4TxtPwG;3)3^j?qDHjEteSTF{rM+4WI`v zCD?tsZ^;k+S&r1&HRMb=j738S=;J$tCKNrc$@P|lZ Date: Mon, 20 Aug 2018 13:35:43 -0700 Subject: [PATCH 04/16] preview added to version --- src/TestFx/TestFx.Netcore.csproj | 1 + src/TestFx/TestFx.nuspec | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TestFx/TestFx.Netcore.csproj b/src/TestFx/TestFx.Netcore.csproj index 1af285b5f4..c2b75c4723 100644 --- a/src/TestFx/TestFx.Netcore.csproj +++ b/src/TestFx/TestFx.Netcore.csproj @@ -21,6 +21,7 @@ https://aka.ms/azps-common-license https://github.com/Azure/azure-powershell-common $(ProjectDir)..\..\artifacts\Package\$(Configuration) + 1.0.0-preview diff --git a/src/TestFx/TestFx.nuspec b/src/TestFx/TestFx.nuspec index d26f499c24..0a52095e43 100644 --- a/src/TestFx/TestFx.nuspec +++ b/src/TestFx/TestFx.nuspec @@ -2,7 +2,7 @@ Microsoft.Azure.PowerShell.TestFx - 1.0.0 + 1.0.0-preview Microsoft Azure PowerShell TestFx Microsoft Corporation Microsoft Corporation From f2f85bf823a50800a95f498e3fe3d697e1e142dc Mon Sep 17 00:00:00 2001 From: vlashch Date: Mon, 20 Aug 2018 14:52:27 -0700 Subject: [PATCH 05/16] Assembly names changed --- src/TestFx/TestFx.Netcore.csproj | 2 +- src/TestFx/TestFx.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestFx/TestFx.Netcore.csproj b/src/TestFx/TestFx.Netcore.csproj index c2b75c4723..36f7f1780d 100644 --- a/src/TestFx/TestFx.Netcore.csproj +++ b/src/TestFx/TestFx.Netcore.csproj @@ -4,7 +4,7 @@ netstandard2.0 - Microsoft.Azure.Commands.TestFx + Microsoft.Azure.Powershell.TestFx Microsoft.Azure.Commands.TestFx false true diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index de8f7a0864..fd554bb941 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -9,7 +9,7 @@ Library Properties Microsoft.Azure.Commands.TestFx - Microsoft.Azure.Commands.TestFx + Microsoft.Azure.Powershell.TestFx v4.5.2 512 From 0706fee8411e3a1140625ef26888796b02271796 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 20 Aug 2018 16:13:08 -0700 Subject: [PATCH 06/16] Fix reference versions --- src/TestFx/TestFx.csproj | 52 +++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index fd554bb941..26e96c8cc3 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -1,6 +1,5 @@  - Debug @@ -67,28 +66,36 @@ ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll - - ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + False + ..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll - + + ..\..\lib\System.Management.Automation.dll + True + - ..\..\packages\xunit.abstractions.2.0.2\lib\net35\xunit.abstractions.dll + ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll + True - - ..\..\packages\xunit.assert.2.4.0\lib\netstandard1.1\xunit.assert.dll + + ..\..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll + True - - ..\..\packages\xunit.extensibility.core.2.4.0\lib\net452\xunit.core.dll + + ..\..\packages\xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.core.dll + True - - ..\..\packages\xunit.extensibility.execution.2.4.0\lib\net452\xunit.execution.desktop.dll + + ..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll + True @@ -107,35 +114,24 @@ {70527617-7598-4aef-b5bd-db9186b8184b} - Commands.Common.Authentication.Abstractions + Authentication.Abstractions {d3804b64-c0d3-48f8-82ec-1f632f833c9e} - Commands.Common.Authentication + Authentication {269ACF73-0A34-42DC-AB9C-4B15931A489D} - Commands.Common.Graph.RBAC + Graph.Rbac {69C2EB6B-CD63-480A-89A0-C489706E9299} - Commands.Common.Authentication.ResourceManager + Authentication.ResourceManager {3436a126-edc9-4060-8952-9a1be34cdd95} - Commands.ScenarioTests.ResourceManager.Common + ScenarioTest.ResourceManager - - - - - - 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}. - - - - - - \ No newline at end of file + From b557bf7d3ef6bd708f20a4d5dd1d478b6f380ad8 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 20 Aug 2018 16:19:04 -0700 Subject: [PATCH 07/16] Update packages.config --- src/TestFx/packages.config | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/TestFx/packages.config b/src/TestFx/packages.config index 3fc28079be..38fb45672b 100644 --- a/src/TestFx/packages.config +++ b/src/TestFx/packages.config @@ -1,22 +1,22 @@  - + - - - - + + + + - - - - - - - - - \ No newline at end of file + + + + + + + + + From 4b47a1c420943625d6b4a974cef76c406e6a16af Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Mon, 20 Aug 2018 16:20:59 -0700 Subject: [PATCH 08/16] Update TestFx.csproj --- src/TestFx/TestFx.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index 26e96c8cc3..483654f2ce 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -34,7 +34,7 @@ - ..\..\packages\Hyak.Common.1.1.0\lib\net45\Hyak.Common.dll + ..\..\packages\Hyak.Common.1.0.3\lib\net45\Hyak.Common.dll ..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.8.1\lib\net452\Microsoft.Azure.Test.HttpRecorder.dll @@ -46,13 +46,13 @@ ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll - ..\..\packages\Microsoft.Rest.ClientRuntime.2.3.13\lib\net452\Microsoft.Rest.ClientRuntime.dll + ..\..\packages\Microsoft.Rest.ClientRuntime.2.3.12\lib\net452\Microsoft.Rest.ClientRuntime.dll - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.15\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll + ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.13\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.3.0\lib\net452\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll + ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.3.1\lib\net452\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.7.2\lib\net452\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll From 9526a7e9974290396709af9a51f01f340c67caf5 Mon Sep 17 00:00:00 2001 From: vlashch Date: Tue, 21 Aug 2018 12:12:38 -0700 Subject: [PATCH 09/16] Newsoft.JSON changed to 10.0.3 --- src/TestFx/TestFx.csproj | 4 ++-- src/TestFx/packages.config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index 483654f2ce..6de6a766a3 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -66,9 +66,9 @@ ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll - + False - ..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/src/TestFx/packages.config b/src/TestFx/packages.config index 38fb45672b..c85b52e4b5 100644 --- a/src/TestFx/packages.config +++ b/src/TestFx/packages.config @@ -11,7 +11,7 @@ - + From 261800213f1b7df4c157487a28c55bd3c24c161c Mon Sep 17 00:00:00 2001 From: vlashch Date: Thu, 13 Sep 2018 14:40:41 -0700 Subject: [PATCH 10/16] Import targets file for dependencies --- src/TestFx/TestFx.csproj | 72 ++-------------------------------------- 1 file changed, 2 insertions(+), 70 deletions(-) diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index 6de6a766a3..d6637f144f 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -11,9 +11,7 @@ Microsoft.Azure.Powershell.TestFx v4.5.2 512 - - - + false true @@ -32,72 +30,6 @@ prompt 4 - - - ..\..\packages\Hyak.Common.1.0.3\lib\net45\Hyak.Common.dll - - - ..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.8.1\lib\net452\Microsoft.Azure.Test.HttpRecorder.dll - - - ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - - ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.2.3.12\lib\net452\Microsoft.Rest.ClientRuntime.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.13\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.3.1\lib\net452\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll - - - ..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.7.2\lib\net452\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll - - - ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll - - - ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll - - - ..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll - - - False - ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - - - - - ..\..\lib\System.Management.Automation.dll - True - - - - - - - - ..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll - True - - - ..\..\packages\xunit.assert.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll - True - - - ..\..\packages\xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.core.dll - True - - - ..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll - True - - From 4a26f3821211e579710703d3c0dedd45a3bb6cf0 Mon Sep 17 00:00:00 2001 From: vlashch Date: Thu, 13 Sep 2018 14:50:03 -0700 Subject: [PATCH 11/16] removed packages.config --- src/TestFx/packages.config | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 src/TestFx/packages.config diff --git a/src/TestFx/packages.config b/src/TestFx/packages.config deleted file mode 100644 index c85b52e4b5..0000000000 --- a/src/TestFx/packages.config +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - From f9780a5c6d6c97645d0ba645d706da489888a32b Mon Sep 17 00:00:00 2001 From: vlashch Date: Thu, 13 Sep 2018 16:06:32 -0700 Subject: [PATCH 12/16] removed packages.config ref from csproj; Powershell replaced with PowerShell in assembly name; --- src/TestFx/TestFx.Netcore.csproj | 2 +- src/TestFx/TestFx.csproj | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/TestFx/TestFx.Netcore.csproj b/src/TestFx/TestFx.Netcore.csproj index 36f7f1780d..ff19fe1fea 100644 --- a/src/TestFx/TestFx.Netcore.csproj +++ b/src/TestFx/TestFx.Netcore.csproj @@ -4,7 +4,7 @@ netstandard2.0 - Microsoft.Azure.Powershell.TestFx + Microsoft.Azure.PowerShell.TestFx Microsoft.Azure.Commands.TestFx false true diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index d6637f144f..3ebaddc49c 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -8,7 +8,7 @@ Library Properties Microsoft.Azure.Commands.TestFx - Microsoft.Azure.Powershell.TestFx + Microsoft.Azure.PowerShell.TestFx v4.5.2 512 false @@ -38,11 +38,6 @@ - - - Designer - - {70527617-7598-4aef-b5bd-db9186b8184b} @@ -66,4 +61,4 @@ - + \ No newline at end of file From b734d6197c40fc3f45b9daeb5def54a0ef4eb2bb Mon Sep 17 00:00:00 2001 From: MiYanni Date: Thu, 13 Sep 2018 16:50:20 -0700 Subject: [PATCH 13/16] Fixes to TestFx project configuration. --- src/Aks/Aks.Netcore.csproj | 4 ++-- src/TestFx/MSSharedLibKey.snk | Bin 160 -> 0 bytes src/TestFx/TestFx.Netcore.csproj | 21 ++++++++++----------- src/TestFx/TestFx.csproj | 31 +++++++++++++++++++------------ 4 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 src/TestFx/MSSharedLibKey.snk diff --git a/src/Aks/Aks.Netcore.csproj b/src/Aks/Aks.Netcore.csproj index 0e6ccd53b2..65eebb0f6c 100644 --- a/src/Aks/Aks.Netcore.csproj +++ b/src/Aks/Aks.Netcore.csproj @@ -1,8 +1,8 @@  - - + + netstandard2.0 Microsoft.Azure.PowerShell.Aks Microsoft.Azure.Commands.Common.Aks diff --git a/src/TestFx/MSSharedLibKey.snk b/src/TestFx/MSSharedLibKey.snk deleted file mode 100644 index 695f1b38774e839e5b90059bfb7f32df1dff4223..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 160 zcmV;R0AK$ABme*efB*oL000060ssI2Bme+XQ$aBR1ONa50098C{E+7Ye`kjtcRG*W zi8#m|)B?I?xgZ^2Sw5D;l4TxtPwG;3)3^j?qDHjEteSTF{rM+4WI`v zCD?tsZ^;k+S&r1&HRMb=j738S=;J$tCKNrc$@P|lZ - + netstandard2.0 - Microsoft.Azure.Powershell.TestFx + Microsoft.Azure.PowerShell.TestFx Microsoft.Azure.Commands.TestFx - false + $(ProjectDir)..\..\artifacts\$(Configuration) true false @@ -21,23 +21,20 @@ https://aka.ms/azps-common-license https://github.com/Azure/azure-powershell-common $(ProjectDir)..\..\artifacts\Package\$(Configuration) + true 1.0.0-preview false TRACE;DEBUG;NETSTANDARD - true - true true - MSSharedLibKey.snk + ..\MSSharedLibKey.snk TRACE;RELEASE;NETSTANDARD;SIGN - true - @@ -50,8 +47,10 @@ - - PreserveNewest - + + + + + \ No newline at end of file diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index d6637f144f..0341371215 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -1,5 +1,5 @@  - + Debug @@ -8,16 +8,18 @@ Library Properties Microsoft.Azure.Commands.TestFx - Microsoft.Azure.Powershell.TestFx + Microsoft.Azure.PowerShell.TestFx v4.5.2 512 + $(ProjectDir)obj\$(Configuration)\net452 + $(BaseIntermediateOutputPath) false true full false - bin\Debug\ + $(ProjectDir)..\..\artifacts\$(Configuration)\net452 DEBUG;TRACE prompt 4 @@ -25,10 +27,20 @@ pdbonly true - bin\Release\ - TRACE + $(ProjectDir)..\..\artifacts\$(Configuration)\net452 + TRACE;SIGN + AnyCPU + $(ProjectDir)..\..\artifacts\$(Configuration)\net452\Management.Utilities.dll.CodeAnalysisLog.xml + true + GlobalSuppressions.cs prompt - 4 + MinimumRecommendedRules.ruleset + ;$(MSBuildProgramFiles32)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Static Analysis Tools\Rule Sets\;$(MSBuildProgramFiles32)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets\ + true + ..\MSSharedLibKey.snk + true + true + false @@ -38,11 +50,6 @@ - - - Designer - - {70527617-7598-4aef-b5bd-db9186b8184b} @@ -66,4 +73,4 @@ - + \ No newline at end of file From b1490e0bd416c6d65e4f2e49283370889277bc53 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 14 Sep 2018 14:46:23 -0700 Subject: [PATCH 14/16] Allowed sign job to sign the TestFx files. Added a fix so that ScenarioTest, ScenarioTest.ResourceManager, and TestFx no longer place xunit/MSTest files into their package content directory. This was a bug from the net452 targets files change. --- build/sign.proj | 1 + src/Dependencies.Test.targets | 6 +++--- .../ScenarioTest.ResourceManager.csproj | 3 +++ src/ScenarioTest/ScenarioTest.csproj | 1 + src/TestFx/TestFx.csproj | 18 ++++++++++-------- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/build/sign.proj b/build/sign.proj index 11801d5a39..9c7176b35a 100644 --- a/build/sign.proj +++ b/build/sign.proj @@ -25,6 +25,7 @@ + - - - + + + diff --git a/src/ScenarioTest.ResourceManager/ScenarioTest.ResourceManager.csproj b/src/ScenarioTest.ResourceManager/ScenarioTest.ResourceManager.csproj index fc735d0ecd..ab3feb38dd 100644 --- a/src/ScenarioTest.ResourceManager/ScenarioTest.ResourceManager.csproj +++ b/src/ScenarioTest.ResourceManager/ScenarioTest.ResourceManager.csproj @@ -1,5 +1,8 @@  + + false + Debug diff --git a/src/ScenarioTest/ScenarioTest.csproj b/src/ScenarioTest/ScenarioTest.csproj index feff97fb8f..f84a32a92a 100644 --- a/src/ScenarioTest/ScenarioTest.csproj +++ b/src/ScenarioTest/ScenarioTest.csproj @@ -2,6 +2,7 @@ true + false diff --git a/src/TestFx/TestFx.csproj b/src/TestFx/TestFx.csproj index 0341371215..22d11bac8e 100644 --- a/src/TestFx/TestFx.csproj +++ b/src/TestFx/TestFx.csproj @@ -1,5 +1,8 @@  + + false + Debug @@ -11,8 +14,12 @@ Microsoft.Azure.PowerShell.TestFx v4.5.2 512 + ..\..\ + true + e5bda5ba $(ProjectDir)obj\$(Configuration)\net452 $(BaseIntermediateOutputPath) + NU5111 false @@ -29,18 +36,13 @@ true $(ProjectDir)..\..\artifacts\$(Configuration)\net452 TRACE;SIGN - AnyCPU - $(ProjectDir)..\..\artifacts\$(Configuration)\net452\Management.Utilities.dll.CodeAnalysisLog.xml - true - GlobalSuppressions.cs - prompt - MinimumRecommendedRules.ruleset - ;$(MSBuildProgramFiles32)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Static Analysis Tools\Rule Sets\;$(MSBuildProgramFiles32)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets\ true ..\MSSharedLibKey.snk true - true + true false + true + pdbonly From 62d6407cf0f9b57d58c812247ce9deb5f0895026 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 14 Sep 2018 14:59:17 -0700 Subject: [PATCH 15/16] Added signing exclusion for net452 test dlls. --- build/sign.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/sign.proj b/build/sign.proj index 9c7176b35a..235254eee3 100644 --- a/build/sign.proj +++ b/build/sign.proj @@ -25,7 +25,7 @@ - + Date: Mon, 15 Oct 2018 13:33:46 -0700 Subject: [PATCH 16/16] PR comments fix; --- src/TestFx/ITestRunnerFactory.cs | 2 +- src/TestFx/TestManager.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TestFx/ITestRunnerFactory.cs b/src/TestFx/ITestRunnerFactory.cs index 6de9e74085..ee3669b94e 100644 --- a/src/TestFx/ITestRunnerFactory.cs +++ b/src/TestFx/ITestRunnerFactory.cs @@ -27,6 +27,6 @@ public interface ITestRunnerFactory ITestRunnerFactory WithExtraRmModules(Func buildModuleList); ITestRunnerFactory WithNewRmModules(Func buildModuleList); ITestRunnerFactory WithExtraUserAgentsToIgnore(Dictionary userAgentsToIgnore); - ITestRunnerFactory WithBuildMatcher(BuildMatcherDelegate buildMatcher); + ITestRunnerFactory WithRecordMatcher(RecordMatcherDelegate recordMatcher); } } diff --git a/src/TestFx/TestManager.cs b/src/TestFx/TestManager.cs index 4124bff6f0..74a9e04d20 100644 --- a/src/TestFx/TestManager.cs +++ b/src/TestFx/TestManager.cs @@ -30,7 +30,7 @@ namespace Microsoft.Azure.Commands.TestFx { - public delegate IRecordMatcher BuildMatcherDelegate (bool ignoreResourcesClient, Dictionary resourceProviders, Dictionary userAgentsToIgnore); + public delegate IRecordMatcher RecordMatcherDelegate (bool ignoreResourcesClient, Dictionary resourceProviders, Dictionary userAgentsToIgnore); public class TestManager : ITestRunnerFactory, ITestRunner { @@ -42,7 +42,7 @@ public class TestManager : ITestRunnerFactory, ITestRunner protected readonly List RmModules; protected readonly List CommonPsScripts = new List(); - protected BuildMatcherDelegate BuildMatcher { get; set; } + protected RecordMatcherDelegate RecordMatcher { get; set; } protected XunitTracingInterceptor Logger { get; set; } @@ -75,7 +75,7 @@ protected TestManager(string callingClassName) Helper.RMResourceModule, }; - BuildMatcher = (ignoreResourcesClient, resourceProviders, userAgentsToIgnore) => + RecordMatcher = (ignoreResourcesClient, resourceProviders, userAgentsToIgnore) => new PermissiveRecordMatcherWithApiExclusion(ignoreResourcesClient, resourceProviders, userAgentsToIgnore); } @@ -143,11 +143,11 @@ public ITestRunnerFactory WithNewRmModules(Func /// Sets a new HttpMockServer.Matcher implementation. By defauls it's PermissiveRecordMatcherWithApiExclusion /// - /// delegate + /// delegate /// self - public ITestRunnerFactory WithBuildMatcher(BuildMatcherDelegate buildMatcher) + public ITestRunnerFactory WithRecordMatcher(RecordMatcherDelegate recordMatcher) { - BuildMatcher = buildMatcher; + RecordMatcher = recordMatcher; return this; } @@ -288,7 +288,7 @@ protected void SetupMockServerMatcher() _userAgentsToIgnore?.Keys.ForEach(k=> userAgentsToIgnore.Add(k, _userAgentsToIgnore[k])); - HttpMockServer.Matcher = BuildMatcher(true, resourceProviders, userAgentsToIgnore); + HttpMockServer.Matcher = RecordMatcher(true, resourceProviders, userAgentsToIgnore); } #endregion