Ejemplo n.º 1
0
        public void Can_log_provider_execution_warnings()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();

            migrator.Update();

            var mockLogger = new Mock<MigrationsLogger>();

            migrator = CreateMigrator<ShopContext_v1>(new WarningMigration());

            var migratorLoggingDecorator
                = new MigratorLoggingDecorator(
                    migrator,
                    mockLogger.Object);

            migratorLoggingDecorator.Update();

            mockLogger
                .Verify(
                    ml => ml.Warning(
                        "Warning! The maximum key length is 900 bytes. The index 'PK_PkTooLong' has maximum length of 902 bytes. For some combination of large values, the insert/update operation will fail."),
                    Times.Once());
        }
        public ApplyMigrationResult ApplyMigrations(string migrationsConfiguration)
        {
            var configType = Type.GetType(migrationsConfiguration);
            var config = (DbMigrationsConfiguration)Activator.CreateInstance(configType);
            MigratorBase migrator = new DbMigrator(config);
            migrator = new MigratorLoggingDecorator(migrator, new MigrationLogR(config.ContextType.Name));

            try
            {
                migrator.Update();
                return ApplyMigrationResult.DatabaseUpToDate;
            }
            catch (AutomaticMigrationsDisabledException)
            {
                return ApplyMigrationResult.PendingModelChanges;
            }
        }