public void ClearAzureProfileClearsDefaultProfile() { ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand(); // Setup ProfileClient client = new ProfileClient(); 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(); Assert.Equal(0, client.Profile.Subscriptions.Count); Assert.Equal(0, client.Profile.Accounts.Count); Assert.Equal(2, client.Profile.Environments.Count); //only default environments }
public void GetAzureSubscriptionByIdChecksAndReturnsOnlyLocal() { 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); client.AddOrSetSubscription(azureSubscription2); var subscriptions = client.GetSubscription(azureSubscription1.Id); Assert.Equal(azureSubscription1.Id, subscriptions.Id); Assert.Throws<ArgumentException>(() => client.GetSubscription(new Guid())); }
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); 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")); }
public void RefreshSubscriptionsMergesFromServer() { SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList()); MockDataStore dataStore = new MockDataStore(); ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); client.AddOrSetEnvironment(azureEnvironment); client.Profile.Accounts[azureAccount.Id] = azureAccount; client.AddOrSetSubscription(azureSubscription1); var subscriptions = client.RefreshSubscriptions(azureEnvironment); Assert.Equal(4, subscriptions.Count); Assert.Equal(4, subscriptions.Count(s => s.Account == "test")); Assert.Equal(1, subscriptions.Count(s => s.Id == azureSubscription1.Id)); Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId))); Assert.Equal(2, subscriptions.First(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)).GetPropertyAsArray(AzureSubscription.Property.SupportedModes).Count()); Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId))); Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(csmSubscription1.SubscriptionId))); }
public void RefreshSubscriptionsUpdatesAccounts() { SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList()); MockDataStore dataStore = new MockDataStore(); ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); 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))); }
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)); }
public void AddOrSetAzureSubscriptionUpdatesInMemory() { MockDataStore dataStore = new MockDataStore(); ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); client.AddOrSetAccount(azureAccount); client.AddOrSetEnvironment(azureEnvironment); client.AddOrSetSubscription(azureSubscription1); AzureSession.SetCurrentContext(azureSubscription1, azureEnvironment, azureAccount); azureSubscription1.Properties[AzureSubscription.Property.StorageAccount] = "testAccount"; Assert.Equal(azureSubscription1.Id, AzureSession.CurrentContext.Subscription.Id); Assert.Equal(azureSubscription1.Properties[AzureSubscription.Property.StorageAccount], AzureSession.CurrentContext.Subscription.Properties[AzureSubscription.Property.StorageAccount]); var newSubscription = new AzureSubscription { Id = azureSubscription1.Id, Environment = azureSubscription1.Environment, Account = azureSubscription1.Account, Name = azureSubscription1.Name }; newSubscription.Properties[AzureSubscription.Property.StorageAccount] = "testAccount1"; client.AddOrSetSubscription(newSubscription); var newSubscriptionFromProfile = client.Profile.Subscriptions[newSubscription.Id]; Assert.Equal(newSubscription.Id, AzureSession.CurrentContext.Subscription.Id); Assert.Equal(newSubscription.Id, newSubscriptionFromProfile.Id); Assert.Equal(newSubscription.Properties[AzureSubscription.Property.StorageAccount], AzureSession.CurrentContext.Subscription.Properties[AzureSubscription.Property.StorageAccount]); Assert.Equal(newSubscription.Properties[AzureSubscription.Property.StorageAccount], newSubscriptionFromProfile.Properties[AzureSubscription.Property.StorageAccount]); }
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; 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)); }
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); }
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); }
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); }
private ProfileClient SetupDefaultProfile() { ProfileClient client = new ProfileClient(); client.AddOrSetEnvironment(azureEnvironment); client.AddOrSetAccount(azureAccount); client.AddOrSetSubscription(azureSubscription1); client.AddOrSetSubscription(azureSubscription2); client.Profile.Save(); return client; }
public void SetAzureSubscriptionUpdatesSubscriptionWithCertificate() { SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand(); // Setup ProfileClient client = new ProfileClient(); client.AddOrSetAccount(azureAccount); client.AddOrSetEnvironment(azureEnvironment); client.AddOrSetSubscription(azureSubscription1); client.Profile.Save(); cmdlt.CommandRuntime = commandRuntimeMock; cmdlt.SubscriptionId = azureSubscription1.Id.ToString(); cmdlt.CurrentStorageAccountName = "NewCloudStorage"; cmdlt.Certificate = SampleCertificate; // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); // Verify client = new ProfileClient(); var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)]; var newAccount = client.Profile.Accounts[SampleCertificate.Thumbprint]; var existingAccount = client.Profile.Accounts[azureAccount.Id]; Assert.Equal(azureEnvironment.Name, newSubscription.Environment); Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount)); Assert.Equal(newAccount.Id, newSubscription.Account); Assert.Equal(AzureAccount.AccountType.Certificate, newAccount.Type); Assert.Equal(SampleCertificate.Thumbprint, newAccount.Id); Assert.Equal(cmdlt.SubscriptionId, newAccount.GetProperty(AzureAccount.Property.Subscriptions)); Assert.Equal(azureAccount.Id, existingAccount.Id); Assert.Equal(AzureAccount.AccountType.User, existingAccount.Type); Assert.True(existingAccount.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Contains(cmdlt.SubscriptionId)); }
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); }
public void AddOrSetAzureSubscriptionChecksAndUpdates() { MockDataStore dataStore = new MockDataStore(); ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); client.AddOrSetAccount(azureAccount); client.AddOrSetEnvironment(azureEnvironment); client.AddOrSetSubscription(azureSubscription1); Assert.Equal(1, client.Profile.Subscriptions.Count); var subscription = client.AddOrSetSubscription(azureSubscription1); Assert.Equal(1, client.Profile.Subscriptions.Count); Assert.Equal(1, client.Profile.Accounts.Count); Assert.Equal(subscription, azureSubscription1); Assert.Throws<ArgumentNullException>(() => client.AddOrSetSubscription(null)); Assert.Throws<ArgumentNullException>(() => client.AddOrSetSubscription( new AzureSubscription { Id = new Guid(), Environment = null, Name = "foo" })); }
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<ArgumentException>(() => client.SetSubscriptionAsCurrent(null, null)); }
public void SelectAzureSubscriptionByIdWorks() { MockDataStore dataStore = new MockDataStore(); ProfileClient.DataStore = dataStore; ProfileClient client = new ProfileClient(); var tempSubscriptions = new List<AzureSubscription> { new AzureSubscription { Id = new Guid("11111111-1383-4740-8A69-748C5B63ADBA"), Name = "Same Name Subscription", Environment = azureEnvironment.Name, Account = azureAccount.Id, Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Default, "True" } } }, new AzureSubscription { Id = new Guid("22222222-1383-4740-8A69-748C5B63ADBA"), Name = "Same Name Subscription", Environment = azureEnvironment.Name, Account = azureAccount.Id, Properties = new Dictionary<AzureSubscription.Property, string>() }, new AzureSubscription { Id = new Guid("33333333-1383-4740-8A69-748C5B63ADBA"), Name = "Same Name Subscription", Environment = azureEnvironment.Name, Account = azureAccount.Id, Properties = new Dictionary<AzureSubscription.Property, string>() } }; client.Profile.Accounts[azureAccount.Id] = azureAccount; client.AddOrSetEnvironment(azureEnvironment); foreach (var s in tempSubscriptions) { client.AddOrSetSubscription(s); } client.SetSubscriptionAsCurrent(tempSubscriptions[0].Name, tempSubscriptions[0].Account); client.Profile.Save(); Assert.Equal(tempSubscriptions[0].Id, AzureSession.CurrentContext.Subscription.Id); var cmdlt = new SelectAzureSubscriptionCommand(); cmdlt.CommandRuntime = new MockCommandRuntime(); cmdlt.SubscriptionId = tempSubscriptions[2].Id.ToString(); cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet"); // Act cmdlt.InvokeBeginProcessing(); cmdlt.ExecuteCmdlet(); cmdlt.InvokeEndProcessing(); Assert.Equal(tempSubscriptions[2].Id, AzureSession.CurrentContext.Subscription.Id); }