Ejemplo n.º 1
0
        public async Task <GetStreamsResponse> Execute(GetStreamsQuery query)
        {
            var streamFilters = new StreamFilterOptions {
                GameName = query.Filters.GameName
            };

            var unpackedTokens = PageTokens.UnpackTokens(query.PageToken);

            var supportedPlatforms = streamPlatformService.GetSupportingPlatforms(streamFilters);

            var platformStreams = await streamPlatformService.GetStreams(supportedPlatforms, streamFilters, query.PageSize, unpackedTokens);

            var packedTokens = PageTokens
                               .FromList(platformStreams.Select(p => new PageToken(p.StreamPlatformName, p.NextPageToken)))
                               .PackTokens();

            var aggregatedStreams = platformStreams.SelectMany(p => p.Streams.Select(s => new Stream
            {
                StreamTitle        = s.StreamTitle,
                StreamerName       = s.StreamerName,
                StreamUrl          = s.StreamUrl,
                IsLive             = s.IsLive,
                Views              = s.Views,
                PlatformName       = p.StreamPlatformName,
                StreamThumbnailUrl = s.StreamThumbnailUrl,
                StreamerAvatarUrl  = s.StreamerAvatarUrl,
            }));

            return(new GetStreamsResponse
            {
                Streams = aggregatedStreams.OrderByDescending(s => s.Views),
                NextPageToken = packedTokens
            });
        }
Ejemplo n.º 2
0
        public void Should_Only_Pack_Non_Empty_Tokens()
        {
            var pageTokens = new PageTokens()
                             .AddToken("youtube", "youtube token")
                             .AddToken("twitch", "");

            var packedTokens = pageTokens.PackTokens();

            var unpackedTokens = PageTokens.UnpackTokens(packedTokens);

            Assert.AreEqual(unpackedTokens.GetTokenOrEmpty("youtube").Token, "youtube token");
            Assert.AreEqual(unpackedTokens.GetTokenOrEmpty("twitch").Token, "");
        }