public void AddFile(bool fileExists, bool keepFile)
{
string directory = TempDirectory();
const string FileName = "file.extension";
string filePath = Path.Combine(directory, FileName);
if (fileExists)
{
File.Create(filePath).Dispose();
}
try
{
using (var collection = new TempFileCollection(directory))
{
// AddFile(fileName) is a misnomer, and should really be AddFile(filePath),
// as only files added with their full path are deleted.
collection.AddFile(filePath, keepFile);
Assert.Equal(fileExists, File.Exists(filePath));
}
Assert.Equal(fileExists && keepFile, File.Exists(filePath));
}
finally
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
}
}