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]; });

No Comments