forked from MatthiWare/MockingTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReservationSystem.cs
More file actions
29 lines (23 loc) · 798 Bytes
/
Copy pathReservationSystem.cs
File metadata and controls
29 lines (23 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using MockingTutorial.Exceptions;
using MockingTutorial.Services;
namespace MockingTutorial
{
public class ReservationSystem
{
private readonly IBookingService bookingService;
public ReservationSystem(IBookingService bookingService)
{
this.bookingService = bookingService;
}
public async Task ReserveAsync(int amountOfBeds)
{
var rooms = await bookingService.GetRoomsAsync(amountOfBeds);
var firstAvailableRoom = rooms.FirstOrDefault(room => !room.IsReserved);
if (firstAvailableRoom is null)
{
throw new NoAvailableRoomsException(amountOfBeds);
}
await bookingService.ReserveRoomAsync(firstAvailableRoom.RoomId);
}
}
}