In using .net Bogus github repository for filling up a database, I would like to both fill a field randomly with something like:
{ "Mother", "Sister", "Brother", "Father", "Uncle","Niece","Nephew","Cousin"}
But also randomly leave occasional nulls too?
I have tried chaining them together but it doesn't seem like there is a syntax that the compiler likes.
.RuleFor(u => u.Gender, f => f.PickRandom<Gender>().ToString())
.RuleFor(u => u.BirthDate, f => f.Date.PastOffset(60,
DateTime.Now.AddYears(-18)).Date.ToShortDateString())
.RuleFor(u => u.FirstName, (f, u) => f.Name.FirstName(ReturnGenderType(u.Gender)))
.RuleFor(u => u.MiddleName, (f, u) => f.Name.FirstName(ReturnGenderType(u.Gender)))
.RuleFor(u => u.LastName, (f, u) => f.Name.LastName(ReturnGenderType(u.Gender)))
.RuleFor(u => u.Salutation, (f, u) => f.Name.Prefix(ReturnGenderType(u.Gender)))
private static Bogus.DataSets.Name.Gender ReturnGenderType(string genderString)
{
if (genderString == "Male")
{
return Bogus.DataSets.Name.Gender.Male;
}
else
{
return Bogus.DataSets.Name.Gender.Female;
}
}
In this example it looks like it might have to be an extension as the Gender type feeds back later into the sane but random names later.