I would like to be able to mock the SendGridClient object so I can unit test my code without actually making any calls to the SendGrid API. Unfortunately the SendGridClient does not implement any interfaces so I have to instantiate it directly instead of being able to use dependency injection to inject the interface.
The old 6.X.X version of the SendGrid client included an ITransport interface which could be mocked for testing without actually hitting the API.
Hello @Tarball,
I'm adding this to our backlog.
In the meantime, we are using StopLight.io's Prism along with SendGrid API's OAI specification to create a mock client.
The instructions for setting this up locally for testing against a mocked version of the SendGrid API is here: https://github.com/sendgrid/sendgrid-csharp/blob/master/CONTRIBUTING.md#testing (this happens automatically on Travis).
With Best Regards,
Elmer
Hi @thinkingserious
I also want to mock SendGridClient.
Can you please provide update on this? I mean when are you planning to apply this change?
Thank you!
Hello @rodchenkov,
This PR fixes this issue: https://github.com/sendgrid/sendgrid-csharp/pull/434
It should be merged soon. Thanks!
With Best Regards,
Elmer
Actually, this is a different issue. My PR enables the mocking of http responses. The request at hand is for SendGridClient to implement a (new) ISendGridClient interface so that the SendGridClient can be altogether mocked.
Thanks for clarifying @ottomatic!
I've added @rodchenkov's vote to this issue in our backlog.
In the mean time @rodchenkov,
@rodchenkov Please have alook at StrongGrid . It's an alternative .net client for SendGrid'a API which implements an interface for easy mocking.
Most helpful comment
Actually, this is a different issue. My PR enables the mocking of http responses. The request at hand is for SendGridClient to implement a (new) ISendGridClient interface so that the SendGridClient can be altogether mocked.