Last Updated: 12 Oct 2018 10:25 by ADMIN
Created on: 02 Oct 2017 10:01
Type: Feature Request
Allow simple mocking of fluent interfaces
If I define a fluent API, I might have an interface such as this:

public interface IRegistrar { 

IRegistrar UsingThis(object someThing);

IRegistrar UsingThat<TThatThing>() }

If I create a mock of this using the default Behaviour.RecursiveLoose and make no arrangements, calls to the methods will return new mocks of the type, rather than the same instance that was called. 

It would be nice to have a behaviour type that can return the same instance (in this case the mocked instance) without having to define a stub for each method call.

My code under test might look like:

IRegistrar reg;


  .UsingThis(new object())


Currently, a test on the second call will fail if written against the mock assigned to 'reg'.
1 comment
Posted on: 12 Oct 2018 10:25
Hello Nick, it is a bit late response for which I want to apologize.

For your scenario, you could use the "create by example" approach to arrange your interface. Here is a link to our documentation where you could find more information: