Skip to content

Commit 4ab7861

Browse files
committed
Fixed the test issue by checking two different paths for file existence.
1 parent b1b6482 commit 4ab7861

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault.Test/Models/UtilitiesTests.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ namespace Microsoft.Azure.Commands.KeyVault.Test.Models
2727
{
2828
public class UtilitiesTests
2929
{
30-
private ITestOutputHelper _output;
31-
3230
public UtilitiesTests(ITestOutputHelper output)
3331
{
34-
_output = output;
3532
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
3633
}
3734

@@ -67,14 +64,12 @@ public void GetWebKeyFromByok()
6764
public void GetWebKeyFromCertificate()
6865
{
6966
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");
7570

7671
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());
7873

7974
Assert.True(webKey.HasPrivateKey());
8075
Assert.True(webKey.IsValid());

0 commit comments

Comments
 (0)