public class Handler
{
...
public void HandleSomethingHappened()
{
_list.ForEachEntry(OnAction);
}
private void OnAction(IEntry entry)
{
entry.DoSomething();
}
...
}
And your test code will have something similar:
[TestMethod]
public void AssertingThatDoSomethingWasCalledForEachEntry()
{
IListOfEntries entriesMock = MockRepository.GenerateMock<IListOfEntries>();
Handler handler = new Handler(entriesMock);
handler.HandleSomethingHappened();
entriesMock.AssertWasCalled(x => x.ForEachEntry(OnAction));
}
private void OnAction(IEntry entry)
{
entry.DoSomething();
}
As you can see, once all these lambdas are compiled into something the
compiler can use, they're actually two totally different methods --
which is why your unit test is failing. You're calling two different
methods (one is in your Handler class and one is in the Unit Test).
I think you need to re-think how to test this situation. In writing a
unit test for Handler.HandleSomethingHappened(), you'll just want to
make sure that it calls IList.ForEachEntry(). A separate unit test on
the implementation of IList.ForEachEntry() should make sure that the
Action<T> passed in is executed for each item.
Hope this helps.
---
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.
>
>
On Jun 10, 2010, at 5:23 PM, Patrick Steele <patrick...@gmail.com>
wrote: