public void Test_Tracks_Get_With_Bpm_And_Tag_Query() { const string expectedUri = @"https://api.soundcloud.com/tracks?limit=200&bpm[from]=100&tags=house&linked_partitioning=1&client_id=myClientId"; var trackList = new PagedResult <Track>(); trackList.collection = new List <Track> { new Track(), new Track() }; var response = new ApiResponse <PagedResult <Track> >(HttpStatusCode.OK, "OK"); response.Data = trackList; var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict); gatewayMock.Setup(x => x.InvokeGetRequest <PagedResult <Track> >(It.Is <Uri>(y => y.ToString() == expectedUri))).Returns(response); var trackEndpoint = new Tracks(gatewayMock.Object); trackEndpoint.Credentials.ClientId = ClientId; var query = new TrackQueryBuilder(); query.BpmFrom = 100; query.Tags.Add("house"); var result = trackEndpoint.Get(query).ToList(); Assert.That(result, Is.EqualTo(trackList.collection)); }
public void Test_Tracks_Get() { const string expectedUri = @"https://api.soundcloud.com/tracks/215850263?client_id=myClientId"; var track = new Track(); var response = new ApiResponse <Track>(HttpStatusCode.OK, "OK"); response.Data = track; var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict); gatewayMock.Setup(x => x.InvokeGetRequest <Track>(It.Is <Uri>(y => y.ToString() == expectedUri))).Returns(response); var trackEndpoint = new Tracks(gatewayMock.Object); trackEndpoint.Credentials.ClientId = ClientId; var result = trackEndpoint.Get(TrackId); Assert.That(result, Is.EqualTo(track)); }
public void should_be_able_to_get_a_single_track() { var tracks = Tracks.GetTracksInArtist(_artist.Id); Tracks.Get(tracks.First().Id).Should().NotBeNull(); }
public void Test_Tracks_InfiniteScroll() { const string firstPageUri = @"https://api.soundcloud.com/tracks?limit=200&linked_partitioning=1&client_id=myClientId"; const string secondPageuri = @"https://api.soundcloud.com/tracks?linked_partitioning=1&limit=200&offset=50&client_id=myClientId"; const string thirdPageUri = @"https://api.soundcloud.com/tracks?linked_partitioning=1&limit=200&offset=100&client_id=myClientId"; var gatewayMock = new Mock <ISoundCloudApiGateway>(MockBehavior.Strict); var firstPage = new PagedResult <Track> { collection = new List <Track>() }; firstPage.next_href = new Uri("https://api.soundcloud.com/tracks?linked_partitioning=1&limit=200&offset=50"); for (var i = 0; i < 50; i++) { firstPage.collection.Add(new Track()); } var secondPage = new PagedResult <Track> { collection = new List <Track>() }; secondPage.next_href = new Uri("https://api.soundcloud.com/tracks?linked_partitioning=1&limit=200&offset=100"); for (var i = 0; i < 50; i++) { secondPage.collection.Add(new Track()); } var thirdPage = new PagedResult <Track> { collection = new List <Track>() }; for (var i = 0; i < 50; i++) { thirdPage.collection.Add(new Track()); } var firstReponse = new ApiResponse <PagedResult <Track> >(HttpStatusCode.OK, "OK"); firstReponse.Data = firstPage; var secondResponse = new ApiResponse <PagedResult <Track> >(HttpStatusCode.OK, "OK"); secondResponse.Data = secondPage; var thirdResponse = new ApiResponse <PagedResult <Track> >(HttpStatusCode.OK, "OK"); thirdResponse.Data = thirdPage; gatewayMock.Setup(x => x.InvokeGetRequest <PagedResult <Track> >(It.Is <Uri>(y => y.ToString() == firstPageUri))).Returns(firstReponse); gatewayMock.Setup(x => x.InvokeGetRequest <PagedResult <Track> >(It.Is <Uri>(y => y.ToString() == secondPageuri))).Returns(secondResponse); gatewayMock.Setup(x => x.InvokeGetRequest <PagedResult <Track> >(It.Is <Uri>(y => y.ToString() == thirdPageUri))).Returns(thirdResponse); var trackEndpoint = new Tracks(gatewayMock.Object); trackEndpoint.Credentials.ClientId = ClientId; var result = trackEndpoint.Get(); var res1 = result.Take(50).ToList(); var res2 = result.Skip(50).Take(50).ToList(); var res3 = result.Skip(100).Take(50).ToList(); Assert.That(res1, Is.EqualTo(firstPage.collection)); Assert.That(res2, Is.EqualTo(secondPage.collection)); Assert.That(res3, Is.EqualTo(thirdPage.collection)); }