【发布时间】:2013-01-11 15:48:01
【问题描述】:
我有以下课程:
public class HelperClass
{
HandleFunction<T>(Func<T> func)
{
// Custom logic here
func.Invoke();
// Custom logic here
}
// The class i want to test
public class MainClass
{
public readonly HelperClass _helper;
// Ctor
MainClass(HelperClass helper)
{
_helper = helper;
}
public void Foo()
{
// Use the handle method
_helper.HandleFunction(() =>
{
// Foo logic here:
Action1();
Action2(); //etc..
}
}
}
我只想测试MainClass。我在测试中使用 RhinoMocks 模拟 HelperClass。
问题是,虽然我对测试HandleFunction() 方法不感兴趣,但我有兴趣检查Action1、Action2 和其他在调用时发送到HandleFunction() 的操作..
如何模拟HandleFunction() 方法,同时避免其内部逻辑,调用作为参数发送给它的代码?
【问题讨论】:
标签: c# unit-testing rhino-mocks