public void RunPsTestWorkflow(
            string scenario,
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var providers = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Compute", null },
                { "Microsoft.Storage", null },
                { "Microsoft.Network", null }
            };

            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-09-01" }
            };

            HttpMockServer.Matcher          = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            try
            {
                using (var context = MockContext.Start(callingClassType, mockName))
                {
                    SetupManagementClients(context);

                    _helper.SetupEnvironment(AzureModule.AzureResourceManager);

                    var rmProfileModule = _helper.RMProfileModule;

                    _helper.SetupModules(
                        AzureModule.AzureResourceManager,
                        PowershellFile,
                        rmProfileModule,
                        _helper.GetRMModulePath("AzureRM.Network.psd1"),
                        "AzureRM.Storage.ps1",
                        _helper.GetRMModulePath("AzureRM.Compute.psd1"),
                        _helper.GetRMModulePath("AzureRM.RecoveryServices.psd1"),
#if !NETSTANDARD
                        _helper.GetRMModulePath("AzureRM.RecoveryServices.SiteRecovery.psd1"),
#endif
                        "AzureRM.Resources.ps1");

                    try
                    {
                        var psScripts = scriptBuilder?.Invoke();
                        if (psScripts != null)
                        {
                            _helper.RunPowerShellTest(psScripts);
                        }
                    }
                    finally
                    {
                        cleanup?.Invoke();
                    }
                }
            }
            catch (UriFormatException)
            {
                // Pass.
            }
        }
Exemplo n.º 2
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <LegacyTest.CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            Dictionary <string, string> providers = new Dictionary <string, string>();

            providers.Add("Microsoft.Resources", null);
            providers.Add("Microsoft.Features", null);
            providers.Add("Microsoft.Authorization", null);
            providers.Add("Microsoft.Compute", null);
            var providersToIgnore = new Dictionary <string, string>();

            providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);

            HttpMockServer.RecordsDirectory =
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            using (RestTestFramework.MockContext context =
                       RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                csmTestFactory = new LegacyTest.CSMTestEnvironmentFactory();

                if (initialize != null)
                {
                    initialize.Invoke(csmTestFactory);
                }

                SetupManagementClients(context);

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var callingClassName =
                    callingClassType
                    .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                string psFile =
                    "ScenarioTests\\" + callingClassName + ".ps1";
                string rmProfileModule = helper.RMProfileModule;
                string rmModulePath    = helper.GetRMModulePath("AzureRM.RecoveryServices.psd1");

                List <string> modules = new List <string>();

                modules.Add(psFile);
                modules.Add(rmProfileModule);
                modules.Add(rmModulePath);
                modules.Add(helper.RMResourceModule);
                modules.Add("AzureRM.Resources.ps1");

                helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());

                try
                {
                    if (scriptBuilder != null)
                    {
                        var psScripts = scriptBuilder();

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup.Invoke();
                    }
                }
            }
        }
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <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);
            d.Add("Microsoft.Compute", null);
            d.Add("Microsoft.Network", 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 (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                this.csmTestFactory = new 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\\ComputeTestCommon.ps1",
                                    "ScenarioTests\\" + callingClassName + ".ps1",
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.RMStorageDataPlaneModule,
                                    helper.RMStorageModule,
                                    helper.GetRMModulePath("AzureRM.Compute.psd1"),
                                    helper.GetRMModulePath("AzureRM.Network.psd1"),
                                    "AzureRM.Storage.ps1",
                                    "AzureRM.Resources.ps1");

                try
                {
                    if (scriptBuilder != null)
                    {
                        var psScripts = scriptBuilder();

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 4
0
        public Collection <PSObject> RunPsTestWorkflow(
            PsBackupProviderTypes providerType,
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var providers = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Compute", null },
                { "Microsoft.Network", null },
                { "Microsoft.Storage", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" },
                { "Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-02-01" }
            };

            HttpMockServer.Matcher          = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            using (var context = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var testFolderName   = providerType.ToString();
                var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                var modules          = new List <string>
                {
                    "ScenarioTests\\Common.ps1",
                    "ScenarioTests\\" + testFolderName + "\\" + callingClassName + ".ps1",
                    _helper.RMProfileModule,
                    _helper.GetRMModulePath("AzureRM.RecoveryServices.psd1"),
                    _helper.RMResourceModule,
#if !NETSTANDARD
                    _helper.GetRMModulePath("AzureRM.RecoveryServices.Backup.psd1"),
                    _helper.RMStorageDataPlaneModule,
#endif
                    _helper.RMStorageModule,
                    _helper.GetRMModulePath("AzureRM.Compute.psd1"),
                    _helper.GetRMModulePath("AzureRM.Network.psd1"),
                    "AzureRM.Storage.ps1",
                    "AzureRM.Resources.ps1"
                };

                var workloadCommonPsFile = Path.Combine("ScenarioTests", testFolderName, "Common.ps1");
                if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, workloadCommonPsFile)))
                {
                    modules.Add(workloadCommonPsFile);
                }

                _helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());

                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (psScripts != null)
                    {
                        return(_helper.RunPowerShellTest(psScripts));
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }

            return(null);
        }