From 070a9dc6303a6827c867f2ccdbb357c4b23e3c15 Mon Sep 17 00:00:00 2001 From: marijnz0r Date: Fri, 19 Jul 2024 23:33:44 +0200 Subject: [PATCH] Remove LoremPixel image service (#556) --- README.md | 14 -- Source/Bogus.Tests/DataSetTests/ImageTest.cs | 23 +- .../GitHubIssues/PullRequest113.cs | 17 -- Source/Bogus/DataSets/Images.LoremPixel.cs | 202 ------------------ Source/Bogus/DataSets/Images.cs | 45 ---- 5 files changed, 1 insertion(+), 300 deletions(-) delete mode 100644 Source/Bogus.Tests/GitHubIssues/PullRequest113.cs delete mode 100644 Source/Bogus/DataSets/Images.LoremPixel.cs diff --git a/README.md b/README.md index cbd1f534..3fc08541 100644 --- a/README.md +++ b/README.md @@ -365,20 +365,6 @@ In the examples above, all three alternative styles of using **Bogus** produce t * `PicsumUrl` - Get an image from the https://picsum.photos service. * `PlaceholderUrl` - Get an image from https://placeholder.com service. * `LoremFlickrUrl` - Get an image from https://loremflickr.com service. - * `LoremPixelUrl` - Creates an image URL with http://lorempixel.com. Note: This service is slow. Consider using PicsumUrl() as a faster alternative. - * `Abstract` - Gets an abstract looking image. - * `Animals` - Gets an image of an animal. - * `Business` - Gets a business looking image. - * `Cats` - Gets a picture of a cat. - * `City` - Gets a city looking image. - * `Food` - Gets an image of food. - * `Nightlife` - Gets an image with city looking nightlife. - * `Fashion` - Gets an image in the fashion category. - * `People` - Gets an image of humans. - * `Nature` - Gets an image of nature. - * `Sports` - Gets an image related to sports. - * `Technics` - Get a technology related image. - * `Transport` - Get a transportation related image. * **`Internet`** * `Avatar` - Generates a legit Internet URL avatar from twitter accounts. * `Email` - Generates an email address. diff --git a/Source/Bogus.Tests/DataSetTests/ImageTest.cs b/Source/Bogus.Tests/DataSetTests/ImageTest.cs index 5417751f..3667ccd0 100644 --- a/Source/Bogus.Tests/DataSetTests/ImageTest.cs +++ b/Source/Bogus.Tests/DataSetTests/ImageTest.cs @@ -1,10 +1,8 @@ using System.IO; -using System.Net; using Bogus.DataSets; using FluentAssertions; using Xunit; using Xunit.Abstractions; -using static Bogus.DataSets.LoremPixelCategory; namespace Bogus.Tests.DataSetTests; @@ -20,25 +18,6 @@ public ImageTest(ITestOutputHelper console) private readonly Images image; - [Fact(Skip = "Explicit")] - public void DownloadAllTest() - { - var wc = new WebClient(); - wc.DownloadFile(image.LoremPixelUrl(Abstract), "abstract.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Animals), "animals.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Business), "business.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Cats), "cats.jpg"); - wc.DownloadFile(image.LoremPixelUrl(City), "city.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Food), "food.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Nightlife), "nightlife.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Fashion), "fashion.jpg"); - wc.DownloadFile(image.LoremPixelUrl(People), "people.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Nature), "nature.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Sports), "sports.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Technics), "technics.jpg"); - wc.DownloadFile(image.LoremPixelUrl(Transport), "transport.jpg"); - } - [Fact] public void svg_data_url() { @@ -70,7 +49,7 @@ public void svg_data_url() [Fact] public void url_generated_should_have_https() { - image.LoremPixelUrl(Sports, https: true).Should().StartWith("https://"); + image.PicsumUrl().Should().StartWith("https://"); } [Fact] diff --git a/Source/Bogus.Tests/GitHubIssues/PullRequest113.cs b/Source/Bogus.Tests/GitHubIssues/PullRequest113.cs deleted file mode 100644 index 6e2eb019..00000000 --- a/Source/Bogus.Tests/GitHubIssues/PullRequest113.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Bogus.DataSets; -using FluentAssertions; -using Xunit; -using static Bogus.DataSets.LoremPixelCategory; - -namespace Bogus.Tests.GitHubIssues; - -public class PullRequest113 : SeededTest -{ - [Fact] - public void category_exists_in_image_url() - { - var images = new Images(); - - images.LoremPixelUrl(Cats).Should().Contain("cat"); - } -} \ No newline at end of file diff --git a/Source/Bogus/DataSets/Images.LoremPixel.cs b/Source/Bogus/DataSets/Images.LoremPixel.cs deleted file mode 100644 index 369dc762..00000000 --- a/Source/Bogus/DataSets/Images.LoremPixel.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; - -namespace Bogus.DataSets; - -public static class LoremPixelCategory -{ - public const string Abstract = "abstract"; - public const string Animals = "animals"; - public const string Business = "business"; - public const string Cats = "cats"; - public const string City = "city"; - public const string Food = "food"; - public const string Nightlife = "nightlife"; - public const string Fashion = "fashion"; - public const string People = "people"; - public const string Nature = "nature"; - public const string Sports = "sports"; - public const string Technics = "technics"; - public const string Transport = "transport"; - public const string Random = "random"; -} - -public partial class Images -{ - /// - /// Gets a random LoremPixel.com image. - /// - [Obsolete("Please use Images.LoremPixelUrl(). Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Image(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl(LoremPixelCategory.Random, width, height, randomize, https); - } - - /// - /// Gets an abstract looking image. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Abstract. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Abstract(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("abstract", width, height, randomize, https); - } - - /// - /// Gets an image of an animal. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Animals. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Animals(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("animals", width, height, randomize, https); - } - - /// - /// Gets a business looking image. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Business. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Business(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("business", width, height, randomize, https); - } - - /// - /// Gets a picture of a cat. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Cats. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Cats(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("cats", width, height, randomize, https); - } - - /// - /// Gets a city looking image. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.City. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string City(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("city", width, height, randomize, https); - } - - /// - /// Gets an image of food. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Food. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Food(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("food", width, height, randomize, https); - } - - /// - /// Gets an image with city looking nightlife. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Nightlife. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Nightlife(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("nightlife", width, height, randomize, https); - } - - /// - /// Gets an image in the fashion category. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Fashion. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Fashion(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("fashion", width, height, randomize, https); - } - - /// - /// Gets an image of humans. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.People. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string People(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("people", width, height, randomize, https); - } - - /// - /// Gets an image of nature. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Nature. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Nature(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("nature", width, height, randomize, https); - } - - /// - /// Gets an image related to sports. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Sports. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Sports(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("sports", width, height, randomize, https); - } - - /// - /// Get a technology related image. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Technics. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Technics(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("technics", width, height, randomize, https); - } - - /// - /// Get a transportation related image. - /// - /// Width - /// Height - /// Adds a random cache busting number to the URL - /// Uses https:// protocol - [Obsolete("Please use Images.LoremPixelUrl() method with category:LoremPixelCategory.Transport. Consider using PicsumUrl() method as a more reliable/faster service.")] - public string Transport(int width = 640, int height = 480, bool randomize = false, bool https = false) - { - return LoremPixelUrl("transport", width, height, randomize, https); - } -} \ No newline at end of file diff --git a/Source/Bogus/DataSets/Images.cs b/Source/Bogus/DataSets/Images.cs index 8838c941..0649a352 100644 --- a/Source/Bogus/DataSets/Images.cs +++ b/Source/Bogus/DataSets/Images.cs @@ -182,49 +182,4 @@ public string LoremFlickrUrl( return Url + sb; } - - /// - /// Creates an image URL with http://lorempixel.com. Note: This service is slow. Consider using PicsumUrl() as a faster alternative. - /// - public string LoremPixelUrl(string category = LoremPixelCategory.Random, int width = 640, int height = 480, bool randomize = false, bool https = false) - { - if( category == LoremPixelCategory.Random ) - { - var categories = new[] - { - LoremPixelCategory.Abstract, - LoremPixelCategory.Animals, - LoremPixelCategory.Business, - LoremPixelCategory.Cats, - LoremPixelCategory.City, - LoremPixelCategory.Food, - LoremPixelCategory.Nightlife, - LoremPixelCategory.Fashion, - LoremPixelCategory.People, - LoremPixelCategory.Nature, - LoremPixelCategory.Sports, - LoremPixelCategory.Technics, - LoremPixelCategory.Transport - }; - - category = this.Random.ArrayElement(categories); - } - - var proto = "http://"; - if( https ) - { - proto = "https://"; - } - var url = $"{proto}lorempixel.com/{width}/{height}"; - if( !string.IsNullOrWhiteSpace(category) ) - { - url += $"/{category}"; - if( randomize ) - { - url += $"/{this.Random.Number(1, 10)}"; - } - } - - return url; - } } \ No newline at end of file