模拟一个将回调类型作为参数的对话框 [英] Mocking a dialog box that takes a callback type as argument

查看:65
本文介绍了模拟一个将回调类型作为参数的对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为以下类型的对话框创建了模拟设置:

I have created the mock setup for the dialog box of type:

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);

现在倒数第二个参数中,我不知道如何传递参数,以便对话框可以调用另一个方法.

Now in the second last parameter I don't know how to pass the argument so that the dialog box can call the another method.

我的函数调用是这样的:

My function call is like this:

uiService.ShowDialog(ViewName.UnlockScriptPassswordDialog,
                     StudioViewName.MainWindow,
                     passwordDictionary,
                     this.OnUnlockScriptSetCallBack, null);

这正在调用OnUnlockScriptSetCallBack方法.

推荐答案

如果我理解的不错,您希望对ShowDialog的调用调用该方法的第四个参数.像这样设置:

If I understand you right you want the call to ShowDialog to invoke the fourth parameter to the method. Set it up like this:

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的参数发送到指定给Callback方法的Action中.调用ShowDialog时,将调用作为closeCallBack给出的Action<Dictionary<string, object>>.

This way the parameters passed to ShowDialog are sent to the Action given to the Callback method. When ShowDialog is invoked, the Action<Dictionary<string, object>> given as closeCallBack will be invoked.

这篇关于模拟一个将回调类型作为参数的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆