Testing if a lambda/action was called by a Mock

261 views
Skip to first unread message

Mark W

unread,
Feb 27, 2012, 12:35:55 PM2/27/12
to Rhino.Mocks
Here's what I have:

public interface IDataCenterMsmqWriter
{
void UpdateData(Action<DataCenterWcfProxy> action);
}

System under test:

public class WcfService : IWcfService
{
private readonly IDataCenterMsmqWriter _writer;

public WcfService(IDataCenterMsmqWriter writer)
{
_writer = writer;
}

#region IWcfService members

public void SendData(SomeData data)
{
_writer.UpdateData(d => d.SendVarData(data));
}

// other members of IWcfService elided
#endregion
}

How do I test with Rhino Mocks setting the _writer as a Mock and want
to test that the correct Action<DataCenterWcfProxy> was called in the
UpdateData method.

I've tried this:

// _writer is setup as a mock
var data = new SomeData();
_wcfServiceSUT.SendData(data);
_writer.AssertWasCalled(d => d.UpdateData(x =>
x.SendVarData(data));

doesn't work.

I can add the:

, p => p.IgnoreArguments() after the UpdateData inside the
AssertWasCalled, but that does not give me what I want, to make sure
SendVarData was called with the data variable.

I've looked at this:

http://stackoverflow.com/questions/6413040/rhino-mocks-how-to-assert-that-an-action-was-called

but my Action<DataCenterWcfProxy> isn't mocked like mockDialogService
in his example.

Is there a way to test if an Action or Func was called properly with
the right input parameters, etc?

Patrick Steele

unread,
Feb 28, 2012, 8:18:12 AM2/28/12
to rhino...@googlegroups.com
I can't wrap my head around a purely Rhino Mocks way of testing this.
The complexity is that your IDataCenterMsmqWriter.UpdateData method
will accept *any* void method that takes a DataCenterWcfProxy. I
assume you want to test that *only* the SendVarData method is called?

---
Patrick Steele
http://weblogs.asp.net/psteele

> --
> You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
> To post to this group, send email to rhino...@googlegroups.com.
> To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
>

Mark Wilkinson

unread,
Feb 28, 2012, 10:09:47 AM2/28/12
to rhino...@googlegroups.com
Yes that is correct, if that is possible of course.  For now I'm just doing Arg<T>.Is.Anything to get the tests to pass.


From: Patrick Steele <patrick...@gmail.com>
To: rhino...@googlegroups.com
Sent: Tuesday, February 28, 2012 7:18 AM
Subject: Re: [RhinoMocks] Testing if a lambda/action was called by a Mock
> To unsubscribe from this group, send email to rhinomocks+unsub...@googlegroups.com.

> For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages