11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . Linq ;
7+ using System . Reflection ;
48using Azure . Core . TestFramework ;
5- using Azure . Storage . Sas ;
69using NUnit . Framework ;
710
811namespace Azure . Storage . Test . Shared
@@ -17,7 +20,32 @@ public void SetSasVersion()
1720 // WARN! Never ever override SAS version in Live mode. We should test the default there.
1821
1922 // TODO Uncomment this to record/playback with different sas version
20- // SasQueryParametersInternals.DefaultSasVersionInternal = "2020-08-04";
23+ // SetSasVersion("2020-08-04");
24+ }
25+ }
26+
27+ private void SetSasVersion ( string version )
28+ {
29+ // The SasQueryParametersInternals is shared source and compiled also into many assemblies which is technically separate class.
30+ // We're using reflection to set it everywhere.
31+ // The alternative of making it all open to all test packages isn't great because it would lead to name clash.
32+ SetSasVersionInAssemblies ( version ,
33+ "Azure.Storage.Common" ,
34+ "Azure.Storage.Blobs" ,
35+ "Azure.Storage.Files.DataLake" ,
36+ "Azure.Storage.Files.Shares" ,
37+ "Azure.Storage.Queues" ) ;
38+ }
39+
40+ private void SetSasVersionInAssemblies ( string version , params string [ ] assemblyNames )
41+ {
42+ IEnumerable < Assembly > assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) . Where ( a => assemblyNames . Contains ( a . GetName ( ) . Name ) ) ;
43+ foreach ( Assembly assembly in assemblies )
44+ {
45+ Type sasQueryParametersInternals = assembly . GetType ( "Azure.Storage.Sas.SasQueryParametersInternals" ) ;
46+ PropertyInfo defaultSasVersionInternal = sasQueryParametersInternals . GetProperty (
47+ "DefaultSasVersionInternal" , BindingFlags . NonPublic | BindingFlags . Static ) ;
48+ defaultSasVersionInternal . SetValue ( null , version ) ;
2149 }
2250 }
2351 }
0 commit comments