I have a concrete class that I am mocking using Mock.Of
, but it does not have a default constructor. Is there any way to get this to work without having to interface this or using new Mock
? The former is overkill at this time, and the latter is uglier. I am going to try creating an extension method that returns a new Mock().Object
, however I do not think that Mock.Get
will work in that scenario
It turns out that Moq does track objects created normally (with new
and pass back Object
) so that they can be used in Mock.Get
. So, this works for me. I would still take a built in way if there is one:
public static T MockOf<T>(params Object[] args) where T : class
{
return new Mock<T>(args).Object;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With