コード例 #1
0
 private TeamAggregate GetValidTeam()
 {
     return(TeamAggregate.Restore(_teamId, _teamName, new List <MemberEntity> {
         _adminMember
     },
                                  new List <TournamentId>()));
 }
コード例 #2
0
        public void validate_member_deletion_should_work_if_same_user()
        {
            var targetedMember = GetCommonMember();
            var team           = TeamAggregate.Restore(_teamId, _teamName,
                                                       new List <MemberEntity> {
                _adminMember, targetedMember
            }, new List <TournamentId>());

            team.ValidateMemberDeletionByMember(targetedMember.Id, targetedMember.Id);
        }
コード例 #3
0
        public void add_member_should_throw_if_user_already_exists()
        {
            var existingUser = GetCommonMember();
            var team         = TeamAggregate.Restore(_teamId, _teamName, new List <MemberEntity> {
                _adminMember, existingUser
            },
                                                     new List <TournamentId>());

            Assert.Throws <DomainException>(() => team.AddMember(existingUser));
        }
コード例 #4
0
        public void leave_not_joined_tournament_should_throw()
        {
            var team = TeamAggregate.Restore(_teamId, _teamName, new List <MemberEntity> {
                _adminMember
            },
                                             new List <TournamentId> {
                TestsHelper.GetTournamentId()
            });

            Assert.Throws <DomainException>(() => team.LeaveTournament(TestsHelper.GetTournamentId(), _adminMember.Id));
        }
コード例 #5
0
        public void remove_member_should_work()
        {
            var targetedMember = GetCommonMember();
            var team           = TeamAggregate.Restore(_teamId, _teamName,
                                                       new List <MemberEntity> {
                _adminMember, targetedMember
            }, new List <TournamentId>());

            team.RemoveMember(targetedMember.Id);
            Assert.AreEqual(1, team.Members.Count);
            CollectionAssert.DoesNotContain(team.Members, targetedMember);
        }
コード例 #6
0
        public void elevate_member_should_work()
        {
            var targetMember = GetCommonMember();
            var team         = TeamAggregate.Restore(_teamId, _teamName, new List <MemberEntity> {
                _adminMember, targetMember
            },
                                                     new List <TournamentId>());

            team.ElevateMember(targetMember.Id);
            Assert.AreEqual(true, targetMember.IsAdmin);
            Assert.AreEqual(false, _adminMember.IsAdmin);
        }
コード例 #7
0
        public void leave_tournament_should_work()
        {
            var existingTournamentId = TestsHelper.GetTournamentId();
            var team = TeamAggregate.Restore(_teamId, _teamName, new List <MemberEntity> {
                _adminMember
            },
                                             new List <TournamentId> {
                existingTournamentId
            });

            team.LeaveTournament(existingTournamentId, _adminMember.Id);
            CollectionAssert.DoesNotContain(team.TournamentIds, existingTournamentId);
        }
コード例 #8
0
        public void leave_tournament_without_admin_account_should_throw()
        {
            var commonMember         = GetCommonMember();
            var existingTournamentId = TestsHelper.GetTournamentId();
            var team = TeamAggregate.Restore(_teamId, _teamName, new List <MemberEntity> {
                _adminMember, commonMember
            },
                                             new List <TournamentId> {
                existingTournamentId
            });

            Assert.Throws <DomainException>(() => team.LeaveTournament(existingTournamentId, commonMember.Id));
        }
コード例 #9
0
        public void validate_member_deletion_should_throw_if_not_admin_and_not_same_user()
        {
            var noRightsMember = GetCommonMember();
            var targetedMember = GetCommonMember();
            var team           = TeamAggregate.Restore(_teamId, _teamName,
                                                       new List <MemberEntity> {
                _adminMember, noRightsMember, targetedMember
            }, new List <TournamentId>());

            Assert.Throws <DomainException>(() =>
            {
                team.ValidateMemberDeletionByMember(noRightsMember.Id, targetedMember.Id);
            });
        }
コード例 #10
0
        private Task <TeamAggregate> ToEntity(Team team)
        {
            var aggregate = TeamAggregate.Restore(
                new TeamId(team.Id),
                team.Name,
                team.UserTeams
                .Where(uT => uT.LeaveDate == null && !uT.User.IsDeleted)
                .Select(uT => new MemberEntity(new UserId(uT.UserId), uT.IsAdmin))
                .ToList(),
                team.ActiveParticipations
                .Select(p => new TournamentId(p.Tournament.Id))
                .Distinct()
                .ToList()
                );

            return(aggregate.ToTask());
        }