Last active
September 23, 2015 04:10
-
-
Save pwelter34/beba8087afeb6df6139e to your computer and use it in GitHub Desktop.
Fluent interface for data generator prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestCase | |
{ | |
public void Configure() | |
{ | |
DataGenerator.Configue(c => c | |
.Entity<User>(m => | |
.AutoMap() | |
.Map(e => { | |
e.Property(p => p.FirstName).DataSource<FirstNameSource>(); | |
e.Property(p => p.LastName).DataSource<LastNameSource>(); | |
e.Property(p => p.Address1).DataSource<StreetSource>(); | |
e.Property(p => p.City).DataSource<CitySource>(); | |
e.Property(p => p.State).DataSource<StateSource>(); | |
e.Property(p => p.Zip).DataSource<PostalSource>(); | |
// metadata | |
e.Property(p => p.Note).DataSource<LoremIpsumSource>().MinLength(5).MaxLength(100); | |
e.Property(p => p.Password).DataSource<RandomSource>().Length(5); | |
// array of values | |
e.Property(p => p.Status).DataSource(new [] { Status.New, Status.Verified }); | |
// delegate source | |
e.Property(p => p.Created).DataSource(c => DateTime.Now); | |
// don't generate | |
e.Property(p => p.Budget).Ignore(); | |
// static value | |
e.Property(p => p.IsActive).Value(true); | |
// delegate value | |
e.Property(p => p.IsActive).Value(c => false); | |
}) | |
) | |
); | |
var user = DataGenerator.Single<User>(); | |
var userList = DataGenerator.List<User>(c => c | |
.Count(50) | |
.Map(e => { | |
// override mapped value | |
e.Property(p => p.IsActive).Value(false); | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment