我有备份某些文件的方法:
public void MakeBackup(IFileWrap file, string path)
{
if (path == null)
throw new ArgumentNullException();
Console.WriteLine();
string backups = Environment.CurrentDirectory + @"\Backups\";
if (!Directory.Exists(backups))
Directory.CreateDirectory(backups);
if (file.Exists(path))
{
file.Copy(path,backups + Path.GetFileName(path),overwrite: true);
Console.WriteLine("Backup of the " + Path.GetFileName(path) + " lies in the " + backups);
}
}
我正在尝试使用 SystemWrapper 和 Rhino Mocks 对其进行测试:
[TestMethod]
public void MakeBackupTest()
{
IFileWrap fileRepository = MockRepository.GenerateMock<IFileWrap>();
fileRepository.Expect(x => x.Exists(@"G:\1.txt"));
fileRepository.Expect(x => x.Copy(@"G:\1.txt", Environment.CurrentDirectory + @"\Backups\1.txt", overwrite: true));
new Windows().MakeBackup(fileRepository,@"G:\1.txt");
fileRepository.VerifyAllExpectations();
}
上面的测试失败了。我究竟做错了什么?