I would like to mock this action in 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(...). 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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.