CHAPTER 4
This will be the shortest chapter in the book by far, mainly because FakeItEasy makes it very easy for us to create a fake.
Creating a fake is very straightforward (we’ve already seen this done in previous sections of this book). Use A.Fake<T> in order to get your fake created. You can create a fake of an interface or class.
Faking an interface:
public interface IAmAnInterface { void DoSomething(); } [TestFixture] { [SetUp] public void Given() { var aFakeInterface = A.Fake<IAmAnInterface>(); } |
Code Listing 21: Creating a fake of an interface
Faking a class:
public class AClass { public virtual void DoSomething() { //some implementation } } [TestFixture] public class WhenFakingAClass { [SetUp] public void Given() { var aFakeClass = A.Fake<AClass>(); } } |
Code Listing 22: Creating a fake of a class
Following the rules outlined in Chapter 3, it’s pretty simple to create a fake. But now that we’ve created a fake, what exactly can we do with it?