Tools – Free Typemock Isolator 2010 license

That’s true, Typemock is giving Isolator 2010 free licenses. All you need to do is:

  • have a Twitter account
  • follow Typemock in Twitter: @Typemock
  • twit from your personal twitter: just entered for a chance to win a free Isolator @typemock RT it to enter the double drawing.
  • Go ahead, last draw is tomorrow, 24/02, and it will be a double draw.

Good luck …

Typemock Isolator – Faking an internal static type and overriding a static method

In most common samples about faking static types, the type itself is public as the static methods are too.

Usually programmers tend to expose all members that going to be targeted by an Unit test. Well, that’s not how I see Unit tests.

I always try to produce code to keep the cyclomatic complexity lower, and If I succeeded I ended up with types that can be easily tested.

I won’t expose code simply to test it, code should always have the minimum visibility that it indeed requires.

Then I rely on tools to test all my type members, either private, internal or public.

Currently I use the Typemock Isolator and I must say that I’m completely satisfied.

So, here’s how I faked an internal static type and also override it’s GetString method to allow me test the first parameter value:

Type globalizationHelperType = Type.GetType("NG.Helper, NG", true);
Isolate.Fake.StaticMethods(globalizationHelperType);
Isolate.WhenCalled(() => globalizationHelperType.GetMethod("GetString", new Type[] { typeof(String) }).Invoke(null, new object[] { null })).DoInstead((callcontext) => { return callcontext.Parameters[0]; });