static void Main(string[] args) { // create data sets var nameDataSet = new Bogus.DataSets.Name(); var addressDataSet = new Bogus.DataSets.Address(); var phoneDataSet = new Bogus.DataSets.PhoneNumbers(); // create list to hold results var list = new List <Address>(); for (var i = 0; i < 780000; i++) { // generate a result var address = new Address(); address.First = nameDataSet.FirstName(); address.Last = nameDataSet.LastName(); address.Street = addressDataSet.StreetAddress(); address.City = addressDataSet.City(); address.State = addressDataSet.State(); address.Zip = addressDataSet.ZipCode(); address.Phone = phoneDataSet.PhoneNumberFormat(0); list.Add(address); } // serialize to output.json var json = Newtonsoft.Json.JsonConvert.SerializeObject(list); File.WriteAllText("output.json", json); }
static void Main() { var random = new Randomizer(); var lorem = new Bogus.DataSets.Lorem(); var addresses = new Bogus.DataSets.Address(); var order = new Order() { OrderId = random.Number(1, 100), Item = string.Join(" ", lorem.Letter(100)), Quantity = random.Number(1, 10), ZipCode = addresses.ZipCode() }; order.Dump(); Console.ReadLine(); var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi", "grapefruit" }; var testOrders = new Faker <Order>() //Ensure all properties have rules. By default, StrictMode is false //Set a global policy by using Faker.DefaultStrictMode .StrictMode(true) //OrderId is deterministic .RuleFor(o => o.OrderId, f => f.Random.Number(1, 100)) //Pick some fruit from a basket .RuleFor(o => o.Item, f => f.PickRandom(fruit)) //A random quantity from 1 to 10 .RuleFor(o => o.Quantity, f => f.Random.Number(1, 10)) .RuleFor(o => o.ZipCode, f => f.Address.ZipCode()); testOrders.Generate(3).ToList().ForEach(o => o.Dump()); Console.ReadLine(); }
private static Customer CreateCustomer(_CustomerType type) { var name = new Bogus.DataSets.Name(); var address = new Bogus.DataSets.Address(); var random = new Randomizer(); if (type == _CustomerType.Individual) { var phoneNo = new Bogus.DataSets.PhoneNumbers(); return(new IndividualCustomer() { FirstName = name.FirstName(), LastName = name.LastName(), CustomerType = type.ToString(), Street = address.StreetName(), City = address.City(), State = address.State(), Zipcode = int.Parse(address.ZipCode("######")), PhoneNo = int.Parse(phoneNo.PhoneNumber("########")), Age = random.Number(18, 100), Gender = (int)random.Enum <_Gender>() }); } else if (type == _CustomerType.Enterprise) { var companyName = new Bogus.DataSets.Company(); return(new EnterpriseCustomer() { FirstName = name.FirstName(), LastName = name.LastName(), CustomerType = type.ToString(), Street = address.StreetName(), City = address.City(), State = address.State(), Zipcode = int.Parse(address.ZipCode("######")), OrganizationName = companyName.CompanyName() + companyName.CompanySuffix(), OrganizationType = random.Enum <_OrganizationType>().ToString() }); } else { return(null); } }
/// <summary> /// Generates a random address using the Bogus library (a port of Faker.js) /// </summary> /// <returns></returns> private static IEnumerable <Address> RandomAddresses() { List <Address> addresses = new List <Address>(); var random = new Random(); for (int i = 0; i < random.Next(1, 5); i++) { var bogusAddress = new Bogus.DataSets.Address(); Country country; State state; var countries = Enum.GetValues(typeof(Country)); var states = Enum.GetValues(typeof(State)); if (random.Next(1, 100) > 75) { country = (Country)countries.GetValue(random.Next(countries.Length)); } else { country = Country.United_States; } if (country == Country.United_States) { state = (State)states.GetValue(random.Next(states.Length)); } else { state = State.NA; } addresses.Add(new Address() { HouseNum = bogusAddress.BuildingNumber(), Street = bogusAddress.StreetName() + (random.Next() % 2 == 0 ? bogusAddress.StreetSuffix() : ""), City = bogusAddress.City(), CountryCode = country, StateCode = state, Zip = bogusAddress.ZipCode(), Pid = System.Guid.NewGuid() }); } return(addresses); }