2

How do I translate this moq code:

fooMoq.Setup(x => x.SayHello("xxx")).Returns("hello").Callback((string name) =>
                {
                    Assert.AreEqual(name, "xxx");
                });

into FakeItEasy?

julianfperez
  • 1,726
  • 5
  • 38
  • 69
Hagai Cohen
  • 111
  • 1
  • 3
  • 10

3 Answers3

4
A.CallTo(() => fooMoq.SayHello("xxx")).Invokes((string name) => { Assert.AreEqual(name, "xxx"); }).Returns("hello");
Patrik Hägne
  • 16,751
  • 5
  • 52
  • 60
1

I think you have to do it like this:

A.CallTo(() => foo.SayHello("name")).Returns("hello");

BTW: Why do you want to use fakeiteasy, it looks to me less powerful than moq?

Fischermaen
  • 12,238
  • 2
  • 39
  • 56
  • 2
    How is it less powerful? If anything it's more powerful, but I's say they're pretty much equal. It's a matter of taste. – Patrik Hägne Dec 17 '11 at 12:25
  • 1
    Also power is not everything. Syntax is really important. One of the main reasons I switched from Rhino Mocks to FakeItEasy is the syntax which is much more readable. Some people are also using [NSubstitute](http://nsubstitute.github.com/) which looks nice. – Toni Parviainen Dec 21 '11 at 15:58
  • I think that FakeItEasy and MOQ are nearly the same (after I took a second look to FakeItEasy). At the time we had to decide which mocking framework we take in our company, MOQ was more powerful than all the others. They were the first using that lambda-syntax. After that decision I didn't look every month if something had changed on the other frameworks. You would only rewrite thousands of unit test to us another mocking framework, if you really have to change ! – Fischermaen Dec 21 '11 at 21:38
  • I found one point which FakeItEasy is superior to MOQ (besides cleaner syntax): partial mocks. Moq requires a loosely-typed object param array in order to call the partial mock constructor. FIE allows the actual constructor call, with strongly typed parameters. – rsenna Aug 16 '12 at 17:53
0

Try this:

A.CallTo(() => foofake.SayHello("name")).WithAnyArguments().Returns("xxx");     
var foo=new foo(foofake);    
var responseReturned=foo.Functioncall(name);
Assert.AreEqual(responseReturned, "xxx");
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sudipto Sarkar
  • 346
  • 2
  • 11