Ayende @ Wiki

Discuss: Rhino Mocks The Do() Handler

Discussion for Rhino Mocks The Do() Handler.
2008/01/03 03:16 by kasajian
Simpler syntax with C# 3.0
Using Lambdas instead of explicit private method.

BEFORE:
public void SayHelloWorld()
{
  INameSource nameSource = mocks.CreateMock();
  Expect.Call(nameSource.CreateName(null,null)).IgnoreArguments().
      Do(new NameSourceDelegate(Formal));
  mocks.ReplayAll();
  string expected = "Hi, my name is Ayende Rahien";
  string actual = new Speaker("Ayende", "Rahien", nameSource).Introduce();
  Assert.AreEqual(expected, actual);
}

delegate string NameSourceDelegate(string first, string suranme); private string Formal(string first, string surname) { return first + " " +surname; }


AFTER:

public void SayHelloWorld()
{
....
  Expect.Call(nameSource.CreateName(null,null)).IgnoreArguments().
      Do( (NameSourceDelegate) ( (first, surname) => first + " " +surname) );
....
}

delegate string NameSourceDelegate(string first, string suranme); // Function Formal() no longer needed

ScrewTurn Wiki version 2.0 Beta. Some of the icons created by FamFamFam.