Moq如何替换过时的表达 [英] Moq how to replace obsolete expression

查看:59
本文介绍了Moq如何替换过时的表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中使用了Moq.我写了一个像这样的表达式:

I'm using Moq in my code. I wrote an expression like:

mockInvoice.VerifySet(x => x.InvoiceAttachmentId, Times.Once());

InvoiceAttachmentId是发票上的属性.

它工作正常,但我得到警告:

It works fine but I get the warning:

Moq.MockExtensions.VerifySet(Moq.Mock, System.Linq.Expressions.Expression>, Moq.Times)"已过时:由VerifySet(Action,Times)取代"

Moq.MockExtensions.VerifySet(Moq.Mock, System.Linq.Expressions.Expression>, Moq.Times)' is obsolete: 'Replaced by VerifySet(Action, Times)'

有人可以告诉我如何重写它以满足编译器的要求并摆脱警告吗?我不确定如何替换Action.

Can anyone tell me how to rewrite it to satisfy the compiler and get rid of the warning? I'm unsure how to make the replacement to Action.

推荐答案

mockInvoice.VerifySet(x => x.InvoiceAttachmentId = 123, Times.Once());

用期望值替换123.

如果要允许任何值,请使用:

If you want to permit any value, use:

mockInvoice.VerifySet(x => x.InvoiceAttachmentId = It.IsAny<int>(),
    Times.Once());

这篇关于Moq如何替换过时的表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆