NSubstitute:匹配任何带有显式参数的字典?

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 中是否存在类似的东西?

you*_*rrr 6

啊,事实证明错误是使用Arg.Any而不是Arg.Is

这对我有用:

mockObject.Received().Method(Arg.Is<Dictionary<string, string>>(x => x.ContainsKey("MyKey") && x["MyKey"] == "MyValue"));