有人建议我按照嘲弄来测试一些方法。我必须像 5 一样多次运行这个模拟。我想知道它是否可以在 lambda 表达式中完成,或者我必须循环它。谢谢
//when you know the parameter values to expect
mockEmailRequest.Verify(r=>r.EmailRecevied(expectedEmail, expectedId));
//when you just want to verify some detail about the values
mockEmailRequest.Verify(r=>r.EmailRecevied(It.Is<EmailResponse>(r=>r.Subject == "Something"), It.Is<int>(i=>i > 17)));
您应该使用以下代码:
mockEmailRequest.Verify(r=>r.EmailRecevied(It.Is<EmailResponse>(r=>r.Subject == "Something"), It.Is<int>(i=>i > 17)), Times.Exactly(5));