File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,22 +14,57 @@ namespace Tests
1414 public class ReservationSystemTests
1515 {
1616 private readonly ReservationSystem reservationSystem ;
17+ private readonly Mock < IBookingService > bookingServiceMock = new ( ) ;
1718
1819 public ReservationSystemTests ( )
1920 {
21+ //reservationSystem = new ReservationSystem(
22+ // new BookingService(new BookingDbContext()));
23+
2024 reservationSystem = new ReservationSystem (
21- new BookingService ( new BookingDbContext ( ) ) ) ;
25+ bookingServiceMock . Object ) ;
2226 }
2327
2428 [ Fact ]
2529 public async Task ReserveAsync_Throws_When_No_Rooms_Available ( )
2630 {
27-
31+ bookingServiceMock
32+ . Setup ( mock => mock . GetRoomsAsync ( 10 ) )
33+ . ReturnsAsync ( Enumerable . Empty < Room > ( ) ) ;
34+
35+ await Assert . ThrowsAsync < NoAvailableRoomsException > (
36+ ( ) => reservationSystem . ReserveAsync ( 10 ) ) ;
2837 }
2938
3039 [ Fact ]
3140 public async Task ReserveAsync_Reserves_The_Available_Room ( )
3241 {
42+ var reservedRoom = new Room
43+ {
44+ Beds = 10 ,
45+ IsReserved = true ,
46+ RoomName = "Room 1"
47+ } ;
48+
49+ var emptyRoom = new Room
50+ {
51+ Beds = 10 ,
52+ IsReserved = false ,
53+ RoomName = "Room 2"
54+ } ;
55+
56+ bookingServiceMock
57+ . Setup ( mock => mock . GetRoomsAsync ( 10 ) )
58+ . ReturnsAsync ( new [ ]
59+ {
60+ reservedRoom ,
61+ emptyRoom ,
62+ } ) ;
63+
64+ await reservationSystem . ReserveAsync ( 10 ) ;
65+
66+ bookingServiceMock
67+ . Verify ( mock => mock . ReserveRoomAsync ( emptyRoom . RoomId ) , Times . Once ( ) ) ;
3368 }
3469 }
3570}
Original file line number Diff line number Diff line change 99
1010 <ItemGroup >
1111 <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 16.11.0" />
12+ <PackageReference Include =" Moq" Version =" 4.18.1" />
1213 <PackageReference Include =" xunit" Version =" 2.4.1" />
1314 <PackageReference Include =" xunit.runner.visualstudio" Version =" 2.4.3" >
1415 <IncludeAssets >runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets >
You can’t perform that action at this time.
0 commit comments