5

Similar to this question about NSubstitute, I want to know if one is able to implement partial mocks using the FakeItEasy library.

FakeItEasy seems to have an overall nicer syntax than moq (like the strongly-typed way the former deals with passing parameters to a constructor of a faked class). I'm thinking about switching to FakeItEasy, but I really need partial mock support.

Community
  • 1
  • 1
rsenna
  • 11,775
  • 1
  • 54
  • 60

1 Answers1

6

Yes. Syntax is no different than regular fake:

var fake = A.Fake<Fake>();
A.CallTo(() => fake.SomeMethod()).CallBaseMethod();

Or, to override all calls with base calls:

var fake = A.Fake<Fake>();
A.CallTo(fake).CallBaseMethod();

Edit Just to make clear: the fake object must be created over a concrete class.

rsenna
  • 11,775
  • 1
  • 54
  • 60
k.m
  • 30,794
  • 10
  • 62
  • 86
  • 1
    I needed to use var fake = A.Fake(); (the concrete object instead of the interface) and make SomeMethod virtual before I got it working (v 1.8.0). – AlignedDev Feb 25 '13 at 19:30
  • @Aligned: you're right, the fake object must be created over the concrete class. I'll edit jimmy_keen's answer in order to make that clear. – rsenna Feb 28 '13 at 19:05