# Unit testing responses with the new C# client?

**URL:** <https://discuss.elastic.co/t/unit-testing-responses-with-the-new-c-client/351279>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 17, 2024, 1:29pm UTC](https://discuss.elastic.co/t/unit-testing-responses-with-the-new-c-client/351279 "2024-01-17T13:29:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![landlord\_matt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/landlord_matt/32/134159_2.png) [@landlord\_matt](https://discuss.elastic.co/u/landlord_matt)\
**Post date:** [January 17, 2024, 1:29pm UTC](https://discuss.elastic.co/t/unit-testing-responses-with-the-new-c-client/351279/1 "2024-01-17T13:29:37Z")

</div>

Hi!

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](https://stackoverflow.com/questions/31298657/unable-to-create-a-search-response-object-how-do-we-mock-search-responses-in-n).

```auto
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.

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 14, 2024, 1:29pm UTC](https://discuss.elastic.co/t/unit-testing-responses-with-the-new-c-client/351279/2 "2024-02-14T13:29:40Z")

</div>

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