Created
June 14, 2018 10:59
-
-
Save danielplawgo/d0cc33f21e53033a649f586472a31ade to your computer and use it in GitHub Desktop.
Nbuilder oraz Faker.NET
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
protected override void Seed(NugetForAspMvc.Models.DataContext context) | |
{ | |
if (context.Users.Any() == false) | |
{ | |
var users = Builder<User>.CreateListOfSize(20) | |
.All() | |
.With(u => u.Email = Faker.Internet.Email()) | |
.With(u => u.FirstName = Faker.Name.First()) | |
.With(u => u.LastName = Faker.Name.Last()) | |
.With(u => u.UserName = Faker.Internet.UserName()) | |
.Build(); | |
foreach (var user in users) | |
{ | |
context.Users.AddOrUpdate(u => u.Email, user); | |
} | |
} | |
} |
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
var users = Builder<User>.CreateListOfSize(10).Build(); |
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
var firstName = Faker.Name.First() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment