Example #1
0
        private async Task <GetNewsfeedQuery> GetNewsfeedQuery(NewsfeedFilter filterData)
        {
            filterData.AssertUrlParameterProvided("filter");
            var filter = filterData.Parse();

            UserId creatorId = null;

            if (!string.IsNullOrWhiteSpace(filterData.CreatorId))
            {
                creatorId = new UserId(filterData.CreatorId.DecodeGuid());
            }

            IReadOnlyList <ChannelId> channelIds = null;

            if (!string.IsNullOrWhiteSpace(filterData.ChannelId))
            {
                channelIds = new List <ChannelId> {
                    new ChannelId(filterData.ChannelId.DecodeGuid())
                };
            }

            var requester = await this.requesterContext.GetRequesterAsync();

            var query = new GetNewsfeedQuery(
                requester,
                creatorId,
                channelIds,
                filter.Origin,
                filter.SearchForwards,
                filter.StartIndex,
                filter.Count);

            return(query);
        }
Example #2
0
        public async Task WhenGettingPreviewNewsfeed_ItShouldReturnResultFromNewsfeedQuery()
        {
            var query       = new GetNewsfeedQuery(Requester, UserId, new[] { ChannelId }, Origin, SearchForwards, NonNegativeInt.Parse(10), PositiveInt.Parse(5));
            var requestData = new NewsfeedFilter
            {
                CreatorId      = UserId.Value.EncodeGuid(),
                ChannelId      = ChannelId.Value.EncodeGuid(),
                Origin         = Origin,
                SearchForwards = SearchForwards,
                Count          = 5,
                StartIndex     = 10
            };

            var queryResult = new GetPreviewNewsfeedQueryResult(new[] { new GetPreviewNewsfeedQueryResult.PreviewPost(UserId, new GetPreviewNewsfeedQueryResult.PreviewPostCreator(Username, null), PostId, BlogId, new GetPreviewNewsfeedQueryResult.PreviewPostBlog(BlogName, null, null), ChannelId, new GetPreviewNewsfeedQueryResult.PreviewPostChannel(ChannelName), new PreviewText(string.Empty), null, null, null, 0, 0, 0, 0, 0, DateTime.UtcNow, 0, 0, false, false) });

            this.requesterContext.Setup(_ => _.GetRequesterAsync()).ReturnsAsync(Requester);
            this.getPreviewNewsfeed.Setup(_ => _.HandleAsync(query)).ReturnsAsync(queryResult);

            var result = await this.target.GetPreviewNewsfeed(requestData);

            Assert.AreEqual(queryResult, result);
        }