Skip to content

Instantly share code, notes, and snippets.

@ChuckBryan
Created November 2, 2014 23:18
Show Gist options
  • Save ChuckBryan/9b4acfa72aa14c4b03ec to your computer and use it in GitHub Desktop.
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.
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