/// <summary> /// Runs the PowerShell test under mock undo context based on the test mode setting (Record|Playback) /// </summary> /// <param name="scriptBuilder">Script builder delegate</param> /// <param name="initialize">initialize action</param> /// <param name="cleanup">cleanup action</param> /// <param name="callingClassType">Calling class type</param> /// <param name="mockName">Mock Name</param> public void RunPsTestWorkflow( Func <string[]> scriptBuilder, Action <LegacyTest.CSMTestEnvironmentFactory> initialize, Action cleanup, string callingClassType, string mockName) { Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("Microsoft.Authorization", AuthorizationApiVersion); d.Add("Microsoft.Resources", null); d.Add("Microsoft.Features", null); var providersToIgnore = new Dictionary <string, string>(); providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"); HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore); HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); using (MockContext context = MockContext.Start(callingClassType, mockName)) { this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory(); if (initialize != null) { initialize(this.csmTestFactory); } SetupManagementClients(context); helper.SetupEnvironment(AzureModule.AzureResourceManager); var callingClassName = callingClassType .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries) .Last(); helper.SetupModules(AzureModule.AzureResourceManager, "ScenarioTests\\Common.ps1", "ScenarioTests\\" + callingClassName + ".ps1", helper.RMProfileModule, helper.RMResourceModule, helper.GetRMModulePath(@"AzureRM.LogicApp.psd1"), "ScenarioTests\\AzureRM.Resources.ps1"); try { if (scriptBuilder != null) { var psScripts = scriptBuilder(); if (psScripts != null) { helper.RunPowerShellTest(psScripts); } } } finally { if (cleanup != null) { cleanup(); } } } }
protected void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts) { var callingClassType = TestUtilities.GetCallingClass(2); var mockName = TestUtilities.GetCurrentMethodName(2); helper.TracingInterceptor = logger; Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("Microsoft.Resources", null); d.Add("Microsoft.Features", null); d.Add("Microsoft.Authorization", null); var providersToIgnore = new Dictionary <string, string>(); providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"); HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore); HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); using (MockContext context = MockContext.Start(callingClassType, mockName)) { this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory(); SetupManagementClients(context); var callingClassName = callingClassType .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries) .Last(); List <string> modules = new List <string>(); //modules.Add("Microsoft.Azure.Commands.NotificationHubs.dll"); modules.Add("ScenarioTests\\" + this.GetType().Name + ".ps1"); modules.Add(helper.RMProfileModule); modules.Add(helper.GetRMModulePath(@"AzureRM.NotificationHubs.psd1")); modules.Add("AzureRM.Resources.ps1"); helper.SetupEnvironment(AzureModule.AzureResourceManager); helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray()); if (scripts != null) { helper.RunPowerShellTest(scripts); } } }
public void RunPsTestWorkflow( Func<string[]> scriptBuilder, Action<LegacyTest.CSMTestEnvironmentFactory> initialize, Action cleanup, string callingClassType, string mockName) { Dictionary<string, string> d = new Dictionary<string, string>(); d.Add("Microsoft.Resources", null); d.Add("Microsoft.Features", null); d.Add("Microsoft.Authorization", null); var providersToIgnore = new Dictionary<string, string>(); providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"); HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore); HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); using (MockContext context = MockContext.Start(callingClassType, mockName)) { this.csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory(); if (initialize != null) { initialize(this.csmTestFactory); } this.SetupManagementClients(context); this.helper.SetupEnvironment(AzureModule.AzureResourceManager); string callingClassName = callingClassType .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries) .Last(); this.helper.SetupModules(AzureModule.AzureResourceManager, "ScenarioTests\\Common.ps1", "ScenarioTests\\" + callingClassName + ".ps1", helper.RMProfileModule, helper.RMResourceModule, helper.GetRMModulePath("AzureRM.Dns.psd1"), "AzureRM.Resources.ps1"); try { if (scriptBuilder != null) { string[] psScripts = scriptBuilder(); if (psScripts != null) { this.helper.RunPowerShellTest(psScripts); } } } finally { if (cleanup != null) { cleanup(); } } } }