public async Task NextPageForPaging()
        {
            var api     = new Mock <IAPIConnector>();
            var config  = SpotifyClientConfig.CreateDefault("FakeToken").WithAPIConnector(api.Object);
            var spotify = new SpotifyClient(config);

            var response = new Paging <PlayHistoryItem>
            {
                Next = "https://next-url"
            };

            await spotify.NextPage(response);

            api.Verify(a => a.Get <Paging <PlayHistoryItem> >(new System.Uri("https://next-url")), Times.Once);
        }
        public async Task NextPageForIPaginatable()
        {
            var api     = new Mock <IAPIConnector>();
            var config  = SpotifyClientConfig.CreateDefault("FakeToken").WithAPIConnector(api.Object);
            var spotify = new SpotifyClient(config);

            var response = new SearchResponse
            {
                Albums = new Paging <SimpleAlbum, SearchResponse>
                {
                    Next = "https://next-url",
                }
            };

            await spotify.NextPage(response.Albums);

            api.Verify(a => a.Get <SearchResponse>(new System.Uri("https://next-url")), Times.Once);
        }
Beispiel #3
0
    /// <summary>
    /// Gets all entries in a paging list and returns the result
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="client">The current SpotifyClient instance</param>
    /// <param name="startingPageList">The beginning of a paging list (first 20/X entries)</param>
    /// <param name="limit">Limit the amount of paging items to retrieve. Limit must be a multiple of 20</param>
    /// <returns></returns>
    public static async Task <IEnumerable <T> > GetAllOfPagingAsync <T>(SpotifyClient client, Paging <T> startingPageList, int limit = -1) where T : class
    {
        List <T> list = new List <T>();

        while (startingPageList.Next != null)
        {
            // Add current range and await next set of items
            list.AddRange(startingPageList.Items);
            startingPageList = await client.NextPage(startingPageList);

            // if a limit is given and list is more than the limit, break and return
            if (limit > 0 && list.Count > limit)
            {
                break;
            }
        }
        // Return final list once complete
        return(list);
    }