Example #1
0
        protected void SetupManagementClients(RestTestFramework.MockContext context)
        {
            this.ResourceManagementClient       = this.GetResourceManagementClient(context);
            this.SubscriptionClient             = this.GetSubscriptionClient();
            this.GalleryClient                  = this.GetGalleryClient();
            this.AuthorizationManagementClient  = this.GetAuthorizationManagementClient();
            this.TrafficManagerManagementClient = this.GetFeatureClient(context);

            this.helper.SetupManagementClients(
                this.ResourceManagementClient,
                this.SubscriptionClient,
                this.GalleryClient,
                this.AuthorizationManagementClient,
                this.TrafficManagerManagementClient);
        }
Example #2
0
 protected ResourceManagementClient GetResourceManagementClient(RestTestFramework.MockContext context)
 {
     return(context.GetServiceClient <ResourceManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment()));
 }
Example #3
0
 private TrafficManagerManagementClient GetFeatureClient(RestTestFramework.MockContext context)
 {
     return(context.GetServiceClient <TrafficManagerManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment()));
 }
Example #4
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            Dictionary <string, string> d = new Dictionary <string, string>();

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

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

            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
            using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                this.csmTestFactory = new CSMTestEnvironmentFactory();

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

                this.helper.SetupEnvironment(AzureModule.AzureResourceManager);

                this.SetupManagementClients(context);

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

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

                try
                {
                    if (scriptBuilder != null)
                    {
                        string[] psScripts = scriptBuilder();

                        if (psScripts != null)
                        {
                            this.helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }