public async Task Handle_GivenInvalidRequest_ShouldThrowEntityAlreadyExistsException() { // Arrange var command = new ModifyTournamentCommand { Id = 1, Name = "TestTournament2" }; var sut = new ModifyTournamentCommandHandler(this.deletableEntityRepository, It.IsAny <ICloudinaryHelper>()); // Act & Assert await Should.ThrowAsync <EntityAlreadyExistsException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
public async Task <IActionResult> Modify(ModifyTournamentCommand command) { if (!this.ModelState.IsValid) { return(this.View(command)); } await this.Mediator.Send(command); return(this.RedirectToAction(nameof(Index))); }
public async Task Handle_GivenValidRequest_ShouldModifyEntity() { // Arrange var cloudinaryHelperMock = new Mock <ICloudinaryHelper>(); var cloudinaryMock = new Mock <Cloudinary>(); var imagePlaceholderUrl = "https://test.bg/1.jpg"; cloudinaryHelperMock .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>())) .ReturnsAsync(imagePlaceholderUrl); var command = new ModifyTournamentCommand { Id = 2, Name = "EditedName", Description = "EditedDescription", StartDate = new DateTime(2019, 09, 02), EndDate = new DateTime(2019, 09, 30), AreSignupsOpen = true, IsActive = false }; var sut = new ModifyTournamentCommandHandler(this.deletableEntityRepository, cloudinaryHelperMock.Object); // Act var id = await sut.Handle(command, It.IsAny <CancellationToken>()); // Assert id.ShouldBeGreaterThan(0); var modifiedTournament = this.deletableEntityRepository.AllAsNoTracking().SingleOrDefault(x => x.Id == id); modifiedTournament.Name.ShouldBe("EditedName"); modifiedTournament.Description.ShouldBe("EditedDescription"); modifiedTournament.StartDate.ShouldBe(new DateTime(2019, 09, 02)); modifiedTournament.EndDate.ShouldBe(new DateTime(2019, 09, 30)); modifiedTournament.AreSignupsOpen.ShouldBe(true); modifiedTournament.IsActive.ShouldBe(false); }