This is a migrated thread and some comments may be shown as answers.

Capture matcher value at runtime for .Returns

1 Answer 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 10 Jul 2013, 02:39 PM
Hi there.  I'm trying to figure out if there's a way to reference the runtime value of a matcher for use in a Returns call.  This seems like a pretty straightforward question, but I wasn't able to find quite what I'm wanting in the documentation, so apologies if I missed something obvious.  Regardless, here's the call I'm trying to make.

service.Arrange<Employee>(emp => emp.LoadByName(Arg.AnyString)).Returns(data.employees.Where(e => e.Name == /* whatever the value matched by Arg.AnyString was */));

Is there another method I should be calling to accomplish the same thing, or is there simply a way to reference the matcher's value?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 11 Jul 2013, 06:10 AM
Hello Jonathan,

Just pass a delegate to Returns that has the same number and type of arguments like the arranged method. Like so:

service.Arrange<Employee>(emp => emp.LoadByName(Arg.AnyString))
    .Returns((string name) => data.employees.Where(e => e.Name == name));


Regards,
Stefan
Telerik
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or