[英]Getting arguments of a called Typemock mocked method
我是RhinoMocks的敏銳用戶,使用NUnit和ReSharper從TDD和AAA角度進行開發。 我正在換工作,我要搬到的團隊使用TypeMock,所以我想實實在在地工作……我遇到了問題。 如何獲得模擬對象上被調用方法的參數。 使用RhinoMocks時,我使用:
mockObject.GetArgumentsForCallsMadeOn(x => x.MethodIWantToGetParametersFrom(null))
返回一個IList類型的對象數組。 大! 我去得到想要的東西,並按照自己的意願進行處理。 現在,使用TypeMock的AAA語法,我似乎無法找到一種方法來做到這一點……請問有人對此有所了解嗎? 我應該做不同的事情嗎?
感謝您的閱讀,我們期待您的回復!
亞當
您可以使用DoInstead():
Isolate.WhenCalled(()=>x.MethodIWantToGetParametersFrom).DoInstead(context => Console.WriteLine(context.Parameters[0].ToString())
您將獲得一個包含參數值的Context對象。
您還可以在自己的類上實現一個具有相同名稱的方法,並將調用從偽造的對象交換到該方法:
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.