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

            RunPsTestWorkflow(
                () => scripts,
                // no custom initializer
                null,
                // no custom cleanup
                null,
                callingClassType,
                mockName);
        }
Exemplo n.º 2
0
        public void RunPsTest(ServiceManagemenet.Common.Models.XunitTracingInterceptor logger, params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            helper.TracingInterceptor = logger;
            RunPsTestWorkflow(
                () => scripts,
                // no custom initializer
                null,
                // no custom cleanup
                null,
                callingClassType,
                mockName);
        }
Exemplo n.º 3
0
        public void RunPsTest(params string[] scripts)
        {
            TestExecutionHelpers.SetUpSessionAndProfile();
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            RunPsTestWorkflow(
                () => scripts,
                // no custom initializer
                null,
                // no custom cleanup
                null,
                callingClassType,
                mockName);
        }
Exemplo n.º 4
0
        public void RunPsTest(bool createWasbAccount, XunitTracingInterceptor logger, params string[] scripts)
        {
            helper.TracingInterceptor = logger;
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            RunPsTestWorkflow(createWasbAccount,
                              () => scripts,
                              // no custom initializer
                              null,
                              // no custom cleanup
                              null,
                              callingClassType,
                              mockName);
        }
Exemplo n.º 5
0
        public void RunPowerShellTest(XunitTracingInterceptor logger, params string[] scripts)
        {
            string callingClassType = TestUtilities.GetCallingClass(2);
            string mockName         = TestUtilities.GetCurrentMethodName(2);

            helper.TracingInterceptor = logger;

            this.RunPsTestWorkflow(
                () => scripts,
                // no custom initializer
                null,
                // no custom cleanup
                null,
                callingClassType,
                mockName);
        }
Exemplo n.º 6
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.º 7
0
        public void RunPsTestWorkflow(bool createWasbAccount,
                                      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);

                // register the namespace.
                this.TryRegisterSubscriptionForResource();
                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.DataLakeAnalytics.psd1"), helper.GetRMModulePath(@"AzureRM.DataLakeStore.psd1"));

                if (createWasbAccount)
                {
                    string storageSuffix;
                    this.resourceGroupName = TestUtilities.GenerateName("abarg1");
                    TryCreateResourceGroup(this.resourceGroupName, resourceGroupLocation);
                    this.azureBlobStoreName      = TestUtilities.GenerateName("azureblob01");
                    this.azureBlobStoreAccessKey = this.TryCreateStorageAccount(this.resourceGroupName,
                                                                                this.azureBlobStoreName,
                                                                                "DataLakeAnalyticsTestStorage", "DataLakeAnalyticsTestStorageDescription", resourceGroupLocation,
                                                                                out storageSuffix);
                }

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

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

                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (createWasbAccount)
                    {
                        try
                        {
                            ResourceManagementClient.ResourceGroups.Delete(this.resourceGroupName);
                        }
                        catch
                        {
                            // best effort cleanup.
                        }
                    }

                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }