public void BaseSetup() { if (AzureSession.DataStore != null && !(AzureSession.DataStore is MemoryDataStore)) { AzureSession.DataStore = new MemoryDataStore(); } currentProfile = new AzureSMProfile(); if (currentProfile.Context.Subscription == null) { var newGuid = Guid.NewGuid(); var client = new ProfileClient(currentProfile); client.AddOrSetAccount(new AzureAccount { Id = "test", Type = AzureAccount.AccountType.User, 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"); } AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
public void RemoveAzureSubscriptionChecksAndRemoves() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); client.Profile.Accounts[azureAccount.Id] = azureAccount; client.AddOrSetEnvironment(azureEnvironment); client.AddOrSetSubscription(azureSubscription1); 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(1, log.Count); Assert.Equal( "The default subscription is being removed. Use Select-AzureSubscription -Default <subscriptionName> to select a new default subscription.", log[0]); Assert.Throws<ArgumentException>(() => client.RemoveSubscription("bad")); Assert.Throws<ArgumentNullException>(() => client.RemoveSubscription(null)); }
public void ImportPublishSettingsUsesPassedInEnvironment() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureProfile(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", 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); }
public void ClearDefaultAzureSubscriptionClearsDefault() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureProfile(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); }
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); }
public void ImportPublishSettingsDefaultsToAzureCloudWithIncorrectManagementUrl() { 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(); currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); 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", null); Assert.True(subscriptions.All(s => s.Environment == EnvironmentName.AzureCloud)); Assert.Equal(6, subscriptions.Count); Assert.Equal(7, client.Profile.Subscriptions.Count); }