コード例 #1
0
        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));
        }
コード例 #2
0
        public async Task <JsonResult> Delete([FromQuery] int id)
        {
            var deleteCmd = new DeleteBookingCommand {
                Id = id
            };

            return(await ApiResponseHelper.RunCommandAsync(deleteCmd));
        }
コード例 #3
0
        public void DeleteBookingCommand_ShouldThrowNotFoundException()
        {
            var command = new DeleteBookingCommand {
                Id = 99
            };

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }