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); }