Created
November 2, 2014 13:42
-
-
Save ChuckBryan/7266adbbfd1f9aa21c19 to your computer and use it in GitHub Desktop.
SpecsFor SeedDataConfig with Entity Framework
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 Microsoft.AspNet.Identity.EntityFramework; | |
using SpecsFor.Mvc; | |
using SpecsForDemo.Web.Models; | |
namespace SpecsForDemo.IntegrationSpecs | |
{ | |
public class SeedDataConfig : SpecsForMvcConfig | |
{ | |
public SeedDataConfig() | |
{ | |
BeforeEachTest(() => | |
{ | |
Database.SetInitializer(new TestDbInitializer()); | |
var context = new ApplicationDbContext(); | |
context.Database.Initialize(true); | |
}); | |
} | |
} | |
public class TestDbInitializer : DropCreateDatabaseAlways<ApplicationDbContext> | |
{ | |
protected override void Seed(ApplicationDbContext context) | |
{ | |
var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context)); | |
var user = new ApplicationUser | |
{ | |
UserName = "real@user.com", | |
Email = "real@user.com", | |
}; | |
IdentityResult ir = um.Create(user, "P@ssw0rd1"); | |
Console.WriteLine(ir.Succeeded); | |
context.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment