public void Resize_AgileInThreeMinutes_ShouldReturnResizedImage() { const int width = 500; const int height = 500; const string url = "https://agilein3minut.es/images/ai3m.png"; const string podcastTitle = "Agile in 3 minutes"; var handler = new Resize.CommandHandler(); var resizedImage = handler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcastTitle }); Assert.AreEqual("agile_in_3_minutes.png", resizedImage.ImageName); }
public void Resize_BrentOzarUnlimited_ShouldReturnNullAsSmallerThanFiveHundredPixels() { const int width = 122; const int height = 122; const string url = "https://www.brentozar.com/wp-content/plugins/powerpress/rss_default.jpg"; const string podcastTitle = "Brent Ozar Unlimited®"; var handler = new Resize.CommandHandler(); var resizedImage = handler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcastTitle }); Assert.AreEqual("brent_ozar_unlimited.jpeg", resizedImage.ImageName); }
public void Resize_InitPython_ShouldReturnResizedImage() { const int width = 100; const int height = 100; const string url = "https://www.podcastinit.com/wp-content/cache/podlove/7a/cf0997aacd0c64b37245739c9c9085/podcast-__init__python_original.png"; const string podcastTitle = "Podcast.__init__(\'Python\')"; var handler = new Resize.CommandHandler(); var resizedImage = handler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcastTitle }); Assert.AreEqual("podcastinitpython.png", resizedImage.ImageName); }
public void Resize_LetsMakeMistakes_ShouldReturnResizedImage() { const int width = 500; const int height = 500; const string url = "http://i1.sndcdn.com/avatars-000180812387-au235m-original.jpg"; const string podcastTitle = "Let\'s Make Mistakes"; var handler = new Resize.CommandHandler(); var resizedImage = handler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcastTitle }); Assert.AreEqual("lets_make_mistakes.jpeg", resizedImage.ImageName); }
public void Resize_NinetyNinePercentInvisible_ShouldReturnResizedImage() { const int width = 500; const int height = 500; const string url = "https://f.prxu.org/99pi/images/42384e27-3dd6-497f-991f-67fabb7e6e5b/99-300.png"; const string podcastTitle = "99% Invisible"; var handler = new Resize.CommandHandler(); var resizedImage = handler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcastTitle }); Assert.AreEqual("99_invisible.png", resizedImage.ImageName); }
public void ResizeAllPodcastImages() { var context = new ApplicationDbContext(); const string containerName = "podcast-images"; const int width = 500; const int height = 500; var podcasts = context.Podcasts .Where(podcast => podcast.IsApproved == true && podcast.ResizedImageUrl == null && podcast.ImageUrl != null && !podcast.Title.Contains("svg")) .ToList(); var resizeHandler = new Resize.CommandHandler(); var uploadHandler = new UploadToBlob.CommandHandler(); foreach (var podcast in podcasts) { var url = podcast.ImageUrl; var resizedImage = resizeHandler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcast.Title }); if (resizedImage == null) { continue; } var resizedImageUrl = uploadHandler.Handle(new UploadToBlob.Command { Bytes = resizedImage.ImageBytes, BlobReference = resizedImage.ImageName, ContainerName = containerName, ContentType = resizedImage.ContentType }); podcast.ResizedImageUrl = resizedImageUrl; } context.SaveChanges(); }
public void UploadToBlob_AgileInThreeMinutes() { const int width = 500; const int height = 500; const string url = "https://agilein3minut.es/images/ai3m.png"; const string containerName = "images-test"; const string podcastTitle = "Agile in 3 Minutes"; var resizeHandler = new Resize.CommandHandler(); var resizedImage = resizeHandler.Handle(new Resize.Command { Width = width, Height = height, ImageUrl = url, PodcastTitle = podcastTitle }); var uploadHandler = new UploadToBlob.CommandHandler(); var result = uploadHandler.Handle(new UploadToBlob.Command { Bytes = resizedImage.ImageBytes, BlobReference = resizedImage.ImageName, ContainerName = containerName, ContentType = resizedImage.ContentType }); Assert.AreEqual($"https://devpodcasts.blob.core.windows.net/{containerName}/agile_in_3_minutes.png", result); }