1212// limitations under the License.
1313// ----------------------------------------------------------------------------------
1414
15- using Microsoft . Azure . Commands . Common . Authentication ;
1615using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
1716using System ;
1817using System . Collections . Generic ;
19- using System . Linq ;
2018using Xunit ;
2119
2220namespace Authentication . Abstractions . Test
@@ -30,31 +28,41 @@ public class AzureEnvironmentTests
3028 public void TestArmAndNonArmBasedCloudMetadataInit ( )
3129 {
3230 Environment . SetEnvironmentVariable ( ArmMetadataEnvVariable , @"TestData\GoodArmResponse.json" ) ;
33- var armEnvironments = AzureEnvironment . InitializeBuiltInEnvironments ( TestOperationsFactory . Create ( ) . GetHttpOperations ( ) ) ;
31+ var armEnvironments = AzureEnvironment . InitializeBuiltInEnvironments ( null , httpOperations : TestOperationsFactory . Create ( ) . GetHttpOperations ( ) ) ;
3432
35- var unequalItemsDict = armEnvironments
36- . Where ( keyValuePair => ! hardCodedEnvironments [ keyValuePair . Key ] . Equals ( keyValuePair . Value ) )
37- . ToDictionary ( entry => entry . Key , entry => entry . Value ) ;
38-
39- if ( unequalItemsDict . Any ( ) )
33+ // Check all discovered environments are loaded.
34+ Assert . Equal ( 4 , armEnvironments . Count ) ;
35+ foreach ( var env in armEnvironments . Values )
4036 {
41- Assert . True ( false , "Hard coded and ARM based cloud metadata initializations have different values." ) ;
37+ Assert . Equal ( AzureEnvironment . TypeDiscovered , env . Type ) ;
4238 }
4339 }
4440
4541 [ Fact ]
4642 public void TestFallbackWhenArmCloudMetadataInitFails ( )
4743 {
4844 Environment . SetEnvironmentVariable ( ArmMetadataEnvVariable , @"TestData\BadArmResponse.json" ) ;
49- var armEnvironments = AzureEnvironment . InitializeBuiltInEnvironments ( TestOperationsFactory . Create ( ) . GetHttpOperations ( ) ) ;
45+ var armEnvironments = AzureEnvironment . InitializeBuiltInEnvironments ( null , httpOperations : TestOperationsFactory . Create ( ) . GetHttpOperations ( ) ) ;
5046
51- var unequalItemsDict = armEnvironments
52- . Where ( keyValuePair => ! hardCodedEnvironments [ keyValuePair . Key ] . Equals ( keyValuePair . Value ) )
53- . ToDictionary ( entry => entry . Key , entry => entry . Value ) ;
47+ // Check all built-in environments are loaded because discover is failed
48+ Assert . Equal ( 4 , armEnvironments . Count ) ;
49+ foreach ( var env in armEnvironments . Values )
50+ {
51+ Assert . Equal ( AzureEnvironment . TypeBuiltIn , env . Type ) ;
52+ }
53+ }
54+
55+ [ Fact ]
56+ public void TestDisableArmCloudMetadataInit ( )
57+ {
58+ Environment . SetEnvironmentVariable ( ArmMetadataEnvVariable , "disabled" ) ;
59+ var armEnvironments = AzureEnvironment . InitializeBuiltInEnvironments ( null , httpOperations : TestOperationsFactory . Create ( ) . GetHttpOperations ( ) ) ;
5460
55- if ( unequalItemsDict . Any ( ) )
61+ // Check all built-in environments are loaded because discover is disabled
62+ Assert . Equal ( 4 , armEnvironments . Count ) ;
63+ foreach ( var env in armEnvironments . Values )
5664 {
57- Assert . True ( false , "Hard coded and ARM based cloud metadata initializations have different values." ) ;
65+ Assert . Equal ( AzureEnvironment . TypeBuiltIn , env . Type ) ;
5866 }
5967 }
6068 }
0 commit comments