public async Task <IActionResult> RequestClubMembership([FromRoute] Guid golfClubId, [FromRoute] Guid playerId, 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 RequestClubMembershipCommand command = RequestClubMembershipCommand.Create(Guid.Parse(playerIdClaim.Value), golfClubId); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"api/players/{playerId}", new RequestClubMembershipResponse { GolfClubId = golfClubId, PlayerId = playerId, MembershipId = Guid.Empty })); }
/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(RequestClubMembershipCommand command, CancellationToken cancellationToken) { // Call the application service method await this.GolfClubMembershipApplicationService.RequestClubMembership(command.PlayerId, command.GolfClubId, cancellationToken); // No response to be set }
public void RequestClubMembershipCommand_CanBeCreated_IsCreated() { RequestClubMembershipCommand command = RequestClubMembershipCommand.Create(GolfClubTestData.PlayerId, GolfClubTestData.AggregateId); command.ShouldNotBeNull(); command.CommandId.ShouldNotBe(Guid.Empty); command.PlayerId.ShouldBe(GolfClubTestData.PlayerId); command.GolfClubId.ShouldBe(GolfClubTestData.AggregateId); }
public void GolfClubCommandHandler_HandleCommand_RequestClubMembershipCommand_CommandHandled() { Mock <IAggregateRepository <GolfClubAggregate> > repository = new Mock <IAggregateRepository <GolfClubAggregate> >(); Mock <ISecurityService> oAuth2SecurityService = new Mock <ISecurityService>(); Mock <IGolfClubMembershipApplicationService> golfClubMembershipApplicationService = new Mock <IGolfClubMembershipApplicationService>(); golfClubMembershipApplicationService.Setup(x => x.RequestClubMembership(It.IsAny <Guid>(), It.IsAny <Guid>(), CancellationToken.None)) .Returns(Task.CompletedTask); GolfClubCommandHandler handler = new GolfClubCommandHandler(repository.Object, oAuth2SecurityService.Object, golfClubMembershipApplicationService.Object); RequestClubMembershipCommand command = GolfClubTestData.GetRequestClubMembershipCommand(); Should.NotThrow(async() => { await handler.Handle(command, CancellationToken.None); }); }
/// <summary> /// Creates the handler. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> private ICommandHandler CreateHandler(RequestClubMembershipCommand command) { return(new GolfClubCommandHandler(this.ClubRepository, this.OAuth2SecurityService, this.GolfClubMembershipApplicationService)); }