You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I'm trying to create some helper methods to make working with NSubstitute more and more convenient. There is a case, when I need to check how many or which mocks have been already created.
Let's take the following case. I have a factory that creates some type of objects.
I want to have the ability to check all of the mocks created by that factory for specified action. In order to do so, I decided to use When.. Do methods:
But... it does not work at all. It does not invoke Do method at all for the following case. I've already created two overloads, one for Action and another one for Func.
Test implementation:
varmockFactory=Substitute.For<IFactory>();varcreatedMocks=mockFactory.SetupNewSubstitute(f =>f.Create(Arg.Any<IParameter>());// Invoking action// createdMocks is always empty.
I've also noticed that passing any substitute/real object to var createdMocks = mockFactory.SetupNewSubstitute(f => f.Create(ANY_REAL_OBJECT_OR_SUBSTITUTE); works.
But well... it's a boilerplate for us, and we'd like to get rid of it if possible.
Are you aware of any way that it could be solved?
The text was updated successfully, but these errors were encountered:
Hi @lukaszksoll ,
Sorry for the delayed response. :(
Would you be able to post a minimal reproduction of this I can copy/paste/run in VS Code? I think just need interface IFactory and associated types (IParameter, IComponent), SetupNewSubstitute extension method, and failing test.
Hi!
I'm trying to create some helper methods to make working with NSubstitute more and more convenient. There is a case, when I need to check how many or which mocks have been already created.
Let's take the following case. I have a factory that creates some type of objects.
I want to have the ability to check all of the mocks created by that factory for specified action. In order to do so, I decided to use When.. Do methods:
But... it does not work at all. It does not invoke
Do
method at all for the following case. I've already created two overloads, one for Action and another one for Func.Test implementation:
Previously I used to use the following pattern:
I've also noticed that passing any substitute/real object to
var createdMocks = mockFactory.SetupNewSubstitute(f => f.Create(ANY_REAL_OBJECT_OR_SUBSTITUTE);
works.But well... it's a boilerplate for us, and we'd like to get rid of it if possible.
Are you aware of any way that it could be solved?
The text was updated successfully, but these errors were encountered: