views:

649

answers:

2

No matter how I try, I cannot mimic the clean syntax of Rhino Mocks, without declaring a delegate.

Example:

Expect.Call(service.HelloWorld("Thanks"))

Do you have any idea on how to do this?

Thanks.

+6  A: 

Using Lambda syntax in 3.5 you can get a similar syntax.

public void Call(Action action)
{
    action();
}

Expect.Call(() => service.HelloWorld("Thanks"));

Moq is a mocking framework that uses Lambda syntax for it's mocking.

var mock = new Mock<IService>();
mock.Setup(service => service.HelloWorld("Thanks")).Returns(42);
Cameron MacFarland
+5  A: 

You could use the Action delegate provided in newer versions of .NET

void Execute(Action action) {
    action();
}

void Test() {
    Execute(() => Console.WriteLine("Hello World!"));
}
Simon Svensson