public async Task <IActionResult> AddTournamentDivision([FromRoute] Guid golfClubId, [FromBody] AddTournamentDivisionToGolfClubRequest request, 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 AddTournamentDivisionToGolfClubCommand command = AddTournamentDivisionToGolfClubCommand.Create(Guid.Parse(golfClubIdClaim.Value), request); // Route the command await this.CommandRouter.Route(command, cancellationToken); // return the result return(this.Created($"{GolfClubController.ControllerRoute}/{golfClubId}/tournamentdivisions/{request.Division}", new AddTournamentDivisionToGolfClubResponse { GolfClubId = golfClubId, TournamentDivision = request.Division })); }
public void AddTournamentDivisionToGolfClubCommand_CanBeCreated_IsCreated() { AddTournamentDivisionToGolfClubCommand command = AddTournamentDivisionToGolfClubCommand.Create(GolfClubTestData.AggregateId, GolfClubTestData.AddTournamentDivisionToGolfClubRequest); command.ShouldNotBeNull(); command.CommandId.ShouldNotBe(Guid.Empty); command.GolfClubId.ShouldBe(GolfClubTestData.AggregateId); command.AddTournamentDivisionToGolfClubRequest.ShouldNotBeNull(); command.AddTournamentDivisionToGolfClubRequest.ShouldBe(GolfClubTestData.AddTournamentDivisionToGolfClubRequest); }
/// <summary> /// Handles the command. /// </summary> /// <param name="command">The command.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> private async Task HandleCommand(AddTournamentDivisionToGolfClubCommand command, CancellationToken cancellationToken) { // Rehydrate the aggregate GolfClubAggregate golfClubAggregate = await this.GolfClubRepository.GetLatestVersion(command.GolfClubId, cancellationToken); // Create the dto from the request in the command TournamentDivisionDataTransferObject tournamentDivisionDataTransferObject = new TournamentDivisionDataTransferObject { Division = command.AddTournamentDivisionToGolfClubRequest.Division, StartHandicap = command.AddTournamentDivisionToGolfClubRequest.StartHandicap, EndHandicap = command.AddTournamentDivisionToGolfClubRequest.EndHandicap }; golfClubAggregate.AddTournamentDivision(tournamentDivisionDataTransferObject); await this.GolfClubRepository.SaveChanges(golfClubAggregate, cancellationToken); }
public void GolfClubCommandHandler_HandleCommand_AddTournamentDivisionToGolfClubCommand_CommandHandled() { Mock <IAggregateRepository <GolfClubAggregate> > repository = new Mock <IAggregateRepository <GolfClubAggregate> >(); repository.Setup(r => r.GetLatestVersion(It.IsAny <Guid>(), CancellationToken.None)).ReturnsAsync(GolfClubTestData.GetCreatedGolfClubAggregate); Mock <ISecurityService> oAuth2SecurityService = new Mock <ISecurityService>(); oAuth2SecurityService .Setup(o => o.RegisterUser(It.IsAny <RegisterUserRequest>(), CancellationToken.None)) .ReturnsAsync(GolfClubTestData.GetRegisterUserResponse()); Mock <IGolfClubMembershipApplicationService> golfClubMembershipApplicationService = new Mock <IGolfClubMembershipApplicationService>(); GolfClubCommandHandler handler = new GolfClubCommandHandler(repository.Object, oAuth2SecurityService.Object, golfClubMembershipApplicationService.Object); AddTournamentDivisionToGolfClubCommand command = GolfClubTestData.GetAddTournamentDivisionToGolfClubCommand(); 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(AddTournamentDivisionToGolfClubCommand command) { return(new GolfClubCommandHandler(this.ClubRepository, this.OAuth2SecurityService, this.GolfClubMembershipApplicationService)); }