如何在 NMock 中检查函数参数的属性
假设我在(NMock)中模拟了以下接口。我如何检查 email.Subject = 'xyz' ?
目前我正在做类似的事情
IEmailService s = mocks.NewMock<IEmailService>();
Expect.Once.On(s).Method("Send").With(?????)
s.Send(new Email { Subject = 'rarr' });
mocks.Verify...();
interface EmailService { void SendEmail(Email email); }
Say if i had the following interface mocked in (NMock). How could i check that email.Subject = 'xyz' ?
Currently im doing something like
IEmailService s = mocks.NewMock<IEmailService>();
Expect.Once.On(s).Method("Send").With(?????)
s.Send(new Email { Subject = 'rarr' });
mocks.Verify...();
interface EmailService { void SendEmail(Email email); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Has.Property
匹配器,如下所示:或者您可以编写一个自定义匹配器来验证参数的类型是否为
Email
并且其Subject
属性具有正确的值。You can use a
Has.Property
matcher like this:Or you could write a custom matcher to verify that the argument is of the type
Email
and that itsSubject
property has the correct value.您想检查 With 中的主题吗?这对我来说很奇怪,因为您正在编写单元测试用例,所以不需要以这种方式验证您自己的测试用例,对吧?
Do you want to check Subject inside With? That's weird to me as you are authoring unit test cases, so there is no need to validate your own test case in this way, right?