public async Task TestPlayList() { var service = new YouTubeService(new SafeHttpClient(), new Configuration.YouTubeConfiguration { ApiKey = _apiKey }); var channelId = await service.GetChannelIdAsync(channelName); Assert.IsNotNull(channelId); var playlistId = await service.GetPlaylistIdAsync(channelId, playlistName); Assert.IsNotNull(playlistId); var progressCounter = 0; var progressIndicator = new Progress <int>(i => Interlocked.Increment(ref progressCounter)); var playlistItems = await service.GetPlaylistVideosAsync(playlistId, progressIndicator); Assert.IsNotNull(playlistItems); Assert.IsNotEmpty(playlistItems); Assert.Greater(progressCounter, 0); TestContext.WriteLine($"Playlist items: {playlistItems.Count}"); foreach (var item in playlistItems) { Assert.IsNotNull(item?.Id); } }
public async Task GetPlaylistIdAsyncNotFoundTest() { // Mock var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict); var youTubeService = new YouTubeService(httpMock.Object, config); httpMock.Setup(x => x.GetAsync <YouTube.PlaylistResponse>(It.Is <string>(s => checkApiCall(s, "playlists", null)))) .ReturnsAsync(null as YouTube.PlaylistResponse); // Run var playlistId = await youTubeService.GetPlaylistIdAsync("1", "Test2"); // Assert Assert.IsNull(playlistId); // Verify httpMock.VerifyAll(); }
public async Task GetPlaylistIdAsyncTest() { // Mock var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict); var youTubeService = new YouTubeService(httpMock.Object, config); httpMock.Setup(x => x.GetAsync <YouTube.PlaylistResponse>(It.Is <string>(s => checkApiCall(s, "playlists", null)))) .ReturnsAsync(_mockPlaylistResponse); // Run var playlistId = await youTubeService.GetPlaylistIdAsync("1", "Test2"); // Assert Assert.AreEqual(_mockPlaylistResponse.Items.Where(i => i.Snippet.Title.Equals("Test2")).First().Id, playlistId); // Verify httpMock.VerifyAll(); }