0

I am creating a c# application that has an embedded webbrowser control. From javascript I am calling a c# method and passing a javascript callback. I am using the dynamic technique from this answer:

public void CallbackTest(object callback)
{
    dynamic callbackFunc = callback;
    callbackFunc("Hello!");
}

My problem is how would I go about unit testing this method? How do I mock (or fake) the callback parameter? For what it's worth, my mocking library of choice is Moq.

1 Answer 1

1

I would imagine that you could just pass in an Action<String> and this should work as a callback. I am not sure if you can get support for this kind of dynamic in Moq directly, though. But, using an Action is pretty straightforward anyway

var mockCallBack = new Action<String>(str => {return;});
CallbackTest(mockCallBack)
Sign up to request clarification or add additional context in comments.

1 Comment

That's it. Don't know why I had such trouble coming up with that on my own. :) Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.