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


C# ProfileClient.SetSubscriptionAsDefault方法代码示例

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


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

示例1: CreateAzureSMProfile

 public static AzureSMProfile CreateAzureSMProfile(string storageAccount)
 {
     var profile = new AzureSMProfile();
     var client = new ProfileClient(profile);
     var tenantId = Guid.NewGuid();
     var subscriptionId = Guid.NewGuid();
     var account = new AzureAccount
     {
         Id = "[email protected]",
         Type = AzureAccount.AccountType.User
     };
     account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString());
     account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString());
     var subscription = new AzureSubscription()
     {
         Id = subscriptionId,
         Name = "Test Subscription 1",
         Environment = EnvironmentName.AzureCloud,
         Account = account.Id,
     };
     subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString());
     subscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount);
     client.AddOrSetAccount(account);
     client.AddOrSetSubscription(subscription);
     client.SetSubscriptionAsDefault(subscriptionId, account.Id);
     return profile;
 }
开发者ID:rohmano,项目名称:azure-powershell,代码行数:27,代码来源:CommonDataCmdletTests.cs

示例2: SetupCertificates

        /// <summary>
        /// Setup certificates required for the unit tests
        /// </summary>
        public static void SetupCertificates()
        {
            PSTestTracingInterceptor.AddToContext();
            var newGuid = Guid.NewGuid();
            var profile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSMCmdlet.CurrentProfile = profile;
            AzureSession.DataStore = new MemoryDataStore();
            AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
            ProfileClient client = new ProfileClient(profile);
            client.AddOrSetAccount( new AzureAccount
            {
                Id = "test",
                Type = AzureAccount.AccountType.User,
                Properties = new Dictionary<AzureAccount.Property, string>
                        {
                            {AzureAccount.Property.Subscriptions, newGuid.ToString()}
                        }
            });
            client.AddOrSetAccount( new AzureAccount
            {
                Id = UnitTestHelper.GetUnitTestClientCertificate().Thumbprint,
                Type = AzureAccount.AccountType.Certificate,
                Properties = new Dictionary<AzureAccount.Property, string>
                        {
                            {AzureAccount.Property.Subscriptions, newGuid.ToString()}
                        }
            });
            client.AddOrSetAccount( new AzureAccount
            {
                Id = UnitTestHelper.GetUnitTestSSLCertificate().Thumbprint,
                Type = AzureAccount.AccountType.Certificate,
                Properties = new Dictionary<AzureAccount.Property, string>
                        {
                            {AzureAccount.Property.Subscriptions, newGuid.ToString()}
                        }
            });
            client.AddOrSetSubscription(new AzureSubscription
            {
                Id = newGuid,
                Name = "test",
                Environment = EnvironmentName.AzureCloud,
                Account = "test"
            });

            client.SetSubscriptionAsDefault(newGuid, "test");
            client.Profile.Save();


            // Check if the cert has been installed 
            Process proc = ExecuteProcess(
                "netsh",
                string.Format(
                    CultureInfo.InvariantCulture,
                    "http show sslcert ipport=0.0.0.0:{0}",
                    DefaultHttpsServerPrefixUri.Port));

            if (proc.ExitCode != 0)
            {
                // Install the SSL and client certificates to the LocalMachine store
                X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                store.Open(OpenFlags.ReadWrite);
                store.Add(UnitTestHelper.GetUnitTestSSLCertificate());
                store.Add(UnitTestHelper.GetUnitTestClientCertificate());
                store.Close();
                store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                store.Open(OpenFlags.ReadWrite);
                store.Add(UnitTestHelper.GetUnitTestSSLCertificate());
                store.Add(UnitTestHelper.GetUnitTestClientCertificate());
                store.Close();

                // Remove any existing certs on the default port 
                proc = ExecuteProcess(
                    "netsh",
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "http delete sslcert ipport=0.0.0.0:{0}",
                        DefaultHttpsServerPrefixUri.Port));

                // Install the ssl cert on the default port
                proc = ExecuteProcess(
                    "netsh",
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2:B}",
                        DefaultHttpsServerPrefixUri.Port,
                        UnitTestHelper.GetUnitTestSSLCertificate().Thumbprint,
                        MockHttpServer.HttpsAppId));

                if (proc.ExitCode != 0)
                {
                    throw new InvalidOperationException(string.Format(
                        CultureInfo.InvariantCulture,
                        "Unable to add ssl certificate: {0}",
                        proc.StandardOutput.ReadToEnd()));
                }
            }
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:100,代码来源:MockHttpServer.cs

示例3: ImportPublishSettingsUsesPassedInEnvironment

        public void ImportPublishSettingsUsesPassedInEnvironment()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureAccount.Id);
            client.Profile.Save();

            client = new ProfileClient();

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Properties.Resources.ValidProfile3);

            client.AddOrSetEnvironment(azureEnvironment);
            var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", azureEnvironment.Name);

            Assert.True(subscriptions.All(s => s.Environment == azureEnvironment.Name));
            Assert.Equal(6, subscriptions.Count);
            Assert.Equal(7, client.Profile.Subscriptions.Count);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:23,代码来源:ProfileClientTests.cs

示例4: ImportPublishSettingsUsesProperEnvironmentWithManagementUrl

        public void ImportPublishSettingsUsesProperEnvironmentWithManagementUrl()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.AddOrSetAccount(azureAccount);
            azureEnvironment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement] = "https://newmanagement.core.windows.net/";
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureAccount.Id);
            client.Profile.Save();

            client = new ProfileClient();

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Properties.Resources.ValidProfile3);

            client.AddOrSetEnvironment(azureEnvironment);
            var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", null);

            Assert.True(subscriptions.All(s => s.Environment == azureEnvironment.Name));
            Assert.Equal(6, subscriptions.Count);
            Assert.Equal(7, client.Profile.Subscriptions.Count);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:24,代码来源:ProfileClientTests.cs

示例5: ClearDefaultAzureSubscriptionClearsDefault

        public void ClearDefaultAzureSubscriptionClearsDefault()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription2);

            Assert.Null(client.Profile.DefaultSubscription);
            client.SetSubscriptionAsDefault(azureSubscription2.Name, azureSubscription2.Account);
            Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id);

            client.ClearDefaultSubscription();

            Assert.Null(client.Profile.DefaultSubscription);
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:17,代码来源:ProfileClientTests.cs

示例6: SetAzureSubscriptionAsDefaultSetsDefaultAndCurrent

        public void SetAzureSubscriptionAsDefaultSetsDefaultAndCurrent()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription2);

            Assert.Null(client.Profile.DefaultSubscription);

            client.SetSubscriptionAsDefault(azureSubscription2.Name, azureSubscription2.Account);

            Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id);
            Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
            Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsDefault("bad", null));
            Assert.Throws<ArgumentNullException>(() => client.SetSubscriptionAsDefault(null, null));
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:18,代码来源:ProfileClientTests.cs

示例7: RemoveAzureSubscriptionChecksAndRemoves

        public void RemoveAzureSubscriptionChecksAndRemoves()
        {
            MockDataStore dataStore = new MockDataStore();
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();

            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsCurrent(azureSubscription1.Name, azureSubscription1.Account);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureSubscription1.Account);

            Assert.Equal(1, client.Profile.Subscriptions.Count);

            List<string> log = new List<string>();
            client.WarningLog = log.Add;

            var subscription = client.RemoveSubscription(azureSubscription1.Name);

            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(azureSubscription1.Name, subscription.Name);
            Assert.Equal(2, log.Count);
            Assert.Equal(
                "The default subscription is being removed. Use Select-AzureSubscription -Default <subscriptionName> to select a new default subscription.",
                log[0]);
            Assert.Equal(
                "The current subscription is being removed. Use Select-AzureSubscription <subscriptionName> to select a new current subscription.",
                log[1]);
            Assert.Throws<ArgumentException>(() => client.RemoveSubscription("bad"));
            Assert.Throws<ArgumentNullException>(() => client.RemoveSubscription(null));
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:31,代码来源:ProfileClientTests.cs

示例8: ImportPublishSettingsUsesPassedInEnvironment

        public void ImportPublishSettingsUsesPassedInEnvironment()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureAccount.Id);
            client.Profile.Save();

            client = new ProfileClient(currentProfile);

            dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
                Microsoft.WindowsAzure.Commands.Common.Test.Properties.Resources.ValidProfile3);

            client.AddOrSetEnvironment(azureEnvironment);
            var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", azureEnvironment.Name);

            Assert.True(subscriptions.All(s => s.Environment == azureEnvironment.Name));
            Assert.Equal(6, subscriptions.Count);
            Assert.Equal(7, client.Profile.Subscriptions.Count);
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:24,代码来源:ProfileClientTests.cs

示例9: ClearDefaultAzureSubscriptionClearsDefault

        public void ClearDefaultAzureSubscriptionClearsDefault()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription2);

            Assert.Null(client.Profile.DefaultSubscription);
            client.SetSubscriptionAsDefault(azureSubscription2.Name, azureSubscription2.Account);
            Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id);

            client.ClearDefaultSubscription();

            Assert.Null(client.Profile.DefaultSubscription);
            Assert.Null(client.Profile.Context.Account);
            Assert.Null(client.Profile.Context.Environment);
            Assert.Null(client.Profile.Context.Subscription);
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:21,代码来源:ProfileClientTests.cs

示例10: SetAzureSubscriptionAsDefaultSetsDefaultAndCurrent

        public void SetAzureSubscriptionAsDefaultSetsDefaultAndCurrent()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            ProfileClient client = new ProfileClient(currentProfile);
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription2);

            Assert.Null(client.Profile.DefaultSubscription);

            client.SetSubscriptionAsDefault(azureSubscription2.Name, azureSubscription2.Account);

            Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id);
            Assert.Equal(azureSubscription2.Id, currentProfile.Context.Subscription.Id);
            Assert.Equal(azureSubscription2.Account, currentProfile.Context.Account.Id);
            Assert.Equal(azureSubscription2.Environment, currentProfile.Context.Environment.Name);
            var notFoundEx = Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsDefault("bad", null));
            var invalidEx = Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsDefault(null, null));
            Assert.Contains("doesn't exist", notFoundEx.Message);
            Assert.Contains("non-null", invalidEx.Message);
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:22,代码来源:ProfileClientTests.cs

示例11: SetupUnitTestSubscription

        /// <summary>
        /// Common helper method for other tests to create a unit test subscription
        /// that connects to the mock server.
        /// </summary>
        /// <param name="powershell">The powershell instance used for the test.</param>
        public static AzureSubscription SetupUnitTestSubscription(System.Management.Automation.PowerShell powershell)
        {
            UnitTestHelper.ImportAzureModule(powershell);

            X509Certificate2 certificate = UnitTestHelper.GetUnitTestClientCertificate();
            Guid subscriptionId = new Guid(UnitTestSubscriptionId);

            // Set the client certificate used in the subscription
            powershell.Runspace.SessionStateProxy.SetVariable(
                "clientCertificate",
                certificate);

            var profile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSMCmdlet.CurrentProfile = profile;
            ProfileClient client = new ProfileClient(profile);
            client.AddOrSetEnvironment(new AzureEnvironment
                {
                    Name = UnitTestEnvironmentName,
                    Endpoints = new Dictionary<AzureEnvironment.Endpoint, string>
                    {
                        {AzureEnvironment.Endpoint.ServiceManagement, MockHttpServer.DefaultHttpsServerPrefixUri.AbsoluteUri},
                        {AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix, ".database.windows.net"}
                    }
                });
            
            var account = new AzureAccount
            {
                Id = certificate.Thumbprint,
                Type = AzureAccount.AccountType.Certificate
            };

            var subscription = new AzureSubscription
            {
                Id = subscriptionId,
                Name = UnitTestSubscriptionName,
                Environment = UnitTestEnvironmentName,
                Account = account.Id
            };

            client.AddOrSetAccount(account);
            client.AddOrSetSubscription(subscription);
            client.SetSubscriptionAsDefault(subscriptionId, account.Id);
            client.Profile.Save();

            return subscription;
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:51,代码来源:UnitTestHelper.cs


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