public async Task <Guid> RegisterPlayer(RegisterPlayerCommand command, PlayerVerification verification)
        {
            command.PlayerId = Guid.NewGuid();
            await _playerVerificationService.VerifyPlayer(verification);

            ICommandHandler <RegisterPlayerCommand> handler = _commandHandlerProvider.GetCommandHandler <RegisterPlayerCommand>();
            await handler.HandleAsync(command);

            return(command.PlayerId);
        }
        public void RegisterPlayerCommand_CanBeCreated_IsCreated()
        {
            RegisterPlayerCommand command = RegisterPlayerCommand.Create(PlayerTestData.AggregateId, PlayerTestData.RegisterPlayerRequest);

            command.ShouldNotBeNull();
            command.CommandId.ShouldNotBe(Guid.Empty);
            command.PlayerId.ShouldBe(PlayerTestData.AggregateId);
            command.RegisterPlayerRequest.ShouldNotBeNull();
            command.RegisterPlayerRequest.ShouldBe(PlayerTestData.RegisterPlayerRequest);
        }
Example #3
0
        public async Task <IActionResult> CreatePlayer([FromBody] RegisterPlayerRequest request,
                                                       CancellationToken cancellationToken)
        {
            Guid playerId = Guid.NewGuid();

            // Create the command
            RegisterPlayerCommand command = RegisterPlayerCommand.Create(playerId, request);

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

            // return the result
            return(this.Created($"{PlayerController.ControllerRoute}/{playerId}", new RegisterPlayerResponse
            {
                PlayerId = playerId
            }));
        }
Example #4
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task HandleCommand(RegisterPlayerCommand command, CancellationToken cancellationToken)
        {
            // Rehydrate the aggregate
            PlayerAggregate player = await this.PlayerRepository.GetLatestVersion(command.PlayerId, cancellationToken);

            // Call the aggregate method
            player.Register(command.RegisterPlayerRequest.GivenName,
                            command.RegisterPlayerRequest.MiddleName,
                            command.RegisterPlayerRequest.FamilyName,
                            command.RegisterPlayerRequest.Gender,
                            command.RegisterPlayerRequest.DateOfBirth,
                            command.RegisterPlayerRequest.ExactHandicap,
                            command.RegisterPlayerRequest.EmailAddress);

            // Now create a security user
            RegisterUserRequest request = new RegisterUserRequest
            {
                EmailAddress = command.RegisterPlayerRequest.EmailAddress,
                Claims       = new Dictionary <String, String>
                {
                    { "PlayerId", command.PlayerId.ToString() }
                },
                Password    = "******",
                PhoneNumber = "123456789",
                MiddleName  = command.RegisterPlayerRequest.MiddleName,
                FamilyName  = command.RegisterPlayerRequest.FamilyName,
                GivenName   = command.RegisterPlayerRequest.GivenName,
                Roles       = new List <String>
                {
                    "Player"
                }
            };
            RegisterUserResponse createSecurityUserResponse = await this.OAuth2SecurityService.RegisterUser(request, cancellationToken);

            // Record this in the aggregate
            player.CreateSecurityUser(createSecurityUserResponse.UserId);

            // Save the changes
            await this.PlayerRepository.SaveChanges(player, cancellationToken);

            // Setup the response
            command.Response = new RegisterPlayerResponse {
                PlayerId = command.PlayerId
            };
        }
        public void PlayerCommandHandler_HandleCommand_RegisterPlayerCommand_CommandHandled()
        {
            Mock <IAggregateRepository <PlayerAggregate> > playerRepository = new Mock <IAggregateRepository <PlayerAggregate> >();

            playerRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(PlayerTestData.GetEmptyPlayerAggregate());
            Mock <ISecurityService> oAuth2SecurityService = new Mock <ISecurityService>();

            oAuth2SecurityService
            .Setup(o => o.RegisterUser(It.IsAny <RegisterUserRequest>(), CancellationToken.None))
            .ReturnsAsync(PlayerTestData.GetRegisterUserResponse());
            Mock <IAggregateRepository <GolfClubAggregate> > clubRepository = new Mock <IAggregateRepository <GolfClubAggregate> >();

            clubRepository.Setup(c => c.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None))
            .ReturnsAsync(GolfClubTestData.GetGolfClubAggregateWithMeasuredCourse());

            PlayerCommandHandler handler = new PlayerCommandHandler(playerRepository.Object, oAuth2SecurityService.Object, clubRepository.Object);

            RegisterPlayerCommand command = PlayerTestData.GetRegisterPlayerCommand();

            Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); });
        }
 public PlayerActionsController(RegisterPlayerCommand registerPlayerCommand, MovePlayerCommand movePlayerCommand)
 {
     this.registerPlayerCommand = registerPlayerCommand;
     this.movePlayerCommand     = movePlayerCommand;
 }
Example #7
0
 public Task Register([FromBody] RegisterPlayerCommand command, CancellationToken cancellationToken)
 {
     return(_mediator.Send(command, cancellationToken));
 }
Example #8
0
 public static RegisterPlayerCommand GetRegisterPlayerCommand()
 {
     return(RegisterPlayerCommand.Create(PlayerTestData.AggregateId, PlayerTestData.RegisterPlayerRequest));
 }
Example #9
0
 /// <summary>
 /// Creates the handler.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 private ICommandHandler CreateHandler(RegisterPlayerCommand command)
 {
     return(new PlayerCommandHandler(this.PlayerRepository, this.OAuth2SecurityService, this.ClubRepository));
 }