本文整理汇总了C#中ProfileClient.AddOrSetSubscription方法的典型用法代码示例。如果您正苦于以下问题:C# ProfileClient.AddOrSetSubscription方法的具体用法?C# ProfileClient.AddOrSetSubscription怎么用?C# ProfileClient.AddOrSetSubscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProfileClient
的用法示例。
在下文中一共展示了ProfileClient.AddOrSetSubscription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: ClearAzureProfileClearsDefaultProfile
public void ClearAzureProfileClearsDefaultProfile()
{
ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
// Setup
var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
AzurePSCmdlet.CurrentProfile = profile;
ProfileClient client = new ProfileClient(profile);
client.AddOrSetAccount(azureAccount);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetSubscription(azureSubscription1);
client.Profile.Save();
cmdlt.CommandRuntime = commandRuntimeMock;
cmdlt.Force = new SwitchParameter(true);
// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();
// Verify
client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
Assert.Equal(0, client.Profile.Subscriptions.Count);
Assert.Equal(0, client.Profile.Accounts.Count);
Assert.Equal(2, client.Profile.Environments.Count); //only default environments
}
示例3: SetAzureSubscriptionDerivesEnvironmentFromBothEndpointParameters
public void SetAzureSubscriptionDerivesEnvironmentFromBothEndpointParameters()
{
SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
// Setup
ProfileClient client = new ProfileClient();
client.AddOrSetAccount(azureAccount);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetSubscription(azureSubscription1);
client.Profile.Save();
cmdlt.CommandRuntime = commandRuntimeMock.Object;
cmdlt.SubscriptionId = azureSubscription1.Id.ToString();
cmdlt.CurrentStorageAccountName = "NewCloudStorage";
cmdlt.ServiceEndpoint = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement);
cmdlt.ResourceManagerEndpoint = azureEnvironment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager);
// Act
cmdlt.InvokeBeginProcessing();
cmdlt.ExecuteCmdlet();
cmdlt.InvokeEndProcessing();
// Verify
client = new ProfileClient();
var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
Assert.Equal(cmdlt.Environment, newSubscription.Environment);
Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
}
示例4: ImportPublishSettingsAddsSecondCertificate
public void ImportPublishSettingsAddsSecondCertificate()
{
MockDataStore dataStore = new MockDataStore();
ProfileClient.DataStore = dataStore;
ProfileClient client = new ProfileClient();
var newSubscription = new AzureSubscription
{
Id = new Guid("f62b1e05-af8f-4203-8f97-421089adc053"),
Name = "Microsoft Azure Sandbox 9-220",
Environment = EnvironmentName.AzureCloud,
Account = azureAccount.Id
};
azureAccount.SetProperty(AzureAccount.Property.Subscriptions, newSubscription.Id.ToString());
client.AddOrSetAccount(azureAccount);
client.AddOrSetSubscription(newSubscription);
client.Profile.Save();
client = new ProfileClient();
dataStore.WriteFile("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings",
Properties.Resources.ValidProfile);
client.AddOrSetEnvironment(azureEnvironment);
var subscriptions = client.ImportPublishSettings("ImportPublishSettingsLoadsAndReturnsSubscriptions.publishsettings", azureEnvironment.Name);
Assert.Equal(2, client.Profile.Accounts.Count());
var certAccount = client.Profile.Accounts.Values.First(a => a.Type == AzureAccount.AccountType.Certificate);
var userAccount = client.Profile.Accounts.Values.First(a => a.Type == AzureAccount.AccountType.User);
Assert.True(subscriptions.All(s => s.Account == certAccount.Id));
Assert.Equal(azureAccount.Id, client.Profile.Subscriptions.Values.First(s => s.Id == newSubscription.Id).Account);
Assert.True(userAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Contains(newSubscription.Id.ToString()));
Assert.True(certAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Contains(newSubscription.Id.ToString()));
Assert.Equal(6, subscriptions.Count);
Assert.Equal(6, client.Profile.Subscriptions.Count);
}
示例5: 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);
}
示例6: 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);
}
示例7: RefreshSubscriptionsListsAllSubscriptions
public void RefreshSubscriptionsListsAllSubscriptions()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
MockDataStore dataStore = new MockDataStore();
ProfileClient.DataStore = dataStore;
ProfileClient client = new ProfileClient();
client.AddOrSetAccount(azureAccount);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetSubscription(azureSubscription1);
PowerShellUtilities.GetCurrentModeOverride = () => AzureModule.AzureServiceManagement;
var subscriptions = client.RefreshSubscriptions(azureEnvironment);
Assert.Equal(4, subscriptions.Count);
Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)));
Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId)));
Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(csmSubscription1.SubscriptionId)));
Assert.True(subscriptions.All(s => s.Environment == "Test"));
Assert.True(subscriptions.All(s => s.Account == "test"));
}
示例8: RefreshSubscriptionsUpdatesAccounts
public void RefreshSubscriptionsUpdatesAccounts()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
MockDataStore dataStore = new MockDataStore();
ProfileClient.DataStore = dataStore;
ProfileClient client = new ProfileClient();
PowerShellUtilities.GetCurrentModeOverride = () => AzureModule.AzureResourceManager;
client.AddOrSetEnvironment(azureEnvironment);
client.Profile.Accounts[azureAccount.Id] = azureAccount;
client.AddOrSetSubscription(azureSubscription1);
var subscriptions = client.RefreshSubscriptions(azureEnvironment);
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription1.SubscriptionId)));
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription2.SubscriptionId)));
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1.SubscriptionId)));
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1withDuplicateId.SubscriptionId)));
}
示例9: GetCurrentEnvironmentReturnsCorrectValue
public void GetCurrentEnvironmentReturnsCorrectValue()
{
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
ProfileClient client = new ProfileClient(currentProfile);
client.AddOrSetEnvironment(azureEnvironment);
client.AddOrSetAccount(azureAccount);
client.AddOrSetSubscription(azureSubscription1);
currentProfile.DefaultSubscription = azureSubscription1;
var newEnv = client.GetEnvironmentOrDefault(azureEnvironment.Name);
Assert.Equal(azureEnvironment.Name, newEnv.Name);
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: GetAzureSubscriptionByIdChecksAndReturnsOnlyLocal
public void GetAzureSubscriptionByIdChecksAndReturnsOnlyLocal()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
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.AddOrSetSubscription(azureSubscription2);
var subscriptions = client.GetSubscription(azureSubscription1.Id);
Assert.Equal(azureSubscription1.Id, subscriptions.Id);
Assert.Throws<ArgumentException>(() => client.GetSubscription(new Guid()));
}
示例14: RefreshSubscriptionsListsAllSubscriptions
public void RefreshSubscriptionsListsAllSubscriptions()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
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);
var subscriptions = client.RefreshSubscriptions(azureEnvironment);
Assert.Equal(3, subscriptions.Count);
Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)));
Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId)));
Assert.Equal(0, subscriptions.Count(s => s.Id == new Guid(csmSubscription1.SubscriptionId)));
Assert.True(subscriptions.All(s => s.Environment == "Test"));
Assert.True(subscriptions.All(s => s.Account == "test"));
}
示例15: RefreshSubscriptionsUpdatesAccounts
public void RefreshSubscriptionsUpdatesAccounts()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
ProfileClient client = new ProfileClient(currentProfile);
client.AddOrSetEnvironment(azureEnvironment);
client.Profile.Accounts[azureAccount.Id] = azureAccount;
client.AddOrSetSubscription(azureSubscription1);
var subscriptions = client.RefreshSubscriptions(azureEnvironment);
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription1.SubscriptionId)));
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription2.SubscriptionId)));
Assert.False(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1.SubscriptionId)));
Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1withDuplicateId.SubscriptionId)));
}