public async Task <IdResponse> HandleAsync(DeleteBookingCommand cmd, CancellationToken ct) { var booking = _bookingRepository.GetById(cmd.id); var result = _bookingRepository.DeleteByT(booking); return(new IdResponse(cmd.id)); }
public async Task <JsonResult> Delete([FromQuery] int id) { var deleteCmd = new DeleteBookingCommand { Id = id }; return(await ApiResponseHelper.RunCommandAsync(deleteCmd)); }
public void DeleteBookingCommand_ShouldThrowNotFoundException() { var command = new DeleteBookingCommand { Id = 99 }; FluentActions.Invoking(() => SendAsync(command)).Should().Throw <NotFoundException>(); }
public async Task Handle_WithAnInvalidDeleteBookingCommand_Throws() { //arrange var invalidCommand = new DeleteBookingCommand { Id = 0 }; //act + assert _ = await Assert .ThrowsAsync <BookingNotFoundException>(() => _handler.Handle(invalidCommand, default)) .ConfigureAwait(false); }
public async Task Handle_WithAValidDeleteBookingCommand_RemovesBookingFromDatabase() { //arrange Context.Add(new Booking()); _ = await Context .SaveChangesAsync() .ConfigureAwait(false); var validCommand = new DeleteBookingCommand { Id = 1 }; //act _ = await _handler .Handle(validCommand, default) .ConfigureAwait(false); //assert Assert.Empty(Context.Bookings); }