public void Given_An_Invalid_CardType_Should_Throw_ArgumentOutOfRange_Exception()
        {
            // Arrange
            const YgoCardType cardType = (YgoCardType)7;

            var card = new Card {
                Id = 23424
            };

            // Act
            Action act = () => CommandMapperHelper.MapCardByCardType(_mapper, cardType, card);

            // Assert
            act.Should().Throw <ArgumentOutOfRangeException>();
        }
        public void Given_A_Monster_CardType_Should_Return_Object_Of_Type_TrapCardDto()
        {
            // Arrange
            const YgoCardType cardType = YgoCardType.Monster;

            var card = new Card {
                Id = 23424
            };

            // Act
            var result = CommandMapperHelper.MapCardByCardType(_mapper, cardType, card);

            // Assert
            result.Should().BeOfType <MonsterCardDto>();
        }
        public async Task <CommandResult> Handle(UpdateCardCommand request, CancellationToken cancellationToken)
        {
            var commandResult = new CommandResult();

            var validationResults = _validator.Validate(request.Card);

            if (validationResults.IsValid)
            {
                var cardModel = _mapper.Map <CardModel>(request.Card);

                var cardUpdated = await _cardService.Update(cardModel);

                if (cardUpdated != null)
                {
                    if (request.Card.ImageUrl != null)
                    {
                        var downloadImageCommand = new DownloadImageCommand
                        {
                            RemoteImageUrl  = request.Card.ImageUrl,
                            ImageFileName   = request.Card.Name,
                            ImageFolderPath = _settings.Value.CardImageFolderPath
                        };

                        await _mediator.Send(downloadImageCommand, cancellationToken);
                    }

                    commandResult.Data         = CommandMapperHelper.MapCardByCardType(_mapper, request.Card.CardType.GetValueOrDefault(), cardUpdated);
                    commandResult.IsSuccessful = true;
                }
                else
                {
                    commandResult.Errors = new List <string> {
                        "Card not updated in data source."
                    };
                }
            }
            else
            {
                commandResult.Errors = validationResults.Errors.Select(err => err.ErrorMessage).ToList();
            }

            return(commandResult);
        }