The rules are:
- It must be a unit test (so don't touch the file system).
- The public signature for
CodeUnderTest
must not be changed.can be extended not reduced - You're allowed to use DI/your favorite mocking framework.
- You can only add code where you see /**/.
[Test]
public void Test()
{
/**/
var text = CodeUnderTest.GetUpperText("foo.txt" /**/);
Assert.That(text, Is.EqualTo("BAR"));
/**/
}
public class CodeUnderTest
{
/**/
public static string GetUpperText(string path /**/)
{
var text = File.ReadAllText(path);
return text.ToUpperInvariant();
}
/**/
}
Please comment below or tweet me @jcansdale.
@ploeh,
You did have the option of doing this: 😄
I understand that starting a parameter with with a capital might break C# coding convention, but I might be inclined to bend this rule because it makes it pretty clear what it's a stand-in for.
If you have time, I'd be interested to see what this (and the test) would look like in F#. Would it make it that much cleaner? I've dabbled with F#, but I'd be interested to see how an F# advocate would code it.
The idea behind StaticMocks is that it allows you to do dependency injection of static methods whilst barely touching the target code (baring a single line private nested class). I think this is useful for some commonly used static classes (e.g. File), when I don't particularly want to create/implement a public interface just so that I can test my code.