public async Task GetVideoAsyncTest() { // 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] } }); // Run var video = await youTubeService.GetVideoAsync("1"); // Assert Assert.AreEqual(_mockVideoResponse.Items[0].Snippet.Title, video.Title); // Verify httpMock.VerifyAll(); }
public async Task TestComments() { var progressCounter = 0; var service = new YouTubeService(new SafeHttpClient(), new Configuration.YouTubeConfiguration { ApiKey = _apiKey }); var videoId = videoUrl; videoId = service.ParseVideoId(new Uri(videoId)) ?? videoId; var video = service.GetVideoAsync(videoId).Result; var totalCommentCount = video.CommentCount; TestContext.WriteLine($"Title: {video.Title}"); TestContext.WriteLine($"Comments: {totalCommentCount}"); TestContext.Write("Parsing comments... "); var progressIndicator = new Progress <int>(i => Interlocked.Increment(ref progressCounter)); var results = await service.GetCommentsAsync(videoId, progressIndicator); TestContext.WriteLine("Done."); var commentsCt = results.Count; TestContext.WriteLine($"\nComments retrieved: { commentsCt }"); Assert.Greater(commentsCt, 100); Assert.Greater(progressCounter, 0); foreach (var comment in results.Take(100)) { Assert.IsNotNull(comment.Content); Assert.IsNotNull(comment.Author); Assert.AreEqual("YouTube", comment.Source); } }
public async Task GetVideoAsyncNotFoundTest() { // 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 video = await youTubeService.GetVideoAsync("1"); // Assert Assert.IsNull(video); // Verify httpMock.VerifyAll(); }