Exemplo n.º 1
0
        public void SignUpForTournamentCommand_CanBeCreated_IsCreated()
        {
            SignUpForTournamentCommand command = SignUpForTournamentCommand.Create(TournamentTestData.AggregateId, TournamentTestData.PlayerId);

            command.ShouldNotBeNull();
            command.CommandId.ShouldNotBe(Guid.Empty);
            command.TournamentId.ShouldBe(TournamentTestData.AggregateId);
            command.PlayerId.ShouldBe(TournamentTestData.PlayerId);
        }
Exemplo n.º 2
0
        public void TournamentCommandHandler_HandleCommand_SignUpForTournamentCommand_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.GetCreatedTournamentAggregate);

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

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

            SignUpForTournamentCommand command = TournamentTestData.GetSignUpForTournamentCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SignInForTournament([FromRoute] Guid playerId,
                                                              [FromRoute] Guid tournamentId,
                                                              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
            SignUpForTournamentCommand command = SignUpForTournamentCommand.Create(tournamentId, Guid.Parse(playerIdClaim.Value));

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

            // return the result
            return(this.Ok());
        }
 public static SignUpForTournamentCommand GetSignUpForTournamentCommand()
 {
     return(SignUpForTournamentCommand.Create(TournamentTestData.AggregateId, TournamentTestData.PlayerId));
 }
 /// <summary>
 /// Handles the command.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 private async Task HandleCommand(SignUpForTournamentCommand command,
                                  CancellationToken cancellationToken)
 {
     await this.TournamentApplicationService.SignUpPlayerForTournament(command.TournamentId, command.PlayerId, cancellationToken);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates the handler.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 private ICommandHandler CreateHandler(SignUpForTournamentCommand command)
 {
     return(new TournamentCommandHandler(this.ClubRepository, this.TournamentRepository, this.TournamentApplicationService));
 }