public async Task WhenGetAllBookings_ShouldReturnsCollection() { // Arrange var LDatabaseContext = GetTestDatabaseContext(); var LGetAllBookingsQueryHandler = new GetAllBookingsQueryHandler(LDatabaseContext); var LRoom = new Rooms { RoomNumber = 101, Bedrooms = 3 }; await LDatabaseContext.Rooms.AddAsync(LRoom); await LDatabaseContext.SaveChangesAsync(); var LBookings = new List <Bookings> { new () { RoomId = LRoom.Id, GuestFullName = StringProvider.GetRandomString(), GuestPhoneNumber = StringProvider.GetRandomString(9), DateFrom = FDateTimeService.Now.AddDays(5), DateTo = FDateTimeService.Now.AddDays(15) }, new () { RoomId = LRoom.Id, GuestFullName = StringProvider.GetRandomString(), GuestPhoneNumber = StringProvider.GetRandomString(9), DateFrom = FDateTimeService.Now.AddDays(1), DateTo = FDateTimeService.Now.AddDays(3) } }; await LDatabaseContext.Bookings.AddRangeAsync(LBookings); await LDatabaseContext.SaveChangesAsync(); // Act var LResults = (await LGetAllBookingsQueryHandler .Handle(new GetAllBookingsQuery(), CancellationToken.None)) .ToList(); // Assert LResults.Should().NotBeNull(); LResults.Should().HaveCount(2); } }
public async Task Test_ForExistingCustomers_ShouldReturnCustomers() { // Arrange var mock = new Mock <IBookingRepository>(); Fixture.RepeatCount = 9; var bookings = Fixture.Create <Booking[]>(); mock.Setup(foo => foo.GetAll()).Returns(bookings); var query = new GetAllBookingsQuery(); var queryHandler = new GetAllBookingsQueryHandler(mock.Object); // Act var result = await queryHandler.Handle(query, CancellationToken.None); // Assert Assert.NotNull(result); Assert.NotEmpty(result); Assert.Equal(bookings.Length, result.Count()); }