当前位置: 首页>>代码示例>>C#>>正文


C# CSMTestEnvironmentFactory类代码示例

本文整理汇总了C#中CSMTestEnvironmentFactory的典型用法代码示例。如果您正苦于以下问题:C# CSMTestEnvironmentFactory类的具体用法?C# CSMTestEnvironmentFactory怎么用?C# CSMTestEnvironmentFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CSMTestEnvironmentFactory类属于命名空间,在下文中一共展示了CSMTestEnvironmentFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        public void Initialize(string className)
        {
            if (initialized)
                return;
            
            if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Record)
            {
                var testFactory = new CSMTestEnvironmentFactory();
                var testEnv = testFactory.GetTestEnvironment();
                var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory);
                var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory);
                var tenantId = testEnv.AuthorizationContext.TenantId;

                //Figure out which locations are available for Key Vault
                location = GetKeyVaultLocation(resourcesClient);

                //Create a resource group in that location
                preCreatedVault = TestUtilities.GenerateName("pshtestvault");
                resourceGroupName = TestUtilities.GenerateName("pshtestrg");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location });
                var createResponse = CreateVault(mgmtClient, location, tenantId);
            }

            initialized = true;
        }
开发者ID:devigned,项目名称:azure-powershell,代码行数:26,代码来源:KeyVaultTestFixture.cs

示例2: SetupEnvironment

        /// <summary>
        /// This overrides the default subscription and default account. This allows the 
        /// test to get the tenant id in the test.
        /// </summary>
        public void SetupEnvironment()
        {
            base.SetupEnvironment(AzureModule.AzureResourceManager);

            TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();

            if (csmEnvironment.SubscriptionId != null)
            {
                //Overwrite the default subscription and default account
                //with ones using user ID and tenant ID from auth context
                var user = GetUser(csmEnvironment);
                var tenantId = GetTenantId(csmEnvironment);

                // Existing test will not have a user or tenant id set
                if (tenantId != null && user != null)
                {
                    var testSubscription = new AzureSubscription()
                    {
                        Id = new Guid(csmEnvironment.SubscriptionId),
                        Name = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name,
                        Environment = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment,
                        Account = user,
                        Properties = new Dictionary<AzureSubscription.Property, string>
                    {
                        {
                            AzureSubscription.Property.Default, "True"
                        },
                        {
                            AzureSubscription.Property.StorageAccount,
                            Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT")
                        },
                        {
                            AzureSubscription.Property.Tenants, tenantId
                        },
                    }
                    };

                    var testAccount = new AzureAccount()
                    {
                        Id = user,
                        Type = AzureAccount.AccountType.User,
                        Properties = new Dictionary<AzureAccount.Property, string>
                    {
                        {
                            AzureAccount.Property.Subscriptions, csmEnvironment.SubscriptionId
                        },
                    }
                    };

                    AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name = testSubscription.Name;
                    AzureRmProfileProvider.Instance.Profile.Context.Subscription.Id = testSubscription.Id;
                    AzureRmProfileProvider.Instance.Profile.Context.Subscription.Account = testSubscription.Account;

                    var environment = AzureRmProfileProvider.Instance.Profile.Environments[AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment];
                    environment.Endpoints[AzureEnvironment.Endpoint.Graph] = csmEnvironment.Endpoints.GraphUri.AbsoluteUri;
                    environment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix] = "core.windows.net"; 
                    AzureRmProfileProvider.Instance.Profile.Save();
                }
            }
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:64,代码来源:SqlEvnSetupHelper.cs

示例3: RunPsTestWorkflow

        public void RunPsTestWorkflow(
            Func<string[]> scriptBuilder,
            Action<CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName, string tenant)
        {
            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 (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();
                    }
                }
            }
        }
开发者ID:singhkays,项目名称:azure-powershell,代码行数:60,代码来源:ProfileController.cs

示例4: GetSiteRecoveryManagementClient

        /// <summary>
        /// Default constructor for management clients, using the TestSupport Infrastructure
        /// </summary>
        /// <param name="testBase">the test class</param>
        /// <returns>A site recovery management client, created from the current context (environment variables)</returns>
        public static SiteRecoveryManagementClient GetSiteRecoveryManagementClient(this TestBase testBase)
        {
            if (ServicePointManager.ServerCertificateValidationCallback == null)
            {
                ServicePointManager.ServerCertificateValidationCallback =
                    IgnoreCertificateErrorHandler;
            }

            TestEnvironment environment = new CSMTestEnvironmentFactory().GetTestEnvironment();
            // TestEnvironment environment = new RDFETestEnvironmentFactory().GetTestEnvironment();
            // environment.BaseUri = new Uri("https://localhost:8443/Rdfeproxy.svc");
            // environment.BaseUri = new Uri("https://sea-bvtd2-srs1-t56tl.cloudapp.net");


            SiteRecoveryTestsBase.MyCloudService = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "RecoveryServices-WHNOWF6LI6NM4B55QDIYR3YG3YAEZNTDUOWHPQX7NJB2LHDGTXJA-West-US" :
                Environment.GetEnvironmentVariable("CLOUD_SERVICE_NAME");

            SiteRecoveryTestsBase.MyVaultName = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "hydratest" :
                Environment.GetEnvironmentVariable("RESOURCE_NAME");

            SiteRecoveryTestsBase.VaultKey = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "loMUdckuT9SEvpQKcSG07A==" :
                Environment.GetEnvironmentVariable("CHANNEL_INTEGRITY_KEY");

            SiteRecoveryTestsBase.MyResourceGroupName = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "RecoveryServices-WHNOWF6LI6NM4B55QDIYR3YG3YAEZNTDUOWHPQX7NJB2LHDGTXJA-West-US" :
                Environment.GetEnvironmentVariable("RESOURCE_GROUP_NAME");

            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.MyCloudService))
            {
                throw new Exception("Please set CLOUD_SERVICE_NAME" + 
                    " environment variable before running the tests in Live mode");
            }
            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.MyVaultName))
            {
                throw new Exception("Please set RESOURCE_NAME" +
                    " environment variable before running the tests in Live mode");
            }
            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.VaultKey))
            {
                throw new Exception("Please set CHANNEL_INTEGRITY_KEY" +
                    " environment variable before running the tests in Live mode");
            }
            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.MyResourceGroupName))
            {
                throw new Exception("Please set RESOURCE_GROUP_NAME" +
                    " environment variable before running the tests in Live mode");
            }

            return new SiteRecoveryManagementClient(
                SiteRecoveryTestsBase.MyVaultName,
                SiteRecoveryTestsBase.MyResourceGroupName,
                "Microsoft.SiteRecoveryBVTD2",
                "SiteRecoveryVault",
                (SubscriptionCloudCredentials)environment.Credentials,
                environment.BaseUri).WithHandler(HttpMockServer.CreateInstance());
        }
开发者ID:RossMerr,项目名称:azure-sdk-for-net,代码行数:64,代码来源:SiteRecoveryManagementTestUtilities.cs

示例5: GetSiteRecoveryManagementClient

        /// <summary>
        /// Default constructor for management clients, using the TestSupport Infrastructure
        /// </summary>
        /// <param name="testBase">the test class</param>
        /// <returns>A site recovery management client, created from the current context (environment variables)</returns>
        public static SiteRecoveryManagementClient GetSiteRecoveryManagementClient(this TestBase testBase)
        {
            if (ServicePointManager.ServerCertificateValidationCallback == null)
            {
                ServicePointManager.ServerCertificateValidationCallback =
                    IgnoreCertificateErrorHandler;
            }

            TestEnvironment environment = new CSMTestEnvironmentFactory().GetTestEnvironment();

            SiteRecoveryTestsBase.MyCloudService = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "testsitegroup" :
                Environment.GetEnvironmentVariable("CLOUD_SERVICE_NAME");

            SiteRecoveryTestsBase.MyVaultName = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "ppeVault2" :
                Environment.GetEnvironmentVariable("RESOURCE_NAME");

            SiteRecoveryTestsBase.VaultKey = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "tmPfTki5UFSdaEq2JFvzuw==" :
                Environment.GetEnvironmentVariable("CHANNEL_INTEGRITY_KEY");

            SiteRecoveryTestsBase.MyResourceGroupName = (HttpMockServer.Mode == HttpRecorderMode.Playback) ?
                "testsitegroup" :
                Environment.GetEnvironmentVariable("RESOURCE_GROUP_NAME");


            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.MyCloudService))
            {
                throw new Exception("Please set CLOUD_SERVICE_NAME" + 
                    " environment variable before running the tests in Live mode");
            }
            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.MyVaultName))
            {
                throw new Exception("Please set RESOURCE_NAME" +
                    " environment variable before running the tests in Live mode");
            }
            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.VaultKey))
            {
                throw new Exception("Please set CHANNEL_INTEGRITY_KEY" +
                    " environment variable before running the tests in Live mode");
            }
            if (string.IsNullOrEmpty(SiteRecoveryTestsBase.MyResourceGroupName))
            {
                throw new Exception("Please set RESOURCE_GROUP_NAME" +
                    " environment variable before running the tests in Live mode");
            }

            return new SiteRecoveryManagementClient(
                SiteRecoveryTestsBase.MyVaultName,
                SiteRecoveryTestsBase.MyResourceGroupName,
                "Microsoft.SiteRecovery",
                (SubscriptionCloudCredentials)environment.Credentials,
                environment.BaseUri).WithHandler(HttpMockServer.CreateInstance());
        }
开发者ID:thomasyip-msft,项目名称:azure-sdk-for-net,代码行数:60,代码来源:SiteRecoveryManagementTestUtilities.cs

示例6: RunPsTestWorkflow

        public void RunPsTestWorkflow(
            Func<string[]> scriptBuilder,
            Action initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            Dictionary<string, string> d = new Dictionary<string, string>();
            d.Add("Microsoft.Authorization", "2014-07-01-preview");
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(false, d);
            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",
                    helper.RMProfileModule, 
                    helper.RMResourceModule,
                    helper.GetRMModulePath("AzureRM.Batch.psd1"));

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

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

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup();
                    }
                }
            }
        }
开发者ID:rohmano,项目名称:azure-powershell,代码行数:55,代码来源:BatchController.cs

示例7: GetSearchServiceClient

        public static SearchServiceClient GetSearchServiceClient(this SearchServiceFixture fixture)
        {
            var factory = new CSMTestEnvironmentFactory();
            TestEnvironment currentEnvironment = factory.GetTestEnvironment();
            Uri baseUri = currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, fixture.SearchServiceName);

            SearchServiceClient client =
                new SearchServiceClient(new SearchCredentials(fixture.PrimaryApiKey), baseUri);

            return TestBaseCopy.AddMockHandler<SearchServiceClient>(ref client);
        }
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:11,代码来源:SearchServiceFixtureExtensions.cs

示例8: RunPsTestWorkflow

        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\\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();
                    }
                }
            }
        }
开发者ID:kjohn-msft,项目名称:azure-powershell,代码行数:53,代码来源:NetworkResourcesController.cs

示例9: RunPsTestWorkflow

        public void RunPsTestWorkflow(
            Func<string[]> scriptBuilder,
            Action initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            HttpMockServer.Matcher = new PermissiveRecordMatcher();
            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();
                    }
                }
            }
        }
开发者ID:shuainie,项目名称:azure-powershell,代码行数:52,代码来源:BatchController.cs

示例10: RunPsTestWorkflow

        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();
                    }
                }
            }
        }
开发者ID:rohmano,项目名称:azure-powershell,代码行数:52,代码来源:ProfileController.cs

示例11: GetRecoveryServicesManagementClient

        /// <summary>
        /// Default constructor for management clients, using the TestSupport Infrastructure
        /// </summary>
        /// <param name="testBase">the test class</param>
        /// <returns>A recovery services management client, created from the current context (environment variables)</returns>
        public static RecoveryServicesManagementClient GetRecoveryServicesManagementClient(this TestBase testBase)
        {
            TestEnvironment environment = new CSMTestEnvironmentFactory().GetTestEnvironment();

            if (ServicePointManager.ServerCertificateValidationCallback == null)
            {
                ServicePointManager.ServerCertificateValidationCallback =
                    IgnoreCertificateErrorHandler;
            }

            return new RecoveryServicesManagementClient(
                (SubscriptionCloudCredentials)environment.Credentials,
                environment.BaseUri).WithHandler(HttpMockServer.CreateInstance());
        }
开发者ID:lygasch,项目名称:azure-sdk-for-net,代码行数:19,代码来源:SiteRecoveryManagementTestUtilities.cs

示例12: SetupEnvironment

        public void SetupEnvironment()
        {
            base.SetupEnvironment(AzureModule.AzureResourceManager);

            TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();

            if (csmEnvironment.SubscriptionId != null)
            {
                //Overwrite the default subscription and default account
                //with ones using user ID and tenant ID from auth context
                var user = GetUser(csmEnvironment);
                var tenantId = GetTenantId(csmEnvironment);                

                var testSubscription = new AzureSubscription()
                {
                    Id = new Guid(csmEnvironment.SubscriptionId),
                    Name = ProfileClient.Profile.DefaultSubscription.Name,
                    Environment = ProfileClient.Profile.DefaultSubscription.Environment,
                    Account = user,
                    Properties = new Dictionary<AzureSubscription.Property, string>
                    {
                        {AzureSubscription.Property.Default, "True"},
                        {
                            AzureSubscription.Property.StorageAccount,
                            Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT")
                        },
                        {AzureSubscription.Property.Tenants, tenantId},
                    }
                };

                var testAccount = new AzureAccount()
                {
                    Id = user,
                    Type = AzureAccount.AccountType.User,
                    Properties = new Dictionary<AzureAccount.Property, string>
                    {
                        {AzureAccount.Property.Subscriptions, csmEnvironment.SubscriptionId},
                    }
                };

                ProfileClient.Profile.Accounts.Remove(ProfileClient.Profile.DefaultSubscription.Account);
                ProfileClient.Profile.Subscriptions[testSubscription.Id] = testSubscription;
                ProfileClient.Profile.Accounts[testAccount.Id] = testAccount;                
                ProfileClient.SetSubscriptionAsDefault(testSubscription.Name, testSubscription.Account);
                
                ProfileClient.Profile.Save();
            }
        }
开发者ID:nityasharma,项目名称:azure-powershell,代码行数:48,代码来源:KeyVaultEnvSetupHelper.cs

示例13: RefreshAccessToken

        public static void RefreshAccessToken(this ApiManagementClient apiManagementClient)
        {
            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                // if it's playback then do nothing
                return;
            }

            var testEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment();
            var context = new AuthenticationContext(new Uri(testEnvironment.Endpoints.AADAuthUri, testEnvironment.Tenant).AbsoluteUri);

            var result = context.AcquireToken("https://management.core.windows.net/", testEnvironment.ClientId, new Uri("urn:ietf:wg:oauth:2.0:oob"), PromptBehavior.Auto);
            var newToken = context.AcquireTokenByRefreshToken(result.RefreshToken, testEnvironment.ClientId, "https://management.core.windows.net/");

            ((TokenCloudCredentials) apiManagementClient.Credentials).Token = newToken.AccessToken;
        }
开发者ID:avkaur,项目名称:azure-sdk-for-net,代码行数:16,代码来源:ApiManagementHelper.cs

示例14: KeyVaultTestBase

        public KeyVaultTestBase()
        {
            var testFactory = new CSMTestEnvironmentFactory();
            var testEnv = testFactory.GetTestEnvironment();
            this.client = GetServiceClient<KeyVaultManagementClient>(testFactory);
            this.resourcesClient = GetServiceClient<ResourceManagementClient>(testFactory);
            
            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                this.tenantId = testEnv.AuthorizationContext.TenatId;
                this.subscriptionId = testEnv.SubscriptionId;
                var graphClient = GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId);
                this.objectId = graphClient.User.Get(testEnv.AuthorizationContext.UserId).User.ObjectId;
                this.applicationId = Guid.NewGuid().ToString();                
                HttpMockServer.Variables[TenantIdKey] = tenantId;
                HttpMockServer.Variables[ObjectIdKey] = objectId;
                HttpMockServer.Variables[SubIdKey] = subscriptionId;
                HttpMockServer.Variables[ApplicationIdKey] = applicationId;
            }
            else if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                tenantId = HttpMockServer.Variables[TenantIdKey];
                objectId = HttpMockServer.Variables[ObjectIdKey];
                subscriptionId = HttpMockServer.Variables[SubIdKey];
                applicationId = HttpMockServer.Variables[ApplicationIdKey];
            }

            var providers = resourcesClient.Providers.Get("Microsoft.KeyVault");
            this.location = providers.Provider.ResourceTypes.Where(
                (resType) =>
                {
                    if (resType.Name == "vaults")
                        return true;
                    else
                        return false;
                }
                ).First().Locations.FirstOrDefault();

        }
开发者ID:thomasyip-msft,项目名称:azure-sdk-for-net,代码行数:39,代码来源:KeyVaultTestBase.cs

示例15: Initialize

        public void Initialize(string className)
        {
            if (initialized)
                return;

            HttpMockServer server;

            try
            {
                server = HttpMockServer.CreateInstance();
            }
            catch (ApplicationException)
            {
                // mock server has never been initialized, we will need to initialize it.
                HttpMockServer.Initialize(className, "InitialCreation");
                server = HttpMockServer.CreateInstance();
            }

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                var testFactory = new CSMTestEnvironmentFactory();
                var testEnv = testFactory.GetTestEnvironment();
                var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory);
                var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory);
                var tenantId = testEnv.AuthorizationContext.TenantId;                

                //Figure out which locations are available for Key Vault
                location = GetKeyVaultLocation(resourcesClient);

                //Create a resource group in that location
                preCreatedVault = TestUtilities.GenerateName("pshtestvault");
                resourceGroupName = TestUtilities.GenerateName("pshtestrg");

                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location });
                var createResponse = CreateVault(mgmtClient, location, tenantId);                
            }

            initialized = true;
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:39,代码来源:KeyVaultTestFixture.cs


注:本文中的CSMTestEnvironmentFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。