public async Task GetVideoListAsyncWithProgressTest() { var progressCalled = 0; var progressIndicator = new Progress <int>(i => Interlocked.Increment(ref progressCalled)); // Mock var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict); var youTubeService = new YouTubeService(httpMock.Object, config); httpMock.Setup(x => x.GetAsync <YouTube.VideoResponse>(It.Is <string>(s => checkApiCall(s, "videos", null)))) .ReturnsAsync(new YouTube.VideoResponse { Items = new List <YouTube.Video> { _mockVideoResponse.Items[0], _mockVideoResponse.Items[1], _mockVideoResponse.Items[2], _mockVideoResponseSecondPage.Items[0] } }); // Run var videos = await youTubeService.GetVideoListAsync(new[] { "1", "2", "3" }, progressIndicator); // Wait for progress Thread.Sleep(10); // Assert Assert.AreEqual(4, videos.Count); Assert.Greater(progressCalled, 0); // Verify httpMock.VerifyAll(); }
public async Task GetVideoListAsyncPagedTest() { // Model Set Up _mockOnlyIdResponse.NextPageToken = _nextPageToken; // Mock var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict); var youTubeService = new YouTubeService(httpMock.Object, config); httpMock.Setup(x => x.GetAsync <YouTube.VideoResponse>(It.Is <string>(s => checkApiCall(s, "videos", null)))) .ReturnsAsync(new YouTube.VideoResponse { Items = new List <YouTube.Video> { _mockVideoResponse.Items[0], _mockVideoResponse.Items[1], _mockVideoResponse.Items[2], _mockVideoResponseSecondPage.Items[0] } }); // Run var videos = await youTubeService.GetVideoListAsync(new[] { "1", "2", "3", "4" }); // Assert Assert.AreEqual(4, videos.Count, "Second page retrieved"); Assert.AreEqual(_mockOnlyIdResponse.Items[0].Id, videos[0].Id); Assert.AreEqual(_mockOnlyIdResponse.Items[1].Id, videos[1].Id); Assert.AreEqual(_mockOnlyIdResponse.Items[2].Id, videos[2].Id); Assert.AreEqual(_mockOnlyIdResponseSecondPage.Items[0].Id, videos[3].Id); // Verify httpMock.VerifyAll(); }
public async Task TestVideoList() { var progressCounter = 0; var service = new YouTubeService(new SafeHttpClient(), new Configuration.YouTubeConfiguration { ApiKey = _apiKey }); TestContext.WriteLine($"Videos: {string.Join(", ", videoIds)}"); TestContext.Write("Getting Videos... "); var progressIndicator = new Progress <int>(i => Interlocked.Increment(ref progressCounter)); var results = await service.GetVideoListAsync(videoIds, progressIndicator); TestContext.WriteLine("Done."); var videosCt = results.Count; TestContext.WriteLine($"\nVideos retrieved: { videosCt }"); Assert.AreEqual(videoIds.Count, videosCt); Assert.Greater(progressCounter, 0); foreach (var video in results) { Assert.IsNotNull(video.Id); Assert.IsNotNull(video.Title); } }
public void GetVideoListAsyncWithCancellationTokenTest() { // Mock var ctSource = new CancellationTokenSource(); ctSource.Cancel(); var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict); var youTubeService = new YouTubeService(httpMock.Object, config); // Assert Assert.ThrowsAsync <TaskCanceledException>(async() => await youTubeService.GetVideoListAsync(new[] { "1", "2", "3" }, ctSource.Token)); // Verify httpMock.VerifyAll(); }
public async Task GetVideoListAsyncNotFoundTest() { // Mock var httpMock = new Mock <ISafeHttpClient>(MockBehavior.Strict); var youTubeService = new YouTubeService(httpMock.Object, config); httpMock.Setup(x => x.GetAsync <YouTube.VideoResponse>(It.Is <string>(s => checkApiCall(s, "videos", null)))) .ReturnsAsync(null as YouTube.VideoResponse); // Run var videos = await youTubeService.GetVideoListAsync(new[] { "1", "2", "3" }); // Assert Assert.IsEmpty(videos); // Verify httpMock.VerifyAll(); }