public async Task Given_An_Valid_DownloadImageCommand_Should_Execute_Publish_Method_Once()
        {
            // Arrange
            var downloadImageCommand = new DownloadImageCommand
            {
                ImageFolderPath = @"c:\windows",
                ImageFileName   = "Call Of The Haunted",
                RemoteImageUrl  = new Uri("http://filesomewhere/callofthehaunted.png")
            };

            _validator.Validate(Arg.Any <DownloadImageCommand>()).Returns(new DownloadImageCommandValidator().Validate(downloadImageCommand));
            _cardImageQueueService.Publish(Arg.Any <DownloadImage>()).Returns(new CardImageCompletion());

            // Act
            await _sut.Handle(downloadImageCommand, CancellationToken.None);

            // Assert
            await _cardImageQueueService.Received(1).Publish(Arg.Any <DownloadImage>());
        }
Beispiel #2
0
        public async Task <CommandResult> Handle(DownloadImageCommand request, CancellationToken cancellationToken)
        {
            var commandResult = new CommandResult();

            var validationResult = _validator.Validate(request);

            if (validationResult.IsValid)
            {
                var result = await _cardImageQueueService.Publish(new core.Models.DownloadImage
                {
                    RemoteImageUrl  = request.RemoteImageUrl,
                    ImageFileName   = request.ImageFileName,
                    ImageFolderPath = request.ImageFolderPath
                });

                commandResult.IsSuccessful = result.IsSuccessful;
            }
            else
            {
                commandResult.Errors = validationResult.Errors.Select(err => err.ErrorMessage).ToList();
            }

            return(commandResult);
        }