Exemplo n.º 1
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                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.Insights.psd1"),
                                     _helper.GetRMModulePath("AzureRM.Network.psd1"),
                                     _helper.GetRMModulePath("AzureRM.Compute.psd1"),
                                     _helper.GetRMModulePath("AzureRM.OperationalInsights.psd1"),
                                     _helper.RMStorageDataPlaneModule,
                                     "AzureRM.Storage.ps1",
                                     "AzureRM.Resources.ps1");

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

                        if (psScripts != null)
                        {
                            _helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
Exemplo n.º 2
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var d = new Dictionary <string, string>
            {
                { "Microsoft.Authorization", AuthorizationApiVersion },
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" }
            };

            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);

            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (var context = MockContext.Start(callingClassType, mockName))
            {
                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.GetRMModulePath(@"AzureRM.LogicApp.psd1"),
                                     "AzureRM.Resources.ps1");

                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (psScripts != null)
                    {
                        _helper.RunPowerShellTest(psScripts);
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
Exemplo n.º 3
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                List <string> modules = Directory.GetFiles("ScenarioTests\\MultiVip".AsAbsoluteLocation(), "*.ps1").ToList();
                modules.AddRange(Directory.GetFiles("ScenarioTests".AsAbsoluteLocation(), "*.ps1"));

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 4
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Compute", null },
                { "Microsoft.Network", null },
                { "Microsoft.Storage", null },
                { "Microsoft.KeyVault", null },
            };

            var providersToIgnore = new Dictionary <string, string>
            {
            };

            HttpMockServer.Matcher          = new PermissiveRecordMatcherWithResourceApiExclusion(true, d, providersToIgnore, resourceTypesToIgnoreApiVersion);
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            // Enable undo functionality as well as mock recording
            using (var context = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                Helper.SetupEnvironment(AzureModule.AzureResourceManager);
                var modules = new List <string>
                {
                    "ScenarioTests\\Common.ps1",
                    "ScenarioTests\\" + GetType().Name + ".ps1",
                    Helper.RMProfileModule,
                    Helper.GetRMModulePath(@"AzureRM.SqlVirtualMachine.psd1"),
                    Helper.GetRMModulePath("AzureRM.Compute.psd1"),
                    Helper.GetRMModulePath("AzureRM.Network.psd1"),
                    "AzureRM.Storage.ps1",
                    "AzureRM.Resources.ps1"
                };
                Helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());
                Helper.RunPowerShellTest(scripts);
            }
        }
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                this.rdfeTestFactory = new RDFETestEnvironmentFactory();

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(AzureModule.AzureServiceManagement,
                                    "ScenarioTests\\" + this.GetType().Name + ".ps1");

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 6
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                    helper.RMProfileModule,
                                    helper.GetRMModulePath(@"AzureRM.StreamAnalytics.psd1"));

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 7
0
        public void RunPowerShellTest(params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            Dictionary <string, string> d = new Dictionary <string, string>();

            d.Add("Microsoft.Features", null);
            d.Add("Microsoft.Authorization", null);
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2017-05-10" }
            };

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

            using (var context = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);
                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.GetRMModulePath(@"AzureRM.Aks.psd1"),
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + callingClassName + ".ps1");

                if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback)
                {
                    AzureSession.Instance.DataStore = new MemoryDataStore();
                    var home         = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                    var dir          = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);
                    var subscription = HttpMockServer.Variables["SubscriptionId"];
                    AzureSession.Instance.DataStore.WriteFile(Path.Combine(home, ".ssh", "id_rsa.pub"), File.ReadAllText(dir + "/Fixtures/id_rsa.pub"));
                    string jsonOutput = @"{""" + subscription + @""":{ ""service_principal"":""foo"",""client_secret"":""bar""}}";
                    AzureSession.Instance.DataStore.WriteFile(Path.Combine(home, ".azure", "acsServicePrincipal.json"), jsonOutput);
                }

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 8
0
        protected Collection <PSObject> RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(1), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                List <string> modules = new List <string>();
                modules.Add("Microsoft.WindowsAzure.Commands.Common.Test.dll");

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(modules.ToArray());

                return(helper.RunPowerShellTest(scripts));
            }
        }
Exemplo n.º 9
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                List <string> modules = Directory.GetFiles("ScenarioTests\\NetworkSecurityGroup", "*.ps1").ToList();
                modules.Add("Common.ps1");

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 10
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Network", null },
                { "Microsoft.KeyVault", null },
            };

            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Graph.RBAC.Version1_6.GraphRbacManagementClient", "1.42-previewInternal" },
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" }
            };

            HttpMockServer.Matcher          = new PermissiveRecordMatcherWithResourceApiExclusion(true, d, providersToIgnore, resourceTypesToIgnoreApiVersion);
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            // Enable undo functionality as well as mock recording
            using (var context = MockContext.Start(callingClassType, mockName))
            {
                Helper.SetupEnvironment(AzureModule.AzureResourceManager);
                SetupManagementClients(context);
                Helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + GetType().Name + ".ps1",
                                    Helper.RMProfileModule,
                                    Helper.GetRMModulePath(@"AzureRM.Sql.psd1"),
                                    Helper.RMNetworkModule,
                                    "AzureRM.Storage.ps1",
                                    "AzureRM.Resources.ps1",
                                    Helper.RMOperationalInsightsModule,
                                    Helper.RMEventHubModule,
                                    Helper.RMMonitorModule,
                                    Helper.RMKeyVaultModule);
                Helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 11
0
        public void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            helper.TracingInterceptor = logger;

            Dictionary <string, string> providers = new Dictionary <string, string>()
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Compute", null }
            };

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

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

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

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\" + callingClassName + ".ps1",
                                    "AzureRM.Resources.ps1",
                                    "ScenarioTests\\Common.ps1",
                                    helper.RMProfileModule,
                                    helper.GetRMModulePath(@"AzureRM.ContainerInstance.psd1"));

                if (scripts != null)
                {
                    helper.RunPowerShellTest(scripts);
                }
            }
        }
Exemplo n.º 12
0
        protected void RunPowerShellTest(XunitTracingInterceptor logger, bool setupManagementClients, bool setupDataClient, params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(2);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            _helper.TracingInterceptor = logger;
            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" }
            };

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

            using (var context = RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                if (setupManagementClients)
                {
                    SetupManagementClients(context);
                    _helper.SetupEnvironment(AzureModule.AzureResourceManager);
                }
                if (setupDataClient)
                {
                    SetupDataClient(context);
                }

                var callingClassName = callingClassType?.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + callingClassName + ".ps1",
                                     _helper.RMProfileModule,
                                     _helper.GetRMModulePath(@"AzureRM.OperationalInsights.psd1"),
                                     "AzureRM.Resources.ps1",
                                     _helper.GetRMModulePath(@"AzureRM.Storage.psd1"));

                _helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 13
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
                SetupManagementClients();

                // Create the resource group
                this.TryRegisterSubscriptionForResource();
                this.TryCreateResourceGroup(this.resourceGroupName, resourceGroupLocation);
                this.TryCreateDataLakeStoreAccount(this.resourceGroupName, this.dataLakeAccountName, resourceGroupLocation);
                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager, "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                    helper.RMProfileModule, helper.GetRMModulePath(@"AzureRM.DataLakeAnalytics.psd1"));

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 14
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            // Enable undo functionality as well as mock recording
            using (UndoContext context = UndoContext.Current)
            {
                // Configure recordings
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

                helper.SetupModules(AzureModule.AzureProfile, "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + this.GetType().Name + ".ps1");

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 15
0
        protected void RunPowerShellTest(string testFolderName, params string[] scripts)
        {
            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);

            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                string psFile                     = "ScenarioTests\\" + testFolderName + "\\" + this.GetType().Name + ".ps1";
                string commonPsFile               = "ScenarioTests\\" + testFolderName + "\\Common.ps1";
                string rmProfileModule            = helper.RMProfileModule;
                string rmModulePath               = helper.GetRMModulePath("AzureRM.RecoveryServices.Backup.psd1");
                string recoveryServicesModulePath =
                    helper.GetRMModulePath("AzureRM.RecoveryServices.psd1");

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

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

                if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, commonPsFile)))
                {
                    modules.Add(commonPsFile);
                }

                modules.Add(psFile);
                modules.Add(rmProfileModule);
                modules.Add(rmModulePath);
                modules.Add(recoveryServicesModulePath);

                helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());
                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 16
0
        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);
                }
            }
        }
Exemplo n.º 17
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            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.Network", null);
            var providersToIgnore = new Dictionary <string, string>();

            providersToIgnore.Add("Microsoft.Azure.Graph.RBAC.Version1_6.GraphRbacManagementClient", "1.42-previewInternal");
            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");

            // Enable undo functionality as well as mock recording
            using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                Helper.SetupEnvironment(AzureModule.AzureResourceManager);

                Helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                    Helper.RMProfileModule,
#if !NETSTANDARD
                                    Helper.RMStorageDataPlaneModule,
#else
                                    Helper.RMStorageModule,
#endif
                                    Helper.GetRMModulePath(@"AzureRM.Sql.psd1"),
                                    Helper.RMNetworkModule,
                                    "AzureRM.Storage.ps1",
                                    "AzureRM.Resources.ps1");
                Helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 18
0
        private void RunPowerShellTest(params string[] scripts)
        {
            for (int i = 0; i < scripts.Length; i++)
            {
                scripts[i] = scripts[i] + string.Format(" {0} {1}", _fixture.ResourceGroupName, _fixture.ApiManagementServiceName);
            }

            using (var context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                _helper.SetupEnvironment(AzureModule.AzureProfile);
                _helper.SetupModules(AzureModule.AzureProfile, "ScenarioTests\\Common.ps1", "ScenarioTests\\" + GetType().Name + ".ps1");

                _helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 19
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                List <string> modules = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScenarioTests\\ReservedIPs"), "*.ps1").ToList();
                modules.AddRange(Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ScenarioTests"), "*.ps1"));
                modules.Add("Common.ps1");

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);
                helper.SetupModules(AzureModule.AzureServiceManagement, modules.ToArray());

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 20
0
        private void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (MockContext context = MockContext.Start(callingClassType, mockName))
            {
                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.GetRMModulePath(@"AzureRM.Profile.psd1"),
                                    helper.GetRMModulePath(@"AzureRM.Resources.psd1"),
                                    helper.GetRMModulePath(@"AzureRM.Intune.psd1"));

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 21
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (MockContext.Start(callingClassType, mockName))
            {
                _helper.SetupManagementClients();
                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                     _helper.RMProfileModule,
                                     _helper.GetRMModulePath(@"AzureRM.Automation.psd1"));

                _helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 22
0
        private void RunPowerShellTest(params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            Dictionary <string, string> d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "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))
            {
                SetupManagementClients(context);

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);
                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + GetType().Name + ".ps1",
                                     _helper.RMProfileModule,
#if NETSTANDARD
                                     _helper.RMStorageModule,
#else
                                     _helper.RMStorageDataPlaneModule,
#endif
                                     _helper.GetRMModulePath("AzureRM.ApiManagement.psd1"),
                                     "AzureRM.Storage.ps1",
                                     "AzureRM.Resources.ps1");

                _helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 23
0
        private void RunPowerShellTest(params string[] scripts)
        {
#if DEBUG
            //Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Record");

            //Environment.SetEnvironmentVariable(
            //    "TEST_CSM_ORGID_AUTHENTICATION",
            //    "SubscriptionId=;Environment=;AADTenant=");

            //Environment.SetEnvironmentVariable(
            //    "TEST_ORGID_AUTHENTICATION",
            //    "SubscriptionId=;Environment=");
#endif
            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);

            using (var context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);
                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + GetType().Name + ".ps1",
                                     _helper.RMProfileModule,
                                     _helper.RMResourceModule,
                                     _helper.RMStorageDataPlaneModule,
                                     _helper.GetRMModulePath("AzureRM.ApiManagement.psd1"),
                                     "AzureRM.Storage.ps1",
                                     "AzureRM.Resources.ps1");

                _helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 24
0
        public void RunPsTest(params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (MockContext.Start(callingClassType, mockName))
            {
                _helper.SetupSomeOfManagementClients();
                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var callingClassName = callingClassType?.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\" + callingClassName + ".ps1",
                                     _helper.RMProfileModule,
                                     _helper.GetRMModulePath(@"AzureRM.UsageAggregates.psd1"));

                _helper.RunPowerShellTest(scripts);
            }
        }
        private void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            using (var context = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\" + callingClassName + ".ps1",
                                    helper.GetRMModulePath(@"AzureRM.Profile.psd1"),
                                    helper.GetRMModulePath(@"AzureRM.Resources.psd1"),
                                    helper.GetRMModulePath(@"AzureRM.ServerManagement.psd1"));

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void RunPowerShellTest(params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            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.Internal.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();
                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\" + callingClassName + ".ps1",
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.RMStorageDataPlaneModule,
                                    "AzureRM.Storage.ps1",
                                    helper.GetRMModulePath(@"AzureRM.RedisCache.psd1"),
                                    "AzureRM.Resources.ps1");

                if (scripts != null)
                {
                    helper.RunPowerShellTest(scripts);
                }
            }
        }
Exemplo n.º 27
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                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.RMResourceModule);
                //modules.Add(helper.RMStorageDataPlaneModule);
                //modules.Add(helper.RMStorageModule);
                modules.Add(helper.GetRMModulePath(@"AzureRM.NotificationHubs.psd1"));

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());
                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 28
0
        protected void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            _helper.TracingInterceptor = logger;
            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2016-07-01" },
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" }
            };

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

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

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);
                UpdateDefaultContextForPlayback();

                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + GetType().Name + ".ps1",
                                     _helper.RMProfileModule,
                                     _helper.GetRMModulePath("AzureRM.DataFactory.psd1"),
                                     "AzureRM.Resources.ps1");

                _helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 29
0
        protected void RunPowerShellTest(bool createWasbAccount, params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
                SetupManagementClients();

                // Create the resource group
                this.TryRegisterSubscriptionForResource();
                this.TryCreateResourceGroup(this.resourceGroupName, resourceGroupLocation);
                this.TryCreateDataLakeStoreAccount(this.resourceGroupName, this.dataLakeStoreAccountName, resourceGroupLocation);
                this.TryCreateDataLakeStoreAccount(this.resourceGroupName, this.secondDataLakeStoreAccountName, resourceGroupLocation);
                if (createWasbAccount)
                {
                    string storageSuffix;
                    this.azureBlobStoreAccessKey = this.TryCreateStorageAccount(this.resourceGroupName,
                                                                                this.azureBlobStoreName,
                                                                                "DataLakeAnalyticsTestStorage", "DataLakeAnalyticsTestStorageDescription", resourceGroupLocation,
                                                                                out storageSuffix);
                }

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                helper.SetupModules(AzureModule.AzureResourceManager, "ScenarioTests\\" + this.GetType().Name + ".ps1",
                                    helper.RMProfileModule, helper.GetRMModulePath(@"AzureRM.DataLakeAnalytics.psd1"));

                // inject the access key into the script if necessary.
                for (int i = 0; i < scripts.Length; i++)
                {
                    if (scripts[i].Contains("-blobAccountKey"))
                    {
                        scripts[i] = scripts[i].Replace("-blobAccountKey",
                                                        string.Format("-blobAccountKey '{0}'", this.azureBlobStoreAccessKey));
                    }
                }

                helper.RunPowerShellTest(scripts);
            }
        }
Exemplo n.º 30
0
        public void RunPowerShellTest(ServiceManagement.Common.Models.XunitTracingInterceptor logger, params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            _helper.TracingInterceptor = logger;
            var providers         = new Dictionary <string, string>();
            var providersToIgnore = new Dictionary <string, string>();

            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 computePath             = _helper.GetRMModulePath(@"AzureRM.Compute.psd1");
                var networkPath             = _helper.GetRMModulePath(@"AzureRM.Network.psd1");
                var operationalInsightsPath = _helper.GetRMModulePath(@"AzureRM.OperationalInsights.psd1");

                var callingClassName = callingClassType?.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                _helper.SetupModules(
                    AzureModule.AzureResourceManager,
                    _helper.RMProfileModule,
                    _helper.GetRMModulePath(@"AzureRM.Security.psd1"),
                    computePath,
                    networkPath,
                    operationalInsightsPath,
                    "ScenarioTests\\Common.ps1",
                    "ScenarioTests\\" + callingClassName + ".ps1",
                    "AzureRM.Storage.ps1",
                    "AzureRM.Resources.ps1");

                _helper.RunPowerShellTest(scripts);
            }
        }