tags:

views:

72

answers:

2

Hi,

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); }
A: 

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?

Lex Li
I was actually doing an integration test. But i wanted to make sure that the object calling Send() was passing in the correct parameters.
mrwayne
Not sure if that's doable with NMock. Consider its own support page,http://www.nmock.org/support.html
Lex Li
A: 

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.

Jeff Sternal