Created
November 2, 2014 23:18
-
-
Save ChuckBryan/9b4acfa72aa14c4b03ec to your computer and use it in GitHub Desktop.
This is an example of the SeedData Class that I am using with SpecsFor.MVC.
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
using System; | |
using System.Data.Entity; | |
using Microsoft.AspNet.Identity; | |
using SpecsFor.Mvc; | |
using SpecsForDemo.Web.Models; | |
namespace SpecsForDemo.IntegrationSpecs | |
{ | |
public class SeedDataConfig : SpecsForMvcConfig | |
{ | |
public SeedDataConfig() | |
{ | |
BeforeEachTest(() => | |
{ | |
Database.SetInitializer(new TestDbInitializer()); | |
ApplicationDbContext context = ApplicationDbContext.Create(); | |
context.Database.Initialize(true); | |
}); | |
} | |
public class TestDbInitializer : DropCreateDatabaseAlways<ApplicationDbContext> | |
{ | |
protected override void Seed(ApplicationDbContext context) | |
{ | |
var user = new ApplicationUser | |
{ | |
UserName = "real@user.com", | |
Email = "real@user.com", | |
LockoutEnabled = true, | |
SecurityStamp = Guid.NewGuid().ToString(), | |
PasswordHash = new PasswordHasher().HashPassword("P@ssw0rd1") | |
}; | |
context.Users.Add(user); | |
context.SaveChanges(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment