I've hit an impasse with Machine.Fakes. I cannot figure out how to mock an out parameter using only Machine.Fakes equipment. Because of a bug in RhinoMocks, I switched our mfakes adapter to FakeItEasy. As far as I can tell, any of the adapters should be interchangable.
The problem is that this caused the "out" tests to fail, things that looked like this no longer compile, because Arg was Rhino.Mocks.
The<IMembershipService>()
.WhenToldTo(x => x.CreateUser(Param<string>.IsAnything,
Param<bool>.IsAnything,
Param<object>.IsAnything,
out Arg<MembershipCreateStatus>
.Out(MembershipCreateStatus.UserRejected)
.Dummy))
.Return(user);
I tried using a "dummy" local variable, set to the same value the original Arg<T> param set it to, but this has caused my tests to fail -- it seems as though the value isn't being passed through! Arg<T> really had the solution, but I can't use it anymore, as it's part of Rhino.Mocks.
Since version 1.7.0 Machine.Fakes supports setting up
outandrefparameters in fake calls - when using the FakeItEasy or NSubstitute adapters. Thus, you don't have to use FakeItEasy directly any more. Alex' example can be simplified like this: