Exemple #1
0
        public void ExtraIndexConstaint()
        {
            //SETUP
            var firstStageLogs = JsonConvert.DeserializeObject <List <CompareLog> >(
                TestData.GetFileContent("DbContextCompareLog01*.json"));

            var options = this.CreateUniqueMethodOptions <MyEntityIndexAddedDbContext>();

            using (var context = new MyEntityIndexAddedDbContext(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 databaseModel = factory.Create(connectionString, new string[] { }, new string[] { });
#elif NETCOREAPP3_0
                var databaseModel = factory.Create(connectionString,
                                                   new DatabaseModelFactoryOptions(new string[] { }, new string[] { }));
#endif
                var handler = new Stage2Comparer(databaseModel);

                //ATTEMPT
                var hasErrors = handler.CompareLogsToDatabase(firstStageLogs);

                //VERIFY
                hasErrors.ShouldBeTrue();
                CompareLog.ListAllErrors(handler.Logs).Single().ShouldEqual(
                    "EXTRA IN DATABASE: Index 'MyEntites', index constraint name. Found = IX_MyEntites_MyInt");
            }
        }
Exemple #2
0
        public void ExtrasNoErrors()
        {
            //SETUP
            var firstStageLogs =
                JsonConvert.DeserializeObject <List <CompareLog> >(TestData.GetFileContent("DbContextCompareLog01*.json"));
            var handler = new Stage2Comparer(_databaseModel);

            //ATTEMPT
            var hasErrors = handler.CompareLogsToDatabase(firstStageLogs);

            //VERIFY
            hasErrors.ShouldBeFalse();
        }
Exemple #3
0
        public void ExtrasProperty()
        {
            //SETUP
            var jArray = JArray.Parse(TestData.GetFileContent("DbContextCompareLog01*.json"));

            jArray[0]["SubLogs"][0]["SubLogs"][0]["Expected"] = "DiffPropName";
            var firstStageLogs = JsonConvert.DeserializeObject <List <CompareLog> >(jArray.ToString());

            var handler = new Stage2Comparer(_databaseModel);

            //ATTEMPT
            var hasErrors = handler.CompareLogsToDatabase(firstStageLogs);

            //VERIFY
            hasErrors.ShouldBeTrue();
            CompareLog.ListAllErrors(handler.Logs).Single().ShouldEqual(
                "EXTRA IN DATABASE: Column 'MyEntites', column name. Found = MyEntityId");
        }
Exemple #4
0
        //------------------------------------------------------
        //private methods

        private bool FinishRestOfCompare(string configOrConnectionString, DbContext[] dbContexts, IDesignTimeServices designTimeService)
        {
            var  databaseModel = GetDatabaseModelViaScaffolder(dbContexts[0], configOrConnectionString, designTimeService);
            bool hasErrors     = false;

            foreach (var context in dbContexts)
            {
                var stage1Comparer = new Stage1Comparer(context.Model, context.GetType().Name, _logs, _config.LogsToIgnore);
                hasErrors |= stage1Comparer.CompareModelToDatabase(databaseModel);
            }

            if (hasErrors)
            {
                return(true);
            }

            //No errors, so its worth running the second phase
            var stage2Comparer = new Stage2Comparer(databaseModel, _config.LogsToIgnore);

            hasErrors = stage2Comparer.CompareLogsToDatabase(_logs);
            _logs.AddRange(stage2Comparer.Logs);
            return(hasErrors);
        }