NOTE: Samples in this file apply only to packages that follow Azure SDK Design Guidelines. Names of such packages usually start with Azure
.
You can use a combination of model factory and Mock
class to create a mock of a client:
// Create a mock response
var mockResponse = new Mock<Response>();
// Create a mock value
var mockValue = SecretModelFactory.KeyVaultSecret(
SecretModelFactory.SecretProperties(new Uri("http://example.com"))
);
// Create a client mock
var mock = new Mock<SecretClient>();
// Setup client method
mock.Setup(c => c.GetSecret("Name", null, default))
.Returns(Response.FromValue(mockValue, mockResponse.Object));
// Use the client mock
SecretClient client = mock.Object;
KeyVaultSecret secret = client.GetSecret("Name");