2

I am making use of ManualResetEvent class in a test.

Basically, I want to invoke the Set() method when a particular function is called. This looks like:

var mre = new ManualResetEvent(false);
mockObj.Setup(dmc => dmc.Foo(param1, param2, param3)).Callback(mre.Set()); //Error here.

However, I get an error saying:

Cannot convert from bool to 'System.Action'

when I try to set the mre.

Am I doing anything wrong here?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
learntogrow-growtolearn
  • 1,190
  • 5
  • 13
  • 37

1 Answers1

1

The error message says it all

Cannot convert from bool to 'System.Action'

Callback requires a lambda expression / Action

//...
var mre = new ManualResetEvent(false);
mockObj
    .Setup(dmc => dmc.Foo(param1, param2, param3))
    .Callback(() => mre.Set()); //<-- Callback requires an Action
//...

Reference Moq Quickstart to get a better under standing of how to use the mocking framework.

Nkosi
  • 235,767
  • 35
  • 427
  • 472