public async Task SignUpPlayerForTournament(Guid tournamentId,
                                                    Guid playerId, CancellationToken cancellationToken)
        {
            // Validate the tournament Id
            TournamentAggregate tournament = await this.TournamentRepository.GetLatestVersion(tournamentId, cancellationToken);

            PlayerAggregate player = await this.PlayerRepository.GetLatestVersion(playerId, cancellationToken);

            if (!player.HasBeenRegistered)
            {
                throw new InvalidOperationException("A player must be registered to sign up for a club tournament");
            }

            try
            {
                GolfClubMembershipAggregate golfClubMembership = await this.ClubMembershipRepository.GetLatestVersion(tournament.GolfClubId, cancellationToken);

                golfClubMembership.GetMembership(player.AggregateId, player.DateOfBirth, player.Gender);
            }
            catch (NotFoundException nex)
            {
                throw new InvalidOperationException("A player must be a member of the club to sign up for a club tournament");
            }

            tournament.SignUpForTournament(playerId);

            await this.TournamentRepository.SaveChanges(tournament, cancellationToken);
        }
Ejemplo n.º 2
0
        public void GolfClubMembershipAggregate_RequestMembership_PlayerToYoung_RequestRejected()
        {
            GolfClubMembershipAggregate aggregate = GolfClubMembershipTestData.GetCreatedGolfClubMembershipAggregate();

            // Get the lowest valid age
            DateTime dateOfBirth = DateTime.Now.AddYears(-13);

            // Now add a day to make it invalid
            dateOfBirth = dateOfBirth.AddDays(1);

            aggregate.RequestMembership(GolfClubMembershipTestData.PlayerId,
                                        GolfClubMembershipTestData.PlayerFullName,
                                        dateOfBirth,
                                        GolfClubMembershipTestData.PlayerGender,
                                        GolfClubMembershipTestData.RequestDateAndTime);

            MembershipDataTransferObject membership = aggregate.GetMembership(GolfClubMembershipTestData.PlayerId, dateOfBirth, GolfClubMembershipTestData.PlayerGender);

            membership.MembershipId.ShouldNotBe(Guid.Empty);
            membership.PlayerId.ShouldBe(GolfClubMembershipTestData.PlayerId);
            membership.PlayerFullName.ShouldBe(GolfClubMembershipTestData.PlayerFullName);
            membership.PlayerDateOfBirth.ShouldBe(dateOfBirth);
            membership.PlayerGender.ShouldBe(GolfClubMembershipTestData.PlayerGender);
            membership.RejectedDateAndTime.ShouldBe(GolfClubMembershipTestData.RequestDateAndTime);
            membership.AcceptedDateAndTime.ShouldBe(DateTime.MinValue);
            membership.RejectionReason.ShouldBe($"Player Id {GolfClubMembershipTestData.PlayerId} is too young.");
            membership.Status.ShouldBe(2);
        }
Ejemplo n.º 3
0
        public void GolfClubMembershipAggregate_GetMembership_NoMemberships_ErrorThrown()
        {
            GolfClubMembershipAggregate aggregate = GolfClubMembershipTestData.GetCreatedGolfClubMembershipAggregate();

            Should.Throw <NotFoundException>(() =>
            {
                aggregate.GetMembership(GolfClubMembershipTestData.PlayerId,
                                        GolfClubMembershipTestData.PlayerDateOfBirth,
                                        GolfClubMembershipTestData.PlayerGender);
            });
        }
Ejemplo n.º 4
0
        public void GolfClubMembershipAggregate_GetMembership_MembershipReturned()
        {
            GolfClubMembershipAggregate aggregate = GolfClubMembershipTestData.GetCreatedGolfClubMembershipAggregateWithMembershipRequested();

            MembershipDataTransferObject membership = aggregate.GetMembership(GolfClubMembershipTestData.PlayerId, GolfClubMembershipTestData.PlayerDateOfBirth, GolfClubMembershipTestData.PlayerGender);

            membership.MembershipId.ShouldNotBe(Guid.Empty);
            membership.PlayerId.ShouldBe(GolfClubMembershipTestData.PlayerId);
            membership.PlayerFullName.ShouldBe(GolfClubMembershipTestData.PlayerFullName);
            membership.PlayerDateOfBirth.ShouldBe(GolfClubMembershipTestData.PlayerDateOfBirth);
            membership.PlayerGender.ShouldBe(GolfClubMembershipTestData.PlayerGender);
            membership.AcceptedDateAndTime.ShouldBe(GolfClubMembershipTestData.RequestDateAndTime);
            membership.RejectedDateAndTime.ShouldBe(DateTime.MinValue);
            membership.RejectionReason.ShouldBeNullOrEmpty();
            membership.Status.ShouldBe(1);
        }
Ejemplo n.º 5
0
        public void GolfClubMembershipAggregate_RequestMembership_NoSpaceForNewMembers_RequestRejected()
        {
            GolfClubMembershipAggregate aggregate = GolfClubMembershipTestData.GetCreatedGolfClubMembershipAggregateWithNumberOfAcceptedMembershipRequests(500);

            aggregate.RequestMembership(GolfClubMembershipTestData.PlayerId,
                                        GolfClubMembershipTestData.PlayerFullName,
                                        GolfClubMembershipTestData.PlayerDateOfBirth,
                                        GolfClubMembershipTestData.PlayerGender,
                                        GolfClubMembershipTestData.RequestDateAndTime);

            MembershipDataTransferObject membership = aggregate.GetMembership(GolfClubMembershipTestData.PlayerId,
                                                                              GolfClubMembershipTestData.PlayerDateOfBirth,
                                                                              GolfClubMembershipTestData.PlayerGender);

            membership.MembershipId.ShouldNotBe(Guid.Empty);
            membership.PlayerId.ShouldBe(GolfClubMembershipTestData.PlayerId);
            membership.PlayerFullName.ShouldBe(GolfClubMembershipTestData.PlayerFullName);
            membership.PlayerDateOfBirth.ShouldBe(GolfClubMembershipTestData.PlayerDateOfBirth);
            membership.PlayerGender.ShouldBe(GolfClubMembershipTestData.PlayerGender);
            membership.RejectedDateAndTime.ShouldBe(GolfClubMembershipTestData.RequestDateAndTime);
            membership.AcceptedDateAndTime.ShouldBe(DateTime.MinValue);
            membership.RejectionReason.ShouldBe($"No more space at club for Player Id {GolfClubMembershipTestData.PlayerId}");
            membership.Status.ShouldBe(2);
        }
Ejemplo n.º 6
0
        public void GolfClubMembershipAggregate_RequestMembership_MembershipRequested()
        {
            GolfClubMembershipAggregate aggregate = GolfClubMembershipTestData.GetCreatedGolfClubMembershipAggregate();

            aggregate.RequestMembership(GolfClubMembershipTestData.PlayerId,
                                        GolfClubMembershipTestData.PlayerFullName,
                                        GolfClubMembershipTestData.PlayerDateOfBirth,
                                        GolfClubMembershipTestData.PlayerGender,
                                        GolfClubMembershipTestData.RequestDateAndTime);

            MembershipDataTransferObject membership = aggregate.GetMembership(GolfClubMembershipTestData.PlayerId,
                                                                              GolfClubMembershipTestData.PlayerDateOfBirth,
                                                                              GolfClubMembershipTestData.PlayerGender);

            membership.MembershipId.ShouldNotBe(Guid.Empty);
            membership.PlayerId.ShouldBe(GolfClubMembershipTestData.PlayerId);
            membership.PlayerFullName.ShouldBe(GolfClubMembershipTestData.PlayerFullName);
            membership.PlayerDateOfBirth.ShouldBe(GolfClubMembershipTestData.PlayerDateOfBirth);
            membership.PlayerGender.ShouldBe(GolfClubMembershipTestData.PlayerGender);
            membership.AcceptedDateAndTime.ShouldBe(GolfClubMembershipTestData.RequestDateAndTime);
            membership.AcceptedDateAndTime.ShouldNotBe(DateTime.MinValue);
            membership.MembershipNumber.ShouldBe("000001");
            membership.Status.ShouldBe(1);
        }