Skip to content

Instantly share code, notes, and snippets.

@joshka
Created March 6, 2011 01:51
Show Gist options
  • Save joshka/856939 to your computer and use it in GitHub Desktop.
Save joshka/856939 to your computer and use it in GitHub Desktop.
public static class ClassToBeTested
{
public static void DoSomething(int input, AnotherCrazyPublicStaticClass staticClass)
{
var result = staticClass.MethodToBeMocked(input); // go hit the database, network, web services, file and everything else you can imagine.
// now some business logic that I want to test
// 400 lines of code
// if result is blah do x otherwise do y
// 20 foreach loops each one with 2 nested loops and 10 if conditions.
}
}
// note class is no longer static
public class AnotherCrazyPublicStaticClass
{
// instance method replacing previous static MethodToBeMocked()
public virtual int MethodToBeMocked(int input)
{
// go hit the database, network, web services, file and everything else you can imagine.
return 0;
}
}
public class MockCrazy : AnotherCrazyPublicStaticClass
{
public override int MethodToBeMocked(int input)
{
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment