/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(CreateTournamentCommand command, CancellationToken cancellationToken) { // Rehydrate the aggregate TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken); // Get the club to validate the input GolfClubAggregate club = await this.GolfClubRepository.GetLatestVersion(command.GolfClubId, cancellationToken); // bug #29 fixes (throw exception if club not created) if (!club.HasBeenCreated) { throw new NotFoundException($"No created golf club found with Id {command.GolfClubId}"); } // Club is valid, now check the measured course, this will throw exception if not found MeasuredCourseDataTransferObject measuredCourse = club.GetMeasuredCourse(command.CreateTournamentRequest.MeasuredCourseId); tournament.CreateTournament(command.CreateTournamentRequest.TournamentDate, command.GolfClubId, command.CreateTournamentRequest.MeasuredCourseId, measuredCourse.StandardScratchScore, command.CreateTournamentRequest.Name, (PlayerCategory)command.CreateTournamentRequest.MemberCategory, (TournamentFormat)command.CreateTournamentRequest.Format); // Save the changes await this.TournamentRepository.SaveChanges(tournament, cancellationToken); // Setup the response command.Response = new CreateTournamentResponse { TournamentId = command.TournamentId }; }
public async Task <IActionResult> CreateTournament([FromRoute] Guid golfClubId, [FromBody] CreateTournamentRequest request, CancellationToken cancellationToken) { Guid tournamentId = Guid.NewGuid(); // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString()); Boolean validationResult = ClaimsHelper.ValidateRouteParameter(golfClubId, golfClubIdClaim); if (validationResult == false) { return(this.Forbid()); } // Create the command CreateTournamentCommand command = CreateTournamentCommand.Create(tournamentId, Guid.Parse(golfClubIdClaim.Value), request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"{TournamentController.ControllerRoute}/{tournamentId}", new CreateTournamentResponse { TournamentId = tournamentId })); }
public async Task <IActionResult> Create() { var viewModel = new CreateTournamentCommand { Formats = await this.Mediator.Send(new GetAllTournamentFormatsSelectListQuery()) }; return(this.View(viewModel)); }
public void CreateTournamentCommand_CanBeCreated_IsCreated() { CreateTournamentCommand command = CreateTournamentCommand.Create(TournamentTestData.AggregateId, TournamentTestData.GolfClubId, TournamentTestData.CreateTournamentRequest); command.ShouldNotBeNull(); command.CommandId.ShouldNotBe(Guid.Empty); command.TournamentId.ShouldBe(TournamentTestData.AggregateId); command.GolfClubId.ShouldBe(TournamentTestData.GolfClubId); command.CreateTournamentRequest.ShouldNotBeNull(); command.CreateTournamentRequest.ShouldBe(TournamentTestData.CreateTournamentRequest); }
private Event[] Map_tournament(string tournament_id, string created, CreateTournamentCommand cmd) { var tournament_data = new TournamentData() { Id = tournament_id, Name = cmd.Name, Created = created }; return(new Event[] { new TournamentCreated(nameof(TournamentCreated), new TournamentContext(tournament_id, nameof(TournamentContext)), tournament_data) }); }
public async Task Handle_GivenInvalidRequest_ShouldThroTournamentActiveDateMustStartOnMondayException() { // Arrange var command = new CreateTournamentCommand { StartDate = new DateTime(2019, 01, 01) }; var sut = new CreateTournamentCommandHandler(It.IsAny <IDeletableEntityRepository <Tournament> >(), It.IsAny <IDeletableEntityRepository <TournamentFormat> >(), It.IsAny <ICloudinaryHelper>(), It.IsAny <IMediator>()); // Act & Assert await Should.ThrowAsync <TournamentActiveDateMustStartOnMondayException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
public async Task <IActionResult> Create(CreateTournamentCommand command) { if (!this.ModelState.IsValid) { command.Formats = await this.Mediator.Send(new GetAllTournamentFormatsSelectListQuery()); return(this.View(command)); } await this.Mediator.Send(command); return(this.RedirectToAction(nameof(Index))); }
public CommandStatus Handle(CreateTournamentCommand command) { var tournament = Initialize_tournament_datas(command); var competitors = Initialize_tournament_competitors(command.competitorsIds); tournament.Competitors = competitors.ToList(); var first_round = _director.New_round(tournament.Competitors, tournament.Options, 0); tournament.Rounds.Add(first_round); _tournament_repo.Save(tournament); return(new Success()); }
public async Task Handle_GivenInvalidRequest_ShouldThrowEntityAlreadyExistsException() { // Arrange var command = new CreateTournamentCommand { Name = "TestTournament1", StartDate = new DateTime(2019, 08, 12), }; var sut = new CreateTournamentCommandHandler(this.deletableEntityRepository, It.IsAny <IDeletableEntityRepository <TournamentFormat> >(), It.IsAny <ICloudinaryHelper>(), It.IsAny <IMediator>()); // Act & Assert await Should.ThrowAsync <EntityAlreadyExistsException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
public string Manage(TournamentFeedModel feedModel) { TournamentByNameQuery query = new TournamentByNameQuery(feedModel.Name); Tournament tournament = queryDispatcher.Dispatch <TournamentByNameQuery, Tournament>(query); if (tournament != null) { return(tournament.Id); } CreateTournamentCommand command = Mapper.Map <CreateTournamentCommand>(feedModel); string tournamentId = commandDispatcher.Dispatch <CreateTournamentCommand, string>(command); return(tournamentId); }
public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException() { // Arrange var command = new CreateTournamentCommand { FormatId = 131341, StartDate = new DateTime(2019, 08, 12), }; var tournamentFormatsRepository = new EfDeletableEntityRepository <TournamentFormat>(this.dbContext); var sut = new CreateTournamentCommandHandler(this.deletableEntityRepository, tournamentFormatsRepository, It.IsAny <ICloudinaryHelper>(), It.IsAny <IMediator>()); // Act & Assert await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>())); }
private Event[] Map_options(string tournament_id, CreateTournamentCommand cmd) { var options_data = new OptionsData() { Tables = cmd.Tables, Sets = cmd.Sets, Points = cmd.Points, Points_drawn = cmd.PointsDrawn, Drawn = cmd.Drawn, Fair_lots = cmd.FairLots }; return(new Event[] { new OptionsCreated(nameof(TournamentCreated), new TournamentContext(tournament_id, nameof(TournamentContext)), options_data) }); }
public ActionResult CreateTournament(TournamentModel tournamentModel) { ISystemResponseMessages systemMessages = new SystemResponseMessages(ApplicationResponseMessagesEnum.NoAction, ""); var tournament = new TournamentData.ApplicationModels.Tournament(); tournament.Name = tournamentModel.Name; var command = new CreateTournamentCommand(tournament, _context); _tournamentDomainClient.PerformCommand(command, out systemMessages); if (systemMessages.MessageState().Equals(ApplicationResponseMessagesEnum.Success)) { return(new HttpStatusCodeResult(HttpStatusCode.OK)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Data not captured")); }
public void TournamentCommandHandler_HandleCommand_CreateTournamentCommand_CommandHandled() { Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >(); golfClubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse()); Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >(); tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(TournamentTestData.GetEmptyTournamentAggregate); Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>(); TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object, tournamentRepository.Object, tournamentApplicationService.Object); CreateTournamentCommand command = TournamentTestData.GetCreateTournamentCommand(); Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); }); }
public void TournamentCommandHandler_HandleCommand_CreateTournamentCommand_ClubNotFound_ErrorThrown() { // test added as part of bug #29 fixes Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >(); golfClubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())).ReturnsAsync(GolfClubTestData.GetEmptyGolfClubAggregate); Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >(); tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(TournamentTestData.GetEmptyTournamentAggregate); Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>(); TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object, tournamentRepository.Object, tournamentApplicationService.Object); CreateTournamentCommand command = TournamentTestData.GetCreateTournamentCommand(); Should.Throw <NotFoundException>(async() => { await handler.Handle(command, CancellationToken.None); }); }
public TournamentDTO Add(CreateTournamentCommand request) { // Validates entity if (request == null) { return(null); } // Mapping var instance = new FIFATournament { Title = request.Title, TimeCreated = DateTime.Now }; FIFATournDB.Add(instance); return(new TournamentDTO { Title = instance.Title, Matches = instance.Matches, }); }
private Tournament Initialize_tournament_datas(CreateTournamentCommand command) { var tournament = new Tournament(); tournament.Id = _id_provider.Get_new_id(); tournament.Name = command.Name; tournament.Date = _date_Provider.Get_current_date(); var options = new Options(); options.Tables = command.Tables; options.Points = command.Points; options.Sets = command.Sets; options.Points_on_tied = command.PointsTied; options.Tied = command.Tied; options.Walkover = command.Walkover; options.Fair_lots = command.FairLots; tournament.Options = options; tournament.Rounds = new List <Round>(); return(tournament); }
public async Task Handle_GivenValidRequest_ShouldCreateEntity() { // Arrange var cloudinaryHelperMock = new Mock <ICloudinaryHelper>(); var cloudinaryMock = new Mock <Cloudinary>(); var imagePlaceholderUrl = "https://steamcdn-a.akamaihd.net/steam/apps/440/header.jpg"; cloudinaryHelperMock .Setup(x => x.UploadImage(It.IsAny <IFormFile>(), It.IsAny <string>(), It.IsAny <Transformation>())) .ReturnsAsync(imagePlaceholderUrl); var tournamentFormatsRepository = new EfDeletableEntityRepository <TournamentFormat>(this.dbContext); var command = new CreateTournamentCommand { Name = "ValidTournament", Description = "ValidDescription", StartDate = new DateTime(2019, 08, 12), EndDate = new DateTime(2019, 09, 08), FormatId = 1, TournamentImage = It.IsAny <IFormFile>() }; var sut = new CreateTournamentCommandHandler(this.deletableEntityRepository, tournamentFormatsRepository, cloudinaryHelperMock.Object, this.mediatorMock.Object); // Act var id = await sut.Handle(command, It.IsAny <CancellationToken>()); // Assert id.ShouldBeGreaterThan(0); var createdTournament = this.deletableEntityRepository.AllAsNoTracking().FirstOrDefault(x => x.Id == id); createdTournament.Name.ShouldBe("ValidTournament"); createdTournament.Description.ShouldBe("ValidDescription"); createdTournament.EndDate.Month.ShouldBe(9); }
public IActionResult Create_tournament(CreateTournamentCommand create_tournament_command) { _logger.LogInformation($"create tournament command: { create_tournament_command.Name }"); using (var msgpump = new MessagePump(_es)) { var id_provider = new IdProvider(); var date_provider = new DateProvider(); var context_manager = new CreateTournamentCommandContextManager(_es); var message_processor = new CreateTournamentCommandProcessor(id_provider, date_provider); msgpump.Register <CreateTournamentCommand>(context_manager, message_processor); var result = msgpump.Handle(create_tournament_command) as CommandStatus; if (result is Success) { return(Ok()); } else { return(BadRequest()); } } }
/// <summary> /// Creates the handler. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> private ICommandHandler CreateHandler(CreateTournamentCommand command) { return(new TournamentCommandHandler(this.ClubRepository, this.TournamentRepository, this.TournamentApplicationService)); }
public CommandResult <SwissTournamentContext> ProcessCommand(SwissTournamentContext context, CreateTournamentCommand command) { var rng = new Random((int)command.Timestamp.UtcTicks); return(new CommandAcceptedResult <SwissTournamentContext>( new SwissTournamentContext(context, tournamentSeed: rng.Next()) )); }
public async Task <IActionResult> CreateTournament(CreateTournamentCommand createTournamentCommand) { var tournamentId = await Mediator.Send(createTournamentCommand); return(CreatedAtAction(nameof(GetTournamentById), new { tournamentId }, null)); }
public async Task <ActionResult <CreateTournamentResult> > CreateTournament([FromBody] CreateTournamentCommand createTournamentCommand) { return(await _mediator.Send(createTournamentCommand)); }
public Task <Response <TournamentDTO> > Create(CreateTournamentCommand request) { return(_mediator.Send(request)); }
public CommandStatus Create_turnier([Payload] CreateTournamentCommand createTournamentCommand) { Console.WriteLine("create new turnier"); return(_createTournamentCommandHandling().Handle(createTournamentCommand)); }
public static CreateTournamentCommand GetCreateTournamentCommand() { return(CreateTournamentCommand.Create(TournamentTestData.AggregateId, TournamentTestData.GolfClubId, TournamentTestData.CreateTournamentRequest)); }