Unit testing responses with the new C# client?


I would like to unit test my function that parses the SearchResponse response into a MyResultRecord array. If you search for this on the internet, you get examples with the old Nest client.

var searchResponseMock = new Mock<ISearchResponse<MyDoc>>();

ISearchResponse doesn't seem to exist in the new client (Elastic.Clients.Elasticsearch 8.9.1) and you still can't instantiate a SearchResponse either. How would I unit test my parsing function?

What makes my parsing function a bit tricky and why a unit test is motivated is that it uses InnerHits, which isn't as smooth as regular hits with documents. The function looks like this.

return response.Hits.Select(p => new MyResultRecord(...)).ToArray()

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.