# Mocking MultiSearchResponse

**URL:** <https://discuss.elastic.co/t/mocking-multisearchresponse/364396>\
**Category:** Elastic Search\
**Created:** [August 5, 2024, 1:57pm UTC](https://discuss.elastic.co/t/mocking-multisearchresponse/364396 "2024-08-05T13:57:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuanhe\_Li](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuanhe_li/32/136522_2.png) [@Yuanhe\_Li](https://discuss.elastic.co/u/Yuanhe_Li)\
**Post date:** [August 5, 2024, 1:57pm UTC](https://discuss.elastic.co/t/mocking-multisearchresponse/364396/1 "2024-08-05T13:57:12Z")

</div>

Hi! I was new to ES, and I am trying to mock a MultiSearchResponse, and I started from successfully mocking a SearchResponse

```auto
        var mockSearchResponse = new Mock<ISearchResponse<CandidateSearchDto>>();
        mockSearchResponse.Setup(sr => sr.Documents)
                          .Returns(new List<CandidateSearchDto>
                          {
                      new CandidateSearchDto(),
                      new CandidateSearchDto(),
                      new CandidateSearchDto()
                          });
        mockSearchResponse.Setup(sr => sr.Total)
                          .Returns(3);

        var mockMultiSearchResponse = new Mock<MultiSearchResponse>();
        mockMultiSearchResponse.Setup(ms => ms.AllResponses)
                               .Returns(new List<IResponse> { mockSearchResponse.Object });

```

However, on mockMultiSearchResponse it is giving me this error:

```auto
 System.NotSupportedException : Unsupported expression: ms => ms.AllResponses
Non-overridable members (here: MultiSearchResponse.get_AllResponses) may not be used in setup / verification expressions.

```

Is there any ways to work around this issue? I found this post

> <https://stackoverflow.com/questions/56905578/moq-non-overridable-members-may-not-be-used-in-setup-verification-expression>

that suggests to create actual instances instead of Mock\<\> ones, but I am not sure how to simply initialize a MultiSearchResponse variable. Can someone help out? Thanks!!

---

<div class="post-metadata">

**Author:** ![Yuanhe\_Li](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuanhe_li/32/136522_2.png) [@Yuanhe\_Li](https://discuss.elastic.co/u/Yuanhe_Li)\
**Post date:** [August 8, 2024, 5:47pm UTC](https://discuss.elastic.co/t/mocking-multisearchresponse/364396/2 "2024-08-08T17:47:06Z")

</div>

Would anyone respond to this? Thanks!

---

<div class="post-metadata">

**Author:** ![Artem\_Shelkovnikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artem_shelkovnikov/32/134322_2.png) [@Artem\_Shelkovnikov](https://discuss.elastic.co/u/Artem_Shelkovnikov)\
**Post date:** [August 9, 2024, 1:15pm UTC](https://discuss.elastic.co/t/mocking-multisearchresponse/364396/3 "2024-08-09T13:15:15Z")

</div>

Hi @Yuanhe_Li,

I'm not a Java expert, but maybe this can help:

Elasticsearch repository is open code, so you can peak at it to find out some best practices.

Here's search by MultiSearchResponse in the repo, page 2: [Code search results · GitHub](https://github.com/search?q=repo%3Aelastic%2Felasticsearch+MultiSearchResponse&type=code&p=2)  
I can see that some code there is testing code.

The testing code above uses `prepareMultiSearch` method: [Code search results · GitHub](https://github.com/search?q=repo%3Aelastic%2Felasticsearch+prepareMultiSearch&type=code)

Looking into examples above might give you a hint, hopefully 🙂

---

<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:** [September 6, 2024, 1:15pm UTC](https://discuss.elastic.co/t/mocking-multisearchresponse/364396/4 "2024-09-06T13:15:20Z")

</div>

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