@@ -1747,18 +1747,19 @@ public void AzurePlatformVMImageNegativeTest()
1747
1747
{
1748
1748
StartTest ( MethodBase . GetCurrentMethod ( ) . Name , testStartTime ) ;
1749
1749
1750
- var imgName = Utilities . GetUniqueShortName ( "img" ) ;
1751
-
1752
- try
1753
- {
1754
- var scripts = new string [ ]
1750
+ Func < string , string [ ] > getScripts = img => new string [ ]
1755
1751
{
1756
1752
"Import-Module '.\\ " + Utilities . AzurePowershellModuleServiceManagementPirModule + "';" ,
1757
1753
"$c1 = New-AzurePlatformComputeImageConfig -Offer test -Sku test -Version test;" ,
1758
1754
"$c2 = New-AzurePlatformMarketplaceImageConfig -PlanName test -Product test -Publisher test -PublisherId test;" ,
1759
- "Set-AzurePlatformVMImage -ImageName " + imgName + " -ReplicaLocations 'West US' -ComputeImageConfig $c1 -MarketplaceImageConfig $c2;"
1755
+ "Set-AzurePlatformVMImage -ImageName " + img + " -ReplicaLocations 'West US' -ComputeImageConfig $c1 -MarketplaceImageConfig $c2;"
1760
1756
} ;
1761
1757
1758
+ var imgName = Utilities . GetUniqueShortName ( "img" ) ;
1759
+
1760
+ try
1761
+ {
1762
+ var scripts = getScripts ( imgName ) ;
1762
1763
vmPowershellCmdlets . RunPSScript ( string . Join ( System . Environment . NewLine , scripts ) , true ) ;
1763
1764
}
1764
1765
catch ( Exception e )
@@ -1775,6 +1776,54 @@ public void AzurePlatformVMImageNegativeTest()
1775
1776
Assert . Fail ( "Exception occurred: {0}" , e . ToString ( ) ) ;
1776
1777
}
1777
1778
}
1779
+
1780
+ // OS Image
1781
+ var osImages = vmPowershellCmdlets . GetAzureVMImage ( ) ;
1782
+ imgName = osImages . First ( ) . ImageName ;
1783
+
1784
+ try
1785
+ {
1786
+ var scripts = getScripts ( imgName ) ;
1787
+ vmPowershellCmdlets . RunPSScript ( string . Join ( System . Environment . NewLine , scripts ) , true ) ;
1788
+ }
1789
+ catch ( Exception e )
1790
+ {
1791
+ var expectedMsg = "ForbiddenError: This operation is not allowed for this subscription." ;
1792
+ if ( e . InnerException != null && e . InnerException . Message != null && e . InnerException . Message . Contains ( expectedMsg ) )
1793
+ {
1794
+ pass = true ;
1795
+ Console . WriteLine ( e . InnerException . ToString ( ) ) ;
1796
+ }
1797
+ else
1798
+ {
1799
+ pass = false ;
1800
+ Assert . Fail ( "Exception occurred: {0}" , e . ToString ( ) ) ;
1801
+ }
1802
+ }
1803
+
1804
+ // VM Image
1805
+ var vmImages = vmPowershellCmdlets . GetAzureVMImageReturningVMImages ( ) ;
1806
+ imgName = vmImages . First ( ) . ImageName ;
1807
+
1808
+ try
1809
+ {
1810
+ var scripts = getScripts ( imgName ) ;
1811
+ vmPowershellCmdlets . RunPSScript ( string . Join ( System . Environment . NewLine , scripts ) , true ) ;
1812
+ }
1813
+ catch ( Exception e )
1814
+ {
1815
+ var expectedMsg = "ForbiddenError: This operation is not allowed for this subscription." ;
1816
+ if ( e . InnerException != null && e . InnerException . Message != null && e . InnerException . Message . Contains ( expectedMsg ) )
1817
+ {
1818
+ pass = true ;
1819
+ Console . WriteLine ( e . InnerException . ToString ( ) ) ;
1820
+ }
1821
+ else
1822
+ {
1823
+ pass = false ;
1824
+ Assert . Fail ( "Exception occurred: {0}" , e . ToString ( ) ) ;
1825
+ }
1826
+ }
1778
1827
}
1779
1828
}
1780
1829
}
0 commit comments