【发布时间】:2009-11-05 18:55:13
【问题描述】:
如何检查接受字典的函数的参数?
IDictionary<string, string> someDictionary = new Dictionary<string, string> {
{"Key1", "Value1"},
{"Key2", "Value2"}
};
Expect.Call(delegate {someService.GetCodes(someDictionary);}).Constraints(...);
基本上,我想验证 GetCodes 的参数是否与变量“someDictionary”具有相同的值。
我忘了提到正在测试的方法会构建字典并将其传递给 someService.GetCodes() 方法。
public void SomeOtherMethod() {
IDictionary<string, string> dict = new Dictionary<string, string> {
{"Key 1", "Value 1"},
{"Key 2", "Value 2"}
};
someService.GetCodes(dict); // This would pass!
IDictionary<string, string> dict2 = new Dictionary<string, string> {
{"Key 1", "Value 1a"},
{"Key 2a", "Value 2"}
};
someService.GetCodes(dict2); // This would fail!
}
所以,我想确保传递给 GetCodes 方法的字典包含与 Expect.Call... 方法中指定的字典相同的字典。
另一个用例是,也许我只是想看看字典的键是否包含“键 1”和“键 2”,但不关心值......或者其他方式。
【问题讨论】:
标签: c# .net unit-testing mocking rhino-mocks