31
31
using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
32
32
using Microsoft . Azure . Commands . ResourceManager . Common ;
33
33
using Microsoft . Azure . Commands . ScenarioTest ;
34
+ using System . Linq ;
34
35
35
36
namespace Microsoft . Azure . Commands . Profile . Test
36
37
{
@@ -327,7 +328,7 @@ public void LoginWithCredentialParameterAndMSA()
327
328
"For more information, please refer to http://go.microsoft.com/fwlink/?linkid=331007&clcid=0x409 " +
328
329
"for more information about the difference between an organizational account and a Microsoft account." ,
329
330
ex . Message ) ;
330
- }
331
+ }
331
332
}
332
333
333
334
[ Fact ]
@@ -353,6 +354,43 @@ public void LoginWithAccessToken()
353
354
Assert . NotNull ( AzureRmProfileProvider . Instance . Profile . DefaultContext ) ;
354
355
}
355
356
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
+
356
394
[ Fact ]
357
395
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
358
396
public void ThrowOnUnknownEnvironment ( )
0 commit comments