I've created a simpel model like this:
using System;
using System.Collections.Generic;
namespace Resa.Models
{
public enum GenderType : byte {
Unknown = 0,
Male = 1,
Female = 2,
NotApplicable = 9
}
public class Profile
{
public Int64 Id { get; set; }
public string FirstName { get; set; }
public string SurName { get; set; }
public GenderType Gender { get; set; } // temporary
public Nullable<DateTime> DayOfBirth { get; set; }
public bool Verified { get; set; }
public string Picture { get; set; }
public DateTime CreatedAt { get; set; }
public Nullable<DateTime> UpdatedAt { get; set; }
public Nullable<DateTime> DeletedAt { get; set; }
public List<Listing> Listings { get; set; }
public List<Address> Addresses { get; set; }
}
}
So I started mapping my model in a DbContext. But now I want to seed it with Bogus and Faker. Gendertype is an Enum and i'd like to generate 1 out of those 3.
This is my code so far for the seeding:
if(!context.Profiles.Any())
{
// Dates to generate random dates
DateTime start = new DateTime(1900, 1, 1);
DateTime end = new DateTime(1998, 1, 1);
var faker = new Bogus.DataSets.Name();
var profileSkeleton = new Faker<Profile>()
.RuleFor(p => p.FirstName, f => faker.FirstName())
.RuleFor(p => p.SurName, f => faker.LastName())
//.RuleFor(p => p.Gender , )
.RuleFor(p => p.DayOfBirth, f => f.Date.Between(start, end))
.RuleFor(p => p.Verified, f => true)
.RuleFor(p => p.Picture, f => f.Image.People());
var profiles = new List<Profile>();
for(var i = 0; i < 50; i++)
{
var profile = profileSkeleton.Generate();
profiles.Add(profile);
}
context.Profiles.AddRange(profiles);
await context.SaveChangesAsync();
}
So the question is: how do I pick a random enum without violating the gendertype?