c# - 下载文件对话框的 Csharp 单元测试

标签 c# unit-testing download nunit

我正在尝试使用 csharp 编写单元测试来检查是否通过单击按钮下载了文件。我如何知道在单击导出按钮后是否打开了下载/保存对话框?

[TestMethod]
public void ExportMyFile()
{
    Home.GoToFilesPage();
    CommonFiles.ViewFile(0);
    CommonFiles.ClickExport();

    //int result = CommonFiles.ClickExport();
    //Assert.AreEqual(1, result); ???
}

public static class CommonFiles
{
    private const string ExportButton = "exportBtn";      

    public static void ClickExport()
    {
        Driver.Click(ExportButton);
    }
}

最佳答案

如果您使用 Windows 中的默认保存对话框,您可以使用 MS Fakes 来模拟它。您的模拟对象将能够告诉您它是否被调用。

关于c# - 下载文件对话框的 Csharp 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32147341/

相关文章:

java - 如何区分 "run all tests"和 "run just this test"?

c# - HttpClient 不使用 .NET Core 在 Windows 上发送客户端证书

c# - SSIS Http Get请求Json反序列化

c# - 在事件服务失败时仅重试一次服务调用逻辑帮助

c# - 单元测试单例

php - 强制下载附件而不是自动打开它

c# - 使用 C# 中的凭据登录到第三方网站

javascript - 单元测试 Angular HTTP 拦截器

html - 如何让用户下载 HTML 文件?

web-services - 如何从 ASMX Web 服务返回 HTTPResponse 到消费者网页