public override InMemoryTestStore CreateTestStore() => InMemoryTestStore.GetOrCreateShared(DatabaseName, () => { using (var context = new DataAnnotationContext(_options)) { DataAnnotationModelInitializer.Seed(context); } });
public override SqliteTestStore CreateTestStore() => SqliteTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder(_options) .UseSqlite(_connectionString); using (var context = new DataAnnotationContext(optionsBuilder.Options)) { context.Database.EnsureClean(); DataAnnotationModelInitializer.Seed(context); } });
public override SqlServerTestStore CreateTestStore() => SqlServerTestStore.GetOrCreateShared(DatabaseName, () => { var options = new DbContextOptionsBuilder(_options) .UseSqlServer(_connectionString, b => b.ApplyConfiguration()) .Options; using (var context = new DataAnnotationContext(options)) { context.Database.EnsureCreated(); DataAnnotationModelInitializer.Seed(context); } });
public override InMemoryTestStore CreateTestStore() => InMemoryTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder() .UseInMemoryDatabase() .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning)) .UseInternalServiceProvider(_serviceProvider); using (var context = new DataAnnotationContext(optionsBuilder.Options)) { DataAnnotationModelInitializer.Seed(context); } });
public override SqlServerTestStore CreateTestStore() => SqlServerTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder() .UseSqlServer(_connectionString, b => b.ApplyConfiguration()) .UseInternalServiceProvider(_serviceProvider); using (var context = new DataAnnotationContext(optionsBuilder.Options)) { context.Database.EnsureCreated(); DataAnnotationModelInitializer.Seed(context); TestSqlLoggerFactory.Reset(); } });
public override void TimestampAttribute_throws_if_value_in_database_changed() { using (var context = CreateContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); DataAnnotationModelInitializer.Seed(context); Assert.True(context.Model.FindEntityType(typeof(Two)).FindProperty("Timestamp").IsConcurrencyToken); } base.TimestampAttribute_throws_if_value_in_database_changed(); // Not validating SQL because not significantly different from other tests and // row version value is not stable. }
public override InMemoryTestStore CreateTestStore() { return(InMemoryTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseInMemoryDatabase(); using (var context = new DataAnnotationContext(_serviceProvider, optionsBuilder.Options)) { context.Database.EnsureDeleted(); if (context.Database.EnsureCreated()) { DataAnnotationModelInitializer.Seed(context); } } })); }
public override SqliteTestStore CreateTestStore() => SqliteTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder() .UseSqlite(_connectionString) .UseInternalServiceProvider(_serviceProvider); using (var context = new DataAnnotationContext(optionsBuilder.Options)) { // TODO: Delete DB if model changed context.Database.EnsureDeleted(); if (context.Database.EnsureCreated()) { DataAnnotationModelInitializer.Seed(context); } TestSqlLoggerFactory.Reset(); } });
public override SqlServerTestStore CreateTestStore() { return(SqlServerTestStore.GetOrCreateShared(DatabaseName, () => { var optionsBuilder = new DbContextOptionsBuilder(); optionsBuilder.UseSqlServer(_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 override void ConcurrencyCheckAttribute_throws_if_value_in_database_changed() { using (var context = CreateContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); DataAnnotationModelInitializer.Seed(context); Fixture.TestSqlLoggerFactory.Clear(); } base.ConcurrencyCheckAttribute_throws_if_value_in_database_changed(); Assert.Equal(@"SELECT TOP(1) [r].[UniqueNo], [r].[MaxLengthProperty], [r].[Name], [r].[RowVersion] FROM [Sample] AS [r] WHERE [r].[UniqueNo] = 1 SELECT TOP(1) [r].[UniqueNo], [r].[MaxLengthProperty], [r].[Name], [r].[RowVersion] FROM [Sample] AS [r] WHERE [r].[UniqueNo] = 1 @p2='1' @p0='ModifiedData' (Nullable = false) (Size = 4000) @p1='00000000-0000-0000-0003-000000000001' @p3='00000001-0000-0000-0000-000000000001' UPDATE [Sample] SET [Name] = @p0, [RowVersion] = @p1 WHERE [UniqueNo] = @p2 AND [RowVersion] = @p3 @p2='1' @p0='ChangedData' (Nullable = false) (Size = 4000) @p1='00000000-0000-0000-0002-000000000001' @p3='00000001-0000-0000-0000-000000000001' UPDATE [Sample] SET [Name] = @p0, [RowVersion] = @p1 WHERE [UniqueNo] = @p2 AND [RowVersion] = @p3", Sql); }