2009-06-26 39 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

相关问题