Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I Change Default Behavior For All Shims In A Test

I'm currently writing unit tests using Microsoft Fakes framework. I've noticed that if I don't supply a delegate for a given property, the default value is returned. However, when initializing my shim I change this behavior to NotImplemented.

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

This is the given behavior I want for all my shims I define. I'd like to be able to set this default at a more global level, instead of having to remember to do it for every shim I create. Is this possible?

like image 323
Brett Janer Avatar asked Nov 11 '22 08:11

Brett Janer


1 Answers

According to documentation, the following code snippet could help you:

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

     var myShim = new ShimMyClass
     { 
         ... 
     }
}

However, it doesn't work on my machine with VS2012. Perhaps it is a bug.

like image 62
Monsignor Avatar answered Nov 14 '22 23:11

Monsignor