c# - 使用 Moq 测试采用结构的方法
问题描述
我有以下方法需要测试
public class S2SJwtGenerator : BaseJwtGenerator, IS2SJwtGenerator
{
public S2SJwtGenerator();
public string Generate(string tenantId, string username, TimeSpan lifetime);
}
我需要模拟生成。
protected readonly Mock<S2SJwtGenerator> tokenGen = new Mock<S2SJwtGenerator>();
var ts = new TimeSpan(1,1,1);
tokenGen.Setup(x => x.Generate(_testTenantId,null, ts)).Returns("NEWTOKEN");
我不断收到 notSupported 错误。
我尝试使用
tokenGen.Setup(x => x.Generate(_testTenantId,null, It.Ref<TimeSpan>.IsAny)).Returns("NEWTOKEN");
我仍然不受支持。TimeSpan
是一个结构。我怎样才能让它工作
解决方案
推荐阅读
- pycharm - 更新使用 Flatpak 运行的 PyCharm
- excel - 到今天和其他日期的日期比较
- java - 如何在 RestTemplate (Spring) 中最后执行 ClientHttpRequestInterceptor
- r - 闪亮:主面板中的多个条件面板不起作用
- xcode - 用于 Cordova、Xcode 10 和模拟器的 Visual Studio 工具
- algorithm - 检查两个 3d 网格是否在有效时间内相等
- python - 在没有函数调用的情况下如何启动函数?
- android - 数据绑定到 MutableList 中复杂类型的对象
- api - 使用python脚本从机器人框架api中删除report.html输出的红色/绿色的任何方法
- css - 停止在 Big Cartel 网站上滚动标题图片