public MovingAppSeedDataFixture() { //Arrange var optionsBuilder = new DbContextOptionsBuilder <MovingAppContext>() .UseInMemoryDatabase("MovingAppTestDb" + new Guid()) .Options; MovingAppContext = new MovingAppContext(optionsBuilder); #region snippet1 MovingAppContext.Task.AddRange( new MovingTask { ID = 1, Title = "Hoover", DueDate = DateTime.Parse("2020-08-25"), Status = (int)StatusTypes.Incomplete }, new MovingTask { ID = 2, Title = "Clean walls", DueDate = DateTime.Parse("2020-08-25"), Status = (int)StatusTypes.Incomplete }, new MovingTask { ID = 3, Title = "Pack Toys", DueDate = DateTime.Parse("2020-08-25"), Status = (int)StatusTypes.Incomplete } ); MovingAppContext.SaveChanges(); #endregion }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MovingAppContext( serviceProvider.GetRequiredService < DbContextOptions <MovingAppContext> >())) { context.Database.EnsureCreated(); if (context.Task.Any()) { return; //DB has already been seeded } context.Task.AddRange( new MovingTask { Title = "Hoover", DueDate = DateTime.Parse("2020-08-25"), Status = (int)StatusTypes.Incomplete }, new MovingTask { Title = "Clean walls", DueDate = DateTime.Parse("2020-08-25"), Status = (int)StatusTypes.Incomplete }, new MovingTask { Title = "Pack Toys", DueDate = DateTime.Parse("2020-08-25"), Status = (int)StatusTypes.Incomplete } ); context.SaveChanges(); } }
public IndexModel(ILogger <IndexModel> logger, MovingAppContext db) { _logger = logger; _db = db; }