public void Can_get_image_from_url() { // arrange/act var image = _mediaScrapper.GetThumbnailForUrl("https://static.skimur.com/content/img/logo.png"); // assert Assert.That(image, Is.Not.Null); // arrange/act image = _mediaScrapper.GetThumbnailForUrl("https://www.reddit.com/r/funny/comments/3qsdnq/join_the_dork_side/"); // assert Assert.That(image, Is.Not.Null); }
public void Handle(GenerateThumbnailForPost command) { var post = _postService.GetPostById(command.PostId); if (post == null) { return; } if (!command.Force && !string.IsNullOrEmpty(post.Thumb)) { // already created and we aren't trying to for it to be recreated return; } try { Image image = null; try { if (post.PostType == PostType.Link) { // grab an image from the url of the post image = _mediaScraper.GetThumbnailForUrl(post.Url); } else if (post.PostType == PostType.Text) { // this is a text post // let's see if there are any links in the users post. var links = _mediaScraper.ExtractLinksFromHtml(post.ContentFormatted); if (links.Count > 0) { } // TODO } if (image != null) { // we found an image for the link _postService.UpdateThumbnailForPost(post.Id, _postThumbnailService.UploadImage(image)); } } finally { if (image != null) { image.Dispose(); } } } catch (Exception ex) { _logger.Error("There was an error trying to get a thumbnail for the post " + post.Id, ex); } }
public void Can_get_image_from_url() { // arrange/act var image = _mediaScrapper.GetThumbnailForUrl("https://static.skimur.com/content/img/logo.png"); // assert image.Should().NotBeNull(); // TODO: Gaurd against invalid urls. They shouldn't throw exceptions. //// arrange/act //image = _mediaScrapper.GetThumbnailForUrl("https://www.reddit.com/r/funny/comments/3qsdnq/join_the_dork_side/"); //// assert //image.Should().NotBeNull(); }