Exemple #1
0
        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");
            }
        }
Exemple #2
0
        public void ComparePropertyComputedColName()
        {
            //SETUP
            var optionsBuilder = new DbContextOptionsBuilder <MyEntityComputedColDbContext>();

            optionsBuilder.UseSqlServer(_connectionString);
            using (var context = new MyEntityComputedColDbContext(optionsBuilder.Options))
            {
                var handler = new Stage1Comparer(context.Model, context.GetType().Name);

                //ATTEMPT
                var hasErrors = handler.CompareModelToDatabase(_databaseModel);

                //VERIFY
                hasErrors.ShouldBeTrue();
                var errors = CompareLog.ListAllErrors(handler.Logs).ToList();
                errors.Count.ShouldEqual(2);
                errors[0].ShouldEqual(
                    "DIFFERENT: MyEntity->Property 'MyDateTime', computed column sql. Expected = getutcdate(), found = <null>");
                errors[1].ShouldEqual(
                    "DIFFERENT: MyEntity->Property 'MyDateTime', value generated. Expected = OnAddOrUpdate, found = Never");
            }
        }