private async Task <EmployeeEntity[]> FakeEmployees(IEnumerable <SalesmanEntity> salesmen, int count) { var salesmenSns = salesmen.Select(x => x.Sn).ToList(); var faker = new Faker <EmployeeEntity>() .RuleFor(x => x.ID, f => f.Person.Ssn()) .RuleFor(x => x.Email, f => f.Person.Email) .RuleFor(x => x.Gender, f => f.PickRandom <EmployeeEntity.GenderTypes>()) .RuleFor(x => x.PicPath, (f, x) => f.Image.LoremFlickrUrl(keywords: f.PickRandom("man", "woman", "face", "person"))) .RuleFor(x => x.FirstName, f => f.Person.FirstName) .RuleFor(x => x.LastName, f => f.Person.LastName) .RuleFor(x => x.IsActive, f => true) .RuleFor(x => x.SalesmanSN, f => { if (salesmenSns.Count == 0) { return(null); } var sn = salesmenSns[0]; salesmenSns.RemoveAt(0); return(sn); }) .RuleFor(x => x.HomeAddress, f => AddressFaker.Generate()) .RuleFor(x => x.WorkAddress, f => AddressFaker.Generate()) .RuleFor(x => x.HomePhone, f => f.Person.Phone) .RuleFor(x => x.JobTitle, f => f.Lorem.Word()) ; _dbContext.Employees.AddRange(faker.Generate(count)); await _dbContext.SaveChangesAsync(); return(await _dbContext.Employees.ToArrayAsync()); }
public IHttpActionResult Post(Order order) { AddressFaker addressFaker = new AddressFaker(); CustomerFaker customerFaker = new CustomerFaker(addressFaker); order = new Order { Customer = new Customer { Id = 4 }, Details = new List <OrderDetail> { new OrderDetail { Item = new Product { Id = 1 }, Quantity = 3, UnitPrice = 2 }, new OrderDetail { Item = new Product { Id = 2 }, Quantity = 5, UnitPrice = 10 }, }, ShipAddress = addressFaker.Generate() }; orderService.Add(order); return(CreatedAtRoute("DefaultApi", new { Id = order.Id }, order)); }
private async Task <BusinessPartner[]> FakeBusinessPartners(IEnumerable <SalesmanEntity> salesmen, IEnumerable <CardGroup> cardGroups, int count) { var faker = new Faker <BusinessPartner>() .RuleFor(c => c.PartnerType, f => f.PickRandom <BusinessPartner.PartnerTypes>()) .RuleFor(c => c.Type, f => f.PickRandom <BusinessPartner.CardType>()) .RuleFor(c => c.CreationDateTime, f => f.Date.Past(6, DateTime.Now)) .RuleFor(c => c.LastUpdateDateTime, (f, c) => new Random().Next(10) < 4 ? f.Date.Between(c.CreationDateTime.Value, DateTime.Now) : new DateTime?()) .RuleFor(c => c.Name, (f, c) => f.Company.CompanyName()) .RuleFor(c => c.FederalTaxId, (f, c) => f.Company.Ein()) .RuleFor(i => i.Currency, f => "$") .RuleFor(c => c.Email, (f, c) => new Random().Next(10) < 6 ? f.Internet.Email(c.Name) : null) .RuleFor(c => c.Phone1, (f, c) => f.Phone.PhoneNumber("0#-#######")) .RuleFor(c => c.Phone2, (f, c) => new Random().Next(10) < 4 ? f.Phone.PhoneNumber("05#-#######") : null) .RuleFor(c => c.Cellular, (f, c) => f.Phone.PhoneNumber("05#-#######")) .RuleFor(c => c.Fax, (f, c) => new Random().Next(10) < 4 ? f.Phone.PhoneNumber("0#-#######") : null) .RuleFor(c => c.IsActive, f => true /*f.Random.Bool()*/) .RuleFor(c => c.GroupSn, (f, c) => f.PickRandom(cardGroups).Sn) .RuleFor(c => c.SalesmanCode, (f, c) => f.PickRandom(salesmen).Sn) .RuleFor(c => c.ShippingAddress, (f, c) => AddressFaker.Generate()) .RuleFor(c => c.BillingAddress, (f, c) => AddressFaker.Generate()) .RuleFor(c => c.OrdersBalance, 0) .RuleFor(c => c.DeliveryNotesBalance, 0) .RuleFor(c => c.IsVatFree, f => f.Random.Bool()) .RuleFor(c => c.DiscountPercent, f => f.Random.Decimal()) .RuleFor(c => c.GeoLocation, (f, c) => new GeoLocation { Address = $"{c.BillingAddress.City},{c.BillingAddress.Street} {c.BillingAddress.NumAtStreet}", Latitude = 15.00, Longitude = 15.5656 }) .RuleFor(c => c.Balance, f => f.Random.Decimal()) .RuleFor(c => c.OrdersBalance, f => f.Random.Decimal()) .RuleFor(c => c.DeliveryNotesBalance, f => f.Random.Decimal()) ; _dbContext.BusinessPartners.AddRange(faker.Generate(count)); await _dbContext.SaveChangesAsync(); return(await _dbContext.BusinessPartners.ToArrayAsync()); }