patterncsharpCritical
Returning value that was passed into a method
Viewed 0 times
returningmethodvaluethatpassedintowas
Problem
I have a method on an interface:
I want to mock this with MOQ, so that it returns whatever was passed in - something like:
Any ideas?
string DoSomething(string whatever);I want to mock this with MOQ, so that it returns whatever was passed in - something like:
_mock.Setup( theObject => theObject.DoSomething( It.IsAny( ) ) )
.Returns( [the parameter that was passed] ) ;Any ideas?
Solution
You can use a lambda with an input parameter, like so:
Or slightly more readable:
.Returns((string myval) => { return myval; });Or slightly more readable:
.Returns(x => x);Code Snippets
.Returns((string myval) => { return myval; });.Returns<string>(x => x);Context
Stack Overflow Q#996602, score: 777
Revisions (0)
No revisions yet.