Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks IgnoreArguments() and testing if a lambda was called correctly

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 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:

How to assert that an action was called

but my Action 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?

like image 824
Mark W Avatar asked Nov 05 '22 05:11

Mark W


1 Answers

The UpdateData should be virtual otherwise rhino mock can not overwrite method

like image 128
andreyi Avatar answered Nov 15 '22 00:11

andreyi