Exemple #1
0
        public void RecordMemberTournamentScoreCommand_CanBeCreated_IsCreated()
        {
            RecordPlayerTournamentScoreCommand command =
                RecordPlayerTournamentScoreCommand.Create(TournamentTestData.PlayerId, TournamentTestData.AggregateId, TournamentTestData.RecordMemberTournamentScoreRequest);

            command.ShouldNotBeNull();
            command.CommandId.ShouldNotBe(Guid.Empty);
            command.TournamentId.ShouldBe(TournamentTestData.AggregateId);
            command.PlayerId.ShouldBe(TournamentTestData.PlayerId);
            command.RecordPlayerTournamentScoreRequest.ShouldNotBeNull();
            command.RecordPlayerTournamentScoreRequest.ShouldBe(TournamentTestData.RecordMemberTournamentScoreRequest);
        }
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(RecordPlayerTournamentScoreCommand command,
                                         CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(command.TournamentId, cancellationToken);

            tournament.RecordPlayerScore(command.PlayerId,
                                         command.RecordPlayerTournamentScoreRequest.PlayingHandicap,
                                         command.RecordPlayerTournamentScoreRequest.HoleScores);

            // Save the changes
            await this.TournamentRepository.SaveChanges(tournament, cancellationToken);
        }
Exemple #3
0
        public void TournamentCommandHandler_HandleCommand_RecordMemberTournamentScoreCommand_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.GetCreatedTournamentAggregateWithPlayerSignedUp);

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

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

            RecordPlayerTournamentScoreCommand command = TournamentTestData.GetRecordPlayerTournamentScoreCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
Exemple #4
0
        public async Task <IActionResult> RecordPlayerScore([FromRoute] Guid playerId,
                                                            [FromRoute] Guid tournamentId,
                                                            [FromBody] RecordPlayerTournamentScoreRequest request,
                                                            CancellationToken cancellationToken)
        {
            // Get the Player Id claim from the user
            Claim playerIdClaim = ClaimsHelper.GetUserClaim(this.User, CustomClaims.PlayerId, playerId.ToString());

            Boolean validationResult = ClaimsHelper.ValidateRouteParameter(playerId, playerIdClaim);

            if (validationResult == false)
            {
                return(this.Forbid());
            }

            // Create the command
            RecordPlayerTournamentScoreCommand command = RecordPlayerTournamentScoreCommand.Create(Guid.Parse(playerIdClaim.Value), tournamentId, request);

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

            // return the result
            return(this.Ok());
        }
 public static RecordPlayerTournamentScoreCommand GetRecordPlayerTournamentScoreCommand()
 {
     return(RecordPlayerTournamentScoreCommand.Create(TournamentTestData.PlayerId, TournamentTestData.AggregateId, TournamentTestData.RecordMemberTournamentScoreRequest));
 }
Exemple #6
0
 /// <summary>
 /// Creates the handler.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 private ICommandHandler CreateHandler(RecordPlayerTournamentScoreCommand command)
 {
     return(new TournamentCommandHandler(this.ClubRepository, this.TournamentRepository, this.TournamentApplicationService));
 }