Beispiel #1
0
        public async Task Handle_GivenValidRequest_ShouldModifyEntity()
        {
            // Arrange
            var cloudinaryHelperMock = new Mock <ICloudinaryHelper>();

            cloudinaryHelperMock
            .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>()))
            .ReturnsAsync(imagePlaceholderUrl);

            var sut = new ModifyGameCommandHandler(deletableEntityRepository, cloudinaryHelperMock.Object, this.mediatorMock.Object);

            var gameId  = 2;
            var command = new ModifyGameCommand()
            {
                Id          = gameId,
                Name        = "Team Fortress 3",
                Description = "Changed description from test",
                GameImage   = new FormFile(It.IsAny <Stream>(), It.IsAny <long>(), It.IsAny <long>(), It.IsAny <string>(), It.IsAny <string>())
            };

            // Act
            var id = await sut.Handle(command, CancellationToken.None);

            // Assert
            var game = this.deletableEntityRepository
                       .AllAsNoTrackingWithDeleted()
                       .SingleOrDefault(x => x.Id == gameId);

            id.ShouldBe(2);
            this.mediatorMock.Verify(x => x.Publish(It.IsAny <GameModifiedNotification>(), It.IsAny <CancellationToken>()));
            game.ShouldNotBeNull();
            game.Name.ShouldBe(command.Name);
            game.Description.ShouldBe(command.Description);
            game.GameImageUrl.ShouldBe(imagePlaceholderUrl);
        }
Beispiel #2
0
        public async Task <IActionResult> Modify(ModifyGameCommand command)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(command));
            }

            await this.Mediator.Send(command);

            return(this.RedirectToAction(nameof(Index)));
        }
Beispiel #3
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var cloudinaryHelperMock = new Mock <ICloudinaryHelper>();

            cloudinaryHelperMock
            .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>()))
            .ReturnsAsync(this.imagePlaceholderUrl);

            var sut = new ModifyGameCommandHandler(deletableEntityRepository, cloudinaryHelperMock.Object, this.mediatorMock.Object);

            var gameId  = 41241;
            var command = new ModifyGameCommand()
            {
                Id          = gameId,
                Name        = It.IsAny <string>(),
                Description = It.IsAny <string>(),
                GameImage   = new FormFile(It.IsAny <Stream>(), It.IsAny <long>(), It.IsAny <long>(), It.IsAny <string>(), It.IsAny <string>())
            };

            // Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }