question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mocking IndicesNamespace?

See original GitHub issue

How do I mock IElasticClient.Indices, in other words, the IndicesNamespace?

Can we instead have it so that IElasticClient.Indices refers to an interface (for instance IIndicesNamespace instead)?

Right now, I can’t mock indices using NSubstitute:

var fakeIndicesNamespace = Substitute.For<IndicesNamespace>(); //crashes with message: System.NotSupportedException : Parent does not have a default constructor. The default constructor must be explicitly defined.

var fakeElasticClient = Substitute.For<IElasticClient>();
fakeElasticClient.Indices.Returns(fakeIndicesNamespace);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

20reactions
ffMathycommented, Dec 19, 2019

Why make it so hard? Why can’t we just turn IndicesNamespace into an interface? That way, everyone can mock like they are used to in virtually every single other NuGet package out there, using their own mocking framework?

6reactions
mkorman-catcommented, Jun 4, 2021

I have some concerns with the suggestions raised in #4076

  • Essentially, by asking your users to create their own wrappers, you’re aking them to do the job that you didn’t want to do, which is introduce the interfaces and mockability. You’re ignoring some genuine use cases and pushing the complexity to the users
  • I don’t want to turn my unit tests into integration tests. I just want to mock a specific response to ensure that my code does the right thing when I get a certain response from the library

At the end of the day, use of interfaces and mockability is considered good practices. It would be amazing if your library accepted those. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Elasticsearch Nest unit tests with Moq : fail to mock ...
I need to mock some methods and properties in Nest.IElasticClient interface that is used in my repo. As example I need to stub...
Read more >
Use CompositeExpectation.shouldReceive in Mockery with ...
Use the shouldReceive method in your next Mockery project with LambdaTest ... m::mock(IndicesNamespace::class);30 $indicesNamespace-> shouldReceive ...
Read more >
Release notes | Elasticsearch-PHP [8.9]
Added a ClientInterface to simplify the mock of the Client, ... Reintroduced Elasticsearch\Namespaces\IndicesNamespace::getAliases() as proxy to ...
Read more >
patch
... +### Docs +- [Docs] Updating readme with mock testing instructions (#591) ... Elasticsearch\Namespaces\IndicesNamespace + + + +Class IndicesNamespace + ...
Read more >
es-php (956ecc5d) · Commits · wallet / token
include::Elasticsearch/Namespaces/IndicesNamespace.asciidoc[] ... \IndicesNamespace";s:40:"45eb11f7e963d832b6cf9a07559b38ae199d010a" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found