dev-resources.site
for different kinds of informations.
Is there any option for Mock EncryptAsync() in Azure.Security.KeyVault.Keys.Cryptography
Published at
6/11/2024
Categories
azure
keyvault
dotnetcore
mock
Author
manu_vr
Author
7 person written this
manu_vr
open
I am trying to mock the functionality of the EncryptAsync method in Azure.Security.KeyVault.Keys.Cryptography.CryptographyClient.
This is the method I am trying to cover in my unit test.
public KeyVaultClientWrapper(KeyClient keyClient, SecretClient secretClient, CryptographyClient cryptographyClient)
{
_keyClient = keyClient;
_cryptographyClient = cryptographyClient;
_secretClient = secretClient;
}
public async Task<EncryptResult> EncryptAsync(string keyName, string algorithm, byte[] plainText, CancellationToken cancellationToken = default)
{
return await _cryptographyClient.EncryptAsync(algorithm, plainText, cancellationToken);
}
I'm unable to create new object of EncryptResult that needs to returned from the mock EncryptAsync method because there is no Set for EncryptResult
var _mockKeyVaultClient = new Mock<IKeyVaultClient>();
var _mockCryptoClient = new Mock<CryptographyClient>();
mockCryptoClient
.Setup(client => client.EncryptAsync(EncryptionAlgorithm.AES, plaintext, default))
.ReturnsAsync(new EncryptResult { Ciphertext = ciphertext });
How can I change this mock class so that EncryptAsync returns a valid EncryptResult object while running the test method?
Is there any alternate option for testing the same?
.NETCore
mock Article's
30 articles in total
FAQ β Bloomer Mock Data Generator
read article
Best Practices: How to Make Your API Smarter and More Flexible
read article
Testing ReactJS Context - A Guide with test-doubles
read article
The beauty of MSW
read article
Realistic data Generation Using Bloomer Mock
read article
Testing Spring Boot Applications: Unit, Integration, and Mocking β A Comprehensive Guide
read article
How to debug your Python mocks or imports
read article
Is there any option for Mock EncryptAsync() in Azure.Security.KeyVault.Keys.Cryptography
currently reading
Learn to Simulate Online APIs Without Server Infrastructure
read article
Diferenças entre o jest.spyOn e jest.mock
read article
Mock Class Constructor in Jest Test with Mocking Partials
read article
You stub/mock incorrectly
read article
Step-by-Step Tutorial on Setting Up a Mock Server Using Postman
read article
Mocking ES6 Class Instances with Jest
read article
Create free mock apis with unlimited storage
read article
Free API server with unlimited access
read article
Handle Variables and Dynamic Values with `jest.fn()`
read article
A way to mock PHP internal functions with xepozz/internal-mocker
read article
Mock vs Stub vs Fake: Understand the difference
read article
Mock modules properly with Jest and Typescript
read article
Simplified Strategies for Mocking API Calls
read article
Fastify Meets WireMock: External Service Mocking
read article
OpenAI API Mock for Devs on a Budget
read article
Mock S3 for AWS SDK for JavaScript (v3)
read article
Simplifying Kafka Testing in Python: A Mockafka-py Tutorial
read article
When to use Mock API?
read article
Datafaker: Simplifying Test Data Generation for Java and Kotlin
read article
NestJS: Mocking Databases for Efficient Tests
read article
Understanding Mocks, Stubs, and Fakes in Software Testing
read article
How to Typescript to JSON with Butlermock
read article
Featured ones: