4

Is it a good practice to use the InMemoryConnection class for unit-testing our Elasticsearch projects?

This class is being used in the actual source code for unit-testing. But the reason I am asking is because it derives from HttpConnection I am not quite sure if it opens any HTTP connection. Our unit tests go to a build server so I would like to avoid that. Thank you for the help.

user11081980
  • 3,059
  • 4
  • 30
  • 48

2 Answers2

3

Yes.

If you look at the implementation of InMemoryConnection, you'll see that it overrides DoSynchronousRequest and DoAsyncRequest (the methdods of HttpConnection that are responsible for actually executing the HTTP request), and simply returns a fake ElasticsearchResponse. No HTTP connections are open and no requests are made, so you are safe to use it in your unit tests.

Greg Marzouka
  • 3,315
  • 1
  • 20
  • 17
0

There is however a NuGet package for real integration tests from c#: https://www.nuget.org/packages/elasticsearch-inside/

(I'm the author)

modec
  • 213
  • 1
  • 9
  • This looks like exactly what I was looking for, but it won't work with dotnet core. – kiml42 Jul 07 '16 at 14:19
  • @kiml42 take a look at the Tests project within NEST that downloads and spins up different Elasticsearch cluster versions for integration tests - https://github.com/elastic/elasticsearch-net/tree/2.x/src/Tests. Specifically, take a look at `ClusterBase` and `ElasticsearchNode` within the integration directory -https://github.com/elastic/elasticsearch-net/tree/2.x/src/Tests/Framework/Integration. These work on dotnet core as well as desktop CLR – Russ Cam Sep 01 '16 at 02:40