Skip to content

Commit 5dd1b24

Browse files
committed
Add live only test to check for context list population
1 parent f7b88e0 commit 5dd1b24

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/ResourceManager/Profile/Commands.Profile.Test/LoginCmdletTests.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
3232
using Microsoft.Azure.Commands.ResourceManager.Common;
3333
using Microsoft.Azure.Commands.ScenarioTest;
34+
using System.Linq;
3435

3536
namespace Microsoft.Azure.Commands.Profile.Test
3637
{
@@ -327,7 +328,7 @@ public void LoginWithCredentialParameterAndMSA()
327328
"For more information, please refer to http://go.microsoft.com/fwlink/?linkid=331007&clcid=0x409 " +
328329
"for more information about the difference between an organizational account and a Microsoft account.",
329330
ex.Message);
330-
}
331+
}
331332
}
332333

333334
[Fact]
@@ -353,6 +354,43 @@ public void LoginWithAccessToken()
353354
Assert.NotNull(AzureRmProfileProvider.Instance.Profile.DefaultContext);
354355
}
355356

357+
[Fact]
358+
[Trait(Category.RunType, Category.LiveOnly)]
359+
public void LoginPopulatesContextList()
360+
{
361+
// Before running this test, make sure to clear the contexts on your machine by removing the following two files:
362+
// - %APPDATA%/Windows Azure Powershell/AzureRmContext.json
363+
// - %APPDATA%/Windows Azure Powershell/AzureRmContextSettings.json
364+
// This will clear all existing contexts on your machine so that this test can re-populate the list with a context for each subscription
365+
366+
var cmdlt = new ConnectAzureRmAccountCommand();
367+
// Setup
368+
cmdlt.CommandRuntime = commandRuntimeMock;
369+
370+
// Act
371+
cmdlt.InvokeBeginProcessing();
372+
cmdlt.ExecuteCmdlet();
373+
cmdlt.InvokeEndProcessing();
374+
375+
var profile = AzureRmProfileProvider.Instance.Profile as AzureRmProfile;
376+
Assert.NotNull(profile);
377+
Assert.NotNull(profile.Contexts);
378+
Assert.NotNull(profile.Subscriptions);
379+
Assert.True(profile.Contexts.Count > 1);
380+
Assert.True(profile.Subscriptions.Count() > 1);
381+
Assert.Equal(profile.Subscriptions.Count(), profile.Contexts.Count);
382+
383+
foreach (var sub in profile.Subscriptions)
384+
{
385+
var contextName = string.Format("{0} - {1}", sub.Name, sub.Id);
386+
Assert.True(profile.Contexts.ContainsKey(contextName));
387+
var context = profile.Contexts[contextName];
388+
Assert.NotNull(context);
389+
Assert.Equal(sub.Id, context.Subscription.Id);
390+
Assert.Equal(sub.GetTenant(), context.Tenant.Id);
391+
}
392+
}
393+
356394
[Fact]
357395
[Trait(Category.AcceptanceType, Category.CheckIn)]
358396
public void ThrowOnUnknownEnvironment()

0 commit comments

Comments
 (0)