Pass DialogResult to Callback method in MessageBox.SHow

3 posts, 1 answers
  1. Sagar
    Sagar avatar
    11 posts
    Member since:
    May 2014

    Posted 13 Aug 2015 Link to this post

    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. Answer
    Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 17 Aug 2015 Link to this post

    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
  3. DevCraft R3 2016 release webinar banner
  4. Sagar
    Sagar avatar
    11 posts
    Member since:
    May 2014

    Posted 17 Aug 2015 in reply to Stefan Link to this post

    Thanks Stefan, the resolution solves my issue.

     

    Thank you,

    Sagar

Back to Top