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

How to mock method that has return type from of the (bool, string)?

The following function has a return value of (bool, string). How to Moq it to be ready for unit testing.

Task<(bool, string)> CreatePhoneCertificate(
    int orderId, 
    CancellationToken cancellationToken);
  var mockInsuranceService = new Mock<IInsuranceService>();
  mockInsuranceService.Setup(x => x.CreatePhoneCertificate(12345, It.IsAny<CancellationToken>())).ReturnsAsync(???);

Thank you

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 :

Just create a value tuple with desired values:

mockInsuranceService.Setup(x => x.CreatePhoneCertificate(12345, It.IsAny<CancellationToken>()))
    .ReturnsAsync((true, "someString"));

Read more:

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