public void GetCertificateWithVersion() { const string VaultName = "fakevault1"; const string SecretName = "secretname1"; const string SecretVersion = "1aaaaaaa1aa11a1111aaaa11111a1111"; const string TenantId = "11111111-1111-1111-aa1a-a1a11a111111"; const string ClientId = "11111111-1111-1111-aa1a-a1a11a111111"; const string ClientSecret = "a.u8w3FFgwy9v_-5R_5gsT~qf96T~a7e6y"; var algorithm = ECDsa.Create(); // string key = null; var path = Path.Combine(Environment.CurrentDirectory, "TestValidationCertificate.pfx"); var certificate = new X509Certificate2(path, "abc123"); var certificateString = Convert.ToBase64String(certificate.RawData); using (var context = ShimsContext.Create()) { ShimKeyVaultKey.AllInstances.KeyGet = new FakesDelegates.Func <KeyVaultKey, JsonWebKey>((key) => { return(new JsonWebKey(algorithm)); }); var fakeKey = new ShimKeyVaultKey() { }; ShimKeyClient.AllInstances.GetKeyAsyncStringStringCancellationToken = new FakesDelegates.Func <KeyClient, string, string, CancellationToken, Task <Response <KeyVaultKey> > >((client, name, version, cancellationToken) => { var keyVaultFakeKeyResponse = new FakeResponse <KeyVaultKey>(fakeKey, 200, "OK", null); return(Task.FromResult(keyVaultFakeKeyResponse as Response <KeyVaultKey>)); }); var testKey = new ShimKeyVaultKey(); var response = new FakeResponse <KeyVaultKey>(testKey, 200, "OK", null); SetupSecretClientConstructorFakes(); var vault = new KeyVault(VaultName, AzureOauthTokenAuthentication.GetOauthTokenCredentialFromClientSecret(TenantId, ClientId, ClientSecret), 3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(10)); var client = vault.GetKeysClient(KeyClientOptions.ServiceVersion.V7_1); var keyValue = client.GetAsync(SecretName, SecretVersion).GetAwaiter().GetResult(); Assert.IsNotNull(keyValue, "Certificate failed to retrieve"); var webKey = (JsonWebKey)keyValue; Assert.IsNotNull(webKey, "Web key not expected"); } }