2009-06-26 77 views
1

我是使用NUnit和ReSharper從TDD和AAA透視圖開發RhinoMocks的敏銳用戶。我正在改變工作,我正在轉移到的團隊使用TypeMock,所以我想要開始運行......而且我遇到了問題。如何獲取模擬對象上的調用方法的參數。當使用RhinoMocks我使用:獲取被調用的Typemock模擬方法的參數

mockObject.GetArgumentsForCallsMadeOn(x => x.MethodIWantToGetParametersFrom(null)) 

它返回一個IList類型的對象數組。大!我去得到我想要的,並按我的願望處理它。現在使用TypeMock的AAA語法,我似乎無法找到一種方法來做到這一點...任何人都可以對此有所瞭解嗎?我應該以不同的方式做嗎?

感謝您的閱讀,我期待您的回覆!

亞當

回答

1

你可以使用DoInstead():

Isolate.WhenCalled(()=>x.MethodIWantToGetParametersFrom).DoInstead(context => Console.WriteLine(context.Parameters[0].ToString()) 

你得到一個包含帕拉姆值的上下文對象。

還可以實現具有相同名稱的方法在自己的班級,和交換從僞裝對象到方法調用:

class MyOwnClass 
    { 
    void MethodIWantTOGetParametersFrom(string s){ 
Console.WriteLine(s); 
} //this is NOT the real method 
    } 

    //in test: 
    MyOwnClass own = new MyOwnClass(); 
    Isolate.Swap.CallsOn(realClassInstance).WithCallsTo(own); //only methods that are implemented in the OwnCalss will be redirected. others will be called on the original instance. 
+0

優秀。非常感謝你。 – Adam 2009-06-28 18:06:15

相關問題