Last active
June 12, 2018 06:30
-
-
Save danielplawgo/917d323411ff96099c2312e8e3778329 to your computer and use it in GitHub Desktop.
Bogus – generowanie danych testowych
This file contains hidden or 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
public class User | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
public string Email { get; set; } | |
public Gender Gender { get; set; } | |
} | |
public enum Gender | |
{ | |
Male = 0, | |
Female = 1 | |
} | |
public class Product | |
{ | |
public string Name { get; set; } | |
public string Company { get; set; } | |
public decimal Price { get; set; } | |
} | |
public class Order | |
{ | |
public DateTime Date { get; set; } | |
public User User { get; set; } | |
public Product Product { get; set; } | |
public int Count { get; set; } | |
public OrderStatus Status { get; set; } | |
} | |
public enum OrderStatus | |
{ | |
New, | |
Processing, | |
Completed, | |
Canceled | |
} |
This file contains hidden or 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
var users = new Faker<User>(locale) | |
.StrictMode(true) | |
.RuleFor(u => u.Gender, (f, u) => f.PickRandom<Gender>()) | |
.RuleFor(u => u.FirstName, (f, u) => f.Name.FirstName((Bogus.DataSets.Name.Gender)u.Gender)) | |
.RuleFor(u => u.LastName, (f, u) => f.Name.FirstName((Bogus.DataSets.Name.Gender)u.Gender)) | |
.RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName)) | |
.Generate(10); |
This file contains hidden or 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
var products = new Faker<Product>(locale) | |
.StrictMode(true) | |
.RuleFor(p => p.Name, (f, p) => f.Commerce.ProductName()) | |
.RuleFor(p => p.Company, (f, p) => f.Company.CompanyName()) | |
.RuleFor(p => p.Price, (f, p) => f.Random.Decimal(0.01M, 1000M)) | |
.Generate(10); | |
var orders = new Faker<Order>(locale) | |
.StrictMode(true) | |
.RuleFor(o => o.User, (f, p) => f.PickRandom(users)) | |
.RuleFor(o => o.Product, (f, p) => f.PickRandom(products)) | |
.RuleFor(o => o.Count, (f, p) => f.Random.Int(1, 20)) | |
.RuleFor(o => o.Date, (f, p) => f.Date.Past(2)) | |
.RuleFor(o => o.Status, (f, p) => f.PickRandom<OrderStatus>()) | |
.Generate(100); |
This file contains hidden or 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
string locale = "pl"; | |
var users = new Faker<User>(locale) | |
.Generate(10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment