# Nest Connection : Mock 2 in-memory response in elastic search in c#

**URL:** <https://discuss.elastic.co/t/nest-connection-mock-2-in-memory-response-in-elastic-search-in-c/159565>\
**Category:** Elasticsearch\
**Created:** [December 5, 2018, 3:34pm UTC](https://discuss.elastic.co/t/nest-connection-mock-2-in-memory-response-in-elastic-search-in-c/159565 "2018-12-05T15:34:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![piyush\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piyush_kumar/32/51705_2.png) [@piyush\_kumar](https://discuss.elastic.co/u/piyush_kumar)\
**Post date:** [December 5, 2018, 3:34pm UTC](https://discuss.elastic.co/t/nest-connection-mock-2-in-memory-response-in-elastic-search-in-c/159565/1 "2018-12-05T15:34:28Z")

</div>

I have to unit test a function that have 2 elastic search query and need to mock 2 responses for it. I am able to mock single response using below code .

```
var responseBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonObject));
        var connection = new InMemoryConnection(responseBytes, 200);
        var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
        var settings = new ConnectionSettings(connectionPool, connection).DefaultIndex("TestElasticProject");
        ElasticSearchService.GetInstance().Init(settings);

```

I have both the mock responses but not to able to configure it in ConnectingSettings .

I need something like

```
var responseBytes1 = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonObject));
    var connection1 = new InMemoryConnection(responseBytes1, 200);

```

var responseBytes2 = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonObject));  
var connection2 = new InMemoryConnection(responseBytes2, 200);

**I have to unit test a function that have 2 elastic search query and need to mock 2 responses for it. I am able to mock single response using below code**.

```auto
var responseBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonObject));
            var connection = new InMemoryConnection(responseBytes, 200);
            var connectionPool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
            var settings = new ConnectionSettings(connectionPool, connection).DefaultIndex("TestElasticProject");
            ElasticSearchService.GetInstance().Init(settings);

```

I have both the mock responses but not to able to configure it in ConnectingSettings .

I need something like

```auto
var responseBytes1 = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonObject));
        var connection1 = new InMemoryConnection(responseBytes1, 200);
var responseBytes2 = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(JsonObject));
        var connection2 = new InMemoryConnection(responseBytes2, 200);

```

Is it possible in elastic search to assign 2 responseByte together ? because in ElasticSearch-Net code in GITHUB i am not able to find any implementation .

In Case its not possible then should i create 1 elastic search query per 1 function so that unit testing will be possible ?

---

<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:** [January 2, 2019, 3:34pm UTC](https://discuss.elastic.co/t/nest-connection-mock-2-in-memory-response-in-elastic-search-in-c/159565/2 "2019-01-02T15:34:31Z")

</div>

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