Exemplo n.º 1
0
        public override async Task <IEnumerable <Status> > GetUserTimelineAsync(StatusListParams statusListParams)
        {
            if (!statusListParams.Count.HasValue)
            {
                return(await base.GetUserTimelineAsync(statusListParams));
            }

            var key = string.Format("user_timeline_{0}", statusListParams.CreatedByUserId);

            var cachedResult = this.cacheProvider.Get <IEnumerable <Status> >(key);

            if (cachedResult != null)
            {
                var statuses = cachedResult
                               .SkipWhile(x => x.StatusId != statusListParams.MaxId)
                               .Skip(1)
                               .Take(statusListParams.Count.Value)
                               .ToList();

                if (statuses.Count == statusListParams.Count.Value)
                {
                    return(statuses);
                }
            }

            var count = statusListParams.Count.Value;

            statusListParams.Count = 100;
            var result = await base.GetUserTimelineAsync(statusListParams);

            cacheProvider.Set(key, result, TimeSpan.FromMinutes(5));

            return(result.Take(count));
        }
        public StatusListParams Map(StatusListParamsModel from, StatusListParams to)
        {
            to.SavedByUserId   = from.SavedByUserId;
            to.CreatedByUserId = from.CreatedByUserId;
            to.MaxId           = from.MaxId;
            to.Count           = from.Count;

            return(to);
        }
        public async Task GetUserTimelineAsyncTest()
        {
            // Arrange
            var count            = 5;
            var statusListParams = new StatusListParams
            {
                CreatedByUserId = "74286565",
                Count           = count,
                MaxId           = "768228028291751936"
            };

            // Act
            var statuses = await this.statusRepository.GetUserTimelineAsync(statusListParams);

            // Assert
            Assert.NotNull(statuses);
            Assert.Equal(count, statuses.Count());
        }
        public async Task CrudTest()
        {
            var statusId    = "1";
            var createdById = "2";
            var userId      = "74286566";
            var status      = new Status {
                StatusId = statusId, Text = "Text", CreatedById = createdById
            };

            this.claimsHelper.GetUserId().Returns(userId);

            await this.statusStoreRepository.SaveAsync(status);

            var savedStatusIds = await this.statusStoreRepository.GetSavedStatusIdsAsync();

            Assert.True(savedStatusIds.Contains(statusId));

            var savedByParams = new StatusListParams
            {
                SavedByUserId   = claimsHelper.GetUserId(),
                CreatedByUserId = createdById
            };

            var savedPosts = await this.statusStoreRepository.GetAllSavedAsync(savedByParams);

            Assert.True(savedPosts.Select(x => x.StatusId).Contains(statusId));

            var userIds = new List <string> {
                userId
            };
            var downloadedStatusesCount = this.statusStoreRepository.GetDownloadStatusCount(userIds)
                                          .FirstOrDefault(x => x.Item1 == userId)
                                          .Item2;

            Assert.Equal(downloadedStatusesCount, 1);

            // Count
            await this.statusStoreRepository.UnsaveAsync(statusId);
        }
        public async Task <IEnumerable <Status> > GetAllSavedAsync(StatusListParams statusListParams)
        {
            var userFilter = new ExpressionFilterDefinition <Status>(
                x => x.SavedByUserId == statusListParams.SavedByUserId &&
                x.CreatedById == statusListParams.CreatedByUserId);

            var maxIdFilter = new JsonFilterDefinition <Status>(
                "{ StatusId: { $lt: '" + statusListParams.MaxId + "' } }");

            var complexFilter = string.IsNullOrEmpty(statusListParams.MaxId)
                ? userFilter
                : userFilter & maxIdFilter;

            var options = new FindOptions <Status>
            {
                Sort  = Builders <Status> .Sort.Descending(x => x.StatusId),
                Limit = statusListParams.Count
            };

            var savedStatuses = await this.dbContext.Statuses.FindAsync(complexFilter, options);

            return(savedStatuses.ToEnumerable());
        }
Exemplo n.º 6
0
        public virtual async Task <IEnumerable <Status> > GetUserTimelineAsync(StatusListParams statusListParams)
        {
            var userTimelineParam = new UserTimelineParameters
            {
                MaximumNumberOfTweetsToRetrieve = statusListParams.Count ?? 100,
                IncludeRTS = true
            };

            if (!string.IsNullOrEmpty(statusListParams.MaxId))
            {
                userTimelineParam.MaxId = long.Parse(statusListParams.MaxId) - 1;
            }

            var userId = new UserIdentifier(long.Parse(statusListParams.CreatedByUserId));

            var tweets = await Auth.ExecuteOperationWithCredentials(
                this.credentials, () => TimelineAsync.GetUserTimeline(userId, userTimelineParam));

            tweets = tweets ?? Enumerable.Empty <ITweet>();

            var mapper = new StatusMapper();

            return(tweets.Select(x => mapper.Map(x, new Status())));
        }