本文整理汇总了C#中ProfileClient.SetSubscriptionAsCurrent方法的典型用法代码示例。如果您正苦于以下问题:C# ProfileClient.SetSubscriptionAsCurrent方法的具体用法?C# ProfileClient.SetSubscriptionAsCurrent怎么用?C# ProfileClient.SetSubscriptionAsCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProfileClient
的用法示例。
在下文中一共展示了ProfileClient.SetSubscriptionAsCurrent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: SetAzureSubscriptionAsCurrentSetsCurrent
public void SetAzureSubscriptionAsCurrentSetsCurrent()
{
MockDataStore dataStore = new MockDataStore();
ProfileClient.DataStore = dataStore;
ProfileClient client = new ProfileClient();
client.Profile.Accounts[azureAccount.Id] = azureAccount;
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetSubscription(azureSubscription1);
client.AddOrSetSubscription(azureSubscription2);
Assert.Null(AzureSession.CurrentContext.Subscription);
client.SetSubscriptionAsCurrent(azureSubscription2.Name, azureSubscription2.Account);
Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsCurrent("bad", null));
Assert.Throws<ArgumentNullException>(() => client.SetSubscriptionAsCurrent(null, null));
}
示例3: 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);
ProfileClient client = new ProfileClient();
client.Profile.Environments[UnitTestEnvironmentName] = 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.SetSubscriptionAsCurrent(UnitTestSubscriptionName, account.Id);
client.Profile.Save();
return subscription;
}