-
Notifications
You must be signed in to change notification settings - Fork 572
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
Refactor StripeClient setup in tests #1631
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ob-stripe
force-pushed
the
ob-refactor-test-fixtures
branch
3 times, most recently
from
May 27, 2019 04:25
7b5f116
to
4b25947
Compare
ob-stripe
force-pushed
the
ob-refactor-test-fixtures
branch
from
May 27, 2019 08:04
4b25947
to
07a0e4d
Compare
brandur-stripe
approved these changes
May 28, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a great improvement! LGTM.
Thanks Brandur! |
ob-stripe
added a commit
that referenced
this pull request
Jun 6, 2019
ob-stripe
added a commit
that referenced
this pull request
Jun 7, 2019
* Better serialization * Remove unnecessary uses of Mapper * Standardize signature of OAuthTokenService.Deauthorize * New `FromJson` method * Modernize StripeConfiguration * Simplify Service request methods * Replace Parameter custom class with KeyValuePair<string, string> * Rewrite expandable field handling * Move base URLs out of resource services where possible * Refactor Client class * Minor fixes * Remove `Mapper` class * Simplify handling of Expand and ExtraParams * Minor improvements in EventUtility * More request encoding refactoring * Introduce new Request class to represent requests to Stripe's API * Revamp HTTP client requestor * Fixes to FileService and OAuthTokenService * Remove BaseOptionsExtensions * Remove ServiceExtensions, allow per-service clients * Add support for telemetry * Make `parent` on `OrderItem` expandable * Automatic request retries * Add missing attributes to StripeError * Remove parameters that are internal only today on PaymentIntent * Various minor cleanups * API key validation * Check validity of JSON in OK responses * Enforce that all properties have a Json attribute * Improved OAuth support (#1542) * Rename DuplicateChargeDocumentation to be more consistent with FileId (#1563) * AnyOf<> generic class to handle polymorphic parameters (#1495) * Add support for file_link_data (#1598) * Add support for passing application information (#1596) * Rename StripeConnectAcconutId to StripeAccount (#1603) * Update README (#1602) * Add wholesome test to check JSON names (#1609) * Remove System.Collections.Immutable dependency (#1615) * Raise ArgumentException on null or empty IDs (#1616) * Move default values for SystemNetHttpClient (#1623) * Remove StripeConfiguration.EnableTelemetry flag (#1622) * Refactor StripeClient setup in tests (#1631) * Set base URLs in StripeClient instead of StripeConfiguration (#1632) * Add support for setting API key and client ID in StripeClient (#1633) * Use StripeClient instance in tests (#1634) * Add support for setting MaxNetworkRetries and AppInfo in SystemNetHttpClient (#1635) * Make base URLs in StripeClient readonly (#1640) * Make client in services readonly (#1639) * Add AddRangeExpand method to BaseOptions (#1643) * Add options classes for Get/GetAsync methods (#1644) * Deprecate Expand properties on services (#1646) * Use constants instead of static strings (#1647) * Update README.md (#1648)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
r? @brandur-stripe @remi-stripe
cc @stripe/api-libraries
Changes the way
StripeClient
is set up in tests.To clarify what's happening here:
MockHttpClientFixture
is only created once for the entire test suite (because it's set up as a "collection fixture" here)BaseStripeTest
is the parent class for all tests, so its constructor is called for each test classThe problem with the previous implementation is that since we set up the global
StripeClient
(viaStripeConfiguration.StripeClient
) inMockHttpClientFixture
, the client was applied for all tests (even those that don't need mocking capabilities). More importantly, if a test needs to modifyStripeConfiguration.StripeClient
for its own purposes, it needs to save the original client and restore it afterwards because other test classes might need theStripeClient
set up byMockHttpClientFixture
.With this change, we create a new
StripeClient
instance for each test class, and use the mock client fromMockHttpClientFixture
if needed. This provides better test isolation, and enables some followup changes I want to make toStripeClient
.