Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking ReturnsAsync using Moq to return 2 values

Given a interface:

Task<Booking> GetBookingAsync(Guid reservationId);

I would mock the following like so:

_bookingLogic.Setup(x => x.GetBookingAsync(It.IsAny<Guid>())).ReturnsAsync(new Booking());

Givent the interface now changes to:

Task<(Booking Booking, IList<GAEvent> GaEvents)> GetBookingAsync(Guid reservationId);

How would this be mocked using Moq?

_bookingLogic.Setup(x => x.GetBookingAsync(It.IsAny<Guid>())).ReturnsAsync(?????);
like image 382
kl00t Avatar asked Feb 18 '26 21:02

kl00t


1 Answers

In second case result is a value tuple so you need to create one. Try:

.ReturnsAsync((new Booking(), (IList<GAEvent>)new List<GAEvent>()))
like image 126
Guru Stron Avatar answered Feb 20 '26 09:02

Guru Stron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!