Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Raising a Callback passed as a parameter in a method call using Mock

I have a method that takes a callback as a a parameter:

  public void GetAllAvailableNames(Action<List<string>> callback, Exchange? exchange = null, string symbol = null)
    {
        callback.Invoke(new List<string> {"test"});
    }

How can I raise the callback using mock, this is what I have tried among other things:

 this._marketDataClientMock
        .Setup(x => x.GetAllAvailableNames( It.IsAny<Action<List<string>>>(), It.IsAny<Exchange>(), It.IsAny<string>()))
        .Callback((List<string> x) => x = this.Vets);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Capture the action parameter within the CallBack and invoke it manually

this._marketDataClientMock
    .Setup(x => x.GetAllAvailableNames( It.IsAny<Action<List<string>>>(), It.IsAny<Exchange>(), It.IsAny<string>()))
    .Callback((Action<List<string>> callback, Exchange? exchange, string symbol) => callback.Invoke(this.Vets));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading