DiyMocksVMoq

November 30, 2010
Any Moq fanboys online? I have a scenario I can't figure out if Moq supports.

A method in the Mock being called from the the class under test is:
  void Receive<T>(int batchSize, Action<T> action);

and the class under test passes in a private method as the action parameter. Ideally, the Mock should invoke the passed method to further exercise the class under test, but I can't find support for this.

...

Ended up with DIY:

    public class FauxTransport : ITransport
{
private readonly Queue<Order> _orders;

public FauxTransport(Queue<AutoFulfillmentOrder> orders)
{
_orders = orders;
}

public void Receive<T>(int batchSize, Action<T> action)
{
for (int i = 0; i < batchSize; i++)
{
action.Invoke((T)(object)_orders.Dequeue());
}
}
}


tags: ComputersAndTechnology