我对 Java 很了解,但对 C# 很陌生。
我在为以下示例代码编写单元测试时遇到困难:
public static IDictionary<string, string> GetVaultSecretsDictionary(Uri keyVaultUrl, ChainedTokenCredential azureChainedCredential, string[] secretNames)
{
var client = new SecretClient(keyVaultUrl, azureChainedCredential);
var vaultSecrets = new Dictionary<string, string>();
foreach (var secretName in secretNames) {
Response<KeyVaultSecret> responseKeyVaultSecret = client.GetSecret(secretName);
var secretValue = responseKeyVaultSecret.Value.Value;
vaultSecrets.Add(secretName, secretValue);
}
return vaultSecrets;
}
Run Code Online (Sandbox Code Playgroud)
我想为上述函数编写单元测试,但我不知道如何模拟 SecretClient,然后以与 Java 中使用InjectMock类似的方式注入它。另外,为了获取responseKeyVaultSecret值,还会向URL发送请求,我不知道如何实现GetSecret以 返回响应模拟值。
我寻找过示例和教程,但对我来说并没有什么成果。
注意:上述函数内不能进行任何更改。