using Bogus
2022/9/13 23:22:17
本文主要是介绍using Bogus,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
using Bogus; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp4 { internal class Program { static void Main(string[] args) { List<Customer> cc = GetCustomerGenerator().Generate(20); foreach (var item in cc) { Console.WriteLine(item.ZipCode); } } public static Faker<Customer> GetCustomerGenerator() { // https://www.cnblogs.com/ljknlb/p/15862473.html var ordergenerator = new Faker<Order>("zh_CN") .RuleFor(o => o.Id, Guid.NewGuid) .RuleFor(o => o.Date, f => f.Date.Past(3)) .RuleFor(o => o.OrderValue, f => f.Finance.Amount(0, 10000)) .RuleFor(o => o.Shipped, f => f.Random.Bool(0.9f)); var customerGenerator = new Faker<Customer>("zh_CN") .RuleFor(c => c.Id, Guid.NewGuid()) .RuleFor(c => c.Name, f => f.Person.LastName + f.Person.FirstName) .RuleFor(x => x.JobTitle, x => x.Name.JobTitle()) .RuleFor(x => x.JobDescription, x => x.Name.JobDescriptor()) .RuleFor(x => x.JobArea, x => x.Name.JobArea()) .RuleFor(x => x.Word, x => x.Lorem.Word()) //Sentence .RuleFor(x => x.Sentence, x => x.Lorem.Sentence()) .RuleFor(x => x.Age, x => x.Random.Int(0, 120)) .RuleFor(c => c.Address, f => f.Address.FullAddress()) .RuleFor(c => c.City, f => f.Address.City()) .RuleFor(c => c.Country, f => f.Address.Country()) .RuleFor(c => c.ZipCode, f => f.Address.ZipCode()) .RuleFor(c => c.Phone, f => f.Phone.PhoneNumber()) .RuleFor(c => c.Email, f => f.Internet.Email()) .RuleFor(c => c.ContactName, (f, c) => f.Person.LastName + f.Person.FirstName) .RuleFor(c => c.VehicleManufacturer, f => f.Vehicle.Manufacturer()) .RuleFor(x => x.CreateOn, x => x.Date.Past(1)) .RuleFor(x => x.Review, x => x.Rant.Review()) .RuleFor(x => x.Balance, x => x.Finance.Amount(0, 1000)) .RuleFor(c => c.Orders, f => ordergenerator.Generate(f.Random.Number(10)).ToList()); //var personFaker = new Faker<Memmber>() // .RuleFor(x => x.ID, x => x.Random.Guid()) // .RuleFor(x => x.NO, x => x.Random.Long(100000000000, 999999999999)) // .RuleFor(x => x.Name, x => x.Person.LastName + x.Person.FirstName) // .RuleFor(x => x.Sex, x => x.Random.Enum<Sex>()) // .RuleFor(x => x.Email, x => x.Person.Email) // .RuleFor(x => x.Phone, x => x.Person.Phone) // .RuleFor(x => x.Age, x => x.Random.Int(0, 120)) // .RuleFor(x => x.Balance, x => x.Finance.Amount(0, 1000)) // .RuleFor(x => x.CreateOn, x => x.Date.Past(1)); return customerGenerator; } } public class Customer { public Guid Id { get; set; } public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string Country { get; set; } public string ZipCode { get; set; } public string Phone { get; set; } public string Email { get; set; } public string ContactName { get; set; } public IEnumerable<Order> Orders { get; set; } public int Age { get; set; } public DateTime CreateOn { get; set; } public decimal Balance { get; internal set; } public object VehicleManufacturer { get; internal set; } public object Review { get; internal set; } public object JobTitle { get; internal set; } public object JobDescription { get; internal set; } public object JobArea { get; internal set; } public object Word { get; internal set; } public object Sentence { get; internal set; } } public class Order { public Guid Id { get; set; } public DateTime Date { get; set; } public Decimal OrderValue { get; set; } public bool Shipped { get; set; } } }
这篇关于using Bogus的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-26大厂数据结构与算法教程:入门级详解
- 2024-12-26大厂算法与数据结构教程:新手入门指南
- 2024-12-26Python编程入门指南
- 2024-12-26数据结构高级教程:新手入门及初级提升指南
- 2024-12-26并查集入门教程:从零开始学会并查集
- 2024-12-26大厂数据结构与算法入门指南
- 2024-12-26大厂算法与数据结构入门教程
- 2024-12-26二叉树入门教程:轻松掌握基础概念与操作
- 2024-12-26初学者指南:轻松掌握链表
- 2024-12-26平衡树入门教程:轻松理解与应用