Pex (program exploration tool) a great capability to create factory helper classes, when PEX itself is not able to guess how to do that automatically.
To make this explicitly useful, you have to now in which case PEX can do it for you.
Here is one example. Assume there is an interface and concrete implementation of it.
Assume now, there is a testing/exploring class which looks like:
Only important thing in this class is that constructor receive an argument of interface type. When exploring methods in the class PEX first has to guess how to create the instance of the class. This is important, because PEX doe not traverse all assemblies and look for implementation of the class. Such kind of searchin in assemblies would take too long. Additionally,, what should PEX do if more concrete implementation are found?
So, PEX will in this case explore all regularly, but with a little warning, which indicates, that PEX is going to create a factory for you.
Click on text marked above and following appears:
Right mouse click on selected text, then accept create factory and PEX is done:
The method ClassFactory.Create() is the place where to implement your factory:
When you now repeat the sample exploration as shown above all will work fine, because PEX has already factory created and it will be used.
Here is the test method, which makes usage of the factory:
Apr 13 2009, 07:18