7

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

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180

1 Answers1

6

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;
}
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180