Using of Factory in Pex

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

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.

image

Assume now, there is a testing/exploring class which looks like:

image

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.

image

Click on text marked  above and following appears:

image

Right mouse click on selected text, then accept create factory and PEX is done:

image

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.

image

Here is the test method, which makes usage of the factory:

image


Posted Apr 13 2009, 07:18 PM by Damir Dobric
developers.de is a .Net Community Blog powered by daenet GmbH.