The Test File System pattern puts file-path calculation behind a helper, so test automation can handle input, output, and temporary files without embedding environment-specific path logic. section 21.3
When cleanup misses the working directory
A high-privilege test run wrote files under C:\Windows\System32, outside the cleanup job’s watched location; accumulated files eventually filled the server disk. section 21.3
Listing 21.6 Helper class to access test file system details
*** Support/TestFileSystem.cs ***
public class TestFileSystem(IFeatureContext featureContext,
IScenarioContext scenarioContext) #A
{
public static readonly string TestRunTimestamp = #B
ToPath(DateTime.Now.ToString("s", CultureInfo.InvariantCulture));
public string OutputFolder => #C
EnsureFolderExists(
Path.Combine(Directory.GetCurrentDirectory(), TestRunTimestamp));
public string InputFolder => #D
AppContext.BaseDirectory;
public string FeatureInputFolder => #E
Path.Combine(InputFolder, featureContext.FeatureInfo.FolderPath);
public string TempFolder => #F
EnsureFolderExists(
Path.Combine(Path.GetTempPath(), "WIMP", TestRunTimestamp));
public string GetScenarioSpecificFileName( #G
string extension = "")
{
string featureAsPath = ToPath(featureContext.FeatureInfo.Title);
string scenarioAsPath = ToPath(scenarioContext.ScenarioInfo.Title);
string baseFileName = $"{featureAsPath}_{scenarioAsPath}";
if (scenarioContext.ScenarioInfo.Arguments is { Count: > 0 })
{
foreach (DictionaryEntry entry in
scenarioContext.ScenarioInfo.Arguments)
{
baseFileName += $"_{entry.Key}-{entry.Value}";
}
}
return baseFileName + extension;
}
public static string ToPath(string s) #H
{
...
}
public static string EnsureFolderExists(string path) #I
{
...
}
}The helper exposes input, feature-input, output, and temporary folders; automation can receive it through scenario-context dependency injection. section 21.3
