Is there a way to setup a Moq Mock using a string parameter instead of an expression? You can do this using the protected extensions for a protected function, but it throws an exception if public. For example, here is how you might setup a protected void function with Moq:
myMock.Protected().Setup("MyProtectedFunction");
I want to be able to do the same thing with a public function. If I can do this I already have some reflection code that can return the names of all of the functions I need to mock, and I can hopeful build on this to avoid having to setup many functions on a huge factory class.
Interesting problem, this is almost possible to do using expressions. Since the setup method takes an expression, you can build it at runtime.
The only bit that needs to happen at compile time is casting the expression to the appropriate lambda type based on the return type of the mocked method. Unfortunately Moq does not provide a
Setupoverload taking nakedExpression, otherwise it could be possible to do what you want 100% at runtime.