public void CompleteTournamentCommand_CanBeCreated_IsCreated() { CompleteTournamentCommand command = CompleteTournamentCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId); command.ShouldNotBeNull(); command.CommandId.ShouldNotBe(Guid.Empty); command.GolfClubId.ShouldBe(TournamentTestData.GolfClubId); command.TournamentId.ShouldBe(TournamentTestData.AggregateId); }
/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(CompleteTournamentCommand command, CancellationToken cancellationToken) { // Rehydrate the aggregate TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken); DateTime completedDateTime = DateTime.Now; tournament.CompleteTournament(completedDateTime); tournament.CalculateCSS(); // Save the changes await this.TournamentRepository.SaveChanges(tournament, cancellationToken); }
public async Task <IActionResult> PatchTournament([FromRoute] Guid golfClubId, [FromRoute] Guid tournamentId, TournamentPatchRequest tournamentPatchRequest, CancellationToken cancellationToken) { // Get the Golf Club Id claim from the user Claim golfClubIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.GolfClubId, golfClubId.ToString()); if (tournamentPatchRequest.Status == TournamentStatusUpdate.Complete) { // Create the command CompleteTournamentCommand command = CompleteTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId); // Route the command await this.CommandRouter.Route(command, cancellationToken); } else if (tournamentPatchRequest.Status == TournamentStatusUpdate.Cancel) { CancelTournamentRequest cancelTournamentRequest = new CancelTournamentRequest { CancellationReason = tournamentPatchRequest.CancellationReason }; // Create the command CancelTournamentCommand command = CancelTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId, cancelTournamentRequest); // Route the command await this.CommandRouter.Route(command, cancellationToken); } else if (tournamentPatchRequest.Status == TournamentStatusUpdate.ProduceResult) { // Create the command ProduceTournamentResultCommand command = ProduceTournamentResultCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId); // Route the command await this.CommandRouter.Route(command, cancellationToken); } else { return(this.BadRequest()); } // return the result return(this.Ok()); }
public void TournamentCommandHandler_HandleCommand_CompleteTournamentCommand_WithScores_CommandHandled() { Mock <IAggregateRepository <GolfClubAggregate> > golfClubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >(); Mock <IAggregateRepository <TournamentAggregate> > tournamentRepository = new Mock <IAggregateRepository <TournamentAggregate> >(); tournamentRepository.Setup(t => t.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>())) .ReturnsAsync(TournamentTestData.GetCreatedTournamentWithScoresRecordedAggregate); Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>(); TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object, tournamentRepository.Object, tournamentApplicationService.Object); CompleteTournamentCommand command = TournamentTestData.GetCompleteTournamentCommand(); Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); }); }
public async Task <IActionResult> Complete([FromRoute] Guid golfClubId, [FromRoute] Guid tournamentId, CancellationToken cancellationToken) { // 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 CompleteTournamentCommand command = CompleteTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.NoContent()); }
public static CompleteTournamentCommand GetCompleteTournamentCommand() { return(CompleteTournamentCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId)); }
/// <summary> /// Creates the handler. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> private ICommandHandler CreateHandler(CompleteTournamentCommand command) { return(new TournamentCommandHandler(this.ClubRepository, this.TournamentRepository, this.TournamentApplicationService)); }