Пример #1
0
        public async Task GetGroupContacts()
        {
            var user             = fillTestDbHelper.Users.FirstOrDefault(opt => opt.Groups.Any());
            var group            = fillTestDbHelper.Groups.FirstOrDefault(opt => opt.UserId == user.Id);
            var expectedContacts = ContactConverter.GetContactsDto(group.ContactGroups.Select(opt => opt.Contact).ToList());
            var actualContacts   = await groupsService.GetGroupContactsAsync(group.GroupId, user.Id);

            Assert.Equal(expectedContacts.Select(opt => opt.ContactId), actualContacts.Select(opt => opt.ContactId));
        }
Пример #2
0
        public async Task <Response> CreateResponseAsync()
        {
            List <ContactDto> contactsDto = await groupsService.GetGroupContactsAsync(
                request.GroupId, clientConnection.UserId.GetValueOrDefault(), request.NavigationUserId.GetValueOrDefault()).ConfigureAwait(false);

            List <ContactVm> contactsVm = ContactConverter.GetContactsVm(contactsDto);
            IEnumerable <IGrouping <long, UserDto> > groupedUsers = contactsDto.Select(opt => opt.ContactUser).GroupBy(opt => opt.NodeId.GetValueOrDefault());
            ConcurrentBag <UserVm> resultUsers   = new ConcurrentBag <UserVm>();
            List <Task>            getUsersTasks = new List <Task>();

            foreach (var group in groupedUsers)
            {
                getUsersTasks.Add(Task.Run(async() =>
                {
                    var nodeConnection = connectionsService.GetNodeConnection(group.Key);
                    if (group.Key != NodeSettings.Configs.Node.Id && nodeConnection != null)
                    {
                        await MetricsHelper.Instance.SetCrossNodeApiInvolvedAsync(request.RequestId).ConfigureAwait(false);
                        var users = await nodeRequestSender.GetUsersInfoAsync(
                            group.Select(opt => opt.Id).ToList(),
                            clientConnection.UserId,
                            nodeConnection).ConfigureAwait(false);
                        resultUsers.AddRange(users);
                        resultUsers.AddRange(users);
                    }
                    else
                    {
                        resultUsers.AddRange(UserConverter.GetUsersVm(group.ToList(), clientConnection.UserId));
                    }
                }));
            }
            await Task.WhenAll(getUsersTasks).ConfigureAwait(false);

            foreach (var contact in contactsVm)
            {
                contact.ContactUser = resultUsers.FirstOrDefault(opt => opt.Id == contact.ContactUserId);
            }
            return(new ContactsResponse(request.RequestId, contactsVm));
        }