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.
Indeed, what your StaticMocks library requires from the SUT seems to be fairly close to what I ended up doing. There still seems to be some clever wizardry going on that I can't quite figure out ๐
What would I have done if I could change the body of
GetUpperText
? Well, used proper dependency injection!My next step, if I could change things even more around, would be to make
CodeUnderTest
a proper class, so that I could use Constructor Injection instead of Method Injection.Going even further, if I could change things arbitrarily, would be to migrate to F# and get rid of the sorry mess altogether, but that's a different story ๐
While I agree with Greg, I consider this challenge as a stand-in for a more complicated problem, so I'm not so worried about 'testing that
ToUpperInvariant
works' ๐