1010using Azure . ResourceManager . Storage . Models ;
1111using NUnit . Framework ;
1212using Sku = Azure . ResourceManager . Storage . Models . Sku ;
13- using SkuTier = Azure . ResourceManager . Storage . Models . SkuTier ;
13+ using SkuTier = Azure . ResourceManager . Storage . Models . SkuTier ;
1414
1515namespace Azure . ResourceManager . Storage . Tests . Helpers
1616{
1717 [ PlaybackOnly ( "https://github.com/Azure/azure-sdk-for-net/issues/23897" ) ]
1818 [ ClientTestFixture ]
19- public class StorageTestBase : ManagementRecordedTestBase < StorageManagementTestEnvironment >
19+ public class StorageTestBase : ManagementRecordedTestBase < StorageManagementTestEnvironment >
2020 {
2121 public static Location DefaultLocation => Location . EastUS2 ;
22- public static string DefaultLocationString = "eastus2" ;
22+ public static string DefaultLocationString = "eastus2" ;
2323 public static bool IsTestTenant = false ;
2424 // These are used to create default accounts
2525 public static Sku DefaultSkuNameStandardGRS = new Sku ( SkuName . StandardGRS ) ;
@@ -34,9 +34,11 @@ public class StorageTestBase:ManagementRecordedTestBase<StorageManagementTestEnv
3434 protected StorageTestBase ( bool isAsync ) : base ( isAsync )
3535 {
3636 }
37+
3738 public StorageTestBase ( bool isAsync , RecordedTestMode mode ) : base ( isAsync , mode )
3839 {
3940 }
41+
4042 public static StorageAccountCreateParameters GetDefaultStorageAccountParameters ( Sku sku = null , Kind ? kind = null , string location = null )
4143 {
4244 Sku skuParameters = sku ?? DefaultSkuNameStandardGRS ;
@@ -46,16 +48,26 @@ public static StorageAccountCreateParameters GetDefaultStorageAccountParameters(
4648 parameters . Tags . InitializeFrom ( DefaultTags ) ;
4749 return parameters ;
4850 }
51+
4952 [ SetUp ]
5053 public void CreateCommonClient ( )
5154 {
5255 Client = GetArmClient ( ) ;
5356 }
5457
58+ [ TearDown ]
59+ public async Task waitForDeletion ( )
60+ {
61+ if ( Mode != RecordedTestMode . Playback )
62+ {
63+ await Task . Delay ( 5000 ) ;
64+ }
65+ }
66+
5567 public async Task < ResourceGroup > CreateResourceGroupAsync ( )
5668 {
5769 string resourceGroupName = Recording . GenerateAssetName ( "teststorageRG-" ) ;
58- ResourceGroupCreateOrUpdateOperation operation = await DefaultSubscription . GetResourceGroups ( ) . CreateOrUpdateAsync (
70+ ResourceGroupCreateOrUpdateOperation operation = await DefaultSubscription . GetResourceGroups ( ) . CreateOrUpdateAsync (
5971 resourceGroupName ,
6072 new ResourceGroupData ( DefaultLocation )
6173 {
@@ -67,7 +79,23 @@ public async Task<ResourceGroup> CreateResourceGroupAsync()
6779 return operation . Value ;
6880 }
6981
70- public static void VerifyAccountProperties ( StorageAccount account , bool useDefaults )
82+ public async Task < string > CreateValidAccountNameAsync ( string prefix )
83+ {
84+ string accountName = prefix ;
85+ for ( int i = 0 ; i < 10 ; i ++ )
86+ {
87+ accountName = Recording . GenerateAssetName ( prefix ) ;
88+ StorageAccountCheckNameAvailabilityParameters parameter = new StorageAccountCheckNameAvailabilityParameters ( accountName ) ;
89+ CheckNameAvailabilityResult result = await DefaultSubscription . CheckStorageAccountNameAvailabilityAsync ( parameter ) ;
90+ if ( result . NameAvailable == true )
91+ {
92+ return accountName ;
93+ }
94+ }
95+ return accountName ;
96+ }
97+
98+ public static void VerifyAccountProperties ( StorageAccount account , bool useDefaults )
7199 {
72100 Assert . NotNull ( account ) ;
73101 Assert . NotNull ( account . Id ) ;
@@ -93,6 +121,7 @@ public static void VerifyAccountProperties(StorageAccount account,bool useDefaul
93121 Assert . AreEqual ( "value2" , account . Data . Tags [ "key2" ] ) ;
94122 }
95123 }
124+
96125 public static AccountSasParameters ParseAccountSASToken ( string accountSasToken )
97126 {
98127 string [ ] sasProperties = accountSasToken . Substring ( 1 ) . Split ( new char [ ] { '&' } ) ;
@@ -147,6 +176,7 @@ public static AccountSasParameters ParseAccountSASToken(string accountSasToken)
147176
148177 return parameters ;
149178 }
179+
150180 public static ServiceSasParameters ParseServiceSASToken ( string serviceSAS , string canonicalizedResource )
151181 {
152182 string [ ] sasProperties = serviceSAS . Substring ( 1 ) . Split ( new char [ ] { '&' } ) ;
@@ -216,26 +246,31 @@ public static ServiceSasParameters ParseServiceSASToken(string serviceSAS, strin
216246
217247 return parameters ;
218248 }
249+
219250 public static void AssertStorageAccountEqual ( StorageAccount account1 , StorageAccount account2 )
220251 {
221252 Assert . AreEqual ( account1 . Id . Name , account2 . Id . Name ) ;
222253 Assert . AreEqual ( account1 . Id . Location , account2 . Id . Location ) ;
223254 }
255+
224256 public static void AssertBlobContainerEqual ( BlobContainer blobContainer1 , BlobContainer blobContainer2 )
225257 {
226258 Assert . AreEqual ( blobContainer1 . Id . Name , blobContainer2 . Id . Name ) ;
227259 Assert . AreEqual ( blobContainer1 . Id . Location , blobContainer2 . Id . Location ) ;
228260 }
261+
229262 public static void AssertFileShareEqual ( FileShare fileShare1 , FileShare fileShare2 )
230263 {
231264 Assert . AreEqual ( fileShare1 . Id . Name , fileShare2 . Id . Name ) ;
232265 Assert . AreEqual ( fileShare1 . Id . Location , fileShare2 . Id . Location ) ;
233266 }
267+
234268 public static void AssertStorageQueueEqual ( StorageQueue storageQueue1 , StorageQueue storageQueue2 )
235269 {
236270 Assert . AreEqual ( storageQueue1 . Id . Name , storageQueue2 . Id . Name ) ;
237271 Assert . AreEqual ( storageQueue1 . Id . Location , storageQueue2 . Id . Location ) ;
238272 }
273+
239274 public static void AssertTableEqual ( Table table1 , Table table2 )
240275 {
241276 Assert . AreEqual ( table1 . Id . Name , table2 . Id . Name ) ;
0 commit comments