public void ParseVideoIdTest(string url, string excpectedId) { var youTubeService = new YouTubeService(null, config); var actualId = youTubeService.ParseVideoId(new Uri(url)); Assert.AreEqual(excpectedId, actualId); }
public void ParseVideoIdNotFoundTest(string url) { var youTubeService = new YouTubeService(null, config); var actualId = youTubeService.ParseVideoId(new Uri(url)); Assert.IsNull(actualId); }
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); } }