【发布时间】:2018-04-07 00:04:54
【问题描述】:
我有一个带有单元测试项目的 UWP C# 应用。在这些单元测试中,我希望能够写入文本文件以制作类似snapshots in Jest 的内容。
Directory.GetCurrentDirectory() 返回C:\path\to\project\bin\x64\Debug\AppX,所以我在项目目录中创建了一个文件夹并导航到它,然后尝试在那里创建一个文件。
[TestMethod]
public void Test()
{
var folder = Path.Combine(Directory.GetCurrentDirectory(), "../../../../Snapshots");
string data = "example data";
string filename = Path.Combine(folder, "Test.snap");
File.WriteAllText(filename, json);
}
但是,此测试会生成 System.UnauthorizedAccessException。我进入 Windows 中的文件夹并授予每个人读/写权限,但这没有任何区别。
我不想以管理员身份运行 Visual Studio。这可能吗?
【问题讨论】:
标签: c# .net visual-studio uwp mstest