Пример #1
0
        public Migrator(
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] IDataStoreCreator dataStoreCreator,
            [NotNull] IMigrationSqlGenerator migrationSqlGenerator,
            [NotNull] SqlStatementExecutor executor,
            [NotNull] IRelationalConnection connection,
            [NotNull] IModelDiffer modelDiffer,
            [NotNull] IModel model,
            [NotNull] MigrationIdGenerator idGenerator,
            [NotNull] ISqlGenerator sqlGenerator)
        {
            Check.NotNull(migrationAssembly, nameof(migrationAssembly));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(dataStoreCreator, nameof(dataStoreCreator));
            Check.NotNull(migrationSqlGenerator, nameof(migrationSqlGenerator));
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(model, nameof(model));
            Check.NotNull(idGenerator, nameof(idGenerator));
            Check.NotNull(sqlGenerator, nameof(sqlGenerator));

            _migrationAssembly = migrationAssembly;
            _historyRepository = historyRepository;
            _dataStoreCreator = (IRelationalDataStoreCreator)dataStoreCreator;
            _migrationSqlGenerator = migrationSqlGenerator;
            _executor = executor;
            _connection = connection;
            _modelDiffer = modelDiffer;
            _model = model;
            _idGenerator = idGenerator;
            _sqlGenerator = sqlGenerator;
        }
        public MigrationScaffolder(
            [NotNull] DbContext context,
            [NotNull] IModel model,
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] IModelDiffer modelDiffer,
            [NotNull] MigrationIdGenerator idGenerator,
            [NotNull] MigrationCodeGenerator migrationCodeGenerator,
            [NotNull] IHistoryRepository historyRepository,
            [NotNull] ILoggerFactory loggerFactory)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(model, nameof(model));
            Check.NotNull(migrationAssembly, nameof(migrationAssembly));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(idGenerator, nameof(idGenerator));
            Check.NotNull(migrationCodeGenerator, nameof(migrationCodeGenerator));
            Check.NotNull(historyRepository, nameof(historyRepository));
            Check.NotNull(loggerFactory, nameof(loggerFactory));

            _contextType = context.GetType();
            _model = model;
            _migrationAssembly = migrationAssembly;
            _modelDiffer = modelDiffer;
            _idGenerator = idGenerator;
            _migrationCodeGenerator = migrationCodeGenerator;
            _historyRepository = historyRepository;
            _logger = new LazyRef<ILogger>(loggerFactory.CreateLogger<MigrationScaffolder>);
        }
        public void CreateId_always_increments_timestamp()
        {
            var generator = new MigrationIdGenerator();

            var id1 = generator.CreateId("Rainbow");
            var id2 = generator.CreateId("Rainbow");

            Assert.NotEqual(id1, id2);
        }
Пример #4
0
        public void CreateId_always_increments_timestamp()
        {
            var generator = new MigrationIdGenerator();

            var id1 = generator.CreateId("Rainbow");
            var id2 = generator.CreateId("Rainbow");

            Assert.NotEqual(id1, id2);
        }
        public void ResolveId_matches_id_when_exact_case()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103100_FLUTTER"),
                new MockMigration("20150302103100_Flutter")
            };
            var id = new MigrationIdGenerator().ResolveId("20150302103100_Flutter", migrations);

            Assert.Equal("20150302103100_Flutter", id);
        }
        public void ResolveId_returns_first_candidate_id()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103100_FLUTTER"),
                new MockMigration("20150302103100_Flutter")
            };
            var id = new MigrationIdGenerator().ResolveId("20150302103100_flutter", migrations);

            Assert.Equal("20150302103100_FLUTTER", id);
        }
Пример #7
0
        public void ResolveId_returns_id_of_first_candidate_name()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103630_PINKIE"),
                new MockMigration("20150302103600_Pinkie")
            };
            var id = new MigrationIdGenerator().ResolveId("pinkie", migrations);

            Assert.Equal("20150302103630_PINKIE", id);
        }
Пример #8
0
        public void ResolveId_matches_name_when_exact_case()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103630_PINKIE"),
                new MockMigration("20150302103600_Pinkie")
            };
            var id = new MigrationIdGenerator().ResolveId("Pinkie", migrations);

            Assert.Equal("20150302103600_Pinkie", id);
        }
Пример #9
0
        public void ResolveId_matches_id_when_exact_case()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103100_FLUTTER"),
                new MockMigration("20150302103100_Flutter")
            };
            var id = new MigrationIdGenerator().ResolveId("20150302103100_Flutter", migrations);

            Assert.Equal("20150302103100_Flutter", id);
        }
Пример #10
0
        public void ResolveId_returns_first_candidate_id()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103100_FLUTTER"),
                new MockMigration("20150302103100_Flutter")
            };
            var id = new MigrationIdGenerator().ResolveId("20150302103100_flutter", migrations);

            Assert.Equal("20150302103100_FLUTTER", id);
        }
        public void CreateId_works()
        {
            var id = new MigrationIdGenerator().CreateId("Twilight");

            Assert.Matches("[0-9]{14}_Twilight", id);
        }
Пример #12
0
        public void IsValidId_returns_true_when_valid()
        {
            var valid = new MigrationIdGenerator().IsValidId("20150302100930_Rarity");

            Assert.True(valid);
        }
Пример #13
0
        public void IsValidId_returns_false_when_invalid()
        {
            var valid = new MigrationIdGenerator().IsValidId("Rarity");

            Assert.False(valid);
        }
        public void GetName_works()
        {
            var name = new MigrationIdGenerator().GetName("20150302100620_Apple");

            Assert.Equal("Apple", name);
        }
Пример #15
0
        public void GetName_works()
        {
            var name = new MigrationIdGenerator().GetName("20150302100620_Apple");

            Assert.Equal("Apple", name);
        }
Пример #16
0
        public void CreateId_works()
        {
            var id = new MigrationIdGenerator().CreateId("Twilight");

            Assert.Matches("[0-9]{14}_Twilight", id);
        }
        public void IsValidId_returns_true_when_valid()
        {
            var valid = new MigrationIdGenerator().IsValidId("20150302100930_Rarity");

            Assert.True(valid);
        }
        public void IsValidId_returns_false_when_invalid()
        {
            var valid = new MigrationIdGenerator().IsValidId("Rarity");

            Assert.False(valid);
        }
        public void ResolveId_returns_id_of_first_candidate_name()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103630_PINKIE"),
                new MockMigration("20150302103600_Pinkie")
            };
            var id = new MigrationIdGenerator().ResolveId("pinkie", migrations);

            Assert.Equal("20150302103630_PINKIE", id);
        }
        public void ResolveId_matches_name_when_exact_case()
        {
            var migrations = new[]
            {
                new MockMigration("20150302103630_PINKIE"),
                new MockMigration("20150302103600_Pinkie")
            };
            var id = new MigrationIdGenerator().ResolveId("Pinkie", migrations);

            Assert.Equal("20150302103600_Pinkie", id);
        }