标签:RuleFor set string get internal Bogus using public
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; }
}
}
标签:RuleFor,set,string,get,internal,Bogus,using,public 来源: https://www.cnblogs.com/renzhe-org/p/16688776.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。