public void ComparePropertySqlDefaultReversed() { //SETUP var options = GetDefaultSqlDbOptions(); DatabaseModel localDatabaseModel; using (var context = new MyEntitySqlDefaultDbContext(options)) { var dtService = context.GetDesignTimeService(); var serviceProvider = dtService.GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); var connectionString = context.Database.GetDbConnection().ConnectionString; context.Database.EnsureCreated(); localDatabaseModel = factory.Create(connectionString, new string[] { }, new string[] { }); } using (var context = new MyEntityDbContext(_options)) { var handler = new Stage1Comparer(context.Model, context.GetType().Name); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(localDatabaseModel); //VERIFY hasErrors.ShouldBeTrue(); var errors = CompareLog.ListAllErrors(handler.Logs).ToList(); errors.Count.ShouldEqual(2); errors[0].ShouldEqual( "DIFFERENT: MyEntity->Property 'MyInt', default value sql. Expected = <null>, found = 123"); errors[1].ShouldEqual( "DIFFERENT: MyEntity->Property 'MyInt', value generated. Expected = Never, found = OnAdd"); } }
public void ComparePropertyComputedColNameReversed() { //SETUP var options = GetComputedColDbOptions(); DatabaseModel localDatabaseModel; using (var context = new MyEntityComputedColDbContext(options)) { var dtService = context.GetDesignTimeService(); var serviceProvider = dtService.GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); var connectionString = context.Database.GetDbConnection().ConnectionString; context.Database.EnsureCreated(); localDatabaseModel = factory.Create(connectionString, new string[] { }, new string[] { }); } using (var context = new MyEntityDbContext(_options)) { var handler = new Stage1Comparer(context.Model, context.GetType().Name); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(localDatabaseModel); //VERIFY hasErrors.ShouldBeTrue(); var errors = CompareLog.ListAllErrors(handler.Logs).ToList(); errors.Count.ShouldEqual(2); errors[0].ShouldEqual( "DIFFERENT: MyEntity->Property 'MyDateTime', column type. Expected = datetime2, found = datetime"); errors[1].ShouldEqual( "DIFFERENT: MyEntity->Property 'MyDateTime', computed column sql. Expected = <null>, found = getutcdate()"); } }
public Stage1ComparerMyEntityDiff(ITestOutputHelper output) { _output = output; _options = this .CreateUniqueClassOptions <MyEntityDbContext>(); var serviceProvider = new SqlServerDesignTimeServices().GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); using (var context = new MyEntityDbContext(_options)) { _connectionString = context.Database.GetDbConnection().ConnectionString; context.Database.EnsureCreated(); _databaseModel = factory.Create(_connectionString, new string[] { }, new string[] { }); } }
public void CompareDefaultValueColumn() { //SETUP var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.DefaultValue); context.Database.EnsureClean(); var comparer = new CompareEfSql(); //ATTEMPT var hasErrors = comparer.CompareEfWithDb(context); //VERIFY hasErrors.ShouldBeFalse(comparer.GetAllErrors); }
public void CompareDefaultConfigNoErrors() { //SETUP using (var context = new MyEntityDbContext(_options)) { var model = context.Model; var handler = new Stage1Comparer(model, context.GetType().Name); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(_databaseModel); //VERIFY hasErrors.ShouldBeFalse(); var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter()); var json = JsonConvert.SerializeObject(handler.Logs, settings); } }
public Stage1ComparerMyEntityDiff(ITestOutputHelper output) { _output = output; var serviceProvider = new SqlServerDesignTimeServices().GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using (var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.NormalTable)) { context.Database.EnsureClean(); var connectionString = context.Database.GetDbConnection().ConnectionString; databaseModel = factory.Create(connectionString, new DatabaseModelFactoryOptions(new string[] { }, new string[] { })); } }
public Stage2ComparerMyEntityDiff(ITestOutputHelper output) { _output = output; var options = this .CreateUniqueClassOptions <MyEntityDbContext>(); var serviceProvider = new SqlServerDesignTimeServices().GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); using (var context = new MyEntityDbContext(options)) { var connectionString = context.Database.GetDbConnection().ConnectionString; context.Database.EnsureCreated(); #if NETCOREAPP2_1 _databaseModel = factory.Create(connectionString, new string[] { }, new string[] { }); #elif NETCOREAPP3_0 _databaseModel = factory.Create(connectionString, new DatabaseModelFactoryOptions(new string[] { }, new string[] { })); #endif } }
public void CompareTotalSchemaConfig() { //SETUP var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using (var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.WholeSchemaSet)) { var model = context.Model; var handler = new Stage1Comparer(context); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(databaseModel); //VERIFY hasErrors.ShouldBeTrue(); CompareLog.ListAllErrors(handler.Logs).Single().ShouldEqual( "NOT IN DATABASE: Entity 'MyEntity', table name. Expected = AllSchema.MyEntites"); } }
public void ComparePropertyDiffTypeName() { //SETUP var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using (var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.StringIsAscii)) { var model = context.Model; var handler = new Stage1Comparer(context); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(databaseModel); //VERIFY hasErrors.ShouldBeTrue(); CompareLog.ListAllErrors(handler.Logs).Single().ShouldEqual( "DIFFERENT: MyEntity->Property 'MyString', column type. Expected = varchar(max), found = nvarchar(max)"); } }
public void ComparePropertyDiffColName() { //SETUP var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using (var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.DifferentColName)) { var model = context.Model; var handler = new Stage1Comparer(context); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(databaseModel); //VERIFY hasErrors.ShouldBeTrue(); CompareLog.ListAllErrors(handler.Logs).Single().ShouldEqual( "NOT IN DATABASE: MyEntity->Property 'MyInt', column name. Expected = OtherColName"); } }
public void TestSchemaDefaultNameSqlite(MyEntityDbContext.Configs config) { //SETUP var options = SqliteInMemory.CreateOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using var context = new MyEntityDbContext(options, config); context.Database.EnsureCreated(); var dtService = context.GetDesignTimeService(); var serviceProvider = dtService.GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); //ATTEMPT var database = factory.Create(context.Database.GetConnectionString(), new DatabaseModelFactoryOptions(new string[] { }, new string[] { })); //VERIFY database.DefaultSchema.ShouldEqual(null); }
public void CompareDefaultConfigNoErrors() { //SETUP var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using (var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.NormalTable)) { var model = context.Model; var handler = new Stage1Comparer(context); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(databaseModel); //VERIFY hasErrors.ShouldBeFalse(); var settings = new JsonSerializerSettings(); settings.Converters.Add(new StringEnumConverter()); var json = JsonConvert.SerializeObject(handler.Logs, settings); } }
public void CompareTemporal() { //SETUP var options = this.CreateUniqueClassOptions <MyEntityDbContext>( builder => builder.ReplaceService <IModelCacheKeyFactory, MyEntityModelCacheKeyFactory>()); using var context = new MyEntityDbContext(options, MyEntityDbContext.Configs.Temporal); context.Database.EnsureCreated(); foreach (var entityType in context.GetService <IDesignTimeModel>().Model.GetEntityTypes()) { context.Database.ExecuteSqlRaw( $"IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{entityType.GetTableName()}') ALTER TABLE [{entityType.GetTableName()}] SET (SYSTEM_VERSIONING = OFF)"); } context.Database.EnsureClean(); var comparer = new CompareEfSql(); //ATTEMPT var hasErrors = comparer.CompareEfWithDb(context); //VERIFY hasErrors.ShouldBeFalse(comparer.GetAllErrors); }