-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added the documentation. * Implemented the LoremFlickr faker. * Added the LoremFlickrFaker to the main faker classes.
- Loading branch information
Showing
8 changed files
with
333 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Faker.LoremFlickr | ||
|
||
|
||
```cs | ||
Faker.LoremFlickr.Image() //=> "http://loremflickr.Com/300/300" | ||
Faker.LoremFlickr.Image("50x60") //=> "http://loremflickr.Com/50/60" | ||
Faker.LoremFlickr.Image("50x60", new[] {"sports"}) //=> "http://loremflickr.Com/50/60/sports" | ||
Faker.LoremFlickr.Image("50x60", new[] {"sports", "fitness"}) //=> "http://loremflickr.Com/50/60/sports,fitness" | ||
Faker.LoremFlickr.Image("50x60", new[] {"sports", "fitness"}, true) //=> "http://loremflickr.Com/50/60/sports,fitness/all" | ||
Faker.LoremFlickr.GrayscaleImage() //=> "http://loremflickr.Com/g/300/300/all" | ||
Faker.LoremFlickr.GrayscaleImage("50x60") //=> "http://loremflickr.Com/g/50/60/all" | ||
Faker.LoremFlickr.GrayscaleImage("50x60", new[] {"sports"}) //=> "http://loremflickr.Com/g/50/60/sports" | ||
Faker.LoremFlickr.GrayscaleImage("50x60", new[] {"sports", "fitness"}) //=> "http://loremflickr.Com/g/50/60/sports,fitness" | ||
Faker.LoremFlickr.GrayscaleImage("50x60", new[] {"sports", "fitness"}, true) //=> "http://loremflickr.Com/g/50/60/sports,fitness/all" | ||
Faker.LoremFlickr.PixelatedImage() //=> "http://loremflickr.Com/p/300/300/all" | ||
Faker.LoremFlickr.PixelatedImage("50x60") //=> "http://loremflickr.Com/p/50/60/all" | ||
Faker.LoremFlickr.PixelatedImage("50x60", new[] {"sports"}) //=> "http://loremflickr.Com/p/50/60/sports" | ||
Faker.LoremFlickr.PixelatedImage("50x60", new[] {"sports", "fitness"}) //=> "http://loremflickr.Com/p/50/60/sports,fitness" | ||
Faker.LoremFlickr.PixelatedImage("50x60", new[] {"sports", "fitness"}, true) //=> "http://loremflickr.Com/p/50/60/sports,fitness/all" | ||
Faker.LoremFlickr.ColorizedImage() //=> "http://loremflickr.Com/red/300/300/all" | ||
Faker.LoremFlickr.ColorizedImage("50x60") //=> "http://loremflickr.Com/red/50/60/all" | ||
Faker.LoremFlickr.ColorizedImage("50x60", 'red') //=> "http://loremflickr.Com/red/50/60/all" | ||
Faker.LoremFlickr.ColorizedImage("50x60", 'red', new[] {"sports"}) //=> "http://loremflickr.Com/red/50/60/sports" | ||
Faker.LoremFlickr.ColorizedImage("50x60", 'red', new[] {"sports", "fitness"}) //=> "http://loremflickr.Com/red/50/60/sports,fitness" | ||
Faker.LoremFlickr.ColorizedImage("50x60", 'red', new[] {"sports", "fitness"}, true) //=> "http://loremflickr.Com/red/50/60/sports,fitness/all" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace FakerDotNet.Fakers | ||
{ | ||
public interface ILoremFlickrFaker | ||
{ | ||
string Image( | ||
string size = "300x300", | ||
string[] searchTerms = null, | ||
bool matchAll = false); | ||
|
||
string GrayscaleImage( | ||
string size = "300x300", | ||
string[] searchTerms = null, | ||
bool matchAll = false); | ||
|
||
string PixelatedImage( | ||
string size = "300x300", | ||
string[] searchTerms = null, | ||
bool matchAll = false); | ||
|
||
string ColorizedImage( | ||
string size = "300x300", | ||
string color = "red", | ||
string[] searchTerms = null, | ||
bool matchAll = false); | ||
} | ||
|
||
internal class LoremFlickrFaker : ILoremFlickrFaker | ||
{ | ||
private readonly IFakerContainer _fakerContainer; | ||
|
||
public LoremFlickrFaker(IFakerContainer fakerContainer) | ||
{ | ||
_fakerContainer = fakerContainer; | ||
} | ||
|
||
public string Image(string size = "300x300", string[] searchTerms = null, bool matchAll = false) | ||
{ | ||
return BuildUrl(size, null, searchTerms, matchAll); | ||
} | ||
|
||
public string GrayscaleImage(string size = "300x300", string[] searchTerms = null, bool matchAll = false) | ||
{ | ||
return BuildUrl(size, "g", searchTerms, matchAll); | ||
} | ||
|
||
public string PixelatedImage(string size = "300x300", string[] searchTerms = null, bool matchAll = false) | ||
{ | ||
return BuildUrl(size, "p", searchTerms, matchAll); | ||
} | ||
|
||
public string ColorizedImage(string size = "300x300", string color = "red", string[] searchTerms = null, | ||
bool matchAll = false) | ||
{ | ||
return BuildUrl(size, color, searchTerms, matchAll); | ||
} | ||
|
||
private static string BuildUrl(string size, string format, string[] searchTerms, bool matchAll) | ||
{ | ||
if (!IsValidSize(size)) | ||
throw new ArgumentException("Size should be specified in format 300x300", nameof(size)); | ||
|
||
return string.Join("/", new[] | ||
{ | ||
"https://loremflickr.com", | ||
format, | ||
string.Join("/", size.Split('x')), | ||
string.Join(",", searchTerms ?? new string[] { }), | ||
matchAll ? "all" : null | ||
}.Where(x => !string.IsNullOrEmpty(x))); | ||
} | ||
|
||
private static bool IsValidSize(string size) | ||
{ | ||
return Regex.IsMatch(size, "^[0-9]+x[0-9]+$"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
tests/FakerDotNet.Tests/Fakers/LoremFlickrFakerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
using FakeItEasy; | ||
using FakerDotNet.Fakers; | ||
using NUnit.Framework; | ||
|
||
namespace FakerDotNet.Tests.Fakers | ||
{ | ||
[TestFixture] | ||
[Parallelizable] | ||
public class LoremFlickrFakerTests | ||
{ | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fakerContainer = A.Fake<IFakerContainer>(); | ||
_loremflickrFaker = new LoremFlickrFaker(_fakerContainer); | ||
} | ||
|
||
private IFakerContainer _fakerContainer; | ||
private ILoremFlickrFaker _loremflickrFaker; | ||
|
||
[Test] | ||
public void Image_returns_an_image_url() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/300/300", | ||
_loremflickrFaker.Image()); | ||
} | ||
|
||
[Test] | ||
public void Image_returns_an_image_url_with_the_specified_size() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/50/60", | ||
_loremflickrFaker.Image("50x60")); | ||
} | ||
|
||
[Test] | ||
public void Image_returns_an_image_url_with_the_specified_search_term() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/50/60/sports", | ||
_loremflickrFaker.Image("50x60", new[] {"sports"})); | ||
} | ||
|
||
[Test] | ||
public void Image_returns_an_image_url_with_the_specified_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/50/60/sports,fitness", | ||
_loremflickrFaker.Image("50x60", new[] {"sports", "fitness"})); | ||
} | ||
|
||
[Test] | ||
public void Image_returns_an_image_url_that_specifies_it_should_match_all_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/50/60/sports,fitness/all", | ||
_loremflickrFaker.Image("50x60", new[] {"sports", "fitness"}, true)); | ||
} | ||
|
||
[Test] | ||
public void GrayscaleImage_returns_a_grayscale_image_url() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/g/300/300", | ||
_loremflickrFaker.GrayscaleImage()); | ||
} | ||
|
||
[Test] | ||
public void GrayscaleImage_returns_a_grayscale_image_url_with_the_specified_size() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/g/50/60", | ||
_loremflickrFaker.GrayscaleImage("50x60")); | ||
} | ||
|
||
[Test] | ||
public void GrayscaleImage_returns_a_grayscale_image_url_with_the_specified_search_term() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/g/50/60/sports", | ||
_loremflickrFaker.GrayscaleImage("50x60", new[] {"sports"})); | ||
} | ||
|
||
[Test] | ||
public void GrayscaleImage_returns_a_grayscale_image_url_with_the_specified_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/g/50/60/sports,fitness", | ||
_loremflickrFaker.GrayscaleImage("50x60", new[] {"sports", "fitness"})); | ||
} | ||
|
||
[Test] | ||
public void GrayscaleImage_returns_a_grayscale_image_url_that_specifies_it_should_match_all_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/g/50/60/sports,fitness/all", | ||
_loremflickrFaker.GrayscaleImage("50x60", new[] {"sports", "fitness"}, true)); | ||
} | ||
|
||
[Test] | ||
public void PixelatedImage_returns_a_pixelated_image_url() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/p/300/300", | ||
_loremflickrFaker.PixelatedImage()); | ||
} | ||
|
||
[Test] | ||
public void PixelatedImage_returns_a_pixelated_image_url_with_the_specified_size() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/p/50/60", | ||
_loremflickrFaker.PixelatedImage("50x60")); | ||
} | ||
|
||
[Test] | ||
public void PixelatedImage_returns_a_pixelated_image_url_with_the_specified_search_term() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/p/50/60/sports", | ||
_loremflickrFaker.PixelatedImage("50x60", new[] {"sports"})); | ||
} | ||
|
||
[Test] | ||
public void PixelatedImage_returns_a_pixelated_image_url_with_the_specified_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/p/50/60/sports,fitness", | ||
_loremflickrFaker.PixelatedImage("50x60", new[] {"sports", "fitness"})); | ||
} | ||
|
||
[Test] | ||
public void PixelatedImage_returns_a_pixelated_image_url_that_specifies_it_should_match_all_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/p/50/60/sports,fitness/all", | ||
_loremflickrFaker.PixelatedImage("50x60", new[] {"sports", "fitness"}, true)); | ||
} | ||
|
||
[Test] | ||
public void ColorizedImage_returns_a_colorized_image_url() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/red/300/300", | ||
_loremflickrFaker.ColorizedImage()); | ||
} | ||
|
||
[Test] | ||
public void ColorizedImage_returns_a_colorized_image_url_with_the_specified_size() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/red/50/60", | ||
_loremflickrFaker.ColorizedImage("50x60")); | ||
} | ||
|
||
[Test] | ||
public void ColorizedImage_returns_a_colorized_image_url_with_the_specified_color() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/red/50/60", | ||
_loremflickrFaker.ColorizedImage("50x60", "red")); | ||
} | ||
|
||
[Test] | ||
public void ColorizedImage_returns_a_colorized_image_url_with_the_specified_search_term() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/red/50/60/sports", | ||
_loremflickrFaker.ColorizedImage("50x60", "red", new[] {"sports"})); | ||
} | ||
|
||
[Test] | ||
public void ColorizedImage_returns_a_colorized_image_url_with_the_specified_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/red/50/60/sports,fitness", | ||
_loremflickrFaker.ColorizedImage("50x60", "red", new[] {"sports", "fitness"})); | ||
} | ||
|
||
[Test] | ||
public void ColorizedImage_returns_a_colorized_image_url_that_specifies_it_should_match_all_search_terms() | ||
{ | ||
Assert.AreEqual( | ||
"https://loremflickr.com/red/50/60/sports,fitness/all", | ||
_loremflickrFaker.ColorizedImage("50x60", "red", new[] {"sports", "fitness"}, true)); | ||
} | ||
} | ||
} |