Example #1
0
        public void ProduceTournamentResultCommand_CanBeCreated_IsCreated()
        {
            ProduceTournamentResultCommand command =
                ProduceTournamentResultCommand.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(ProduceTournamentResultCommand command,
                                         CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken);

            // Produce the result
            tournament.ProduceResult();

            // 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());
        }
Example #4
0
        public void TournamentCommandHandler_HandleCommand_ProduceTournamentResultCommand_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.GetCompletedTournamentAggregateWithCSSCalculatedAggregate(1, 2, 2, 2, 5, 3));

            Mock <ITournamentApplicationService> tournamentApplicationService = new Mock <ITournamentApplicationService>();

            TournamentCommandHandler handler = new TournamentCommandHandler(golfClubRepository.Object,
                                                                            tournamentRepository.Object,
                                                                            tournamentApplicationService.Object);

            ProduceTournamentResultCommand command = TournamentTestData.GetProduceTournamentResultCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
Example #5
0
        public async Task <IActionResult> ProduceResult([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
            ProduceTournamentResultCommand command = ProduceTournamentResultCommand.Create(Guid.Parse(golfClubIdClaim.Value), tournamentId);

            // Route the command
            await this.CommandRouter.Route(command, cancellationToken);

            // return the result
            return(this.NoContent());
        }
 public static ProduceTournamentResultCommand GetProduceTournamentResultCommand()
 {
     return(ProduceTournamentResultCommand.Create(TournamentTestData.GolfClubId, TournamentTestData.AggregateId));
 }
Example #7
0
 /// <summary>
 /// Creates the handler.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 private ICommandHandler CreateHandler(ProduceTournamentResultCommand command)
 {
     return(new TournamentCommandHandler(this.ClubRepository, this.TournamentRepository, this.TournamentApplicationService));
 }