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.ResourceManager.ResourceManagementClient", "2016-07-01");
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);
}
helper.SetupEnvironment(AzureModule.AzureResourceManager);
SetupManagementClients(context);
var callingClassName = callingClassType
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
.Last();
helper.SetupModules(AzureModule.AzureResourceManager,
"ScenarioTests\\Common.ps1",
"ScenarioTests\\" + callingClassName + ".ps1",
helper.RMProfileModule,
helper.RMResourceModule,
helper.RMResourceManagerStartup,
helper.RMInsightsModule);
try
{
if (scriptBuilder != null)
{
var psScripts = scriptBuilder();
if (psScripts != null)
{
helper.RunPowerShellTest(psScripts);
}
}
}
finally
{
if (cleanup != null)
{
cleanup();
}
}
}
}