Mock.Of <T> with constructor arguments
I have a specific class that I mock using Mock.Of, but it does not have a default constructor. Is there a way to make this work without binding it or using new Mock? Currently, the former is redundant, and the latter is more ugly. I will try to create an extension method that returns new Mock().Object, however I don't think it Mock.Getwill work in this scenario
+5
1 answer
It turns out that Moq normally tracks the created objects (from newand back to back Object) so that they can be used in Mock.Get. So this works for me. I would still do the built-in way if there is one:
public static T MockOf<T>(params Object[] args) where T : class
{
return new Mock<T>(args).Object;
}
+3