public void CancelTournamentCommand_CanBeCreated_IsCreated() { CancelTournamentCommand command = CancelTournamentCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId, TournamentTestData.CancelTournamentRequest); command.ShouldNotBeNull(); command.CommandId.ShouldNotBe(Guid.Empty); command.GolfClubId.ShouldBe(TournamentTestData.GolfClubId); command.TournamentId.ShouldBe(TournamentTestData.AggregateId); command.CancelTournamentRequest.ShouldNotBeNull(); command.CancelTournamentRequest.ShouldBe(TournamentTestData.CancelTournamentRequest); }
/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(CancelTournamentCommand command, CancellationToken cancellationToken) { // Rehydrate the aggregate TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken); DateTime cancelledDateTime = DateTime.Now; tournament.CancelTournament(cancelledDateTime, command.CancelTournamentRequest.CancellationReason); // 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_CancelTournamentCommand_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); CancelTournamentCommand command = TournamentTestData.GetCancelTournamentCommand(); Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); }); }
public async Task <IActionResult> Cancel([FromRoute] Guid golfClubId, [FromRoute] Guid tournamentId, [FromBody] CancelTournamentRequest request, 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 CancelTournamentCommand command = CancelTournamentCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId, request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.NoContent()); }
public static CancelTournamentCommand GetCancelTournamentCommand() { return(CancelTournamentCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId, TournamentTestData.CancelTournamentRequest)); }
/// <summary> /// Creates the handler. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> private ICommandHandler CreateHandler(CancelTournamentCommand command) { return(new TournamentCommandHandler(this.ClubRepository, this.TournamentRepository, this.TournamentApplicationService)); }