Exemplo n.º 1
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            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))
            {
                SetupManagementClients(context);

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     _helper.RMProfileModule,
                                     _helper.RMResourceModule,
                                     _helper.RMStorageDataPlaneModule,
                                     _helper.RMStorageModule,
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + callingClassName + ".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 <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(callingClassType, mockName);

                this.csmTestFactory = new CSMTestEnvironmentFactory();

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

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

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

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

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void RunPsTestWorkflow(
            XunitTracingInterceptor logger,
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            _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 = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

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

                try
                {
                    var psScripts = scriptBuilder?.Invoke();

                    if (psScripts != null)
                    {
                        _helper.RunPowerShellTest(psScripts);
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
Exemplo n.º 4
0
        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);
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);

            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.WebSites.psd1"));

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(callingClassType, mockName);

                this.armTestEnvironmentFactory = new CSMTestEnvironmentFactory();

                if (initialize != null)
                {
                    initialize(this.armTestEnvironmentFactory);
                }

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

                SetupManagementClients();

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

                List <string> modules = this.SetupCommonModules();
                modules.Add(callingClassName + ".ps1");
                modules.Add(helper.RMProfileModule);
                modules.Add(helper.RMResourceModule);
                helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var providers = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null }
            };
            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))
            {
                _csmTestFactory = new CSMTestEnvironmentFactory();

                initialize?.Invoke(_csmTestFactory);

                SetupManagementClients(context);

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

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

                _helper.SetupModules(
                    AzureModule.AzureResourceManager,
                    _helper.RMProfileModule,
                    _helper.GetRMModulePath(@"AzureRM.PolicyInsights.psd1"),
                    "ScenarioTests\\Common.ps1",
                    "ScenarioTests\\" + callingClassName + ".ps1");

                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (null != psScripts)
                    {
                        _helper.RunPowerShellTest(psScripts);
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
Exemplo n.º 7
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(callingClassType, mockName);

                this.csmTestFactory = SetupCSMTestEnvironmentFactory();
                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                helper.SetupModules(
                    AzureModule.AzureResourceManager,
                    "ScenarioTests\\Common.ps1",
                    "ScenarioTests\\" + callingClassName + ".ps1",
                    "Microsoft.Azure.Commands.Batch.Test.dll"
                    );

                try
                {
                    if (initialize != null)
                    {
                        initialize();
                    }

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            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\\" + callingClassName + ".ps1",
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.GetRMModulePath("AzureRM.Network.psd1"));

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName, string tenant)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(callingClassType, mockName);

                this.csmTestFactory = new CSMTestEnvironmentFactory();

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

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureResourceManager);
                var oldFactory = AzureSession.AuthenticationFactory as MockTokenAuthenticationFactory;
                AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(oldFactory.Token.UserId, oldFactory.Token.AccessToken, tenant);

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    callingClassName + ".ps1",
                                    helper.RMProfileModule);

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void RunPsTestWorkFlow(Func <string[]> scriptBuilder, System.Action cleanup, string callingClassType, string mockName)
        {
            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Network", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.OperationalInsights", null }
            };

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

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

            using (var context = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClient(context);
                _helper.SetupEnvironment(AzureModule.AzureResourceManager);
                KeyVaultClient = GetKeyVaultClient();
                TestHelper     = GetTestHelper();

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

                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + callingClassName + ".ps1",
                                     _helper.RMProfileModule,
                                     _helper.GetRMModulePath(@"AzureRM.HDInsight.psd1"),
                                     _helper.GetRMModulePath("AzureRM.OperationalInsights.psd1"),
                                     _helper.GetRMModulePath("AzureRM.ManagedServiceIdentity.psd1"),
                                     _helper.RMKeyVaultModule,
                                     "AzureRM.Storage.ps1",
                                     "AzureRM.Resources.ps1");
                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (psScripts != null)
                    {
                        _helper.RunPowerShellTest(psScripts);
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
Exemplo n.º 11
0
        private void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName,
            string tenant)
        {
            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" },
                { "Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10" }
            };

            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 oldFactory = AzureSession.Instance.AuthenticationFactory as MockTokenAuthenticationFactory;
                AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(oldFactory?.Token.UserId, oldFactory?.Token.AccessToken, tenant);

                var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                _helper.SetupModules(AzureModule.AzureResourceManager,
                                     "Common.ps1",
                                     callingClassName + ".ps1",
                                     _helper.RMProfileModule,
                                     "AzureRM.Resources.ps1"
                                     );

                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (psScripts != null)
                    {
                        _helper.RunPowerShellTest(psScripts);
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
        protected void RunPowerShellTest(params string[] scripts)
        {
            SetupManagementClients();

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

            helper.RunPowerShellTest(scripts);
        }
Exemplo n.º 13
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Network", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" }
            };

            HttpMockServer.Matcher          = new UrlDecodingRecordMatcher(true, d, providersToIgnore);
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (var context = AdlMockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                // register the namespace.
                _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.RMNetworkModule,
                                     _helper.GetRMModulePath(@"AzureRM.DataLakeStore.psd1"),
                                     "AzureRM.Resources.ps1");

                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (psScripts != null)
                    {
                        _helper.RunPowerShellTest(psScripts);
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                    ReSetDataLakeStoreFileSystemManagementClient();
                }
            }
        }
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <TestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            HttpMockServer.Matcher = new PermissiveRecordMatcher();
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(callingClassType, mockName);

                this.testFactory = GetFactory();

                if (initialize != null)
                {
                    initialize(this.testFactory);
                }

                SetupManagementClients();

                helper.SetupEnvironment(this.Module);

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                helper.SetupModules(
                    this.Module,
                    "Profile\\" + callingClassName + ".ps1");

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

                helper.SetupEnvironment(AzureModule.AzureServiceManagement);

                helper.SetupModules(AzureModule.AzureServiceManagement, "ScenarioTests\\" + this.GetType().Name + ".ps1");
                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;

            var d = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Network", null },
                { "Microsoft.KeyVault", null },
                { "Microsoft.EventHub", null },
                { "Microsoft.Insights", null },
                { "Microsoft.OperationalInsights", 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);
            }
        }
        protected void RunPowerShellTest(params string[] scripts)
        {
            HttpMockServer.Matcher = new PermissiveRecordMatcher();
            using (UndoContext context = UndoContext.Current)
            {
                context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

                SetupManagementClients();

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

                helper.RunPowerShellTest(scripts);
            }
        }
        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.º 20
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.º 21
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);
            }
        }
Exemplo n.º 22
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.º 23
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.º 24
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.º 25
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.º 26
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.º 27
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.º 28
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.º 29
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.º 30
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);
                }
            }
        }