public override DataAnnotationContext CreateContext(SqlCeTestStore testStore) { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.EnableSensitiveDataLogging().UseSqlCe(testStore.Connection); var context = new DataAnnotationContext(_serviceProvider, optionsBuilder.Options); context.Database.UseTransaction(testStore.Transaction); return(context); }
public override SqlCeTestStore CreateTestStore() { return(SqlCeTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseSqlCe(_connectionString); using (var context = new DataAnnotationContext(_serviceProvider, optionsBuilder.Options)) { // TODO: Delete DB if model changed context.Database.EnsureDeleted(); if (context.Database.EnsureCreated()) { DataAnnotationModelInitializer.Seed(context); } TestSqlLoggerFactory.SqlStatements.Clear(); } })); }
public static void Seed(DataAnnotationContext context) { context.Ones.Add(new One { RequiredColumn = "First", RowVersion = new Guid("00000001-0000-0000-0000-000000000001") }); context.Ones.Add(new One { RequiredColumn = "Second", RowVersion = new Guid("00000001-0000-0000-0000-000000000001") }); context.Twos.Add(new Two { Data = "First" }); context.Twos.Add(new Two { Data = "Second" }); context.Books.Add(new Book { Id = "Book1" }); context.SaveChanges(); }