I am new (as of today) to NUnit and TDD. However, I am very interested in the technique and I am trying to learn. I have a test case I would like to read from a file if it exists, otherwise I will grab from the registry. How do I test both conditions? Here is an example of the code I would like to write a test case for:
public static string ReferenceDirectory
{
get
{
string referenceDir = Path.Combine(_summitDataDirectory, REFERENCES_DIR); ;
//If Windows Compliant data location does not exist, fall back on registry values
if (!Directory.Exists(referenceDir))
referenceDir = Path.Combine(GetRegistryValue("appPath"), @"Data\Databases\");
return referenceDir;
}
}
What I'm confused about is do I have to create two test cases: one in which I create the directory and another in which I remove the directory and read from registry? Also, at some point the registry will be cleaned and the value no longer will be in the registry which will mean this code is no longer valid unless I create the value in the registry.
To provide larger context, this code is for migrating our app to Vista/Win7 and thus I need to support the legacy path to the registry until all users are migrated.
Note: specific test code examples would be helpful as I'm completely new to NUnit.
EDIT: Modified code example based on comments.