In Visual Studio 2015, I have a test project to which I added a fake assembly.
In the unit test itself, I create a pad for a static universal method that returns an instance of a generic type, for example:
using (ShimsContext.Create()) { ShimStaticClass.TheMethod<MyType>(() => instanceOfMyType); // ... code that uses StaticClass.TheMethod here ... }
When the solution is built in debug mode, the test passes normally and passes. However, when the solution is built in release mode, the flashed version of TheMethod is not called, which leads to a test failure.
I know that the shimmed method is not called because I changed it to make an exception:
using (ShimsContext.Create()) { ShimForStaticClass.TheMethod<MyType>(() => { throw new InvalidOperationException("Shim was called"); }); // ... code that uses StaticClass.TheMethod here ... }
and this exception is not thrown.
I have included diagnostic logging and noisy verbosity for fake, but build logs do not indicate any problems.
source share