The Stub
call sets up an optional Expect
call. The function passed to Stub
(x => x.GetUserByName("ayende")
, in this instance) is actually executed against the mock object (which is a Castle DynamicProxy object). The call is intercepted and recorded in the MockRepository
, with its parameters, as an expectation. An IMethodOptions<>
object is generated from data saved about the call and returned, which Return(theUserObject)
is subsequently called on.
You can use something like dotPeek to disassemble and examine Rhino.Mocks.dll in more detail; the relevant code is in RhinoMocksExtensions.cs
, in the Rhino.Mocks
namespace.