Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moq equivalent to Rhino Mock's GetArgumentsForCallsMadeOn

trying to inspect and argument and need to retrieve it. what is the equivalent in Moq? or a way to do it in Moq?

like image 790
Jon Erickson Avatar asked May 06 '11 15:05

Jon Erickson


1 Answers

figured it out, utilizing the callback functionality on the Mock Setup

int captured_int;

mocked_obj.Setup(x => x.SomeMethod(It.IsAny<int>()))
    .Callback<int>(x => captured_int = x);

if your method has multiple params

int captured_int;
object captured_object;

mocked_obj.Setup(x => x.SomeMethod(It.IsAny<int>(), It.IsAny<object>()))
    .Callback<int, object>((i, o) => {
                                         captured_int = i;
                                         captured_object = o;
                                     });

then you can do asserts on the captured values;

like image 150
Jon Erickson Avatar answered Oct 22 '22 02:10

Jon Erickson