public LoginServiceTest() { var dbOptions = new DbContextOptionsBuilder <MvcTodoContext>().UseInMemoryDatabase("test").Options; var dbContext = new MvcTodoContext(dbOptions); var repo = new MvcTodo.Repo.UserRepo(dbContext); dbContext.Users.RemoveRange(dbContext.Users); dbContext.Users.Add(new User() { Username = "******", Password = PasswordUtils.Hashpassword("test") }); dbContext.SaveChanges(); this.service = new MvcTodo.Services.AuthService(repo); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MvcTodoContext( serviceProvider.GetRequiredService < DbContextOptions <MvcTodoContext> >())) { // Look for any movies. if (context.TodoList.Any()) { return; // DB has been seeded } context.TodoList.AddRange( new TodoItem { Title = "When Harry Met Sally", IsDone = true }, new TodoItem { Title = "Ghostbusters ", IsDone = false }, new TodoItem { Title = "Ghostbusters 2", IsDone = true }, new TodoItem { Title = "Rio Bravo", IsDone = false } ); context.SaveChanges(); } }