public override async Task <BookingResult> ExecuteAsync(GetBookingById query, CancellationToken cancellationToken = new CancellationToken()) { using (var uow = new BookingContext(_options)) { var repository = new RoomBookingRepositoryAsync(new EFUnitOfWork(uow)); var booking = await repository.GetAsync(query.BookingId, cancellationToken); return(new BookingResult(booking)); } }
public override async Task <BookGuestRoomOnAccount> HandleAsync(BookGuestRoomOnAccount command, CancellationToken cancellationToken = new CancellationToken()) { Guid messageId; using (var uow = new BookingContext(_options)) { using (var trans = uow.Database.BeginTransaction()) { var repository = new RoomBookingRepositoryAsync(new EFUnitOfWork(uow)); var roomBooking = new RoomBooking( command.BookingId, command.DateOfFirstNight, command.NumberOfNights, command.NumberOfGuests, command.Type, command.Price, command.AccountId); await repository.AddAsync(roomBooking, cancellationToken); messageId = _messagePublisher.DepositPost(new GuestRoomBookingMade { BookingId = roomBooking.RoomBookingId.ToString(), DateOfFirstNight = roomBooking.DateOfFirstNight, NumberOfGuests = roomBooking.NumberOfGuests, NumberOfNights = roomBooking.NumberOfNights, Type = roomBooking.RoomType, Price = roomBooking.Price, AccountId = roomBooking.AccountId, }); trans.Commit(); } } _messagePublisher.ClearOutbox(messageId); return(await base.HandleAsync(command, cancellationToken)); }
public async Task When_adding_a_room_booking_on_account() { using (var uow = new BookingContext(_options)) { //arrange var booking = new BookGuestRoomOnAccount() { BookingId = Guid.NewGuid(), AccountId = Guid.NewGuid().ToString(), DateOfFirstNight = DateTime.UtcNow, NumberOfNights = 1, NumberOfGuests = 1, Type = RoomType.King, Price = 120 }; var commandProcessor = new FakeCommandProcessor(); var handler = new BookGuestRoomOnAccountHandlerAsync(_options, commandProcessor); //act await handler.HandleAsync(booking); //assert var roomBookingRepositoryAsync = new RoomBookingRepositoryAsync(new EFUnitOfWork(uow)); var savedBooking = await roomBookingRepositoryAsync.GetAsync(booking.BookingId); Assert.That(savedBooking.RoomBookingId, Is.EqualTo(booking.BookingId)); Assert.That(savedBooking.DateOfFirstNight, Is.EqualTo(booking.DateOfFirstNight)); Assert.That(savedBooking.NumberOfNights, Is.EqualTo(booking.NumberOfNights)); Assert.That(savedBooking.NumberOfGuests, Is.EqualTo(booking.NumberOfGuests)); Assert.That(savedBooking.RoomType, Is.EqualTo(booking.Type)); Assert.That(savedBooking.Price, Is.EqualTo(booking.Price)); Assert.That(savedBooking.AccountId, Is.EqualTo(booking.AccountId)); Assert.That(commandProcessor.AllSent); Assert.That(commandProcessor.RaiseRoomBookingEvent); } }
public async Task When_mapping_a_guest_room_booking() { using (var uow = new BookingContext(_options)) { //arrange var booking = new RoomBooking { RoomBookingId = Guid.NewGuid(), DateOfFirstNight = new DateTime(2019, 07, 11), Price = 226, RoomType = RoomType.MasterSuite, NumberOfGuests = 3, NumberOfNights = 3, AccountId = Guid.NewGuid().ToString(), LockedBy = "SYS", LockExpiresAt = DateTime.Now.AddMilliseconds(500).Ticks.ToString() }; var roomRepository = new RoomBookingRepositoryAsync(new EFUnitOfWork(uow)); //act await roomRepository.AddAsync(booking); //assert await Task.Delay(50); var savedBooking = await roomRepository.GetAsync(booking.RoomBookingId); Assert.That(savedBooking.RoomBookingId, Is.EqualTo(booking.RoomBookingId)); Assert.That(savedBooking.DateOfFirstNight, Is.EqualTo(booking.DateOfFirstNight)); Assert.That(savedBooking.Price, Is.EqualTo(booking.Price)); Assert.That(savedBooking.RoomType, Is.EqualTo(booking.RoomType)); Assert.That(savedBooking.NumberOfGuests, Is.EqualTo(booking.NumberOfGuests)); Assert.That(savedBooking.NumberOfNights, Is.EqualTo(booking.NumberOfNights)); Assert.That(savedBooking.AccountId, Is.EqualTo(booking.AccountId)); } }
public async Task When_getting_a_booking_by_id() { using (var uow = new BookingContext(_options)) { //arrange var booking = new RoomBooking { RoomBookingId = Guid.NewGuid(), DateOfFirstNight = new DateTime(2019, 07, 11), Price = 226, RoomType = RoomType.MasterSuite, NumberOfGuests = 3, NumberOfNights = 3, AccountId = Guid.NewGuid().ToString(), LockedBy = "SYS", LockExpiresAt = DateTime.Now.AddMilliseconds(500).Ticks.ToString() }; var repository = new RoomBookingRepositoryAsync(new EFUnitOfWork(uow)); await repository.AddAsync(booking); var handler = new GetBookingByIdHandlerAsync(_options); //act var bookingResult = await handler.ExecuteAsync(new GetBookingById(booking.RoomBookingId)); //assert Assert.That(bookingResult.BookingId, Is.EqualTo(booking.RoomBookingId.ToString())); Assert.That(bookingResult.DateOfFirstNight, Is.EqualTo(booking.DateOfFirstNight)); Assert.That(bookingResult.Price, Is.EqualTo(booking.Price)); Assert.That(bookingResult.RoomType, Is.EqualTo(booking.RoomType)); Assert.That(bookingResult.NumberOfNights, Is.EqualTo(booking.NumberOfNights)); Assert.That(bookingResult.NumberOfGuests, Is.EqualTo(booking.NumberOfGuests)); Assert.That(bookingResult.AccountId, Is.EqualTo(booking.AccountId)); } }