开发者

How to check property of function argument in NMock

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开发者_Python百科").With(?????)

s.Send(new Email { Subject = 'rarr' });

mocks.Verify...();

interface EmailService { void SendEmail(Email email); }


You can use a Has.Property matcher like this:

IEmailService s = mocks.NewMock<IEmailService>();

Expect.Once.On(s).Method("Send").
    With(Has.Property("Subject", Is.EqualTo("rarr")));

s.Send(new Email { Subject = 'rarr' });
mocks.Verify...();

Or you could write a custom matcher to verify that the argument is of the type Email and that its Subject property has the correct value.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜