我是新手,以前从未做过单元测试。
我制作了一个压缩文件和发送电子邮件的控制台应用程序。现在我想做单元测试。但我不确定我的代码是否可测试。
例如,我有一个名为 -
public static void readAndEmailCsvFiles(string filePath)
{
DirectoryInfo directory = new DirectoryInfo(filePath);
var files = directory.GetFiles("*.csv", SearchOption.AllDirectories);
var dirDate = string.Format("{0:yyyy-MM-dd HH-mm}", DateTime.Now);
bool isExists = System.IO.Directory.Exists(filePath + "\\" + "PROCESSED" + "\\" + dirDate);
if (!isExists)
{
System.IO.Directory.CreateDirectory(filePath + "\\" + "PROCESSED" + "\\" + dirDate);
}
try
{
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
{
foreach (var file in files)
{
Console.WriteLine("Processing File : " + file + "\n");
zip.AddFile(file.FullName, "");
zip.Save(Path.Combine(filePath, "PROCESSED", dirDate, file.Name) + ".zip");
sendEmail.SendMailMessage(Path.Combine(filePath, "PROCESSED", dirDate, file.Name) + ".zip");
}
}
foreach (var file in files)
{
File.Delete(file.FullName);
Console.WriteLine("");
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
如何为上述方法创建测试?