@@ -27,11 +27,8 @@ namespace Microsoft.Azure.Commands.KeyVault.Test.Models
27
27
{
28
28
public class UtilitiesTests
29
29
{
30
- private ITestOutputHelper _output ;
31
-
32
30
public UtilitiesTests ( ITestOutputHelper output )
33
31
{
34
- _output = output ;
35
32
XunitTracingInterceptor . AddToContext ( new XunitTracingInterceptor ( output ) ) ;
36
33
}
37
34
@@ -67,14 +64,12 @@ public void GetWebKeyFromByok()
67
64
public void GetWebKeyFromCertificate ( )
68
65
{
69
66
string password = "123" ;
70
- _output . WriteLine ( $ "Assembly: { Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) } ") ;
71
- _output . WriteLine ( $ "Current: { Directory . GetCurrentDirectory ( ) } ") ;
72
- _output . WriteLine ( $ "Exists: { new FileInfo ( "./Resources/pshtest.pfx" ) . Exists } ") ;
73
- string path = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Resources" , "pshtest.pfx" ) ;
74
- _output . WriteLine ( $ "Path: { path } ") ;
67
+ // This allows the test to run in Visual Studio and in the console runner. The file will exist in one of the two locations depending on the environment.
68
+ var consolePath = Path . Combine ( Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ?? String . Empty , "Resources" , "pshtest.pfx" ) ;
69
+ var vsPath = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Resources" , "pshtest.pfx" ) ;
75
70
76
71
IWebKeyConverter converters = WebKeyConverterFactory . CreateConverterChain ( ) ;
77
- var webKey = converters . ConvertKeyFromFile ( new FileInfo ( path ) , password . ConvertToSecureString ( ) ) ;
72
+ var webKey = converters . ConvertKeyFromFile ( new FileInfo ( File . Exists ( consolePath ) ? consolePath : vsPath ) , password . ConvertToSecureString ( ) ) ;
78
73
79
74
Assert . True ( webKey . HasPrivateKey ( ) ) ;
80
75
Assert . True ( webKey . IsValid ( ) ) ;
0 commit comments