public void Can_Create_One_User() { var user = new Faker<User>().Create(); Assert.IsNotNull(user); Assert.IsNotNull(user.Name); Assert.AreNotEqual(user.Name, ""); Assert.IsNotNull(user.Email); Assert.IsTrue(user.Email.Contains("@")); }
public void issue_12_bogus_should_be_thread_safe() { int threadCount = 20; var barId = 0; var faker = new Faker<Bar>() .RuleFor( b => b.Id, f => barId++) .RuleFor(b => b.Email, f => f.Internet.Email()) .RuleFor(b => b.Name, f => f.Name.FirstName()) .RuleFor(b => b.LastName, f => f.Name.LastName()); var threads = new List<Task>(); for( var x = 0; x < threadCount; x++) { var thread = Task.Run(() => { var fakes = faker.Generate(3); fakes.Dump(); }); threads.Add(thread); } Task.WaitAll(threads.ToArray()); Console.WriteLine(barId); barId.Should().Be(60); var result = Parallel.For(0, threadCount, i => { var fakes = faker.Generate(3).ToList(); }); Console.WriteLine(barId); barId.Should().Be(120); }
public void Can_Initialize_Lists() { var car = new Faker<Car>().Create(); Assert.IsNotNull(car); Assert.IsNotNull(car.Skils); }
public void Can_Create_Car_Without_Color() { var car = new Faker<Car>().Create(x => x.Color = ""); Assert.IsNotNull(car); Assert.AreEqual(car.Color, ""); }
public void every_new_generation_should_have_a_new_unqiue_index() { var faker = new Faker<User>() .RuleFor(u => u.FirstName, f => f.Person.FirstName) .RuleFor(u => u.LastName, f => f.Person.LastName) .RuleFor(u => u.Email, f => f.Person.Email) .RuleFor(u => u.Username, f => f.UniqueIndex + f.Person.UserName); var fakes = faker.Generate(10).ToList(); fakes.Dump(); faker.FakerHub.UniqueIndex.Should().Be(10); var values = fakes .Select(u => u.Username.Left(1).ToInt32()) .ToArray(); values.Should().BeEquivalentTo(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); var morefakes = faker.Generate(3).ToList(); morefakes.Dump(); faker.FakerHub.UniqueIndex.Should().Be(13); }
public void By_Default_Dont_Use_Numbers_In_Generated_Values_On_CreateMany() { var workers = new Faker<Worker>().CreateMany(3); Assert.IsTrue(workers.Any(x => !x.Name.Contains("1"))); Assert.IsTrue(workers.Any(x => !x.Name.Contains("2"))); Assert.IsTrue(workers.Any(x => !x.Name.Contains("3"))); }
public void parse_test() { var f = new Faker(); Tokenizer.Parse("{{name.lastName}}, {{name.firstName}} {{name.suffix}}", f.Name) .Dump(); }
public void Can_Create_10_Users() { var users = new Faker<User>().CreateMany(10); Assert.IsNotNull(users); Assert.AreEqual(10, users.Count()); Assert.IsTrue(users.First().Email.Contains("@")); Assert.IsTrue(users.Last().Email.Contains("@")); }
public void Can_Create_5_Without_Color_And_Model() { var cars = new Faker<Car>().CreateMany(5, x => { x.Color = ""; x.Model = ""; }); Assert.IsNotNull(cars); Assert.AreEqual(5, cars.Count()); Assert.IsTrue(cars.All(x => x.Color == "" && x.Model == "")); }
public void issue_13_readonly_property() { var faker = new Faker<ReadOnly>() .StrictMode(true) .RuleFor(ro => ro.Name, f => f.Name.FirstName()); faker.Validate().Should().BeTrue(); faker.TypeProperties.Count.Should().Be(1); }
public void should_throw_exception_on_incomplete_rules() { var testOrders = new Faker<Examples.Order>() .StrictMode(true) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)); testOrders.Invoking(faker => faker.Generate()) .ShouldThrow<InvalidOperationException>(); }
public void BeforeEachBenchmark() { var counter = 1; this.docs = new Faker<TestDoc>() .RuleFor(x => x.Counter, f => Interlocked.Increment(ref counter)) .RuleFor(x => x.SomeString, f => f.Lorem.Sentence()) .RuleFor(x => x.SomeDate, f => f.Date.Recent()) .RuleFor(x => x.SomeOtherString, f => f.Lorem.Sentence()) .RuleFor(x => x.SomeDateOffset, f => f.Date.Future()); }
public void should_not_throw_exception_on_complete_rule_set() { var testOrders = new Faker<Examples.Order>() .StrictMode(true) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)) .RuleFor(o => o.Item, f => f.Lorem.Sentence()) .RuleFor(o => o.OrderId, f => f.Random.Number()); testOrders.Invoking(faker => faker.Generate()) .ShouldNotThrow<InvalidOperationException>(); }
public void should_be_able_to_drive_manual_index() { int indexer = 0; var faker = new Faker<User>() .RuleFor(u => u.FirstName, f => f.Name.FirstName()) .RuleFor(u => u.LastName, f => new[] {"A", "B", "C", "D"}[indexer % 4]) .FinishWith((f, u) => indexer++); var fakes = faker.Generate(10).ToList(); fakes.Dump(); }
public void should_be_able_to_create_some_hash_ids() { var faker = new Faker<Video>() .RuleFor(v => v.VideoId, f => f.Hashids.EncodeLong(f.UniqueIndex)) .RuleFor(v => v.Summary, f => f.Lorem.Sentence()); var fakes = faker.Generate(5).ToList(); fakes.Dump(); var ids = fakes.Select(v => v.VideoId).ToArray(); ids.Should().BeEquivalentTo("gY", "jR", "k5", "l5", "mO"); }
public void issue_10_should_be_able_to_fake_fields() { var faker = new Faker<Bar>() .RuleFor(b => b.Email, f => f.Internet.Email()) .RuleFor(b => b.Name, f => f.Name.FirstName()) .RuleFor(b => b.LastName, f => f.Name.LastName()); var bar = faker.Generate(); bar.Dump(); bar.Name.Should().NotBeNullOrEmpty(); bar.Email.Length.Should().BeGreaterOrEqualTo(2); bar.Email.Should().NotBeNullOrEmpty(); bar.Email.Length.Should().BeGreaterOrEqualTo(2); bar.LastName.Should().NotBeNullOrEmpty(); bar.LastName.Length.Should().BeGreaterOrEqualTo(2); }
public static void Seed(ApplicationDbContext context) { // CONFIG var numUsersToGen = 50; // USER RULES var testUsers = new Faker<User>() .RuleFor(u => u.UserId, f => Guid.NewGuid()) .RuleFor(u => u.UserName, f => f.Name.FirstName()) .RuleFor(u => u.LastName, f => f.Name.LastName()) .RuleFor(u => u.Email, f => f.Internet.Email()) //.RuleFor(u => u.Logins, f => 0) ; while (numUsersToGen > 0) { context.Users.Add(testUsers.Generate()); numUsersToGen--; } }
public static void Main(string[] args) { var fakeUser = new Faker<User>("en") .RuleFor(u => u.FirstName, f => f.Name.FirstName()) .RuleFor(u => u.LastName, f => f.Name.LastName()); var users = fakeUser.Generate(4); foreach (var user in users) { Console.WriteLine($"{user.FirstName} {user.LastName}"); } Console.ReadLine(); }
public void should_be_able_to_run_default_ruleset() { var orderIds = 0; var testCustomers = new Faker<Customer>() .RuleSet("Good", (set) => { set.StrictMode(true); set.RuleFor(c => c.Id, f => orderIds++); set.RuleFor(c => c.Description, f => f.Lorem.Sentence()); set.RuleFor(c => c.GoodCustomer, f => true); }) .StrictMode(true) .RuleFor(c => c.Id, f => orderIds++) .RuleFor(c => c.Description, f => f.Lorem.Sentence()) .RuleFor(c => c.GoodCustomer, f => false); var results = testCustomers.Generate(5); results.All(s => s.GoodCustomer).Should().BeFalse(); results.Dump(); }
public FakeEntityService(Faker <TEntity> faker) { entities = faker.Generate(100); }
public void Initialize() { faker = new Faker(); }
public InstitutionFactory() { CompetenceFactory = new CompetenceFactory(); faker = new Faker <Institution>(); faker.Rules((f, institution) => { var countryCode = f.Random.ListItem(Constraints.Countries); var languageCode = f.Random.RandomLocale().Substring(0, 2); institution.officialID = $"{countryCode}:{f.Random.AlphaNumeric(10)}"; institution.cLDId = f.Company.CompanyName(); institution.countryCode = new Value { value = countryCode }; institution.isPublicIndicator = new Value { value = f.Random.Number(1).ToString() }; institution.isLiaisonBodyIndicator = new Value { value = f.Random.Number(1).ToString() }; institution.Relations = new List <Relation>(); institution.Name = new List <Translation> { new Translation { languageCode = languageCode, text = f.Company.CompanyName() }, new Translation { languageCode = "en", text = f.Company.CompanyName() } }; institution.ValidityPeriod = new ValidityPeriod { start = f.Date.Past().ToUniversalTime().Date }; institution.ContactInfo = new ContactInfo { URLs = new List <URL> { new URL { uRL = f.Internet.Url() } }, EmailAddresses = new List <EmailAddress> { new EmailAddress { emailAddress = f.Internet.Email() } }, FaxNumbers = new List <FaxNumber> { new FaxNumber { faxNumber = f.Phone.PhoneNumber() } }, PhoneNumbers = new List <PhoneNumber> { new PhoneNumber { phoneNumber = f.Phone.PhoneNumber() } } }; institution.PostalAddresses = new List <PostalAddress> { new PostalAddress { isVisitorAddress = false, Street = new Street { Translation = new Translation { languageCode = languageCode, text = f.Address.StreetName() } }, Town = new Town { Translation = new Translation { languageCode = languageCode, text = f.Address.City() } } } }; institution.Competences = CompetenceFactory.Create(CompetencesPerInstitution); institution.EbMSSignatureCertificates = new List <EbMSSignatureCertificate> { new EbMSSignatureCertificate { CertificateIdentification = new CertificateIdentification() } }; institution.BusinessSignatureCertificates = new List <BusinessSignatureCertificate> { new BusinessSignatureCertificate { CertificateIdentification = new CertificateIdentification() } }; institution.BusinessMessageEndpoint = new MessageEndpoint { channel = f.Random.AlphaNumeric(10), messageExchangePattern = "pull" }; institution.SystemMessageEndpoint = new MessageEndpoint { channel = $"{f.Random.AlphaNumeric(10)}:SYSTEM", messageExchangePattern = "pull" }; }); }
public void When_Set_UseSequenceNumbers_We_Have_Numbers_In_Generated_Values_On_CreateMany() { var workers = new Faker<Worker>(useSequenceNumbers: true).CreateMany(3); Assert.IsTrue(workers.Any(x => x.Name.Contains("1"))); Assert.IsTrue(workers.Any(x => x.Name.Contains("2"))); Assert.IsTrue(workers.Any(x => x.Name.Contains("3"))); }
public async void CreateReservation_ContactTypeInvalid_False() { //arrange var contact = ContactFaker.GetContactContactNameGreater(); var contactType = ContactTypeFaker.GetContactTypeOk(); var faker = new Faker(); var message = faker.Lorem.Paragraph(); var createReservationCommand = new CreateReservationCommand( contactId: contact.Id, contactName: contact.Name, contactPhone: contact.Name, contactBirthdate: contact.BirthDate, contactTypeId: contactType.Id, message: message ); _dependencyResolverMock .Setup(x => x.Resolve <IReservationRepository>()) .Returns(_reservationRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IMediatorHandler>()) .Returns(_mediatorHandler.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactRepository>()) .Returns(_contactRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactTypeRepository>()) .Returns(_contactTypeRepositoryMock.Object); _contactRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactId.Value)) .Returns(Task.FromResult((Contact)null)); _contactTypeRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactTypeId)) .Returns(Task.FromResult((ContactType)null)); var handler = new ReservationCommandHandler(_dependencyResolverMock.Object); //Act var result = await handler.Handle(createReservationCommand, new CancellationToken()); //Assert Assert.False(result.Success); _contactRepositoryMock.Verify(x => x.GetByIdAsync(createReservationCommand.ContactId.Value), Times.Once); _reservationRepositoryMock.Verify(x => x.AddAsync(It.IsAny <Reservation>()), Times.Never); _reservationRepositoryMock.Verify(x => x.CommitAsync(), Times.Never); _mediatorHandler.Verify(x => x.NotifyDomainNotification(It.IsAny <DomainNotification>()), Times.Once); }
public void Init() { Faker faker = new Faker(); foo = faker.Create <Foo>(); }
public void Fill_With_Real_Name_Properties_Called_Name() { var worker = new Faker<Worker>().Create(); var firstName = worker.Name.Split(' ').First(); var lastName = worker.Name.Split(' ')[1]; Assert.IsTrue(NameGenerator.Names.Any(x => firstName.Contains(x))); Assert.IsTrue(NameGenerator.LastNames.Any(x => lastName.Contains(x))); }
public void Fill_With_Real_Name_Properties_Called_Name() { var worker = new Faker<Worker>().Create(); Assert.IsTrue(worker.Name.Split(' ').Count() > 1); Assert.IsTrue(!worker.Name.ToLower().Contains("worker")); }
public void Fill_With_Real_Email_Properties_Called_Email_Or_Mail() { var worker = new Faker<Worker>().Create(); Assert.IsTrue(worker.Mail.Contains("@")); Assert.IsTrue(worker.Email.Contains("@")); }
public void By_Default_Dont_Use_Numbers_In_Generated_Values_On_Create() { var worker = new Faker<Worker>().Create(); Assert.IsTrue(!worker.Name.Contains("1")); }
public DataSeed() { _categories = new List <Category> { new Category { Id = 0, Name = "Film" }, new Category { Id = 1, Name = "Concert" }, new Category { Id = 2, Name = "Party" } }; var cityId = 0; _cities = new Faker <City>() .RuleFor(c => c.Id, f => cityId++) .RuleFor(c => c.Name, f => f.Address.City()); var venueId = 0; _venues = new Faker <Venue>() .RuleFor(v => v.Id, f => venueId++) .RuleFor(v => v.Name, f => f.Name.JobArea()) .RuleFor(v => v.Address, f => f.Address.StreetAddress()) .RuleFor(x => x.City, () => _cities) .RuleFor(x => x.CityId, (f, v) => v.City.Id); var eventId = 0; _events = new Faker <Event>() .RuleFor(e => e.Id, f => eventId++) .RuleFor(e => e.CategoryId, f => f.Random.Number(0, 2)) .RuleFor(e => e.Name, f => f.Commerce.ProductName()) .RuleFor(x => x.Venue, () => _venues) .RuleFor(x => x.VenueId, (f, e) => e.Venue.Id); var userId = new[] { "123id", "id123", "id123id" }; _users = new Faker <User>() .RuleFor(u => u.Id, f => f.PickRandom(userId)) .RuleFor(u => u.Login, f => f.Internet.UserName()); var ticketId = 0; _tickets = new Faker <Ticket>() .RuleFor(t => t.Id, f => ticketId) .RuleFor(t => t.EventId, f => f.Random.Number(0, 2)) .RuleFor(t => t.Bought, f => false) .RuleFor(t => t.UserIdSeller, f => "123id") .RuleFor(t => t.User, f => GetUsers()[0]); var orderId = 0; _orders = new Faker <Order>() .RuleFor(o => o.Id, f => orderId++) .RuleFor(x => x.Ticket, () => _tickets) .RuleFor(x => x.TicketId, (f, o) => o.Ticket.Id) .RuleFor(o => o.UserIdBuyer, f => "id123") .RuleFor(o => o.User, f => GetUsers()[1]) .RuleFor(o => o.Status, f => Constants.Selling); _orders.Generate(); }
public void Seed() { var faker = new Faker(); Randomizer.Seed = new Random(840); var customers = new Faker <Customer>("de").Rules((f, c) => { c.Firstname = f.Name.FirstName(); c.Lastname = f.Name.LastName(); c.Email = f.Internet.Email(); c.Address = new Address { Street = f.Address.StreetAddress(), Zip = f.Random.Int(1000, 9999).ToString(), City = f.Address.City(), Country = f.Address.CountryCode() }; }) .Generate(10) .ToList(); Customers.AddRange(customers); SaveChanges(); var stores = new Faker <Store>("de").Rules((f, s) => { s.Name = f.Company.CompanyName(); }) .Generate(10) .GroupBy(s => s.Name).Select(g => g.First()) .Take(5) .ToList(); Stores.AddRange(stores); SaveChanges(); var productCategories = faker.Commerce.Categories(5) .Select(c => new ProductCategory { Name = c }) .ToList(); ProductCategories.AddRange(productCategories); SaveChanges(); var productCategoriesWithProducs = productCategories.Take(3).ToList(); var products = new Faker <Product>("de").Rules((f, p) => { p.Ean = f.Random.Int(100000, 999999); p.Name = f.Commerce.ProductName(); p.ProductCategory = f.Random.ListItem(productCategoriesWithProducs); }) .Generate(25) .ToList(); Products.AddRange(products); SaveChanges(); var productsWithOffers = products.Take(20).ToList(); var offers = new Faker <Offer>("de").Rules((f, o) => { o.Product = f.Random.ListItem(productsWithOffers); o.Store = f.Random.ListItem(stores); o.Price = Math.Round(f.Random.Decimal(0, 9999), 2); o.LastUpdate = new DateTime(2020, 1, 1).AddSeconds(f.Random.Int(0, 366 * 86400)); }) .Generate(40) .ToList(); Offers.AddRange(offers); SaveChanges(); var customersWithShoppingCard = customers.Take(5).ToList(); var shoppingCarts = new Faker <ShoppingCart>("de").Rules((f, s) => { s.Customer = f.Random.ListItem(customersWithShoppingCard); s.DateAdded = new DateTime(2020, 1, 1).AddSeconds(f.Random.Int(0, 366 * 86400)); s.Offer = f.Random.ListItem(offers); s.Quantity = f.Random.Int(1, 4); }) .Generate(20) .ToList(); ShoppingCarts.AddRange(shoppingCarts); SaveChanges(); }
public void Can_Create_Without_Using_IFaker_Interface() { var car = new Faker<Car>().Create(); Assert.IsNotNull(car); }
public static void SeedDB(ApplicationDbContext context, string adminId) { // Look for any db data. if (context.AppUsers.OfType <Student>().Any()) { return; // DB has been seeded } var testFakeStudents = new Faker <Student>() // .RuleFor(st => st.UserID, f => f.Random.Guid()) .RuleFor(st => st.Country, f => f.Address.Country()) .RuleFor(st => st.DateOfBirth, f => f.Person.DateOfBirth) .RuleFor(st => st.Email, f => f.Person.Email) .RuleFor(st => st.FirstName, f => f.Person.FirstName) .RuleFor(st => st.Gender, f => f.PickRandom <Gender>()) // .RuleFor(st => st.Image, f => f.Person.Avatar) .RuleFor(st => st.LastLogin, f => f.Date.Recent(10)) .RuleFor(st => st.LastName, f => f.Person.LastName) .RuleFor(st => st.PhoneNumber, f => f.Person.Phone) .RuleFor(st => st.RegNo, f => f.Internet.Random.AlphaNumeric(10)) .RuleFor(st => st.StateOfOrigin, f => f.Address.State()); var testFakeParent = new Faker <Parent>() // .RuleFor(st => st.UserID, f => f.Random.Guid()) .RuleFor(st => st.Country, f => f.Address.Country()) //.RuleFor(st => st.DateOfBirth, f => f.Person.DateOfBirth) .RuleFor(st => st.Email, f => f.Person.Email) .RuleFor(st => st.FirstName, f => f.Person.FirstName) .RuleFor(st => st.Gender, f => f.PickRandom <Gender>()) .RuleFor(st => st.LastLogin, f => f.Date.Recent(10)) .RuleFor(st => st.LastName, f => f.Person.LastName) .RuleFor(st => st.PhoneNumber, f => f.Person.Phone) .RuleFor(st => st.StateOfOrigin, f => f.Address.State()) .RuleFor(st => st.AltPhoneNumber, f => f.Person.Phone) .RuleFor(st => st.Address, f => f.Person.Address.Street) .RuleFor(st => st.Occupation, f => f.Person.Company.Name); var classess = new List <dClass>() { new dClass { ClassName = "Jss1" }, new dClass { ClassName = "Jss2" }, new dClass { ClassName = "Jss3" }, new dClass { ClassName = "Sss1" } }; var sections = new List <Section>() { new Section { dClassID = new Guid("186b00d8-3ffa-4467-4034-08d6deecacf1"), SectionName = "JSS1A" }, new Section { dClassID = new Guid("186b00d8-3ffa-4467-4034-08d6deecacf1"), SectionName = "JSS1B" }, new Section { dClassID = new Guid("186b00d8-3ffa-4467-4034-08d6deecacf1"), SectionName = "JSS1C" }, }; List <Parent> ptList = testFakeParent.Generate(20); List <Student> studs = testFakeStudents.Generate(20); context.dClasses.AddRange(classess); context.SaveChanges(); var jss1id = context.dClasses.First(x => x.ClassName == "Jss1").dClassID; foreach (var item in sections) { item.dClassID = jss1id; } context.Sections.AddRange(sections); context.AppUsers.AddRange(studs); context.SaveChanges(); }
public PagamentoTeste() { _faker = new Faker(); }
static void Main(string[] args) { ExcelPackage.LicenseContext = LicenseContext.Commercial; ExcelPackage.LicenseContext = LicenseContext.NonCommercial; var modelSales = new Faker <Sales>() .RuleFor(e => e.CustomerId, f => f.Random.Number(1, 99999)) .RuleFor(e => e.EmployeeId, f => f.Random.Number(1, 499)) .RuleFor(e => e.RegionFromId, f => f.Random.Number(1, 6)) .RuleFor(e => e.RegionToId, f => f.Random.Number(1, 6)) .RuleFor(e => e.CountryFromId, f => f.Random.Number(1, 39)) .RuleFor(e => e.CountryToId, f => f.Random.Number(1, 39)) .RuleFor(e => e.ProductId, f => f.Random.Number(1, 2915)) .RuleFor(e => e.CategoryId, f => f.Random.Number(1, 15)) .RuleFor(e => e.CompanyId, f => f.Random.Number(1, 499)) .RuleFor(e => e.Quantity, f => f.Random.Number(1, 10)) .RuleFor(e => e.Amount, f => f.Finance.Amount(1, 100)) .RuleFor(e => e.Time, f => f.Date.Past(5, DateTime.Now)); //var modelEmployee = new Faker<Employee>() // .RuleFor(e => e.FirstName, f => f.Person.FirstName) // .RuleFor(e => e.LastName, f => f.Person.LastName) // .RuleFor(e => e.Gender, f => f.Person.Gender.ToString()) // .RuleFor(e => e.Email, f => f.Person.Email) // .RuleFor(e => e.Phone, f => f.Phone.PhoneNumber("###-###-####")); //var modelCompany = new Faker<Company>() // .RuleFor(com => com.CompanyName, f => f.Company.CompanyName(1)) // .RuleFor(com => com.CompanySuffix, f => f.Company.CompanySuffix()) // .RuleFor(com => com.Bs, f => f.Company.Bs()) // .RuleFor(com => com.CatchPhrase, f => f.Company.CatchPhrase()); //var modelCustomer = new Faker<Customer>() // .RuleFor(c => c.FirstName, f => f.Person.FirstName) // .RuleFor(c => c.LastName, f => f.Person.LastName) // .RuleFor(c => c.Gender, f => f.Person.Gender.ToString()) // .RuleFor(c => c.Email, f => f.Person.Email) // .RuleFor(c => c.JobTitle, f => f.Name.JobTitle()) // .RuleFor(c => c.JobType, f => f.Name.JobType()) // .RuleFor(c => c.IpAddress, f => f.Internet.Ip()) // .RuleFor(c => c.Address, f => f.Address.StreetAddress()); //var modelProduct = new Faker<Product>() // .RuleFor(p => p.Ean, f => f.Commerce.Ean13()) // .RuleFor(p => p.Price, f => f.Commerce.Price()) // .RuleFor(p => p.CategoryName, f => f.Commerce.Categories(1)) // .RuleFor(p => p.ProductName, f => f.Commerce.Product()); //var modelFinance = new Faker<Finance>() // .RuleFor(f => f.Account, f => f.Finance.Account(10)) // .RuleFor(f => f.AccountName, f => f.Finance.AccountName()) // //.RuleFor(f => f.Amount, f => f.Finance.Amount()) // .RuleFor(f => f.TransactionType, f => f.Finance.TransactionType()) // .RuleFor(f => f.CreditCardCvv, f => f.Finance.CreditCardCvv()) // .RuleFor(f => f.CreditCardNumber, f => f.Finance.CreditCardNumber()); ExcelPackage excel = new ExcelPackage(); var workSheet = excel.Workbook.Worksheets.Add("Sheet1"); //customer //workSheet.Cells[1, 1].Value = "ID"; //workSheet.Cells[1, 2].Value = "FirstName"; //workSheet.Cells[1, 3].Value = "LastName"; //workSheet.Cells[1, 4].Value = "Gender"; //workSheet.Cells[1, 5].Value = "Email"; //workSheet.Cells[1, 6].Value = "JobTitle"; //workSheet.Cells[1, 7].Value = "JobType"; //workSheet.Cells[1, 8].Value = "IpAddress"; //workSheet.Cells[1, 9].Value = "Address"; //finance //workSheet.Cells[1, 1].Value = "ID"; //workSheet.Cells[1, 2].Value = "Account"; //workSheet.Cells[1, 3].Value = "AccountName"; ////workSheet.Cells[1, 4].Value = "Amount"; //workSheet.Cells[1, 4].Value = "TransactionType"; //workSheet.Cells[1, 5].Value = "CreditCardCvv"; //workSheet.Cells[1, 6].Value = "CreditCardNumber"; ////company //workSheet.Cells[1, 1].Value = "ID"; //workSheet.Cells[1, 2].Value = "CompanySuffix"; //workSheet.Cells[1, 3].Value = "CompanyName"; //workSheet.Cells[1, 4].Value = "Bs"; //workSheet.Cells[1, 5].Value = "CatchPhrase"; ////sales workSheet.Cells[1, 1].Value = "ID"; workSheet.Cells[1, 2].Value = "ID CUSTOMER"; workSheet.Cells[1, 3].Value = "ID EMPLOYEE"; workSheet.Cells[1, 4].Value = "ID REGIONFROM"; workSheet.Cells[1, 5].Value = "ID REGIONTO"; workSheet.Cells[1, 6].Value = "ID COUNTRYFROM"; workSheet.Cells[1, 7].Value = "ID COUNTRYTO"; workSheet.Cells[1, 8].Value = "ID FINANCE"; workSheet.Cells[1, 9].Value = "ID PRODUCT"; workSheet.Cells[1, 10].Value = "ID CATEGORY"; workSheet.Cells[1, 11].Value = "ID COMPANY"; workSheet.Cells[1, 12].Value = "QUANTITY"; workSheet.Cells[1, 13].Value = "AMOUNT"; workSheet.Cells[1, 14].Value = "TIME"; for (int i = 2; i < 1000001; i++) { //var myModelCustomer = modelFinance.Generate(); //var myModel = modelCompany.Generate(); //var myModelCustomer = modelCustomer.Generate(); //var myModelSales = modelSales.Generate(); //var myModel = modelEmployee.Generate(); //var myModelEmployee = modelEmployee.Generate(); var myModelSales = modelSales.Generate(); //sales workSheet.Cells[i, 1].Value = i - 1; workSheet.Cells[i, 2].Value = myModelSales.CustomerId; workSheet.Cells[i, 3].Value = myModelSales.EmployeeId; workSheet.Cells[i, 4].Value = myModelSales.CountryFromId; workSheet.Cells[i, 5].Value = myModelSales.RegionToId; workSheet.Cells[i, 6].Value = myModelSales.CountryFromId; workSheet.Cells[i, 7].Value = myModelSales.CountryToId; workSheet.Cells[i, 8].Value = myModelSales.CustomerId; workSheet.Cells[i, 9].Value = myModelSales.ProductId; workSheet.Cells[i, 10].Value = myModelSales.CategoryId; workSheet.Cells[i, 11].Value = myModelSales.CompanyId; workSheet.Cells[i, 12].Value = myModelSales.Quantity; workSheet.Cells[i, 13].Value = myModelSales.Amount; workSheet.Cells[i, 14].Value = myModelSales.Time; ////employee //workSheet.Cells[i, 1].Value = i - 1; //workSheet.Cells[i, 2].Value = myModelEmployee.FirstName; //workSheet.Cells[i, 3].Value = myModelEmployee.LastName; //workSheet.Cells[i, 4].Value = myModelEmployee.Gender; //workSheet.Cells[i, 5].Value = myModelEmployee.Email; //workSheet.Cells[i, 6].Value = myModelEmployee.Phone; ////company //workSheet.Cells[i, 1].Value = i - 1; //workSheet.Cells[i, 2].Value = myModelCompany.CompanySuffix; //workSheet.Cells[i, 3].Value = myModelCompany.CompanyName; //workSheet.Cells[i, 4].Value = myModelCompany.Bs; //workSheet.Cells[i, 5].Value = myModelCompany.CatchPhrase; ////finance //workSheet.Cells[i, 1].Value = i - 1; //workSheet.Cells[i, 2].Value = myModelFinance.Account; //workSheet.Cells[i, 3].Value = myModelFinance.AccountName; ////workSheet.Cells[i, 4].Value = myModelFinance.Amount; //workSheet.Cells[i, 4].Value = myModelFinance.TransactionType; //workSheet.Cells[i, 5].Value = myModelFinance.CreditCardCvv; //workSheet.Cells[i, 6].Value = myModelFinance.CreditCardNumber; ////customer //workSheet.Cells[i, 1].Value = i - 1; //workSheet.Cells[i, 2].Value = myModelCustomer.FirstName; //workSheet.Cells[i, 3].Value = myModelCustomer.LastName; //workSheet.Cells[i, 4].Value = myModelCustomer.Gender; //workSheet.Cells[i, 5].Value = myModelCustomer.Email; //workSheet.Cells[i, 6].Value = myModelCustomer.JobTitle; //workSheet.Cells[i, 7].Value = myModelCustomer.JobType; //workSheet.Cells[i, 8].Value = myModelCustomer.IpAddress; //workSheet.Cells[i, 9].Value = myModelCustomer.Address; Console.WriteLine(i); } string pStrPath = "D:\\sales.xlsx"; if (File.Exists(pStrPath)) { File.Delete(pStrPath); } FileStream fileStream = File.Create(pStrPath); fileStream.Close(); File.WriteAllBytes(pStrPath, excel.GetAsByteArray()); excel.Dispose(); }
public static Faker <T> WithRecord <T>(this Faker <T> faker) where T : class { faker.CustomInstantiator(_ => FormatterServices.GetUninitializedObject(typeof(T)) as T ?? throw new Exception("Unable to match type")); return(faker); }
public async void CreateReservation_ContactDoesNotExist_True() { //arrange var contact = ContactFaker.GetContactOk(); var contactType = ContactTypeFaker.GetContactTypeOk(); var faker = new Faker(); var message = faker.Lorem.Paragraph(); var createReservationCommand = new CreateReservationCommand( contactId: contact.Id, contactName: contact.Name, contactPhone: contact.PhoneNumber, contactBirthdate: contact.BirthDate, contactTypeId: contactType.Id, message: message ); _dependencyResolverMock .Setup(x => x.Resolve <IReservationRepository>()) .Returns(_reservationRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactRepository>()) .Returns(_contactRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactTypeRepository>()) .Returns(_contactTypeRepositoryMock.Object); _contactRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactId.Value)) .Returns(Task.FromResult((Contact)null)); _contactTypeRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactTypeId)) .Returns(Task.FromResult(contactType)); _reservationRepositoryMock.Setup(x => x.CommitAsync()) .Returns(Task.FromResult(CommitResponse.Ok())); _contactRepositoryMock.Setup(x => x.CommitAsync()) .Returns(Task.FromResult(CommitResponse.Ok())); var handler = new ReservationCommandHandler(_dependencyResolverMock.Object); //Act var result = await handler.Handle(createReservationCommand, new CancellationToken()); //Assert Assert.True(result.Success); _contactRepositoryMock.Verify(x => x.GetByIdAsync(createReservationCommand.ContactId.Value), Times.Once); _reservationRepositoryMock.Verify(x => x.AddAsync(It.IsAny <Reservation>()), Times.Once); _reservationRepositoryMock.Verify(x => x.CommitAsync(), Times.Once); _contactRepositoryMock.Verify(x => x.CommitAsync(), Times.Once); _contactRepositoryMock.Verify(x => x.AddAsync(It.IsAny <Contact>()), Times.Once); }
public void When_Create_First_Level_Etity_Must_Create_Second_And_Third_Level_Entities() { var firstLevel = new Faker<FirtLevel>().Create(); Assert.IsNotNull(firstLevel); Assert.IsNotNull(firstLevel.SecondLevel); Assert.IsNotNull(firstLevel.SecondLevel.ThirdLevel); }
public static async Task Seed(IMessageHandlerContext ctx) { var roleIds = new Dictionary <string, Guid>(); var saga = ctx.Saga(Guid.NewGuid()); // define all used roles foreach (var role in Users.SelectMany(x => x.Roles).Distinct()) { var id = Guid.NewGuid(); roleIds[role] = id; saga.Command(new eShop.Identity.Role.Commands.Define { RoleId = id, Name = role }); } // define all defined users foreach (var user in Users) { saga.Command(new eShop.Identity.User.Commands.Register { GivenName = user.GivenName, UserName = user.UserName, Password = user.Password }); foreach (var role in user.Roles) { saga.Command(new eShop.Identity.User.Entities.Role.Commands.Assign { UserName = user.UserName, RoleId = roleIds[role] }); } } await saga.Start().ConfigureAwait(false); // Define some random users var bogus = new Faker <Types.User>() .StrictMode(false) .Rules((f, o) => { o.UserName = f.Internet.UserName(); o.Password = f.Internet.Password(); o.GivenName = f.Name.FindName(withPrefix: false, withSuffix: false); o.Roles = new[] { "customer" }; }); var users = bogus.Generate(20); var saga2 = ctx.Saga(Guid.NewGuid()); foreach (var user in users) { saga2.Command(new eShop.Identity.User.Commands.Register { GivenName = user.GivenName, UserName = user.UserName, Password = user.Password }); foreach (var role in user.Roles) { saga2.Command(new eShop.Identity.User.Entities.Role.Commands.Assign { UserName = user.UserName, RoleId = roleIds[role] }); } } await saga2.Start().ConfigureAwait(false); Users = Users.Concat(users).ToArray(); }
public TransformerNullToSetTest() { var faker = new Faker(); _value = faker.Company.CompanyName(); }
static BuildLogProcessorTests() { Faker = new Faker(); }
private static IMultiPointGeoShape GenerateRandomMultiPoint(Faker p) => new MultiPointGeoShape(GenerateGeoCoordinates(p, p.Random.Int(1, 5)));
public async Task Test_CanEnqueue_NewTask_ParallelProducers(int nProducers) { Faker faker = new Faker(); CountdownEvent notificationWaitHandle = new CountdownEvent(nProducers); DateTimeOffset postedAt = mDataSource.LastPostedAt .AddTicks(1); PostgreSqlTaskQueueProducer taskQueueProducer = CreateTaskQueueProducer(() => postedAt); EventHandler <ClearForDequeueEventArgs> handleClearForDequeue = (s, e) => { if (e.Reason == ClearForDequeReason.NewTaskPostedNotificationReceived) { notificationWaitHandle.Signal(); } }; Task[] producers = new Task[nProducers]; using (PostgreSqlTaskQueueConsumer taskQueueConsumer = CreateTaskQueueConsumer(() => postedAt)) { taskQueueConsumer.ClearForDequeue += handleClearForDequeue; await taskQueueConsumer .StartReceivingNewTaskUpdatesAsync(); Assert.IsTrue(taskQueueConsumer .IsReceivingNewTaskUpdates); for (int i = 0; i < nProducers; i++) { producers[i] = Task.Run(async() => { //Enqueue task and check result IQueuedTask queuedTask = await taskQueueProducer .EnqueueAsync(payload: new SampleTaskPayload(100), source: nameof(Test_CanEnqueue_NewTask_ParallelProducers), priority: faker.Random.Int(1, 100)); Assert.NotNull(queuedTask); await Assert_ResultAddedOrUpdatedCorrectly(queuedTask); }); } notificationWaitHandle.Wait(); await taskQueueConsumer .StopReceivingNewTaskUpdatesAsync(); Assert.IsFalse(taskQueueConsumer .IsReceivingNewTaskUpdates); taskQueueConsumer.ClearForDequeue -= handleClearForDequeue; } }
private static IPolygonGeoShape GeneratePolygon(Faker p) => new PolygonGeoShape(new List <IEnumerable <GeoCoordinate> > { GeneratePolygonCoordinates(p, GenerateGeoCoordinate(p)) });
public void SetUp() { _gen = new Faker(); }
private static GeoCoordinate GenerateGeoCoordinate(Faker p) => new GeoCoordinate(p.Address.Latitude(), p.Address.Longitude());
public void Setup() { _config = new FakerConfig(); _faker = new Faker(_config); }
public static string RandomInformationText(int numWords = 10) { var faker = new Faker(); return(string.Join(" ", faker.Lorem.Words(numWords))); }
public async Task LogoutNotExistedTest() { var faker = new Faker(); var account = Cluster.GrainFactory.GetGrain <IAccount>(faker.Person.UserName); await account.Logout(); }
public AutorTeste() { _faker = FakerBuilder.Novo().Build(); }
static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .MinimumLevel.Debug() .WriteTo.Console( outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); HBaseConfig.Instance.ServiceProvider = new ServiceCollection() .AddLogging(cfg => cfg.AddSerilog(Log.Logger)) .BuildServiceProvider(); StudentFaker = new Faker <Student>() .StrictMode(true) .RuleFor(t => t.Name, f => f.Name.FindName()) .RuleFor(t => t.Address, f => f.Address.FullAddress()) .RuleFor(t => t.Age, f => f.Random.Int(1, 100)) .RuleFor(t => t.Create, f => f.Date.Recent()) .RuleFor(t => t.Modify, f => f.Date.Soon().OrNull(f)) .RuleFor(t => t.Score, f => f.Random.Float(0, 5)) .RuleFor(t => t.IsMarried, f => f.Random.Bool().OrNull(f)) .RuleFor(t => t.Courses, f => Enumerable.Range(0, f.Random.Int(0, 10)).Select(i => f.Company.CompanyName()).ToList().OrNull(f)) ; Values = new Dictionary <string, Dictionary <string, byte[]> > { { ConstString.DefaultFamily, new Dictionary <string, byte[]> { { "key", "value".ToUtf8Bytes() } } } }; var client = await new StandardClient(ZkQuorum).Build(); if (client == null) { return; } var admin = await new AdminClient(ZkQuorum).Build(); if (admin == null) { return; } var ado = new AdminClientOperation(admin); await ado.ExecAll(); var sth = new Stopwatch(); var sto = new SingleThreadOperation(client); var create = new CreateTableCall(Table.ToUtf8Bytes(), new[] { new ColumnFamily(ConstString.DefaultFamily), new ColumnFamily("special") }) { SplitKeys = Enumerable.Range('1', 9).Concat(Enumerable.Range('a', 6)).Select(t => $"{(char)t}") .ToArray() }; var tables = await admin.ListTableNames(new ListTableNamesCall { Regex = Table }); if (true != tables?.Any()) { await admin.CreateTable(create); } await sto.ExecCheckAndPut(); const int putCount = 10000; var mto = new MultiThreadOperation(client); sth.Restart(); await mto.ExecPut(putCount); Log.Logger.Information($"exec multi thread put ,count: {putCount},take :{sth.Elapsed}"); sth.Restart(); await sto.ExecPut(putCount / 100); Log.Logger.Information($"exec single thread put ,count: {putCount / 100},take :{sth.Elapsed}"); await sto.ExecAppend(); await sto.ExecIncrement(); sth.Restart(); await sto.ExecScan(); Log.Logger.Information($"exec scan,take :{sth.Elapsed}"); await sto.ExecScanAndDelete(); Console.WriteLine($"Do you want to delete table {Table}?(y)"); if (Console.ReadKey().Key == ConsoleKey.Y) { await admin.DisableTable(new DisableTableCall(Table.ToUtf8Bytes())); var dt = await admin.DeleteTable(new DeleteTableCall(Table.ToUtf8Bytes())); Log.Logger.Information($"del table:{Table},result:{dt}"); } }
public void Fill_With_Real_Login_Properties_Called_Login() { var worker = new Faker<Worker>().Create(); Assert.IsTrue(LoginGenerator.Logins.Any(x => worker.Login.Contains(x))); }
private static IPointGeoShape GenerateRandomPoint(Faker p) => new PointGeoShape(GenerateGeoCoordinate(p));
public void TestIgnore() { var faker = new Faker<Order>() .StrictMode(true) .Ignore(o => o.Item) .RuleFor(o => o.OrderId, f => 3343) .RuleFor(o => o.Quantity, f => f.Random.Number(3)); var fake = faker.Generate(); fake.Dump(); fake.Item.Should().BeNull(); }
private static ILineStringGeoShape GenerateLineString(Faker p) => new LineStringGeoShape(GenerateGeoCoordinates(p, 3));
public void Handlebar() { var faker = new Faker(); var randomName = faker.Parse("{{name.lastName}}, {{name.firstName}} {{name.suffix}}"); randomName.Dump(); }
private static IMultiPolygonGeoShape GenerateMultiPolygon(Faker p) => new MultiPolygonGeoShape( new List <IEnumerable <IEnumerable <GeoCoordinate> > > { new[] { GeneratePolygonCoordinates(p, GenerateGeoCoordinate(p)) } });
public void TestAPIDesign() { //Set the randomzier seed if you wish to generate repeatable data sets. Randomizer.Seed = new Random(3897234); var fruit = new[] { "apple", "banana", "orange", "strawberry", "kiwi" }; var orderIds = 0; var testOrders = new Faker<Order>() //Ensure all properties have rules. By default, StrictMode is false //Set a global policy by using Faker.DefaultStrictMode if you prefer. .StrictMode(true) //OrderId is deterministic .RuleFor(o => o.OrderId, f => orderIds++) //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)); var userIds = 0; var testUsers = new Faker<User>() //Optional: Call for objects that have complex initialization .CustomInstantiator(f => new User(userIds++, f.Random.Replace("###-##-####"))) //Basic rules using built-in generators .RuleFor(u => u.FirstName, f => f.Name.FirstName()) .RuleFor(u => u.LastName, f => f.Name.LastName()) .RuleFor(u => u.Avatar, f => f.Internet.Avatar()) .RuleFor(u => u.UserName, (f, u) => f.Internet.UserName(u.FirstName, u.LastName)) .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName)) .RuleFor(u => u.SomethingUnique, f => $"Value {f.UniqueIndex}") .RuleFor(u => u.SomeGuid, Guid.NewGuid) //Use an enum outside scope. .RuleFor(u => u.Gender, f => f.PickRandom<Gender>()) //Use a method outside scope. .RuleFor(u => u.CartId, f => Guid.NewGuid()) //Compound property with context, use the first/last name properties .RuleFor(u => u.FullName, (f, u) => u.FirstName + " " + u.LastName) //And composability of a complex collection. .RuleFor(u => u.Orders, f => testOrders.Generate(3).ToList()) //After all rules are applied finish with the following action .FinishWith((f, u) => { Console.WriteLine("User Created! Name={0}", u.FullName); }); //RunAfter //InvokeAfterRules //FinalizeWith //AfterRulesInvoke //PostProcess //InvokeAfterAll //BeforeReturn //FinallyInvoke //FinishWith var user = testUsers.Generate(3); user.Dump(); }
public ChallengeDataSet(Faker faker) { Faker = faker; }
public static T GetRandomItem <T>(IEnumerable <T> items) { var faker = new Faker(); return(faker.PickRandom(items)); }