public async Task HandleResponseMultiple()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page  = 1,
                Count = 2
            };

            command.SetParameters();

            var expectedArtists = new List <LastArtist>
            {
                new LastArtist
                {
                    Name      = "Anathema",
                    PlayCount = 5216,
                    Mbid      = "20aa23e3-3532-42ca-acf6-e8c2e9df2688",
                    Url       = new Uri("http://www.last.fm/music/Anathema"),
                    MainImage =
                        new LastImageSet("http://userserve-ak.last.fm/serve/34/12571597.jpg",
                                         "http://userserve-ak.last.fm/serve/64/12571597.jpg",
                                         "http://userserve-ak.last.fm/serve/126/12571597.jpg",
                                         "http://userserve-ak.last.fm/serve/252/12571597.jpg",
                                         "http://userserve-ak.last.fm/serve/_/12571597/Anathema+Judgement+promo.jpg")
                },
                new LastArtist
                {
                    Name      = "Insomnium",
                    PlayCount = 4670,
                    Mbid      = "c1f8e226-75ea-4fe6-83ce-59c122bcbca4",
                    Url       = new Uri("http://www.last.fm/music/Insomnium"),
                    MainImage =
                        new LastImageSet("http://userserve-ak.last.fm/serve/34/70409268.jpg",
                                         "http://userserve-ak.last.fm/serve/64/70409268.jpg",
                                         "http://userserve-ak.last.fm/serve/126/70409268.jpg",
                                         "http://userserve-ak.last.fm/serve/252/70409268.jpg",
                                         "http://userserve-ak.last.fm/serve/500/70409268/Insomnium.jpg")
                },
            };

            var file     = GetFileContents("UserApi.UserGetTopArtistsMultiple.json");
            var response = CreateResponseMessage(file);
            //var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsMultiple));
            var parsed = await command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(2, parsed.PageSize);
            Assert.AreEqual(1124, parsed.TotalItems);
            Assert.AreEqual(562, parsed.TotalPages);
            Assert.AreEqual(2, parsed.Content.Count);

            var actualArtists = parsed.Content;

            TestHelper.AssertSerialiseEqual(expectedArtists, actualArtists);
        }
Example #2
0
 public async Task<PageResponse<LastArtist>> GetTopArtistsAsync(int page = 1, int itemsPerPage = LastFm.DefaultPageLength)
 {
     var command = new GetTopArtistsCommand(Auth)
     {
         Page = page,
         Count = itemsPerPage,
         HttpClient = HttpClient
     };
     return await command.ExecuteAsync();
 }
Example #3
0
        public async Task <PageResponse <LastArtist> > GetTopArtistsAsync(int page = 1, int itemsPerPage = LastFm.DefaultPageLength)
        {
            var command = new GetTopArtistsCommand(Auth)
            {
                Page  = page,
                Count = itemsPerPage
            };

            return(await command.ExecuteAsync());
        }
Example #4
0
        public async Task<PageResponse<LastArtist>> GetTopArtists(string username, LastStatsTimeSpan span, int pagenumber = 0, int count = LastFm.DefaultPageLength)
        {
            var command = new GetTopArtistsCommand(Auth, username, span)
            {
                Page = pagenumber,
                Count = count,
                HttpClient = HttpClient
            };

            return await command.ExecuteAsync();
        }
Example #5
0
        /// <summary>
        /// Get the top artists tagged by this tag, ordered by tag count.
        /// </summary>
        public Task <PageResponse <LastArtist> > GetTopArtistsAsync(string tagName, int page = 1, int itemsPerPage = LastFm.DefaultPageLength)
        {
            var command = new GetTopArtistsCommand(Auth, tagName)
            {
                HttpClient = HttpClient,
                Page       = page,
                Count      = itemsPerPage
            };

            return(command.ExecuteAsync());
        }
Example #6
0
        public async Task ErrorIfTagIsEmpty()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, "errorTag");

            var response = CreateResponseMessage(Encoding.UTF8.GetString(TagApiResponses.GetTopArtistsError));

            var parsed = await command.HandleResponse(response);

            Assert.IsFalse(parsed.Success);
            Assert.IsTrue(parsed.Status == LastResponseStatus.MissingParameters);
        }
Example #7
0
        public async Task <PageResponse <LastArtist> > GetTopArtists(string username, LastStatsTimeSpan span, int pagenumber = 0, int count = LastFm.DefaultPageLength)
        {
            var command = new GetTopArtistsCommand(Auth, username, span)
            {
                Page       = pagenumber,
                Count      = count,
                HttpClient = HttpClient
            };

            return(await command.ExecuteAsync());
        }
Example #8
0
        public async Task HandleSuccessResponse()
        {
            //Arrange
            GetTopArtistsCommand command = new GetTopArtistsCommand(MAuth.Object, "disco");

            //Act
            var response = CreateResponseMessage(Encoding.UTF8.GetString(TagApiResponses.GetTopArtistsSuccess));
            var parsed   = await command.HandleResponse(response);

            //Assert
            Assert.IsTrue(parsed.Success);
            Assert.IsNotNull(parsed.Content);
        }
        public void ParametersCorrect()
        {
            var expected = new Dictionary <string, string>
            {
                { "user", USER },
                { "period", SPAN.GetApiName() },
                { "page", "5" },
                { "limit", "10" }
            };

            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page  = 5,
                Count = 10
            };

            command.SetParameters();
            command.Parameters.Remove("disablecachetoken");

            TestHelper.AssertSerialiseEqual(expected, command.Parameters);
        }
        public async Task HandleResponseError()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page  = 1,
                Count = 1
            };

            command.SetParameters();

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsError));
            var parsed   = await command.HandleResponse(response);

            Assert.IsFalse(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(0, parsed.PageSize);
            Assert.AreEqual(0, parsed.TotalItems);
            Assert.AreEqual(1, parsed.TotalPages);
            Assert.AreEqual(0, parsed.Content.Count);
            Assert.AreEqual(LastResponseStatus.MissingParameters, parsed.Status);
        }
        public async Task HandleResponseEmpty()
        {
            const string USER_WITH_NO_PLAYS = "e";
            var          command            = new GetTopArtistsCommand(MAuth.Object, USER_WITH_NO_PLAYS, SPAN)
            {
                Page  = 1,
                Count = 1
            };

            command.SetParameters();

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsEmpty));
            var parsed   = await command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(0, parsed.PageSize);
            Assert.AreEqual(0, parsed.TotalItems);
            Assert.AreEqual(1, parsed.TotalPages);
            Assert.AreEqual(0, parsed.Content.Count);
        }
        public void ParametersCorrect()
        {
            var expected = new Dictionary<string, string>
            {
                {"user", USER},
                {"period", SPAN.GetApiName()},
                {"page", "5"},
                {"limit", "10"}
            };

            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page = 5,
                Count = 10
            };

            command.SetParameters();
            command.Parameters.Remove("disablecachetoken");

            TestHelper.AssertSerialiseEqual(expected, command.Parameters);
        }
        public async Task HandleResponseSingle()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page  = 1,
                Count = 1
            };

            command.SetParameters();

            var expectedArtist = new LastArtist
            {
                Name      = "Anathema",
                PlayCount = 5216,
                Mbid      = "20aa23e3-3532-42ca-acf6-e8c2e9df2688",
                Url       = new Uri("http://www.last.fm/music/Anathema"),
                MainImage =
                    new LastImageSet("http://userserve-ak.last.fm/serve/34/12571597.jpg",
                                     "http://userserve-ak.last.fm/serve/64/12571597.jpg",
                                     "http://userserve-ak.last.fm/serve/126/12571597.jpg",
                                     "http://userserve-ak.last.fm/serve/252/12571597.jpg",
                                     "http://userserve-ak.last.fm/serve/_/12571597/Anathema+Judgement+promo.jpg")
            };

            var file     = GetFileContents("UserApi.UserGetTopArtistsSingle.json");
            var response = CreateResponseMessage(file);
            //var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsSingle));
            var parsed = await command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(1, parsed.PageSize);
            Assert.AreEqual(1124, parsed.TotalItems);
            Assert.AreEqual(1124, parsed.TotalPages);
            Assert.AreEqual(1, parsed.Content.Count);

            var actualArtist = parsed.Content.First();

            TestHelper.AssertSerialiseEqual(expectedArtist, actualArtist);
        }
        public async Task HandleResponseSingle()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page = 1,
                Count = 1
            };

            command.SetParameters();

            var expectedArtist = new LastArtist
            {
                Name = "Anathema",
                PlayCount = 5216,
                Mbid = "20aa23e3-3532-42ca-acf6-e8c2e9df2688",
                Url = new Uri("http://www.last.fm/music/Anathema"),
                MainImage =
                    new LastImageSet("http://userserve-ak.last.fm/serve/34/12571597.jpg",
                        "http://userserve-ak.last.fm/serve/64/12571597.jpg",
                        "http://userserve-ak.last.fm/serve/126/12571597.jpg",
                        "http://userserve-ak.last.fm/serve/252/12571597.jpg",
                        "http://userserve-ak.last.fm/serve/_/12571597/Anathema+Judgement+promo.jpg")
            };

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsSingle));
            var parsed = await command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(1, parsed.PageSize);
            Assert.AreEqual(1124, parsed.TotalItems);
            Assert.AreEqual(1124, parsed.TotalPages);
            Assert.AreEqual(1, parsed.Content.Count);

            var actualArtist = parsed.Content.First();

            TestHelper.AssertSerialiseEqual(expectedArtist, actualArtist);
        }
        public async Task HandleResponseEmpty()
        {
            const string USER_WITH_NO_PLAYS = "e";
            var command = new GetTopArtistsCommand(MAuth.Object, USER_WITH_NO_PLAYS, SPAN)
            {
                Page = 1,
                Count = 1
            };

            command.SetParameters();

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsEmpty));
            var parsed = await command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(0, parsed.PageSize);
            Assert.AreEqual(0, parsed.TotalItems);
            Assert.AreEqual(1, parsed.TotalPages);
            Assert.AreEqual(0, parsed.Content.Count);
        }
        public async Task HandleResponseError()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page = 1,
                Count = 1
            };

            command.SetParameters();

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsError));
            var parsed = await command.HandleResponse(response);

            Assert.IsFalse(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(0, parsed.PageSize);
            Assert.AreEqual(0, parsed.TotalItems);
            Assert.AreEqual(1, parsed.TotalPages);
            Assert.AreEqual(0, parsed.Content.Count);
            Assert.AreEqual(LastResponseStatus.MissingParameters, parsed.Status);
        }
        public async Task HandleResponseMultiple()
        {
            var command = new GetTopArtistsCommand(MAuth.Object, USER, SPAN)
            {
                Page = 1,
                Count = 2
            };

            command.SetParameters();

            var expectedArtists = new List<LastArtist>
            {
                new LastArtist
                {
                    Name = "Anathema",
                    PlayCount = 5216,
                    Mbid = "20aa23e3-3532-42ca-acf6-e8c2e9df2688",
                    Url = new Uri("http://www.last.fm/music/Anathema"),
                    MainImage =
                        new LastImageSet("http://userserve-ak.last.fm/serve/34/12571597.jpg",
                            "http://userserve-ak.last.fm/serve/64/12571597.jpg",
                            "http://userserve-ak.last.fm/serve/126/12571597.jpg",
                            "http://userserve-ak.last.fm/serve/252/12571597.jpg",
                            "http://userserve-ak.last.fm/serve/_/12571597/Anathema+Judgement+promo.jpg")
                },
                new LastArtist
                {
                    Name = "Insomnium",
                    PlayCount = 4670,
                    Mbid = "c1f8e226-75ea-4fe6-83ce-59c122bcbca4",
                    Url = new Uri("http://www.last.fm/music/Insomnium"),
                    MainImage =
                        new LastImageSet("http://userserve-ak.last.fm/serve/34/70409268.jpg",
                            "http://userserve-ak.last.fm/serve/64/70409268.jpg",
                            "http://userserve-ak.last.fm/serve/126/70409268.jpg",
                            "http://userserve-ak.last.fm/serve/252/70409268.jpg",
                            "http://userserve-ak.last.fm/serve/500/70409268/Insomnium.jpg")
                },
            };

            var response = CreateResponseMessage(Encoding.UTF8.GetString(UserApiResponses.UserGetTopArtistsMultiple));
            var parsed = await command.HandleResponse(response);

            Assert.IsTrue(parsed.Success);
            Assert.AreEqual(1, parsed.Page);
            Assert.AreEqual(2, parsed.PageSize);
            Assert.AreEqual(1124, parsed.TotalItems);
            Assert.AreEqual(562, parsed.TotalPages);
            Assert.AreEqual(2, parsed.Content.Count);

            var actualArtists = parsed.Content;

            TestHelper.AssertSerialiseEqual(expectedArtists, actualArtists);
        }