public LoginCmdletTests() { dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureRmProfileProvider.Instance.Profile = new AzureRMProfile(); }
public EnvironmentSetupHelper() { var datastore = new MemoryDataStore(); AzureSession.DataStore = datastore; var profile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); var rmprofile = new AzureRMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); rmprofile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()); rmprofile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.Environments["foo"], new AzureTenant()); rmprofile.Context.Subscription.Environment = "foo"; if (AzureRmProfileProvider.Instance.Profile == null) { AzureRmProfileProvider.Instance.Profile = rmprofile; } AzureSession.DataStore = datastore; ProfileClient = new ProfileClient(profile); // Ignore SSL errors System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true; AdalTokenCache.ClearCookies(); // Set RunningMocked TestMockSupport.RunningMocked = HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback; }
public ContextCmdletTests() { dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
public TenantCmdletTests(ITestOutputHelper output) { XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureRmProfileProvider.Instance.Profile = new AzureRMProfile(); }
public ContextCmdletTests(ITestOutputHelper output) { XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output)); dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
public ProfileCmdltsTests() : base() { dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; commandRuntimeMock = new MockCommandRuntime(); SetMockData(); AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory(); }
public void NewProfileFromCertificateWithNullsThrowsArgumentNullException() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; AzureSMProfile newProfile = new AzureSMProfile(); ProfileClient client1 = new ProfileClient(newProfile); Assert.Throws<ArgumentNullException>(() => client1.InitializeProfile(null, Guid.NewGuid(), new X509Certificate2(), "foo")); Assert.Throws<ArgumentNullException>(() => client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"], Guid.NewGuid(), null, "foo")); }
public void ProfileMigratesOldData() { MemoryDataStore dataStore = new MemoryDataStore(); dataStore.VirtualStore[oldProfileDataPath] = oldProfileData; AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); Assert.False(dataStore.FileExists(oldProfileDataPath)); Assert.True(dataStore.FileExists(newProfileDataPath)); }
static AzureSession() { ClientFactory = new ClientFactory(); AuthenticationFactory = new AuthenticationFactory(); DataStore = new MemoryDataStore(); TokenCache = new TokenCache(); OldProfileFile = "WindowsAzureProfile.xml"; OldProfileFileBackup = "WindowsAzureProfile.xml.bak"; ProfileDirectory = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Resources.AzureDirectoryName); ; ProfileFile = "AzureProfile.json"; TokenCacheFile = "TokenCache.dat"; }
public EnvironmentSetupHelper() { var datastore = new MemoryDataStore(); AzureSession.DataStore = datastore; var profile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); AzureSMCmdlet.CurrentProfile = profile; AzureSession.DataStore = datastore; ProfileClient = new ProfileClient(profile); // Ignore SSL errors System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true; // Set RunningMocked if (HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback) { TestMockSupport.RunningMocked = true; } else { TestMockSupport.RunningMocked = false; } }
public void AddOrSetAzureSubscriptionChecksAndUpdates() { 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); 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 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); }
public void NewProfileFromCertificateReturnsProfile() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; AzureSMProfile newProfile = new AzureSMProfile(); ProfileClient client1 = new ProfileClient(newProfile); var subscriptionId = Guid.NewGuid(); var certificate = new X509Certificate2(Convert.FromBase64String(dummyCertificate)); client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"], subscriptionId, certificate, null); Assert.Equal("AzureCloud", newProfile.DefaultSubscription.Environment); Assert.Equal(subscriptionId, newProfile.DefaultSubscription.Id); Assert.Equal(certificate.Thumbprint, newProfile.DefaultSubscription.Account); Assert.False(newProfile.DefaultSubscription.Properties.ContainsKey(AzureSubscription.Property.StorageAccount)); }
public void SetAzureEnvironmentUpdatesEnvironment() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); Assert.Equal(4, client.Profile.Environments.Count); Assert.Throws<ArgumentNullException>(() => client.AddOrSetEnvironment(null)); var env2 = client.AddOrSetEnvironment(azureEnvironment); Assert.Equal(env2.Name, azureEnvironment.Name); Assert.NotNull(env2.Endpoints[AzureEnvironment.Endpoint.ServiceManagement]); AzureEnvironment newEnv = new AzureEnvironment { Name = azureEnvironment.Name }; newEnv.Endpoints[AzureEnvironment.Endpoint.Graph] = "foo"; env2 = client.AddOrSetEnvironment(newEnv); Assert.Equal("foo", env2.Endpoints[AzureEnvironment.Endpoint.Graph]); Assert.NotNull(env2.Endpoints[AzureEnvironment.Endpoint.ServiceManagement]); }
public void GetAzureEnvironmentReturnsCorrectValue() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; ProfileClient client = new ProfileClient(currentProfile); client.AddOrSetEnvironment(azureEnvironment); var defaultEnv = client.GetEnvironmentOrDefault(null); Assert.Equal(EnvironmentName.AzureCloud, defaultEnv.Name); var newEnv = client.GetEnvironmentOrDefault(azureEnvironment.Name); Assert.Equal(azureEnvironment.Name, newEnv.Name); Assert.Throws<ArgumentException>(() => client.GetEnvironmentOrDefault("bad")); }
public void RemoveAzureAccountRemovesSubscriptions() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Accounts[azureAccount.Id] = azureAccount; azureSubscription3withoutUser.Account = "test2"; client.Profile.Accounts["test2"] = new AzureAccount { Id = "test2", Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { {AzureAccount.Property.Subscriptions, azureSubscription3withoutUser.Id.ToString()} } }; client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; List<string> log = new List<string>(); client.WarningLog = log.Add; Assert.Equal(3, client.Profile.Subscriptions.Count); client.RemoveAccount("test2"); Assert.Equal(2, client.Profile.Subscriptions.Count); Assert.Equal(0, log.Count); }
public void RemoveAzureEnvironmentDoesNotRemoveEnvironmentSubscriptionsAndAccountsForAzureCloudOrChinaCloud() { 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; azureSubscription1.Environment = EnvironmentName.AzureCloud; azureSubscription2.Environment = EnvironmentName.AzureChinaCloud; client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; Assert.Equal(1, client.Profile.Subscriptions.Values.Count(s => s.Environment == EnvironmentName.AzureCloud)); Assert.Equal(1, client.Profile.Subscriptions.Values.Count(s => s.Environment == EnvironmentName.AzureChinaCloud)); Assert.Equal(4, client.Profile.Environments.Count); Assert.Equal(1, client.Profile.Accounts.Count); Assert.Throws<ArgumentException>(() => client.RemoveEnvironment(EnvironmentName.AzureCloud)); Assert.Throws<ArgumentException>(() => client.RemoveEnvironment(EnvironmentName.AzureChinaCloud)); Assert.Equal(1, client.Profile.Subscriptions.Values.Count(s => s.Environment == EnvironmentName.AzureCloud)); Assert.Equal(1, client.Profile.Subscriptions.Values.Count(s => s.Environment == EnvironmentName.AzureChinaCloud)); Assert.Equal(4, client.Profile.Environments.Count); Assert.Equal(1, client.Profile.Accounts.Count); }
public void GetAzureEnvironmentsListsEnvironments() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); var env1 = client.ListEnvironments(null); Assert.Equal(4, env1.Count); var env2 = client.ListEnvironments("bad"); Assert.Equal(0, env2.Count); var env3 = client.ListEnvironments(EnvironmentName.AzureCloud); Assert.Equal(1, env3.Count); }
public void AddAzureAccountIsCaseInsensitive() { SetMocks(new[] { rdfeSubscription1, guestRdfeSubscription }.ToList(), new List<Microsoft.Azure.Subscriptions.Models.Subscription>(), new[] { commonTenant, guestTenant }.ToList(), (userAccount, environment, tenant) => { var token = new MockAccessToken { UserId = tenant == commonTenant.TenantId ? userAccount.Id : "USERA", AccessToken = "def", LoginType = LoginType.OrgId }; userAccount.Id = token.UserId; return token; }); MemoryDataStore dataStore = new MemoryDataStore(); dataStore.VirtualStore[oldProfileDataPath] = oldProfileData; AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "UserA", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null); var userA = client.GetAccount("UserA"); var secondUserA = client.GetAccount("USERA"); Assert.NotNull(userA); Assert.NotNull(secondUserA); Assert.Equal(userA.Id, secondUserA.Id); }
public GetAzureEnvironmentTests() { dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; }
public void GetAzureAccountWithoutEnvironmentReturnsAccount() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser; client.Profile.Accounts[azureAccount.Id] = azureAccount; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; var account = client.ListAccounts("test").ToList(); Assert.Equal(1, account.Count); Assert.Equal("test", account[0].Id); Assert.Equal(2, account[0].GetSubscriptions(client.Profile).Count); Assert.True(account[0].GetSubscriptions(client.Profile).Any(s => s.Id == azureSubscription1.Id)); Assert.True(account[0].GetSubscriptions(client.Profile).Any(s => s.Id == azureSubscription2.Id)); }
public void RemoveAzureAccountRemovesDefaultAccountFromSubscription() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Accounts[azureAccount.Id] = azureAccount; azureSubscription3withoutUser.Account = "test2"; client.Profile.Accounts["test2"] = new AzureAccount { Id = "test2", Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { {AzureAccount.Property.Subscriptions, azureSubscription1.Id.ToString()} } }; client.Profile.Subscriptions[azureSubscription1.Id].Account = azureAccount.Id; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; var account = client.RemoveAccount(azureAccount.Id); Assert.Equal("test2", client.Profile.Subscriptions[azureSubscription1.Id].Account); }
public void RemoveAzureAccountRemovesDefaultSubscriptionAndWritesWarning() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Accounts[azureAccount.Id] = azureAccount; azureSubscription3withoutUser.Account = "test2"; client.Profile.Accounts["test2"] = new AzureAccount { Id = "test2", Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { {AzureAccount.Property.Subscriptions, azureSubscription3withoutUser.Id.ToString()} } }; client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; List<string> log = new List<string>(); client.WarningLog = log.Add; Assert.Equal(3, client.Profile.Subscriptions.Count); var account = client.RemoveAccount("test"); Assert.Equal(1, client.Profile.Subscriptions.Count); Assert.Equal("test", account.Id); Assert.Equal(2, account.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Length); 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]); }
public void GetAzureAccountReturnsEmptyEnumerationForNonExistingUser() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser; client.Profile.Accounts[azureAccount.Id] = azureAccount; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; var account = client.ListAccounts("test2").ToList(); Assert.Equal(0, account.Count); }
public void AddOrSetAzureSubscriptionUpdatesInMemory() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; ProfileClient client = new ProfileClient(currentProfile); client.AddOrSetAccount(azureAccount); client.AddOrSetEnvironment(azureEnvironment); client.AddOrSetSubscription(azureSubscription1); currentProfile.DefaultSubscription = azureSubscription1; azureSubscription1.Properties[AzureSubscription.Property.StorageAccount] = "testAccount"; Assert.Equal(azureSubscription1.Id, currentProfile.Context.Subscription.Id); Assert.Equal(azureSubscription1.Properties[AzureSubscription.Property.StorageAccount], currentProfile.Context.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, currentProfile.Context.Subscription.Id); Assert.Equal(newSubscription.Id, newSubscriptionFromProfile.Id); Assert.Equal(newSubscription.Properties[AzureSubscription.Property.StorageAccount], currentProfile.Context.Subscription.Properties[AzureSubscription.Property.StorageAccount]); Assert.Equal(newSubscription.Properties[AzureSubscription.Property.StorageAccount], newSubscriptionFromProfile.Properties[AzureSubscription.Property.StorageAccount]); }
public void RemoveAzureEnvironmentRemovesEnvironmentSubscriptionsAndAccounts() { 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.Profile.Environments[azureEnvironment.Name] = azureEnvironment; client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; Assert.Equal(2, client.Profile.Subscriptions.Values.Count(s => s.Environment == "Test")); Assert.Equal(5, client.Profile.Environments.Count); Assert.Equal(1, client.Profile.Accounts.Count); Assert.Throws<ArgumentNullException>(() => client.RemoveEnvironment(null)); Assert.Throws<ArgumentException>(() => client.RemoveEnvironment("bad")); var env = client.RemoveEnvironment(azureEnvironment.Name); Assert.Equal(azureEnvironment.Name, env.Name); Assert.Equal(0, client.Profile.Subscriptions.Values.Count(s => s.Environment == "Test")); Assert.Equal(4, client.Profile.Environments.Count); Assert.Equal(0, client.Profile.Accounts.Count); }
public void RemoveAzureSubscriptionChecksAndRemoves() { 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(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 GetAzureAccountReturnsAllAccountsWithNullUser() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Accounts[azureAccount.Id] = azureAccount; azureSubscription3withoutUser.Account = "test2"; client.Profile.Accounts["test2"] = new AzureAccount { Id = "test2", Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { {AzureAccount.Property.Subscriptions, azureSubscription3withoutUser.Id.ToString()} } }; client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; var account = client.ListAccounts(null).ToList(); Assert.Equal(2, account.Count); }
public void RemoveAzureAccountRemovesInMemoryAccount() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; ProfileClient client = new ProfileClient(currentProfile); client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1; client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2; client.Profile.Accounts[azureAccount.Id] = azureAccount; azureSubscription3withoutUser.Account = "test2"; client.Profile.Accounts["test2"] = new AzureAccount { Id = "test2", Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { {AzureAccount.Property.Subscriptions, azureSubscription1.Id.ToString()} } }; client.Profile.Subscriptions[azureSubscription1.Id].Account = azureAccount.Id; client.Profile.Environments[azureEnvironment.Name] = azureEnvironment; currentProfile.DefaultSubscription = azureSubscription1; client.RemoveAccount(azureAccount.Id); Assert.Equal("test2", currentProfile.Context.Account.Id); Assert.Equal("test2", currentProfile.Context.Subscription.Account); Assert.Equal(azureSubscription1.Id, currentProfile.Context.Subscription.Id); client.RemoveAccount("test2"); Assert.Null(currentProfile.Context.Account); Assert.Null(currentProfile.Context.Subscription); Assert.Null(currentProfile.Context.Environment); }
public void AddAzureEnvironmentAddsEnvironment() { MemoryDataStore dataStore = new MemoryDataStore(); AzureSession.DataStore = dataStore; currentProfile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); ProfileClient client = new ProfileClient(currentProfile); Assert.Equal(4, client.Profile.Environments.Count); Assert.Throws<ArgumentNullException>(() => client.AddOrSetEnvironment(null)); var env = client.AddOrSetEnvironment(azureEnvironment); Assert.Equal(5, client.Profile.Environments.Count); Assert.Equal(env, azureEnvironment); }