This is a migrated thread and some comments may be shown as answers.

Pass DialogResult to Callback method in MessageBox.SHow

2 Answers 17 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sagar
Top achievements
Rank 1
Sagar asked on 13 Aug 2015, 02:35 PM

Hi,

  I have a MessageBox.Show method, which has a CallBack action associated with it. I want to Pass a Mocked parameter to that action, which would eventually execute the action statements based on Parameter passed.

Action<DialogResult> callback = (result) =>
                    {
                        if (result == DialogResult.Yes)
                        {
                           //Do something here  
                        }
                    };
MessageBox.Show("Are you Sure?","Test App",DialogButton.YesNo, DialogImage.Question,callback);

  I tried something like below, but it did not work.

 

Mock.Arrange(() => dialog.Show(Arg.AnyString, Arg.AnyString,DialogButton.YesNo, DialogImage.Question, Arg.IsAny<Action<DialogResult>>())).
           DoInstead((Action<DialogResult> action) =>
           {
             action.Invoke(DialogResult.Yes);
           });

 I want to execute the Original callback, with a mocked DialogResult. 

How can we do that?

 

Thanks in Advance,

Sagar

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 17 Aug 2015, 07:28 AM
Hello Sagar,

The delegate passed to DoInstead should have the same signature as the arranged method:
Mock.Arrange(() => dialog.Show(Arg.AnyString, Arg.AnyString,DialogButton.YesNo, DialogImage.Question, Arg.IsAny<Action<DialogResult>>())).
           DoInstead((string message, string title, DialogButton buttons, DialogImage image, Action<DialogResult> action) =>
           {
             action.Invoke(DialogResult.Yes);
           });


Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Sagar
Top achievements
Rank 1
answered on 17 Aug 2015, 08:55 AM

Thanks Stefan, the resolution solves my issue.

 

Thank you,

Sagar

Tags
General Discussions
Asked by
Sagar
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Sagar
Top achievements
Rank 1
Share this question
or