4
我有一个类实现如下。 MethodUnderTest()是调用委托使用一些自定义过滤器更新网格的方法,具有回调函数 - UpdateGridCallback。如何在moq中模拟代理
public class MyClass
{
public delegate void UpdateGridDelegate(MyCustomFilters filter);
public UpdateGridDelegate del;
public MyCustomFilters filter;
public void MethodUnderTest()
{
//.... some code...
// For simplicity of example I am passing somename.. should be passing rows..
// set status bar saying retriving data..
del = new UpdateGridDelegate(UpdateGrid);
del.BeginInvoke(filter, UpdateGridCallback, null);
}
public void UpdateGrid(MyCustomFilters filter)
{
// Upadte Grid with passed rows.
}
public void UpdateGridCallback(IAsyncResult result)
{
// callback .. do some action here.. like updating status bar saying - Ready
}
}
我正在使用Nunit和Moq.delegate。 MethodUnderTest()是待测试的方法。我如何模拟MethodUnderTest()中正在使用的委托?
我想确保从我的NUnit测试用例中调用委托(或执行回调)。