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


C# CSMTestEnvironmentFactory.GetTestEnvironment方法代码示例

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


在下文中一共展示了CSMTestEnvironmentFactory.GetTestEnvironment方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: GraphTestBase

        public GraphTestBase()
        {
            var testFactory = new CSMTestEnvironmentFactory();
            TestEnvironment environment = testFactory.GetTestEnvironment();

            string tenantId = null;
            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                tenantId = environment.AuthorizationContext.TenantId;
                Domain = environment.AuthorizationContext.UserId
                            .Split(new [] {"@"}, StringSplitOptions.RemoveEmptyEntries)
                            .Last();

                HttpMockServer.Variables[TenantIdKey] = tenantId;
                HttpMockServer.Variables[DomainKey] = Domain;
            }
            else if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                tenantId = HttpMockServer.Variables[TenantIdKey];
                Domain = HttpMockServer.Variables[DomainKey];
            }

            GraphClient = TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId);
        }
开发者ID:ca-ta,项目名称:azure-sdk-for-net,代码行数:24,代码来源:GraphTestBase.cs

示例6: GetGraphClient

        protected GraphRbacManagementClient GetGraphClient()
        {
            var testFactory = new CSMTestEnvironmentFactory();
            var environment = testFactory.GetTestEnvironment();
            string tenantId = Guid.Empty.ToString();

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                tenantId = environment.AuthorizationContext.TenantId;
                UserDomain = environment.AuthorizationContext.UserDomain;

                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;
                }
            }

            return TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId);
        }
开发者ID:dulems,项目名称:azure-powershell,代码行数:30,代码来源:SqlTestsBase.cs

示例7: 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)
            {
                fromConfig = FromConfiguration();

                if (!fromConfig)
                {
                    var testFactory = new CSMTestEnvironmentFactory();
                    var testEnv = testFactory.GetTestEnvironment();
                    var secret = Guid.NewGuid().ToString();
                    var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory);
                    var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory);
                    var tenantId = testEnv.AuthorizationContext.TenantId;
                    var graphClient = TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId);
                    var appDisplayName = TestUtilities.GenerateName("sdktestapp");

                    //Setup things in AAD

                    //Create an application
                    var app = CreateApplication(graphClient, appDisplayName, secret);
                    appObjectId = app.Application.ObjectId;

                    //Create a corresponding service principal
                    var servicePrincipal = CreateServicePrincipal(app, graphClient);

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

                    //Create a resource group in that location
                    vaultName = TestUtilities.GenerateName("sdktestvault");
                    rgName = TestUtilities.GenerateName("sdktestrg");

                    resourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup {Location = location});

                    //Create a key vault in that resource group
                    var createResponse = CreateVault(mgmtClient, location, tenantId, servicePrincipal);

                    vaultAddress = createResponse.Vault.Properties.VaultUri;
                    _ClientCredential = new ClientCredential(app.Application.AppId, secret);

                    //Wait a few seconds before trying to authenticate
                    TestUtilities.Wait(TimeSpan.FromSeconds(30));
                }
            }

            initialized = true;
        }
开发者ID:bganapa,项目名称:azure-sdk-for-net,代码行数:64,代码来源:KeyVaultTestFixture.cs

示例8: Dispose

        public void Dispose()
        {
            if (HttpMockServer.Mode == HttpRecorderMode.Record && !fromConfig)
            {
                var testFactory = new CSMTestEnvironmentFactory();
                var testEnv = testFactory.GetTestEnvironment();
                var mgmtClient = TestBase.GetServiceClient<KeyVaultManagementClient>(testFactory);
                var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory);
                var tenantId = testEnv.AuthorizationContext.TenantId;
                var graphClient = TestBase.GetGraphServiceClient<GraphRbacManagementClient>(testFactory, tenantId);

                mgmtClient.Vaults.Delete(rgName, vaultName);
                graphClient.Application.Delete(appObjectId);
                resourcesClient.ResourceGroups.Delete(rgName);
            }
        }
开发者ID:bganapa,项目名称:azure-sdk-for-net,代码行数:16,代码来源:KeyVaultTestFixture.cs

示例9: ResetPreCreatedVault

        public void ResetPreCreatedVault()
        {
            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 = Guid.Parse(testEnv.AuthorizationContext.TenantId);

                var policies = new AccessPolicyEntry[] { };

                mgmtClient.Vaults.CreateOrUpdate(
                resourceGroupName: resourceGroupName,
                vaultName: preCreatedVault,
                parameters: new VaultCreateOrUpdateParameters
                {
                    Location = location,
                    Tags = new Dictionary<string, string> { { tagName, tagValue } },
                    Properties = new VaultProperties
                    {
                        EnabledForDeployment = false,
                        Sku = new Sku { Family = "A", Name = "Premium" },
                        TenantId = tenantId,
                        VaultUri = "",
                        AccessPolicies = policies
                    }
                }
                );
            }
        }
开发者ID:devigned,项目名称:azure-powershell,代码行数:31,代码来源:KeyVaultTestFixture.cs

示例10: Dispose

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (HttpMockServer.Mode == HttpRecorderMode.Record && initialized)
                {
                    var testFactory = new CSMTestEnvironmentFactory();
                    var testEnv = testFactory.GetTestEnvironment();
                    var resourcesClient = TestBase.GetServiceClient<ResourceManagementClient>(testFactory);

                    resourcesClient.ResourceGroups.Delete(resourceGroupName);
                }
            }
        }
开发者ID:devigned,项目名称:azure-powershell,代码行数:14,代码来源:KeyVaultTestFixture.cs

示例11: GetSearchIndexClientForKey

        private SearchIndexClient GetSearchIndexClientForKey(string indexName, string apiKey)
        {
            var factory = new CSMTestEnvironmentFactory();
            TestEnvironment currentEnvironment = factory.GetTestEnvironment();

            Uri baseUri = 
                new Uri(
                    currentEnvironment.GetBaseSearchUri(ExecutionMode.CSM, SearchServiceName), 
                    String.Format("indexes/{0}/", indexName));

            SearchIndexClient client = new SearchIndexClient(new SearchCredentials(apiKey), baseUri);
            return TestBaseCopy.AddMockHandler<SearchIndexClient>(ref client);
        }
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:13,代码来源:IndexFixture.cs


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