我已经为类型为
的对话框创建了模拟设置void ShowDialog(string windowName,
string parentWindowName,
Dictionary<string, object> inputFields,
Action<Dictionary<string, object>> closeCallBack,
Dictionary<string, object> windowProperties = null);
像:
UIServicemock.Setup(u => u.ShowDialog(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<Dictionary<string, object>>(),
It.IsAny<Action<Dictionary<string, object>>>(),
It.IsAny<Dictionary<string, object>>())).Callback(ViewName.UnlockScriptPassswordDialog,
StudioViewName.MainWindow,
passwordDictionary, ,
null);
现在在倒数第二个参数中,我不知道如何传递参数,以便对话框可以调用另一个方法。
我的函数调用是这样的:
uiService.ShowDialog(ViewName.UnlockScriptPassswordDialog,
StudioViewName.MainWindow,
passwordDictionary,
this.OnUnlockScriptSetCallBack, null);
这是调用OnUnlockScriptSetCallBack
方法。
答案 0 :(得分:2)
如果我理解你,你希望调用ShowDialog
来调用该方法的第四个参数。设置如下:
UIServicemock.Setup(
u =>
u.ShowDialog(It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<Dictionary<string, object>>(),
It.IsAny<Action<Dictionary<string, object>>>(),
It.IsAny<Dictionary<string, object>>()))
.Callback<string,
string,
Dictionary<string, object>,
Action<Dictionary<string, object>>,
Dictionary<string, object>>(
(windowName,
parentWindowName,
inputFields,
closeCallBack,
windowProperties) =>
closeCallBack(windowProperties /* or whatever dictionary should go here*/)
);
这样,传递给ShowDialog
的参数将发送给Action
方法的Callback
。调用ShowDialog
时,将调用Action<Dictionary<string, object>>
closeCallBack
作为{{1}}。