Skip to content

Make SendGridClient implement an interface for DI and mocking in tests #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tarball opened this issue Feb 20, 2017 · 7 comments
Closed
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@Tarball
Copy link

Tarball commented Feb 20, 2017

Issue Summary

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.

@thinkingserious thinkingserious added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap labels Feb 20, 2017
@thinkingserious
Copy link
Contributor

thinkingserious commented Feb 20, 2017

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

@rodchenkov
Copy link

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!

@thinkingserious
Copy link
Contributor

Hello @rodchenkov,

This PR fixes this issue: #434

It should be merged soon. Thanks!

With Best Regards,

Elmer

@ottomatic
Copy link
Contributor

ottomatic commented Apr 12, 2017

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.

@thinkingserious
Copy link
Contributor

thinkingserious commented Apr 12, 2017

Thanks for clarifying @ottomatic!

I've added @rodchenkov's vote to this issue in our backlog.

In the mean time @rodchenkov,

You can mock the SendGrid API currently with Prism.

@Jericho
Copy link

Jericho commented Apr 16, 2017

@rodchenkov Please have alook at StrongGrid . It's an alternative .net client for SendGrid'a API which implements an interface for easy mocking.

thinkingserious added a commit that referenced this issue May 16, 2017
Fix issue #403 - implement an interface for mocking and DI
@thinkingserious
Copy link
Contributor

Fixed with #456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

5 participants