public void Test_Performance_WithFilledExcelFile()
{
// given
var lorenzBahlsenCicToExcelJobWorker = new LorenzBahlsenCicToExcelJobWorker();
var environment = new TestEnvironment(lorenzBahlsenCicToExcelJobWorker, nameof(Test_Performance_WithFilledExcelFile));
string binDirectory = Path.GetDirectoryName(GetType().GetTypeInfo().Assembly.Location);
var testFile = Path.Combine(binDirectory, "TestFiles", CICSynchronisedTestFile);
var excelFileCurrent = Path.Combine(binDirectory, "TestFiles", "next_delivery.xlsx");
var excelFolderTarget = environment.EnvironmentDataStoragePath;
File.Copy(excelFileCurrent, excelFolderTarget);
}
我对复制文件有疑问,为什么要在将文件复制到目标位置时出现异常:
“无法加载指定的文件”
但是,当我调试代码时,我有一个异常:
目标文件 'C:\ Project \ lorenz-bahlsen \ LorenzBahlsen.CICtoExcel.Test \ bin \ Debug \ netcoreapp1.1 \ Environments \ Test_Performance_WithFilledExcelFile \ data-storage' 是目录,而不是文件。'
您能帮我找到解决方法吗?
答案 0 :(得分:0)
根据documentation,File.Copy期望您将提供目标文件名,而不是文件夹名。 因此,在您的示例中为:
public void Test_Performance_WithFilledExcelFile()
{
// given
var lorenzBahlsenCicToExcelJobWorker = new LorenzBahlsenCicToExcelJobWorker();
var environment = new TestEnvironment(lorenzBahlsenCicToExcelJobWorker, nameof(Test_Performance_WithFilledExcelFile));
string binDirectory = Path.GetDirectoryName(GetType().GetTypeInfo().Assembly.Location);
var testFile = Path.Combine(binDirectory, "TestFiles", CICSynchronisedTestFile);
var excelFileCurrent = Path.Combine(binDirectory, "TestFiles", "next_delivery.xlsx");
var excelFolderTarget = environment.EnvironmentDataStoragePath;
var destinationFile = Path.Combine(excelFolderTarget, "next_delivery.xlsx");
File.Copy(excelFileCurrent, destinationFile);
}