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

InitIndex method is returning SearchIndex rather than ISearchIndex #745

Closed
OmarPani93 opened this issue Nov 10, 2020 · 4 comments
Closed

Comments

@OmarPani93
Copy link

OmarPani93 commented Nov 10, 2020

  • Algolia Client Version: 6.8.0

I was building some unit tests for my code using the Moq library and I was not able to mock the InitIndex method since is not returning ISearchIndex.

For example, I'm not able to do that;

Mock<ISearchClient> searchClient = new Mock<ISearchClient>();
Mock<ISearchIndex> searchIndex = new Mock<ISearchIndex>();

searchClient.Setup(el => el.InitIndex(It.IsAny<string>())).Returns(searchIndex.Object);

I think it would be more appropriate having:

ISearchIndex InitIndex(string indexName);

rather than:

SearchIndex InitIndex(string indexName);

in ISearchClient.

@OmarPani93 OmarPani93 changed the title InitIndex method is returning SearchIndex rathern than ISearchIndex InitIndex method is returning SearchIndex rather than ISearchIndex Nov 10, 2020
@TomKlotzPro
Copy link
Contributor

Hello!

I've open a PR that I'll reopen when we will do a new major version of the client since this change is breaking. Because we cannot implicitly convert an interface to a class.

It's still in discussion if the DX is good enough to return an interface instead of the class. I understand about mocking needs.

@kentico-ericd
Copy link

Is there any progress on this? It's still not possible to mock ISearchClient.InitIndex

@lee-m
Copy link

lee-m commented Jul 14, 2023

+1 for this from me.

I've recently started using Algolia in my .NET application and was surprised to see that InitIndex returns a concrete type when ISearchIndex is available to be returned instead.

This has made writing unit tests around my application logic that consumes the Algolia search results more difficult than it needs to be since I've had to wrap Algolia client code within a custom interface that I can stub out for testing purposes.

@morganleroi
Copy link
Contributor

Hello,

A new client has been released on Nuget.

You can now easily mock you test thanks to the interface returned by all clients (Search, Recommend, Insights, ...)

If you have time, we need customer feedback about this new version. It's still not GA so you may not want to use it in production.

There is no more deps on Newtonsoft, all Algolia APIs are now available (Insights, Recommend, Query Perso, ...) and all models and routes are synced.

To help you migrate, there is a Migration guide.

Happy to help in your migration process !

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.

5 participants