You can also configure to return different values in multiple calls. The following example demonstrates this function by calling properties. The call methods are the same.
1 Public Interface Icalculator 2 { 3 Int Add ( Int A, Int B ); 4 String Mode { Get ; Set ;} 5 } 6 7 [Testmethod] 8 Public Void Test_multiplereturnvalues_returnmultiplevalues () 9 { 10 VaR Calculator = substitute. For <icalculator> (); 11 12 Calculator. mode. Returns ( " Dec " , " HEX " , " Bin " ); 13 Assert. areequal ( " Dec " , Calculator. mode ); 14 Assert. areequal ( " HEX " , Calculator. mode ); 15 Assert. areequal ( " Bin " , Calculator. mode ); 16 }
Of course, this method can also be done by using the function to return results, but passing multiple values to returns () seems easier and more readable.
Using callback to return multiple values returns () also supports passing multiple functions that create returned results, which allows you to call or throw exceptions in a series of calls or execute some actions.
1 [Testmethod] 2 [Expectedexception ( Typeof (Exception)] 3 Public Void Test_multiplereturnvalues_usingcallbacks () 4 { 5 VaR Calculator = substitute. For <icalculator> (); 6 7 Calculator. mode. Returns (x =>" Dec " , X => " HEX " , X => { Throw New Exception ();}); 8 Assert. areequal ( " Dec " , Calculator. mode ); 9 Assert. areequal (" HEX " , Calculator. mode ); 10 VaR Result = Calculator. mode; 11 }