Example #1
0
        public async Task RemoveTest()
        {
            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);
            var tracks1 = res2.Result.First().Tracks;

            Assert.True(1 <= tracks1.Length);
            var uris1 = tracks1
                        .OrderBy(e => e.TrackNo)
                        .Select(e => e.Uri)
                        .ToArray();

            var res3 = await Tracklist.Add(uris1);

            Assert.True(res3.Succeeded);

            var tlIds = res3.Result
                        .Select(e => e.TlId)
                        .ToArray();
            var uris = res3.Result
                       .Select(e => e.Track.Uri)
                       .ToArray();

            var res4 = await Tracklist.GetTlTracks();

            Assert.True(res4.Succeeded);
            Assert.Contains(res4.Result, e => e.TlId == tlIds[0]);
            Assert.Contains(res4.Result, e => e.TlId == tlIds[1]);
            Assert.Contains(res4.Result, e => e.TlId == tlIds[2]);
            Assert.Contains(res4.Result, e => e.TlId == tlIds[3]);

            var res5 = await Tracklist.Remove(new int[]
            {
                tlIds[0],
                tlIds[1],
                tlIds[2],
                tlIds[3]
            });

            Assert.True(res5.Succeeded);
            Assert.Equal(4, res5.Result.Length);

            var res6 = await Tracklist.GetLength();

            Assert.True(res6.Succeeded);
            Assert.Equal(tracks1.Length - 4, res6.Result);

            var res7 = await Tracklist.GetTlTracks();

            Assert.True(res7.Succeeded);
            Assert.DoesNotContain(res7.Result, e => e.TlId == tlIds[0]);
            Assert.DoesNotContain(res7.Result, e => e.TlId == tlIds[1]);
            Assert.DoesNotContain(res7.Result, e => e.TlId == tlIds[2]);
            Assert.DoesNotContain(res7.Result, e => e.TlId == tlIds[3]);

            Assert.Contains(res7.Result, e => e.Track.Uri == uris[4]);
            Assert.Contains(res7.Result, e => e.Track.Uri == uris[5]);
            Assert.Contains(res7.Result, e => e.Track.Uri == uris[6]);

            var res8 = await Tracklist.Remove(new string[]
            {
                uris[4],
                uris[5],
                uris[6]
            });

            Assert.True(res8.Succeeded);
            Assert.Equal(3, res8.Result.Length);

            var res9 = await Tracklist.GetLength();

            Assert.True(res9.Succeeded);
            Assert.Equal(tracks1.Length - 7, res9.Result);

            var res10 = await Tracklist.GetTlTracks();

            Assert.True(res10.Succeeded);
            Assert.DoesNotContain(res10.Result, e => e.Track.Uri == uris[4]);
            Assert.DoesNotContain(res10.Result, e => e.Track.Uri == uris[5]);
            Assert.DoesNotContain(res10.Result, e => e.Track.Uri == uris[6]);

            Assert.Contains(res10.Result, e => e.TlId == tlIds[7]);
            Assert.Contains(res10.Result, e => e.Track.Uri == uris[8]);

            var res11 = await Tracklist.Remove(tlIds[7]);

            Assert.True(res11.Succeeded);
#pragma warning disable xUnit2013 // Do not use equality check to check for collection size.
            Assert.Equal(1, res11.Result.Length);
#pragma warning restore xUnit2013 // Do not use equality check to check for collection size.

            var res12 = await Tracklist.Remove(uris[8]);

            Assert.True(res12.Succeeded);
#pragma warning disable xUnit2013 // Do not use equality check to check for collection size.
            Assert.Equal(1, res12.Result.Length);
#pragma warning restore xUnit2013 // Do not use equality check to check for collection size.

            var res13 = await Tracklist.GetLength();

            Assert.True(res13.Succeeded);
            Assert.Equal(tracks1.Length - 9, res13.Result);

            var res14 = await Tracklist.GetTlTracks();

            Assert.True(res14.Succeeded);
            Assert.DoesNotContain(res14.Result, e => e.TlId == tlIds[7]);
            Assert.DoesNotContain(res14.Result, e => e.Track.Uri == uris[8]);
        }