Skip to content
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

Recommended strategy for stubbing entities in unit tests in version 27.0.0 #1651

Closed
samcic opened this issue Jun 10, 2019 · 4 comments · Fixed by #1655
Closed

Recommended strategy for stubbing entities in unit tests in version 27.0.0 #1651

samcic opened this issue Jun 10, 2019 · 4 comments · Fixed by #1655

Comments

@samcic
Copy link

samcic commented Jun 10, 2019

OS version: Windows 10
.NET Core version: 2.2
Stripe.net version: 27.0.0

Before version 27.0.0 it was trivial to create unit tests with mocking/stubbing behavior, e.g.

[TestMethod]
public async Task Example()
{
    Moq<ISomeServiceThatMakesStripeApiRequest>().Setup(m => m.GetCustomer("cus_x")).ReturnsAsync(new Customer{DefaultSourceId = "src_x"});
    var result = await _target.SomeWrapperMethodAsync("cus_x");
    ...
}

In version 27.0.0 the method above no longer compiles because many of the core resources (e.g. Customer) now contain properties that are readonly.

What's the recommended approach for creating stubbed resources (e.g. a Customer with DefaultSourceId set to a test value) now? Of course we could create our own wrapper objects for all your entities, but this would be a maintenance pain.

We're concerned that you guys have neglected unit-test considerations with version 27.0.0.

@TheNowyn
Copy link

TheNowyn commented Jun 10, 2019

Fully agree.

I was waiting for Immutables dependency to drop only to now get a bunch of broken tests...

At least make all that read-only properties virtual to allow mocking.

@ob-stripe
Copy link
Contributor

Hi, thanks for the report and sorry for the inconvenience. We changed the way expandable fields are handled, and in the process removed setters for the ID and expanded versions of these fields, but failed to realize these setters were useful for unit tests/mocking. We'll add the setters back and publish a new version soon.

@ob-stripe
Copy link
Contributor

Fixed in 27.1.0.

@TheNowyn
Copy link

While setters are back and code compiles, when trying to set a Customer or CustomerId properties of say a Charge throws NullReferenceException.

Are charges being tested at all before releasing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants