@@ -611,6 +611,93 @@ public void SetEnvironmentWithOnPremise()
611
611
Assert . Equal ( env3 . GetEndpoint ( AzureEnvironment . Endpoint . Gallery ) , cmdlet3 . GalleryEndpoint ) ;
612
612
}
613
613
614
+ [ Fact ]
615
+ [ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
616
+ public void SetEnvironmentForStack ( )
617
+ {
618
+ Mock < ICommandRuntime > commandRuntimeMock = new Mock < ICommandRuntime > ( ) ;
619
+ SetupConfirmation ( commandRuntimeMock ) ;
620
+ var cmdlet = new SetAzureRMEnvironmentCommand ( )
621
+ {
622
+ CommandRuntime = commandRuntimeMock . Object ,
623
+ Name = "Stack" ,
624
+ ARMEndpoint = "https://management.local.azurestack.external/"
625
+ } ;
626
+
627
+ Mock < EnvironmentHelper > envHelperMock = new Mock < EnvironmentHelper > ( ) ;
628
+ MetadataResponse metadataEndpoints = new MetadataResponse
629
+ {
630
+ GalleryEndpoint = "https://galleryendpoint" ,
631
+ GraphEndpoint = "https://graphendpoint" ,
632
+ PortalEndpoint = "https://portalendpoint" ,
633
+ authentication = new Authentication
634
+ {
635
+ Audiences = new [ ] { "audience1" , "audience2" } ,
636
+ LoginEndpoint = "https://loginendpoint"
637
+ }
638
+ } ;
639
+ envHelperMock . Setup ( f => f . RetrieveMetaDataEndpoints ( It . IsAny < string > ( ) ) ) . ReturnsAsync ( metadataEndpoints ) ;
640
+ envHelperMock . Setup ( f => f . RetrieveDomain ( It . IsAny < string > ( ) ) ) . Returns ( "domain" ) ;
641
+ cmdlet . EnvHelper = envHelperMock . Object ;
642
+ cmdlet . SetParameterSet ( "ARMEndpoint" ) ;
643
+ cmdlet . InvokeBeginProcessing ( ) ;
644
+ cmdlet . ExecuteCmdlet ( ) ;
645
+ cmdlet . InvokeEndProcessing ( ) ;
646
+
647
+ commandRuntimeMock . Verify ( f => f . WriteObject ( It . IsAny < PSAzureEnvironment > ( ) ) , Times . Once ( ) ) ;
648
+ IAzureEnvironment env = AzureRmProfileProvider . Instance . Profile . GetEnvironment ( "Stack" ) ;
649
+ Assert . Equal ( env . Name , cmdlet . Name ) ;
650
+ Assert . Equal ( cmdlet . ARMEndpoint , env . GetEndpoint ( AzureEnvironment . Endpoint . ResourceManager ) ) ;
651
+ Assert . Equal ( "https://loginendpoint/" , env . GetEndpoint ( AzureEnvironment . Endpoint . ActiveDirectory ) ) ;
652
+ Assert . Equal ( "audience1" , env . GetEndpoint ( AzureEnvironment . Endpoint . ActiveDirectoryServiceEndpointResourceId ) ) ;
653
+ Assert . Equal ( "https://graphendpoint" , env . GetEndpoint ( AzureEnvironment . Endpoint . GraphEndpointResourceId ) ) ;
654
+ envHelperMock . Verify ( f => f . RetrieveDomain ( It . IsAny < string > ( ) ) , Times . Once ) ;
655
+ envHelperMock . Verify ( f => f . RetrieveMetaDataEndpoints ( It . IsAny < string > ( ) ) , Times . Once ) ;
656
+
657
+ // Update onpremise to true
658
+ var cmdlet2 = new SetAzureRMEnvironmentCommand ( )
659
+ {
660
+ CommandRuntime = commandRuntimeMock . Object ,
661
+ Name = "Stack" ,
662
+ EnableAdfsAuthentication = true
663
+ } ;
664
+
665
+ cmdlet2 . MyInvocation . BoundParameters . Add ( "Name" , "Stack" ) ;
666
+ cmdlet2 . MyInvocation . BoundParameters . Add ( "EnableAdfsAuthentication" , true ) ;
667
+
668
+ cmdlet2 . InvokeBeginProcessing ( ) ;
669
+ cmdlet2 . ExecuteCmdlet ( ) ;
670
+ cmdlet2 . InvokeEndProcessing ( ) ;
671
+
672
+ commandRuntimeMock . Verify ( f => f . WriteObject ( It . IsAny < PSAzureEnvironment > ( ) ) , Times . Exactly ( 2 ) ) ;
673
+ IAzureEnvironment env2 = AzureRmProfileProvider . Instance . Profile . GetEnvironment ( "stack" ) ;
674
+ Assert . Equal ( env2 . Name , cmdlet2 . Name ) ;
675
+ Assert . Equal ( env2 . GetEndpoint ( AzureEnvironment . Endpoint . PublishSettingsFileUrl ) , cmdlet . PublishSettingsFileUrl ) ;
676
+ Assert . True ( env2 . OnPremise ) ;
677
+
678
+ // Update gallery endpoint
679
+ var cmdlet3 = new SetAzureRMEnvironmentCommand ( )
680
+ {
681
+ CommandRuntime = commandRuntimeMock . Object ,
682
+ Name = "Stack" ,
683
+ GalleryEndpoint = "http://galleryendpoint.com" ,
684
+ } ;
685
+
686
+ cmdlet3 . MyInvocation . BoundParameters . Add ( "Name" , "stack" ) ;
687
+ cmdlet3 . MyInvocation . BoundParameters . Add ( "GalleryEndpoint" , "http://galleryendpoint.com" ) ;
688
+
689
+ cmdlet3 . InvokeBeginProcessing ( ) ;
690
+ cmdlet3 . ExecuteCmdlet ( ) ;
691
+ cmdlet3 . InvokeEndProcessing ( ) ;
692
+
693
+ // Ensure gallery endpoint is updated and OnPremise value is preserved
694
+ commandRuntimeMock . Verify ( f => f . WriteObject ( It . IsAny < PSAzureEnvironment > ( ) ) , Times . Exactly ( 3 ) ) ;
695
+ IAzureEnvironment env3 = AzureRmProfileProvider . Instance . Profile . GetEnvironment ( "stack" ) ;
696
+ Assert . Equal ( env3 . Name , cmdlet3 . Name ) ;
697
+ Assert . Equal ( env3 . GetEndpoint ( AzureEnvironment . Endpoint . PublishSettingsFileUrl ) , cmdlet . PublishSettingsFileUrl ) ;
698
+ Assert . True ( env3 . OnPremise ) ;
699
+ Assert . Equal ( env3 . GetEndpoint ( AzureEnvironment . Endpoint . Gallery ) , cmdlet3 . GalleryEndpoint ) ;
700
+ }
614
701
615
702
[ Fact ]
616
703
[ Trait ( Category . AcceptanceType , Category . CheckIn ) ]
0 commit comments