protected void SetupDataClient(RestTestFramework.MockContext context)
        {
            var credentials = new ApiKeyClientCredentials("DEMO_KEY");
            var operationalInsightsDataClient = new OperationalInsightsDataClient(credentials, HttpMockServer.CreateInstance());

            _helper.SetupManagementClients(operationalInsightsDataClient);
        }
Beispiel #2
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.Authorization", null);
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);

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

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

                SetupManagementClients(context);

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\ComputeTestCommon.ps1",
                                    "ScenarioTests\\" + callingClassName + ".ps1",
                                    helper.RMProfileModule,
                                    helper.RMResourceModule,
                                    helper.RMStorageDataPlaneModule,
                                    helper.RMStorageModule,
                                    helper.GetRMModulePath("AzureRM.Compute.psd1"),
                                    helper.GetRMModulePath("AzureRM.Network.psd1"));

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
 protected Management.Sql.SqlManagementClient GetSqlClient(RestTestFramework.MockContext context)
 {
     Management.Sql.SqlManagementClient client =
         context.GetServiceClient <Management.Sql.SqlManagementClient>(
             RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
     return(client);
 }
Beispiel #4
0
        protected void RunPowerShellTest(params string[] scripts)
        {
            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(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2)))
            {
                SetupManagementClients(context);

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

                helper.RunPowerShellTest(scripts);
            }
        }
Beispiel #5
0
        private void SetupManagementClients(RestTestFramework.MockContext context)
        {
            Microsoft.Azure.Management.ResourceManager.ResourceManagementClient ResourceManagerResourceManagementClient = GetResourceManagerResourceManagementClient(context);
            this.ResourceManagementClient      = this.GetResourceManagementClient();
            this.SubscriptionClient            = this.GetSubscriptionClient();
            this.GalleryClient                 = this.GetGalleryClient();
            this.NetworkManagementClient       = this.GetNetworkManagementClient(context);
            this.ComputeManagementClient       = this.GetComputeManagementClient(context);
            this.StorageManagementClient       = this.GetStorageManagementClient(context);
            this.AuthorizationManagementClient = this.GetAuthorizationManagementClient();
            this.InsightsManagementClient      = this.GetInsightsManagementClient();
            this.RedisManagementClient         = this.GetRedisManagementClient(context);

            helper.SetupManagementClients(
                ResourceManagerResourceManagementClient,
                ResourceManagementClient,
                SubscriptionClient,
                GalleryClient,
                this.NetworkManagementClient,
                this.ComputeManagementClient,
                this.StorageManagementClient,
                this.AuthorizationManagementClient,
                this.InsightsManagementClient,
                this.RedisManagementClient);
        }
        protected GraphRbacManagementClient GetGraphClient(RestTestFramework.MockContext context)
        {
            var    environment = RestTestFramework.TestEnvironmentFactory.GetTestEnvironment();
            string tenantId    = null;

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                tenantId   = environment.Tenant;
                UserDomain = environment.UserName.Split(new[] { "@" }, StringSplitOptions.RemoveEmptyEntries).Last();

                HttpMockServer.Variables[TenantIdKey] = tenantId;
                HttpMockServer.Variables[DomainKey]   = UserDomain;
            }
            else if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                if (HttpMockServer.Variables.ContainsKey(TenantIdKey))
                {
                    tenantId = HttpMockServer.Variables[TenantIdKey];
                    AzureRmProfileProvider.Instance.Profile.Context.Tenant.Id = new Guid(tenantId);
                }
                if (HttpMockServer.Variables.ContainsKey(DomainKey))
                {
                    UserDomain = HttpMockServer.Variables[DomainKey];
                    AzureRmProfileProvider.Instance.Profile.Context.Tenant.Domain = UserDomain;
                }
            }

            var client = context.GetGraphServiceClient <GraphRbacManagementClient>(environment);

            client.TenantID = tenantId;
            return(client);
        }
        private void SetupManagementClients(RestTestFramework.MockContext context)
        {
            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                // This allows the use of a particular subscription if the user is associated to several
                // "TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId=<subscription-id>"
                string subId = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION");
                RestTestFramework.TestEnvironment environment = new RestTestFramework.TestEnvironment(connectionString: subId);
                this.MonitorManagementClient = this.GetInsightsManagementClient(context: context, env: environment);
                ResourceManagementClient     = this.GetResourceManagementClient(context: context, env: environment);
                StorageManagementClient      = this.GetStorageManagementClient(context: context, env: environment);
                ApplicationInsightsClient    = this.GetApplicationInsightsManagementClient(context: context, env: environment);
            }
            else if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                this.MonitorManagementClient = this.GetInsightsManagementClient(context: context, env: null);
                ResourceManagementClient     = this.GetResourceManagementClient(context: context, env: null);
                StorageManagementClient      = this.GetStorageManagementClient(context: context, env: null);
                ApplicationInsightsClient    = GetApplicationInsightsManagementClient(context, env: null);
            }

            _helper.SetupManagementClients(
                ResourceManagementClient,
                this.MonitorManagementClient,
                StorageManagementClient,
                this.ApplicationInsightsClient);
        }
 private SiteRecoveryManagementClient GetSiteRecoveryManagementClient(
     string scenario,
     RestTestFramework.MockContext context)
 {
     return(context.GetServiceClient <SiteRecoveryManagementClient>(
                RestTestFramework.TestEnvironmentFactory.GetTestEnvironment()));
 }
Beispiel #9
0
        protected override void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var sqlClient          = GetSqlClient(context);
            var newResourcesClient = GetResourcesClient(context);

            Helper.SetupSomeOfManagementClients(sqlClient, newResourcesClient);
        }
        private SiteRecoveryManagementClient GetSiteRecoveryManagementClient(
            string scenario,
            RestTestFramework.MockContext context)
        {
            var resourceGroupName = "";
            var resourceName      = "";

            switch (scenario)
            {
            case Constants.NewModel:
                resourceName      = this.asrVaultCreds.ResourceName;
                resourceGroupName = this.asrVaultCreds.ResourceGroupName;
                break;

            default:
                resourceName      = this.asrVaultCreds.ResourceName;
                resourceGroupName = this.asrVaultCreds.ResourceGroupName;
                break;
            }

            ;

            var client = this.GetSiteRecoveryManagementClient(context);

            client.ResourceGroupName = resourceGroupName;
            client.ResourceName      = resourceName;

            return(client);
        }
        private void SetupManagementClients(RestTestFramework.MockContext context)
        {
            ResourceManagementClient = GetResourceManagementClient();
            SubscriptionClient       = GetSubscriptionClient();
            StorageClient            = GetStorageManagementClient(context);
            GalleryClient            = GetGalleryClient();
            //var eventsClient = GetEventsClient();
            KeyVaultManagementClient         = GetKeyVaultManagementClient(context);
            NetworkManagementClient          = this.GetNetworkManagementClientClient(context);
            ComputeManagementClient          = GetComputeManagementClient(context);
            AuthorizationManagementClient    = GetAuthorizationManagementClient();
            InternalNetworkManagementClient  = this.GetNetworkManagementClientInternal(context);
            InternalResourceManagementClient = this.GetResourceManagementClientInternal(context);
            // GraphClient = GetGraphClient();

            helper.SetupManagementClients(
                ResourceManagementClient,
                SubscriptionClient,
                StorageClient,
                GalleryClient,
                //eventsClient,
                KeyVaultManagementClient,
                NetworkManagementClient,
                ComputeManagementClient,
                AuthorizationManagementClient,
                InternalNetworkManagementClient,
                InternalResourceManagementClient);
            // GraphClient);
        }
Beispiel #12
0
        protected void SetupManagementClients(RestTestFramework.MockContext context)
        {
            RsClient         = GetRsClient(context);
            InternalRmClient = GetInternalRmClient(context);

            _helper.SetupManagementClients(RsClient, InternalRmClient);
        }
 private IMonitorClient GetMonitorClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env)
 {
     // currentEnvironment: RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
     return(env != null
         ? context.GetServiceClient <MonitorClient>(currentEnvironment : env)
         : context.GetServiceClient <MonitorClient>());
 }
        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 networkPath = helper.GetStackRMModulePath("AzureRM.Network");
                var computePath = helper.GetStackRMModulePath("AzureRM.Compute");

                var callingClassName = callingClassType
                                       .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
                                       .Last();
                helper.SetupModules(AzureModule.AzureResourceManager,
                                    "ScenarioTests\\Common.ps1",
                                    "ScenarioTests\\" + callingClassName + ".ps1",
                                    helper.StackRMProfileModule,
                                    helper.StackRMResourceModule,
                                    helper.GetRMModulePath("AzureRM.Insights.psd1"),
                                    helper.GetRMModulePath("AzureRM.RedisCache.psd1"),
                                    networkPath,
                                    computePath,
                                    helper.RMStorageDataPlaneModule,
                                    helper.StackRMStorageModule);

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
        protected NetworkManagementClient GetNetworkClient(RestTestFramework.MockContext context)
        {
            NetworkManagementClient client =
                context.GetServiceClient <NetworkManagementClient>(
                    RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());

            return(client);
        }
        protected virtual void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var sqlClient       = GetSqlClient(context);
            var sqlLegacyClient = GetLegacySqlClient();
            var resourcesClient = GetResourcesClient();

            helper.SetupSomeOfManagementClients(sqlClient, sqlLegacyClient, resourcesClient);
        }
Beispiel #17
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var providers = new Dictionary <string, string>()
            {
                { "Microsoft.Insights", null },
                { "Microsoft.Network", null },
                { "Microsoft.OperationalInsights", null }
            };

            var providersToIgnore = new Dictionary <string, string>();

            providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");

            HttpMockServer.Matcher          = new PermissiveRecordMatcherWithApiExclusion(ignoreResourcesClient: true, providers: providers, userAgents: providersToIgnore);
            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,
                                     _helper.RMProfileModule,
                                     _helper.GetRMModulePath("AzureRM.Monitor.psd1"),
                                     "ScenarioTests\\Common.ps1",
                                     "ScenarioTests\\" + callingClassName + ".ps1",
                                     "AzureRM.Storage.ps1",
                                     "AzureRM.Resources.ps1",
                                     _helper.GetRMModulePath("AzureRM.ApplicationInsights.psd1"),
                                     _helper.GetRMModulePath("AzureRM.OperationalInsights.psd1"),
                                     _helper.GetRMModulePath("AzureRM.Network.psd1"));

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

                        if (psScripts != null)
                        {
                            _helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }
        }
Beispiel #18
0
        protected void SetupManagementClients(RestTestFramework.MockContext context)
        {
            ResourceManagementClient       = GetResourceManagementClient(context);
            TrafficManagerManagementClient = GetFeatureClient(context);

            _helper.SetupManagementClients(
                ResourceManagementClient,
                TrafficManagerManagementClient);
        }
        protected override void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var sqlClient           = GetSqlClient(context);
            var sqlLegacyClient     = GetLegacySqlClient();
            var resourcesClient     = GetResourcesClient();
            var authorizationClient = GetAuthorizationManagementClient();

            helper.SetupSomeOfManagementClients(sqlClient, sqlLegacyClient, resourcesClient, authorizationClient);
        }
        protected StorageManagementClient GetStorageV2Client(RestTestFramework.MockContext context)
        {
#if NETSTANDARD
            var client = context.GetServiceClient <StorageManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
#else
            var client = TestBase.GetServiceClient <StorageManagementClient>(new CSMTestEnvironmentFactory());
#endif
            return(client);
        }
Beispiel #21
0
        protected override void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var newResourcesClient = GetResourcesClient(context);
            var sqlClient          = GetSqlClient(context);
            var networkClient      = GetNetworkClient(context);
            var graphClient        = GetGraphClientVersion1_6(context);

            Helper.SetupSomeOfManagementClients(newResourcesClient, sqlClient, networkClient, graphClient);
        }
        protected void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var operationalInsightsManagementClient = GetOperationalInsightsManagementClient(context);
            var resourceManagementClient            = GetResourceManagementClient(context);

            _helper.SetupManagementClients(
                operationalInsightsManagementClient,
                resourceManagementClient);
        }
Beispiel #23
0
        private void SetupManagementClients(RestTestFramework.MockContext context)
        {
            ResourceManagementClient = GetResourceManagementClient(context);
            CognitiveServicesClient  = GetCognitiveServicesManagementClient(context);

            _helper.SetupManagementClients(
                ResourceManagementClient,
                CognitiveServicesClient);
        }
        protected virtual void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var sqlCSMClient  = GetSqlClient();
            var storageClient = GetStorageClient();
            //TODO, Remove the MockDeploymentFactory call when the test is re-recorded
            var resourcesClient     = MockDeploymentClientFactory.GetResourceClient(GetResourcesClient());
            var authorizationClient = GetAuthorizationManagementClient();

            helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, resourcesClient, authorizationClient);
        }
Beispiel #25
0
 protected void SetupManagementClients(string scenario, RestTestFramework.MockContext context)
 {
     RmRestClient = GetRmRestClient(context);
     RecoveryServicesMgmtClient = GetRecoveryServicesManagementClient(context);
     SiteRecoveryMgmtClient     = GetSiteRecoveryManagementClient(scenario, context);
     _helper.SetupManagementClients(
         RmRestClient,
         RecoveryServicesMgmtClient,
         SiteRecoveryMgmtClient);
 }
 protected Management.Sql.SqlManagementClient GetSqlClient(RestTestFramework.MockContext context)
 {
     Management.Sql.SqlManagementClient client =
         context.GetServiceClient <Management.Sql.SqlManagementClient>(
             RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
     if (HttpMockServer.Mode == HttpRecorderMode.Playback)
     {
         client.LongRunningOperationRetryTimeout = 0;
     }
     return(client);
 }
        protected override void SetupManagementClients(RestTestFramework.MockContext context)
        {
            var sqlClient                           = GetSqlClient(context);
            var storageV2Client                     = GetStorageManagementClient(context);
            var newResourcesClient                  = GetResourcesClient(context);
            var monitorManagementClient             = GetMonitorManagementClient(context);
            var eventHubManagementClient            = GetEventHubManagementClient(context);
            var operationalInsightsManagementClient = GetOperationalInsightsManagementClient(context);

            Helper.SetupSomeOfManagementClients(sqlClient, storageV2Client, storageV2Client,
                                                newResourcesClient, monitorManagementClient, eventHubManagementClient,
                                                operationalInsightsManagementClient);
        }
Beispiel #28
0
        public void RunPsTestWorkflow(
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            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();
                    }
                }
            }
        }
        private void SetupManagementClients(RestTestFramework.MockContext context)
        {
            ResourceManagementClient = GetResourceManagementClient();
            SubscriptionClient       = GetSubscriptionClient();
            ACEProvisioningManagementPartnerAPIClient = GetACEProvisioningGSMAPIClient(context);
            GalleryClient = GetGalleryClient();


            helper.SetupManagementClients(
                ResourceManagementClient,
                SubscriptionClient,
                ACEProvisioningManagementPartnerAPIClient,
                GalleryClient);
        }
        protected void SetupManagementClients(
            RestTestFramework.MockContext context)
        {
            this.RmRestClient = this.GetRmRestClient(context);
            this.ResourceManagementRestClient = this.GetResourceManagementClientRestClient(context);
            this.RecoveryServicesMgmtClient   = this.GetRecoveryServicesManagementClient(context);
            this.SiteRecoveryMgmtClient       = this.GetSiteRecoveryManagementClient(context);

            this.helper.SetupManagementClients(
                this.RmRestClient,
                this.RecoveryServicesMgmtClient,
                this.SiteRecoveryMgmtClient,
                this.ResourceManagementRestClient);
        }