示例#1
0
        public async Task Success_Accept_Pending_Friend_Invitation()
        {
            await _relationService.RelationInviteAsync(SenderId, TargetId, CharacterRelationType.Friend);

            IEnumerable <RelationInvitationDto> invitations = await _relationService.GetPendingInvitationByCharacterIdAsync(TargetId);

            Assert.IsNotNull(invitations);

            RelationInvitationDto invitation = invitations.FirstOrDefault(s => s.OwnerId == SenderId);

            Assert.IsNotNull(invitation);

            // accept the invitation
            List <RelationDto> relation = await _relationService.RelationInviteProcessAsync(invitation.Id, RelationInvitationProcessType.Accept);

            IEnumerable <RelationDto> relations = await _relationService.GetRelationListByCharacterIdAsync(SenderId);

            Assert.IsTrue(relations.Any(s => s.OwnerId == SenderId && s.TargetId == TargetId && s.Type == CharacterRelationType.Friend && relation.Any(c => c.Id == s.Id)));

            // invitations should be clear
            IEnumerable <RelationInvitationDto> invitationsEmpty = await _relationService.GetPendingInvitationByCharacterIdAsync(TargetId);

            Assert.IsTrue(!invitationsEmpty.Any());

            await _relationService.RelationRemoveAsync(relations);
        }
        protected override async Task Handle(RelationInvitationProcessEvent e, CancellationToken cancellation)
        {
            IEnumerable <RelationInvitationDto> invitations = await _relationService.GetPendingInvitationByCharacterIdAsync(e.Sender.Id);

            RelationInvitationDto invitation = invitations.FirstOrDefault(s => s.TargetId == e.Sender.Id && s.OwnerId == e.TargetCharacterId);

            if (invitation == null)
            {
                // no invitation to process
                return;
            }

            await _relationService.RelationInviteProcessAsync(invitation.Id, e.Type);
        }