you*_*rrr 1 c# testing dictionary unit-testing nsubstitute
使用 NSubstitute,我如何匹配“任何”字典 - 只要它包含一组特定的键值对?
以下内容将匹配任何字典:
mockObject.Received().Method(Arg.Any<Dictionary<string, string>>());
但我希望能够匹配任何字典,只要它具有给定的键值对。例如,我想做类似的事情:
mockObject.Received().Method(Arg.Any<Dictionary<string, string>> { {"MyKey": "MyValue"} });
NSubstitute 中是否存在类似的东西?
啊,事实证明错误是使用Arg.Any而不是Arg.Is。
这对我有用:
mockObject.Received().Method(Arg.Is<Dictionary<string, string>>(x => x.ContainsKey("MyKey") && x["MyKey"] == "MyValue"));
| 归档时间: |
|
| 查看次数: |
1606 次 |
| 最近记录: |