public async Task Handle_GivenInvalidRequest_ShouldThrowEntityAlreadyExistsException() { // Arrange var tournamentFormatsRepositoryMock = new Mock <IDeletableEntityRepository <TournamentFormat> >(); var dataSet = new List <TournamentFormat> { new TournamentFormat { Name = "5v5", GameId = 123, Id = It.IsAny <int>(), TeamPlayersCount = 5, TotalPlayersCount = 10, Description = It.IsAny <string>() } }.AsQueryable(); var dataSetMock = dataSet.BuildMock(); tournamentFormatsRepositoryMock.Setup(m => m.AllAsNoTrackingWithDeleted()).Returns(dataSetMock.Object); var request = new CreateTournamentFormatCommand { Name = "5v5", GameId = 123 }; var sut = new CreateTournamentFormatCommandHandler(tournamentFormatsRepositoryMock.Object, It.IsAny <IDeletableEntityRepository <Game> >()); // Act & Assert await Should.ThrowAsync <EntityAlreadyExistsException>(sut.Handle(request, CancellationToken.None)); }
public async Task <IActionResult> Create() { var viewModel = new CreateTournamentFormatCommand { Games = await this.Mediator.Send(new GetAllGamesSelectListQuery()) }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(CreateTournamentFormatCommand command) { if (!this.ModelState.IsValid) { command.Games = await this.Mediator.Send(new GetAllGamesSelectListQuery()); return(this.View(command)); } await this.Mediator.Send(command); return(this.RedirectToAction(nameof(Index))); }
public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException() { // Arrange var request = new CreateTournamentFormatCommand() { GameId = 90125, Name = "5v5", Description = "Plain old 5v5 classic counter-strike competitie format", TeamPlayersCount = 5 }; IDeletableEntityRepository <Game> gameRepo = new EfDeletableEntityRepository <Game>(this.dbContext); var sut = new CreateTournamentFormatCommandHandler(deletableEntityRepository, gameRepo); // Act & Assert await Should.ThrowAsync <NotFoundException>(sut.Handle(request, CancellationToken.None)); }
public async Task Handle_GivenValidRequest_ShouldCreateValidEntity() { // Arrange var request = new CreateTournamentFormatCommand() { GameId = 2, Name = "5v5", Description = "Plain old 5v5 classic counter-strike competitive format", TeamPlayersCount = 5 }; IDeletableEntityRepository <Game> gameRepo = new EfDeletableEntityRepository <Game>(this.dbContext); var sut = new CreateTournamentFormatCommandHandler(base.deletableEntityRepository, gameRepo); // Act var result = await sut.Handle(request, CancellationToken.None); // Assert result.ShouldBe(4); }