mercredi 19 juillet 2023

Create a Moq Mock from System.Type

Is it possible to create a Mock from a System.Type variable?

We are converting projects from Rhino to Moq. In Rhino we could previously do this:

var type = typeof(/* Some type */);
MockRepository.GenerateStub(type);

The creation methods in Moq are (at least as far as I have found) all based on generic type parameters instead of System.Type.

Unfortunately there are a lot of different types for which a Mock is needed packed in different infrastructure layers and handed over as a variable of System.Type to the point where the Mock is created. So converting all this to generic is very cumbersome if it can be done at all.





Aucun commentaire:

Enregistrer un commentaire