public void ComparePropertyComputedColSelf() { //SETUP var options = GetComputedColDbOptions(); 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(); #if NETCOREAPP2_1 var localDatabaseModel = factory.Create(connectionString, new string[] { }, new string[] { }); #elif NETCOREAPP3_0 var localDatabaseModel = factory.Create(connectionString, new DatabaseModelFactoryOptions(new string[] { }, new string[] { })); #endif var handler = new Stage1Comparer(context.Model, context.GetType().Name); //ATTEMPT var hasErrors = handler.CompareModelToDatabase(localDatabaseModel); //VERIFY hasErrors.ShouldBeTrue(); //The setting of a computed col changed the column type var errors = CompareLog.ListAllErrors(handler.Logs).ToList(); errors.Count.ShouldEqual(1); errors[0].ShouldEqual( "DIFFERENT: MyEntity->Property 'MyDateTime', column type. Expected = datetime2, found = datetime"); } }
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(3); 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()"); errors[2].ShouldEqual( "DIFFERENT: MyEntity->Property 'MyDateTime', value generated. Expected = Never, found = OnAddOrUpdate"); } }