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
Hello @michal-ciechan in this issue do you mean when I have a class inject other class into constructor?
If this is true, I think create recursive Create() when the parameter type IsClass using reflection.
hey @damianpumar, it will already recursively generate concrete classes if you specify Create<T>(autogenerate: true).
This is so that you can provide a single instance to use for a specific Create<T>(). Similar to something like the below:
Example Class
class SystemUnderTest {
// ctor
public SystemUnderTest(StringBuilder builder, ISomeInterface interface) { ... }
}
Example Test
var sb = new StringBuilder("Some Test String");
_moq.Create<SystemUnderTest>(sb);
I would expect this to inject the local concrete instance variable sb into SystemUnderTest constructor parameter ctor(StringBuilder builder, ...).
There are a number of times I have needed to use a third party concrete type, which I want to pass in a single instace.
Currently I am using the following workaround:
Workaround
var sb = new StringBuilder("Some Test String");
_moq.Use(sb);
_moq.Create<SystemUnderTest>();
This uses my specific local variable sb as the ctor parameter, as it is registered with the container globally. The drawback for this workaround is that anywhere else a class requests StrignBuilder that specific instance will be passed in.
The text was updated successfully, but these errors were encountered: