Search The Blog
Latest Posts
from 5whys.com
Twitter: @RoyOsherove
About this site

TDD in .NET Online Course

TDD and BDD in Ruby Online Course

 

Subscribe!

This site aims to connect all the dots of my online activities - from tools, books blogs and twitter accounts, to upcoming conferences, engagements and user group talks.

« Video: (part 7 - The bug that wouldn't die) Go Game Engine with TDD and Pair Programming | Main | Video: (part 6 - Total n00b mistakes) Go Game Engine with TDD and Pair Programming »
Sunday
Jul082012

Faking static methods in Moq, FakeItEasy and NSubstitute might be closer than imagined

Update: the version that works with .net 4.0 is here (link to InjecttionExample3.zip in that page). the examples from the link below work in .net 3.5 and under.

While I was doing my TDD course at Soluto this week, One of the architects, Shai, Found an interesting article on CodeProject that shows how to change the pointer of a managed method in C# to redirect to a different method.

They even tried it and showed it can work to allow changing the behavior of a static method by intercepting it. This does not use the profiler API at all (like typemock or Justmock do), but it is a non-safe (unsafe) way to do it in a managed way.

This needs more examination, but if this works out, it could be the beginning of a new era of unconstrained Isolation frameworks in .NET, that are fully open source. It’s not just static methods that can be replaced, and that’s where it gets REALLY interesting.

Let’s keep our fingers crossed, and I expect the devs of Moq, FakeItEasy and NSubstitue to work on that. If they don’t , I certainly will!

PrintView Printer Friendly Version

Web Analytics