-
Notifications
You must be signed in to change notification settings - Fork 12
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. * Added the data. * Implemented the Commerce faker. * Added the CommerceFaker to the main faker classes. * Fixed the test.
- Loading branch information
Showing
9 changed files
with
365 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,22 @@ | ||
# Faker.Commerce | ||
|
||
```cs | ||
Faker.Commerce.Color() //=> "lavender" | ||
# Optional arguments max=3, fixedAmount=false | ||
Faker.Commerce.Department() //=> "Grocery, Health & Beauty" | ||
Faker.Commerce.Department(5) //=> "Grocery, Books, Health & Beauty" | ||
Faker.Commerce.Department(2, true) //=> "Books & Tools" | ||
Faker.Commerce.Material() //=> "Steel" | ||
Faker.Commerce.ProductName() //=> "Practical Granite Shirt" | ||
Faker.Commerce.Price() //=> "44.6" | ||
Faker.Commerce.Price(mew Range<double>(0, 10)) //=> "2.18" | ||
# Generate a random promotion code. | ||
# Optional argument digits = 6 for number of random digits in suffix | ||
Faker.Commerce.PromotionCode() //=> "AmazingDeal829102" | ||
Faker.Commerce.PromotionCode(digits = 2) //=> "AmazingPrice57" | ||
``` |
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,126 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FakerDotNet.Data | ||
{ | ||
internal static class CommerceData | ||
{ | ||
public static readonly IEnumerable<string> Departments = new[] | ||
{ | ||
"Books", | ||
"Movies", | ||
"Music", | ||
"Games", | ||
"Electronics", | ||
"Computers", | ||
"Home", | ||
"Garden", | ||
"Tools", | ||
"Grocery", | ||
"Health", | ||
"Beauty", | ||
"Toys", | ||
"Kids", | ||
"Baby", | ||
"Clothing", | ||
"Shoes", | ||
"Jewelry", | ||
"Sports", | ||
"Outdoors", | ||
"Automotive", | ||
"Industrial" | ||
}; | ||
|
||
public static readonly IEnumerable<string> ProductNames = new[] | ||
{ | ||
"Chair", | ||
"Car", | ||
"Computer", | ||
"Gloves", | ||
"Pants", | ||
"Shirt", | ||
"Table", | ||
"Shoes", | ||
"Hat", | ||
"Plate", | ||
"Knife", | ||
"Bottle", | ||
"Coat", | ||
"Lamp", | ||
"Keyboard", | ||
"Bag", | ||
"Bench", | ||
"Clock", | ||
"Watch", | ||
"Wallet" | ||
}; | ||
|
||
public static readonly IEnumerable<string> ProductAdjectives = new[] | ||
{ | ||
"Small", | ||
"Ergonomic", | ||
"Rustic", | ||
"Intelligent", | ||
"Gorgeous", | ||
"Incredible", | ||
"Fantastic", | ||
"Practical", | ||
"Sleek", | ||
"Awesome", | ||
"Enormous", | ||
"Mediocre", | ||
"Synergistic", | ||
"Heavy Duty", | ||
"Lightweight", | ||
"Aerodynamic", | ||
"Durable" | ||
}; | ||
|
||
public static readonly IEnumerable<string> Materials = new[] | ||
{ | ||
"Steel", | ||
"Wooden", | ||
"Concrete", | ||
"Plastic", | ||
"Cotton", | ||
"Granite", | ||
"Rubber", | ||
"Leather", | ||
"Silk", | ||
"Wool", | ||
"Linen", | ||
"Marble", | ||
"Iron", | ||
"Bronze", | ||
"Copper", | ||
"Aluminum", | ||
"Paper" | ||
}; | ||
|
||
public static readonly IEnumerable<string> PromotionCodeAdjectives = new[] | ||
{ | ||
"Amazing", | ||
"Awesome", | ||
"Cool", | ||
"Good", | ||
"Great", | ||
"Incredible", | ||
"Killer", | ||
"Premium", | ||
"Special", | ||
"Stellar", | ||
"Sweet" | ||
}; | ||
|
||
public static readonly IEnumerable<string> PromotionCodeNouns = new[] | ||
{ | ||
"Code", | ||
"Deal", | ||
"Discount", | ||
"Price", | ||
"Promo", | ||
"Promotion", | ||
"Sale", | ||
"Savings" | ||
}; | ||
} | ||
} |
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,72 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text; | ||
using FakerDotNet.Data; | ||
|
||
namespace FakerDotNet.Fakers | ||
{ | ||
public interface ICommerceFaker | ||
{ | ||
string Color(); | ||
string Department(int max = 3, bool fixedAmount = false); | ||
string Material(); | ||
string ProductName(); | ||
string Price(Range<double> range = null); | ||
string PromotionCode(int digits = 6); | ||
} | ||
|
||
internal class CommerceFaker : ICommerceFaker | ||
{ | ||
private readonly IFakerContainer _fakerContainer; | ||
|
||
public CommerceFaker(IFakerContainer fakerContainer) | ||
{ | ||
_fakerContainer = fakerContainer; | ||
} | ||
|
||
public string Color() | ||
{ | ||
return _fakerContainer.Color.ColorName(); | ||
} | ||
|
||
public string Department(int max = 3, bool fixedAmount = false) | ||
{ | ||
var num = fixedAmount ? max : Convert.ToInt32(_fakerContainer.Number.Between(1, max)); | ||
|
||
if (num <= 1) return _fakerContainer.Random.Element(CommerceData.Departments); | ||
|
||
var departments = _fakerContainer.Random.Assortment(CommerceData.Departments, num).ToArray(); | ||
|
||
return string.Join(" & ", | ||
string.Join(", ", departments.Take(departments.Length - 1)), | ||
departments.Last()); | ||
} | ||
|
||
public string Material() | ||
{ | ||
return _fakerContainer.Random.Element(CommerceData.Materials); | ||
} | ||
|
||
public string ProductName() | ||
{ | ||
return string.Join(" ", | ||
_fakerContainer.Random.Element(CommerceData.ProductAdjectives), | ||
_fakerContainer.Random.Element(CommerceData.Materials), | ||
_fakerContainer.Random.Element(CommerceData.ProductNames)); | ||
} | ||
|
||
public string Price(Range<double> range = null) | ||
{ | ||
range = range ?? new Range<double>(0, 100); | ||
return _fakerContainer.Number.Between(range.Minimum, range.Maximum).ToString("#.##"); | ||
} | ||
|
||
public string PromotionCode(int digits = 6) | ||
{ | ||
return string.Join("", | ||
_fakerContainer.Random.Element(CommerceData.PromotionCodeAdjectives), | ||
_fakerContainer.Random.Element(CommerceData.PromotionCodeNouns), | ||
_fakerContainer.Number.Number(digits)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.