2014-03-13 63 views
1

我已經創建了一個類型的對話框,模擬設置:嘲笑一個對話框,需要一個回調類型作爲參數

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方法。

回答

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的參數發送到給予Callback方法Action。當調用ShowDialog時,將調用Action<Dictionary<string, object>>作爲closeCallBack

+0

是的,我會嘗試一下,然後將增加關於此解決方案的進一步評論工作與否。感謝很多希望的光芒。 – priya

+0

非常感謝帕特里克解決方案工作正常。 – priya