public void Handle_Should_ContainEachFailure_When_SomeFailuresArePassed()
        {
            var failure1 = new ValidationFailure("test1", "failure on something");
            var failure2 = new ValidationFailure("test2", "failure on something else");
            var input    = new List <ValidationFailure> {
                failure1, failure2
            };

            var result = sut.CreateMessage(input);

            result.Should().Contain($"{failure1.PropertyName}- {failure1.ErrorMessage}");
            result.Should().Contain($"{failure2.PropertyName}- {failure2.ErrorMessage}");
        }
        public async Task Handle(UpdateBoardGameCommand command, CancellationToken cancellationToken)
        {
            var boardGame = await _unitOfWork.BoardGameRepository.GetByIdAsync(command.Id, cancellationToken);

            if (boardGame == null)
            {
                throw new BoardGameNotFoundException(command.Id);
            }

            boardGame.Name  = command.Name;
            boardGame.Price = command.Price;
            var validationResult = _validator.Validate(boardGame);

            if (validationResult.IsValid)
            {
                await _unitOfWork.BoardGameRepository.Update(boardGame);

                await _unitOfWork.SaveChangesAsync(cancellationToken);
            }
            else
            {
                var validationMessage = _validationMessageBuilder.CreateMessage(validationResult.Errors);
                throw new CustomValidationException(validationMessage);
            }
        }
        public async Task Handle(UpdateClientCommand command, CancellationToken cancellationToken)
        {
            var client = await _unitOfWork.ClientRepository.GetByIdAsync(command.Id, cancellationToken);

            if (client == null)
            {
                throw new ClientNotFoundException(command.Id);
            }

            client.FirstName     = command.FirstName;
            client.LastName      = command.LastName;
            client.EmailAddress  = command.EmailAddress;
            client.ContactNumber = command.ContactNumber;
            var validationResult = _validator.Validate(client);

            if (validationResult.IsValid)
            {
                await _unitOfWork.ClientRepository.Update(client);

                await _unitOfWork.SaveChangesAsync(cancellationToken);
            }
            else
            {
                var validationMessage = _validationMessageBuilder.CreateMessage(validationResult.Errors);
                throw new CustomValidationException(validationMessage);
            }
        }
        public async Task Handle(AddBoardGameCommand command,
                                 CancellationToken cancellationToken)
        {
            var newBoardGame     = new BoardGame(command.NewBoardGameGuid, command.Name, command.Price);
            var validationResult = _validator.Validate(newBoardGame);

            if (validationResult.IsValid)
            {
                await _unitOfWork.BoardGameRepository.AddAsync(newBoardGame, cancellationToken);

                await _unitOfWork.SaveChangesAsync(cancellationToken);
            }
            else
            {
                var validationMessage = _validationMessageBuilder.CreateMessage(validationResult.Errors);
                throw new CustomValidationException(validationMessage);
            }
        }
        public async Task Handle(AddClientCommand command, CancellationToken cancellationToken)
        {
            var newClient = new Client(command.NewClientGuid, command.FirstName, command.LastName,
                                       command.ContactNumber,
                                       command.EmailAddress);
            var validationResult = _validator.Validate(newClient);

            if (validationResult.IsValid)
            {
                await _unitOfWork.ClientRepository.AddAsync(newClient, cancellationToken);

                await _unitOfWork.SaveChangesAsync(cancellationToken);
            }
            else
            {
                var validationMessage = _validationMessageBuilder.CreateMessage(validationResult.Errors);
                throw new CustomValidationException(validationMessage);
            }
        }
        public async Task Handle(AddRentalCommand command, CancellationToken cancellationToken)
        {
            var newGameRental = new Rental(command.NewGameRentalGuid, command.ClientGuid,
                                           command.BoardGameGuid,
                                           command.ChargedDeposit)
            {
                Status = Status.InProgress
            };
            var validationResult = _validator.Validate(newGameRental);

            if (!validationResult.IsValid)
            {
                var validationMessage = _validationMessageBuilder.CreateMessage(validationResult.Errors);
                throw new CustomValidationException(validationMessage);
            }

            var client      = _unitOfWork.ClientRepository.GetByIdAsync(command.ClientGuid, cancellationToken);
            var boardGame   = _unitOfWork.BoardGameRepository.GetByIdAsync(command.BoardGameGuid, cancellationToken);
            var canBeRented =
                _unitOfWork.RentalRepository.AreAllCompletedForBoardGameAsync(command.BoardGameGuid, cancellationToken);
            await Task.WhenAll(client, boardGame, canBeRented);

            if (client.Result == null)
            {
                throw new ClientNotFoundException(command.ClientGuid);
            }
            if (boardGame.Result == null)
            {
                throw new BoardGameNotFoundException(command.BoardGameGuid);
            }
            if (!canBeRented.Result)
            {
                throw new BoardGameHasOpenRentalException(command.BoardGameGuid);
            }

            await _unitOfWork.RentalRepository.AddAsync(newGameRental, cancellationToken);

            await _unitOfWork.SaveChangesAsync(cancellationToken);
        }