Can I change the default behavior for all pads in the test

I am currently writing unit tests using the Microsoft Fakes framework. I noticed that if I did not provide a delegate for this property, the default value is returned. However, when initializing my pad, I change this behavior to NotImplemented.

var myShim = new ShimMyClass
{
    InstanceBehavior = ShimBehaviors.NotImplemented
}

This is the given behavior that I want for all my shims that I define. I would like to be able to set this default value on a more global level, instead of forgetting to do this for each gasket that is being created. Is it possible?

+4
source share
2 answers

, :

using (ShimsContext.Create())
{
     ShimBehaviors.Current = ShimBehaviors.NotImplemented;

     var myShim = new ShimMyClass
     { 
         ... 
     }
}

VS2012. , .

+1

, , .

protected static ShimBehavior Default = ShimBehavior.NotImplemented;

:

public ShimSuperClass
{
    InstanceBehavior = Default
}

, base()

0

Source: https://habr.com/ru/post/1540293/


All Articles