If you want to use PexCreatableByClassFactory, you need a class that implements the IPexClassFactory interface. Here is an example:
public partial class LogicFactory : IPexClassFactory<Logic> { public Logic Create() {
It should be noted that IPexClassFactory works with specific classes, not with interfaces. Now, if Pex decides that an instance of the Logic class should be created, the following code will be created:
LogicFactory2 s2 = new LogicFactory(); Logic s1 = ((IPexClassFactory<Logic>)s2).Create();
If you prefer to use PexFactoryMethod , this is also possible. However, PexFactoryMethod also works with specific classes, for example:
[PexFactoryMethod(typeof(Logic))] public static Logic Create(string defaultUICulture, bool saveSuccessful) {
If you use both solutions at the same time, i.e. If you define the pex factory method and the pex factory class for the same type, then, in my experience, the pex factory method will have a higher priority.
If you have more than one class that implements the ILogic interface, you need to define a pex factory method and / or a pex factory class for each of these classes. Otherwise, PEX will try to instantiate these classes on its own.
If you want to get rid of this warning, right-click it and select "Fix" from the context menu. Pex will create the following attribute for you:
[assembly: PexUseType(typeof(SpecificLogic))]
MichaΕ Komorowski
source share