Ejemplo n.º 1
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowEntityAlreadyExistsException()
        {
            // Arrange
            var command = new ModifyTeamCommand
            {
                Id          = 1,
                Name        = "FooTeam2",
                Description = "ModifiedDescription",
                HomepageUrl = "ModifiedHomepage",
                TeamImage   = new Mock <IFormFile>().Object
            };

            var cloudinaryHelperMock = new Mock <ICloudinaryHelper>();

            cloudinaryHelperMock
            .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>()))
            .ReturnsAsync("http://test.bg/1.jpg");

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");

            var sut = new ModifyTeamCommandHandler(this.deletableEntityRepository, cloudinaryHelperMock.Object, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <EntityAlreadyExistsException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 2
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var command = new ModifyTeamCommand
            {
                Id = 311,
            };

            var sut = new ModifyTeamCommandHandler(this.deletableEntityRepository, It.IsAny <ICloudinaryHelper>(), It.IsAny <IUserAccessor>());

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Modify(ModifyTeamCommand command)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(command));
            }

            await this.Mediator.Send(command);

            return(this.RedirectToAction(nameof(Details), new GetTeamDetailsQuery {
                Id = command.Id
            }));
        }
Ejemplo n.º 4
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowForbiddenException()
        {
            // Arrange
            var command = new ModifyTeamCommand
            {
                Id = 1
            };

            var cloudinaryHelperMock = new Mock <ICloudinaryHelper>();

            cloudinaryHelperMock
            .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>()))
            .ReturnsAsync("http://test.bg/1.jpg");

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("InvalidId");

            var sut = new ModifyTeamCommandHandler(this.deletableEntityRepository, cloudinaryHelperMock.Object, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <ForbiddenException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Ejemplo n.º 5
0
        public async Task Handle_GivenValidRequest_ShouldModifyTeam()
        {
            // Arrange
            var command = new ModifyTeamCommand
            {
                Id          = 1,
                Name        = "ModifiedName",
                Description = "ModifiedDescription",
                HomepageUrl = "ModifiedHomepage",
                TeamImage   = new Mock <IFormFile>().Object
            };

            var cloudinaryHelperMock = new Mock <ICloudinaryHelper>();

            cloudinaryHelperMock
            .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>()))
            .ReturnsAsync("http://test.bg/1.jpg");

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");

            var sut = new ModifyTeamCommandHandler(this.deletableEntityRepository, cloudinaryHelperMock.Object, userAccessorMock.Object);

            // Act
            var id = await sut.Handle(command, It.IsAny <CancellationToken>());

            //Assert
            var modifiedTeam = this.dbContext.Teams.SingleOrDefault(x => x.Id == id);

            modifiedTeam.ShouldNotBeNull();
            modifiedTeam.Name.ShouldBe("ModifiedName");
            modifiedTeam.Description.ShouldBe("ModifiedDescription");
            modifiedTeam.HomepageUrl.ShouldBe("ModifiedHomepage");
            modifiedTeam.ImageUrl.ShouldBe("http://test.bg/1.jpg");
        }