I’ve added a new way to create fake objects in FakeItEasy. You might call the “traditional” way of doing it in FakeItEasy is the “Rhino-style”:
public static void TraditionalWay() { var foo = A.Fake<IFoo>(); foo.Configure().CallsTo(x => x.Baz()).Returns(10); int value = foo.Baz(); Fake.Assert(foo).WasCalled(x => x.Baz()); }
When creating fakes in this way the returned faked object is of the type specified in the A.Fake-call, faking an IFoo returns an IFoo. When creating a fake the new way, which we might call the “Moq-style” you instead create a fake object that provides an api for configuring the faked object as well as a reference to the faked object:
public static void TheOtherWay() { var foo = new Fake<IFoo>(); foo.CallsTo(x => x.Baz()).Returns(10); int value = foo.FakedObject.Baz(); foo.Assert().WasCalled(x => x.Baz()); }
Both styles are equally supported so that the developer can choose what ever style he/she is most comfortable with.
No comments:
Post a Comment