gpt4 book ai didi

以StorageFile为参数的C#测试方法

转载 作者:行者123 更新时间:2023-11-30 15:36:06 25 4
gpt4 key购买 nike

首先,这是一个 Microsoft Store winrt 库,我正在尝试使用此签名测试一个公共(public)方法:

string GetStringFromFile(StorageFile storageFile);

但是 StorageFile 没有构造函数,所以我无法在我的 NUnit 测试代码中创建它。另外,我想我不能在 WinRt 上使用 Moq 或任何其他 Mocking 库。

我一直在寻找从 IStorageFile 接口(interface)创建一个手工制作的假货​​,但它内部有很多方法,我再次坚持另一个深层属性,指出 StorageFile< 中没有公共(public)构造函数的类 作为示例中的 ImageProperties

那么...使用 StorageFile 和/或 ImageProperties 类测试方法的最佳方法是什么?

最佳答案

StorageFile 类实现了一个接口(interface) IStorageFile所以你应该改变你的依赖,然后你可以使用模拟或 stub (如果你不能使用 Moq 等,可能是你创建的类)。

关于以StorageFile为参数的C#测试方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14085697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com