我RhinoMocks敏锐的用户从TDD和AAA透视使用Nunit和ReSharper的发展。我换工作,我移动到团队使用TypeMock所以我想旗开得胜......和我所遇到的一个问题。我怎样才能得到一个模仿对象上调用方法的参数。当使用RhinoMocks我使用:

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

它返回类型的对象阵列的IList的。大!我去得到我想要的东西,并处理它我多么希望。现在,使用TypeMock的AAA语法我似乎无法找出一种方法来做到这一点...谁能一些线索这吗?我应该做不同呢?

感谢您的阅读,我期待你的答复!

亚当

有帮助吗?

解决方案

可以使用DoInstead():

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

您获取包含PARAM值的上下文对象。

您还可以实现在自己的类具有相同名称的方法,并交换电话从伪装对象来表示方法:

 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归因
不隶属于 StackOverflow
scroll top