You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ISearchClient should depend on interfaces and not concrete types. This breaks Liskov substitution principle when testing this. The concrete type SearchIndex has a internal constructor making it harder to wrap this for testing.
Use Moq to create a Mock of SearchClient and setup responses to various calls:
using Moq;using Moq.AutoMock;AutoMocker_mocker=new();varsearchClient= _mocker.GetMock<ISearchClient>();varsearchIndex= _mocker.GetMock<SearchIndex>();// Can't use `ISearchIndex` here because `InitIndex` returns Concrete type with internal constructor
searchClient.Setup(b => b.InitIndex("test_items")).Returns((SearchIndex)searchIndex.Object);
The text was updated successfully, but these errors were encountered:
Description
ISearchClient
should depend on interfaces and not concrete types. This breaks Liskov substitution principle when testing this. The concrete typeSearchIndex
has ainternal
constructor making it harder to wrap this for testing.algoliasearch-client-csharp/src/Algolia.Search/Clients/ISearchClient.cs
Lines 45 to 50 in 0c2faad
Steps To Reproduce
Use
Moq
to create a Mock ofSearchClient
and setup responses to various calls:The text was updated successfully, but these errors were encountered: