Rhino Mocks 中不区分大小写的期望
我正在使用 Rhino Mocks 等待电话。有一个参数,它是一个字符串。但我并不关心字符串的大小写。即使情况是错误的,我也希望测试能够通过。所以我正在做以下事情:
//expect log message to be called with a string parameter.
//We want to ignore case when verifying so we use a constraint
//instead of a direct parameter
Expect.Call(delegate { logger.LogMessage(null); })
.Constraints(Is.Matching<string>(x => x.ToLower()=="f2"));
这似乎有点啰嗦。有更明智的方法吗?
I'm using Rhino Mocks to expect a call. There is a single parameter which is a string. But I'm not bothered about the case of the string. I want the test to pass even if the case is wrong. So I'm doing the following:
//expect log message to be called with a string parameter.
//We want to ignore case when verifying so we use a constraint
//instead of a direct parameter
Expect.Call(delegate { logger.LogMessage(null); })
.Constraints(Is.Matching<string>(x => x.ToLower()=="f2"));
It seems a bit long-winded. Is there a more sensible way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不关心参数而只关心方法调用:
If you don't care about parameters but just the method call:
我会使用 @Darin 建议的 AAA 格式(或类似格式)。我认为它更简洁,但我认为您仍然必须使用相同的基本约束来进行不区分大小写的匹配。辅助方法可以使其更具可读性。
I would use the AAA format that @Darin suggests (or similar). I think it's more concise, but you'll still have to use the same basic constraint for case insensitive matching, I think. A helper method can make this more readable.