Declined
Last Updated: 12 Oct 2018 10:25 by ADMIN
Nick
Created on: 02 Oct 2017 10:01
Type: Feature Request
0
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;

reg

  .UsingThis(new object())

  .UsingThat<int>();

Currently, a test on the second call will fail if written against the mock assigned to 'reg'.
1 comment
ADMIN
Mihail
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: https://docs.telerik.com/devtools/justmock/basic-usage/create-mocks-by-example