[英]Mock a lambda parameter in Moq
I would like to mock this action in Moq: 我想在Moq中嘲笑这个动作:
Action<string, long> cursorPersister;
I have tried to implemented in this way: 我试图以这种方式实现:
var cursorPersister = new Mock<Action<string, long>>();
cursorPersister.Setup(cp => cp.Invoke(It.IsAny<string>(), It.IsAny<long>()));
cursorPersister.Verify();
However it does not work. 但它不起作用。 Program freeze on the line where I call Setup(...).
程序在我调用Setup(...)的行上冻结。 Anyone can explain this and offer an alternative approach?
任何人都可以解释这个并提供另一种方法吗?
Problem solved. 问题解决了。 Instead of
代替
cursorPersister.Setup(cp => cp.Invoke(It.IsAny<string>(), It.IsAny<long>()));
Use 采用
cursorPersister.Setup(cp => cp(It.IsAny<string>(), It.IsAny<long>()));
Just create a method with a string and long parameters and pass it instead of the mock. 只需使用字符串和长参数创建一个方法,然后传递它而不是模拟。 Why do you want to mock it?
你为什么要嘲笑它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.