

How to generate Random words, Numbers and Alphanumeric values Generate() method will return a list of 100 AccountHolders objects. Var AccountHolders = dataFaker.Generate(100) : Once we have set all the rules, this line calls Generate() method with the number of records to generate. RuleFor(x => x.City, faker => ) : Here I am generating city names for test data. Here I am generating the date between the range. RuleFor(x => x.OpeningDate, faker => ((-10), DateTime.Today)) : This line generates Dates for account opening date. Finance class also provides some properties like Vehicle. RuleFor(x => x.AccountNumber, faker => ()) : Here I am using the Finance class (Similar to the Person class earlier) to get the dummy account number. RuleFor(x => x.Email, faker => ) : Generates email from the Person class. Person class also has other options, like FirstName, LastName, Website, Gender, UserName, Avatar, Email, Phone, Company, and DateOfBirth.
#CREATE MOCK DATA ONLINE FULL#
RuleFor(x => x.Name, faker => ) : This line generates the full name of a person. RuleFor(x => x.Id, faker => faker.IndexFaker) : IndexFaker property of Faker (non-generic) class generates int values here, it will generate values 0,1,2 and so on. Var dataFaker = new Faker() – Creates an object of Faker class with AccountHolder as generic parameter. We use the RuleFor method to set the rules for a property. You can set rules for each property in your class. Here I am supplying AccountHolder class as a generic parameter. Faker is a generic class that takes class as a generic parameter for which you want to generate the data. In the above example, I am creating an object of Bogus.Faker class. Var AccountHolders = dataFaker.Generate(100) RuleFor(x => x.Id, faker => faker.IndexFaker)

Don’t forget to add the Bogus nugget package before you try this example. The AccountHolder class has int, string, and Date properties. We want to generate some records for AccountHolder class. In C#, you can use the NuGet package to generate test data. Most developers do not like to write this data generation code where you create objects manually. Sometimes Developers may need to create mock data, and there can be many reasons for generating Mock data. We often need some test data for unit tests or dev testing, and developers require this test data to check the code’s functionality.
