Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Moq Return value using lambda

Is it possible to return different results based on the input, like in

MoqSecurityAdminHelper.Setup(x => x.GetAllQuestions(It.IsAny<Boolean>()))     .Returns(new Dictionary<String, String>     {         {"Key1", "Value1"},         {"Key2", "Value2"}     }); 

but if the argument is true return one result, if false... another.

Or is the only way to do it having 2 separate setups?

Thanks

like image 608
kooshka Avatar asked Feb 24 '12 09:02

kooshka


1 Answers

MoqSecurityAdminHelper.Setup(x => x.GetAllQuestions(It.IsAny<Boolean>()))                       .Returns((bool param) => param ?                                            someResult :                                            someOtherResult ); 
like image 55
Ufuk Hacıoğulları Avatar answered Sep 25 '22 14:09

Ufuk Hacıoğulları