is not that hard. You can add a factory method to the static class to create the dependency, and change the factory method at test-time.
Here's an example:
[csharp]
public static class WithDependencies
{
public static string MethodWithDependencies()
{
using (var thing = new HardCodedThing())
{
return DoSomething();
}
}
}
[/csharp]
which can be turned into:
[csharp]
public static class WithDependencies
{
public static Func<HardCodedThing> CreateHardCodedThing = () => new HardCodedThing();
public static void MethodWithDependencies()
{
using (var thing = CreateHardCodedThing())
{
DoSomething();
}
}
}
[/csharp]
With this code in your test:
[csharp]
[TestFixture]
public class WhenDoingSomething
{
private Mock<HardCodedThing> mockThing;
[SetUp]
public void SetUpMockThing()
{
// mockThing.Setup( ... ) ... etc ...
}
public void Given_hardcodedthing_does_X_should_get_Y()
{
//Arrange
WithDependencies.CreateHardCodedThing = () => mockThing.Object;
//Act
var result= WithDependencies.MethodWithDependencies();
//Assert
Assert.AreEqual("Y", result);
}
}[/csharp]
Easy to follow, readable…heck I had developed to leave a commment!