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

Update return types of IPostgrestTable<TModel> from Table<TModel> to IPostgrestTable<TModel> #92

Closed
jackwalkernz opened this issue May 7, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@jackwalkernz
Copy link

Feature request

I have recently started using this client library for doing some database operations across a series of services for a product I am making, and I would like to mock our the client and methods so that I can isolate the behaviour of my services.

I have opted to use Mock, NSubstitute, and Bogus as my mocking frameworks.

I would like to create mocks of IPostgrestTable<TModel>/Table<TModel> so that I can override/implement the desired behaviour using the above frameworks.

When reading through the codebase, I noticed that IPostgrestTable<TModel>'s methods (where applicable) return the concrete type Table<TModel> instead of IPostgrestTable<T>.

Table<TModel>'s methods are not virtual, and as a result, I can't mock out my client, as the interface has concrete return types, and the concrete type does not have methods that can be overridden.

Describe the solution you'd like

I would like for IPostgrestTable<TModel>'s methods to have their return type changed from Table<TModel> to IPostgrestTable<TModel>. This means that the interface can be implemented using NSubstitute and mocked out, successfully enabling future unit testing.

Describe alternatives you've considered

I noticed that unit testing for this package is done using a docker container. I could do this, however, I would like to separate out my integration and E2E testing from my unit testing. I would also prefer to not have to mock out quite a complex database within the container, as well as populate test data.

@jackwalkernz jackwalkernz added the enhancement New feature or request label May 7, 2024
@jackwalkernz
Copy link
Author

acupofjose added a commit that referenced this issue May 7, 2024
@acupofjose
Copy link
Contributor

Good call! Can you check #93 and see if that's what you're looking for?

@jackwalkernz
Copy link
Author

Looks good to me

acupofjose added a commit that referenced this issue May 7, 2024
Re: #92 Changes `IPostgrestTable<>` contract to return the interface rather than a concrete type.
@acupofjose
Copy link
Contributor

Available in v4.0.1

@jackwalkernz
Copy link
Author

Thanks for sorting @acupofjose! Much appreciated. When will these changes bubble through to supabase-csharp?

@acupofjose
Copy link
Contributor

I’ll get to it probably this evening or tomorrow morning!

@jackwalkernz
Copy link
Author

Awesome! Thanks for that. Getting this fix has been so much faster than other SDKs I've come across. I appreciate it 🙏🏼

@acupofjose
Copy link
Contributor

Luckily an easy one to implement (and one that should've been implemented earlier!) - had a few minutes and went ahead and bumped the main repo. Should be seeing v1.0.1 hit nuget in a few minutes. Happy deving!

@jackwalkernz
Copy link
Author

Wicked, this stuff now works with common testing frameworks like Moq and NSubstitute 😍 How good!

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

No branches or pull requests

2 participants