Esempio n. 1
0
        public async Task FilterTest()
        {
            var res1 = await Tracklist.Clear();

            Assert.True(res1);

            var res2 = await Library.Search(
                queryArtist : "Air Supply",
                queryAlbum : "Strangers In Love"
                );

            Assert.True(res2.Succeeded);
            Assert.True(1 <= res2.Result.Length);
            Assert.True(1 <= res2.Result.First().Tracks.Length);
            var uris = res2.Result.First().Tracks
                       .OrderBy(e => e.TrackNo)
                       .Select(e => e.Uri)
                       .ToArray();

            var res3 = await Tracklist.Add(uris);

            Assert.True(res3.Succeeded);
            Assert.Equal(uris.Length, res3.Result.Length);

            var filtered1 = new string[]
            {
                uris[1],
                uris[3],
                uris[5],
                uris[7],
            };

            var criteria = new Tracklist.Criteria();

            criteria.TlId.Add(res3.Result[1].TlId);
            criteria.TlId.Add(res3.Result[3].TlId);
            criteria.TlId.Add(res3.Result[5].TlId);
            criteria.TlId.Add(res3.Result[7].TlId);
            //criteria.Uri.Add("local:track:");

            var res4 = await Tracklist.Filter(criteria);

            Assert.True(res4.Succeeded);
            Assert.Equal(filtered1.Length, res4.Result.Length);
            for (var i = 0; i < filtered1.Length; i++)
            {
                Assert.Equal(filtered1[i], res4.Result[i].Track.Uri);
            }

            criteria.Clear();
            criteria.Uri.Add(res3.Result[1].Track.Uri);
            criteria.Uri.Add(res3.Result[3].Track.Uri);
            criteria.Uri.Add(res3.Result[5].Track.Uri);
            criteria.Uri.Add(res3.Result[7].Track.Uri);

            var res5 = await Tracklist.Filter(criteria);

            Assert.True(res5.Succeeded);
            Assert.Equal(filtered1.Length, res5.Result.Length);
            for (var i = 0; i < filtered1.Length; i++)
            {
                Assert.Equal(filtered1[i], res5.Result[i].Track.Uri);
            }

            var res6 = await Tracklist.Filter(tlId : new int[]
            {
                res3.Result[1].TlId,
                res3.Result[3].TlId,
                res3.Result[5].TlId,
                res3.Result[7].TlId,
            });

            Assert.True(res6.Succeeded);
            Assert.Equal(filtered1.Length, res6.Result.Length);
            for (var i = 0; i < filtered1.Length; i++)
            {
                Assert.Equal(filtered1[i], res6.Result[i].Track.Uri);
            }

            var res7 = await Tracklist.Filter(uri : new string[]
            {
                res3.Result[1].Track.Uri,
                res3.Result[3].Track.Uri,
                res3.Result[5].Track.Uri,
                res3.Result[7].Track.Uri,
            });

            Assert.True(res7.Succeeded);
            Assert.Equal(filtered1.Length, res7.Result.Length);
            for (var i = 0; i < filtered1.Length; i++)
            {
                Assert.Equal(filtered1[i], res7.Result[i].Track.Uri);
            }

            var res8 = await Tracklist.Filter(tlId : res3.Result[1].TlId);

            Assert.True(res8.Succeeded);
            Assert.Single(res8.Result);
            Assert.Equal(res3.Result[1].Track.Uri, res8.Result[0].Track.Uri);

            var res9 = await Tracklist.Filter(uri : res3.Result[3].Track.Uri);

            Assert.True(res9.Succeeded);
            Assert.Single(res9.Result);
            Assert.Equal(res3.Result[3].TlId, res9.Result[0].TlId);


            var res10 = await Tracklist.GetTlTracks();

            Assert.True(res10.Succeeded);
            Assert.Equal(uris.Length, res10.Result.Length);

            for (var i = 0; i < uris.Length; i++)
            {
                Assert.Equal(uris[i], res10.Result[i].Track.Uri);
            }
        }