2

If I understand correctly, the SecretClient from Azure.Security.KeyVault.Certificates.nupkg is meant to replace KeyVaultClient from Microsoft.Azure.KeyVault.nupkg but it doesn't have an interface which makes it hard to mock using NSubstitute.

Working with KeyVaultClient was easy as I could simply do: Substitute.For<IKeyVaultClient>();

What is the guidance here? I don't want to have to create my own unit testable wrappers or use a different mocking framework.

EDIT I was able to do this:

var secretClient = Substitute.For<SecretClient>();
var page = Page<SecretProperties>.FromValues(new[] { new SecretProperties("SecretName") }, "continuationToken", null);
var pages = new List<Page<SecretProperties>> { page };
secretClient.GetPropertiesOfSecrets().Returns(Pageable<SecretProperties>.FromPages(pages));
secretClient.GetPropertiesOfSecrets().Dump();
secretClient.Received(1).GetPropertiesOfSecrets();
Andrew Pham
  • 185
  • 1
  • 11
  • There has been an alarming trend as of late by the Azure SDK team to be resistant to implementing interfaces on their classes. I don't know why they insist on it, but it is making things very difficult for the rest of us. – David L Nov 20 '20 at 22:08
  • Totally off-topic, but could you use configuration (that can read from KV) instead of reading secrets yourself? – Alexei Levenkov Nov 20 '20 at 22:32
  • @Connell.O'Donnell that actually works! Unfortunately mocking the Pageables is a pain.. – Andrew Pham Nov 20 '20 at 22:48

0 Answers0