algoliasearch-client-csharp
algoliasearch-client-csharp copied to clipboard
InitIndex method is returning SearchIndex rather than ISearchIndex
- 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
.
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.
Is there any progress on this? It's still not possible to mock ISearchClient.InitIndex
+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.
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 !