示例#1
0
        private MigrationsScaffolder CreateMigrationScaffolder <TContext>()
            where TContext : DbContext, new()
        {
            var currentContext = new CurrentDbContext(new TContext());
            var idGenerator    = new MigrationsIdGenerator();
            var code           = new CSharpHelper();
            var reporter       = new TestOperationReporter();

            return(new MigrationsScaffolder(
                       new MigrationsScaffolderDependencies(
                           currentContext,
                           new Model(),
                           new MigrationsAssembly(
                               currentContext,
                               new DbContextOptions <TContext>().WithExtension(new FakeRelationalOptionsExtension()),
                               idGenerator),
                           new MigrationsModelDiffer(
                               new TestRelationalTypeMapper(new RelationalTypeMapperDependencies()),
                               new MigrationsAnnotationProvider(new MigrationsAnnotationProviderDependencies()),
                               new FakeStateManager(),
                               RelationalTestHelpers.Instance.CreateCommandBatchPreparer()),
                           idGenerator,
                           new CSharpMigrationsGenerator(
                               new MigrationsCodeGeneratorDependencies(),
                               new CSharpMigrationsGeneratorDependencies(
                                   code,
                                   new CSharpMigrationOperationGenerator(
                                       new CSharpMigrationOperationGeneratorDependencies(code)),
                                   new CSharpSnapshotGenerator(new CSharpSnapshotGeneratorDependencies(code)))),
                           new MockHistoryRepository(),
                           reporter,
                           new MockProvider(),
                           new SnapshotModelProcessor(reporter))));
        }
    public void CreateId_uses_invariant_calendar()
    {
        var invariantYear = CultureInfo.InvariantCulture.Calendar.GetYear(DateTime.Today).ToString();

        var id = new MigrationsIdGenerator().GenerateId("Zecora");

        Assert.StartsWith(invariantYear, id);
    }
        private IMigrationsScaffolder CreateMigrationScaffolder <TContext>()
            where TContext : DbContext, new()
        {
            var currentContext = new CurrentDbContext(new TContext());
            var idGenerator    = new MigrationsIdGenerator();
            var code           = new CSharpHelper();
            var reporter       = new TestOperationReporter();
            var migrationAssembly
                = new MigrationsAssembly(
                      currentContext,
                      new DbContextOptions <TContext>().WithExtension(new FakeRelationalOptionsExtension()),
                      idGenerator);
            var historyRepository = new MockHistoryRepository();

            var services = RelationalTestHelpers.Instance.CreateContextServices();

            return(new MigrationsScaffolder(
                       new MigrationsScaffolderDependencies(
                           currentContext,
                           new Model(),
                           migrationAssembly,
                           new MigrationsModelDiffer(
                               new FallbackRelationalCoreTypeMapper(
                                   TestServiceFactory.Instance.Create <CoreTypeMapperDependencies>(),
                                   TestServiceFactory.Instance.Create <RelationalTypeMapperDependencies>(),
                                   TestServiceFactory.Instance.Create <TestRelationalTypeMapper>()),
                               new MigrationsAnnotationProvider(new MigrationsAnnotationProviderDependencies()),
                               services.GetRequiredService <IChangeDetector>(),
                               services.GetRequiredService <StateManagerDependencies>(),
                               services.GetRequiredService <CommandBatchPreparerDependencies>()),
                           idGenerator,
                           new MigrationsCodeGeneratorSelector(
                               new[]
            {
                new CSharpMigrationsGenerator(
                    new MigrationsCodeGeneratorDependencies(),
                    new CSharpMigrationsGeneratorDependencies(
                        code,
                        new CSharpMigrationOperationGenerator(
                            new CSharpMigrationOperationGeneratorDependencies(code)),
                        new CSharpSnapshotGenerator(new CSharpSnapshotGeneratorDependencies(code))))
            }),
                           historyRepository,
                           reporter,
                           new MockProvider(),
                           new SnapshotModelProcessor(reporter),
                           new Migrator(
                               migrationAssembly,
                               historyRepository,
                               services.GetRequiredService <IDatabaseCreator>(),
                               services.GetRequiredService <IMigrationsSqlGenerator>(),
                               services.GetRequiredService <IRawSqlCommandBuilder>(),
                               services.GetRequiredService <IMigrationCommandExecutor>(),
                               services.GetRequiredService <IRelationalConnection>(),
                               services.GetRequiredService <ISqlGenerationHelper>(),
                               services.GetRequiredService <IDiagnosticsLogger <DbLoggerCategory.Migrations> >(),
                               services.GetRequiredService <IDatabaseProvider>()))));
        }
示例#4
0
        public void CreateId_always_increments_timestamp()
        {
            var generator = new MigrationsIdGenerator();

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

            Assert.NotEqual(id1, id2);
        }
        private MigrationScaffolder CreateMigrationScaffolder <TContext>()
            where TContext : DbContext, new()
        {
            var context     = new TContext();
            var idGenerator = new MigrationsIdGenerator();
            var code        = new CSharpHelper();

            return(new MigrationScaffolder(
                       context,
                       new Model(),
                       new MigrationsAssembly(
                           context,
                           new DbContextOptions <TContext>().WithExtension(new MockRelationalOptionsExtension()),
                           idGenerator),
                       new MigrationsModelDiffer(
                           new TestMetadataExtensionProvider(),
                           new MigrationsAnnotationProvider()),
                       idGenerator,
                       new CSharpMigrationGenerator(code, new CSharpMigrationOperationGenerator(code), new CSharpModelGenerator(code)),
                       new MockHistoryRepository(),
                       new LoggerFactory()));
        }
示例#6
0
        private MigrationsScaffolder CreateMigrationScaffolder <TContext>()
            where TContext : DbContext, new()
        {
            var currentContext = new CurrentDbContext(new TContext());
            var idGenerator    = new MigrationsIdGenerator();
            var code           = new CSharpHelper();

            return(new MigrationsScaffolder(
                       currentContext,
                       new Model(),
                       new MigrationsAssembly(
                           currentContext,
                           new DbContextOptions <TContext>().WithExtension(new MockRelationalOptionsExtension()),
                           idGenerator),
                       new MigrationsModelDiffer(
                           new TestRelationalTypeMapper(),
                           new TestAnnotationProvider(),
                           new MigrationsAnnotationProvider()),
                       idGenerator,
                       new CSharpMigrationsGenerator(code, new CSharpMigrationOperationGenerator(code), new CSharpSnapshotGenerator(code)),
                       new MockHistoryRepository(),
                       new LoggerFactory(),
                       new MockProviderServices()));
        }
        private IMigrationsScaffolder CreateMigrationScaffolder <TContext>()
            where TContext : DbContext, new()
        {
            var currentContext             = new CurrentDbContext(new TContext());
            var idGenerator                = new MigrationsIdGenerator();
            var sqlServerTypeMappingSource = new SqlServerTypeMappingSource(
                TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>());
            var sqlServerAnnotationCodeGenerator = new SqlServerAnnotationCodeGenerator(
                new AnnotationCodeGeneratorDependencies(sqlServerTypeMappingSource));
            var code     = new CSharpHelper(sqlServerTypeMappingSource);
            var reporter = new TestOperationReporter();
            var migrationAssembly
                = new MigrationsAssembly(
                      currentContext,
                      new DbContextOptions <TContext>().WithExtension(new FakeRelationalOptionsExtension()),
                      idGenerator,
                      new FakeDiagnosticsLogger <DbLoggerCategory.Migrations>());
            var historyRepository = new MockHistoryRepository();

            var services = RelationalTestHelpers.Instance.CreateContextServices();
            var model    = new Model().FinalizeModel();

            model.AddRuntimeAnnotation(RelationalAnnotationNames.RelationalModel, new RelationalModel(model));

            return(new MigrationsScaffolder(
                       new MigrationsScaffolderDependencies(
                           currentContext,
                           model,
                           migrationAssembly,
                           new MigrationsModelDiffer(
                               new TestRelationalTypeMappingSource(
                                   TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                                   TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>()),
                               new MigrationsAnnotationProvider(
                                   new MigrationsAnnotationProviderDependencies()),
                               services.GetRequiredService <IChangeDetector>(),
                               services.GetRequiredService <IUpdateAdapterFactory>(),
                               services.GetRequiredService <CommandBatchPreparerDependencies>()),
                           idGenerator,
                           new MigrationsCodeGeneratorSelector(
                               new[]
            {
                new CSharpMigrationsGenerator(
                    new MigrationsCodeGeneratorDependencies(
                        sqlServerTypeMappingSource,
                        sqlServerAnnotationCodeGenerator),
                    new CSharpMigrationsGeneratorDependencies(
                        code,
                        new CSharpMigrationOperationGenerator(
                            new CSharpMigrationOperationGeneratorDependencies(
                                code)),
                        new CSharpSnapshotGenerator(
                            new CSharpSnapshotGeneratorDependencies(
                                code, sqlServerTypeMappingSource, sqlServerAnnotationCodeGenerator))))
            }),
                           historyRepository,
                           reporter,
                           new MockProvider(),
                           new SnapshotModelProcessor(reporter, services.GetRequiredService <IModelRuntimeInitializer>()),
                           new Migrator(
                               migrationAssembly,
                               historyRepository,
                               services.GetRequiredService <IDatabaseCreator>(),
                               services.GetRequiredService <IMigrationsSqlGenerator>(),
                               services.GetRequiredService <IRawSqlCommandBuilder>(),
                               services.GetRequiredService <IMigrationCommandExecutor>(),
                               services.GetRequiredService <IRelationalConnection>(),
                               services.GetRequiredService <ISqlGenerationHelper>(),
                               services.GetRequiredService <ICurrentDbContext>(),
                               services.GetRequiredService <IModelRuntimeInitializer>(),
                               services.GetRequiredService <IDiagnosticsLogger <DbLoggerCategory.Migrations> >(),
                               services.GetRequiredService <IRelationalCommandDiagnosticsLogger>(),
                               services.GetRequiredService <IDatabaseProvider>()))));
        }
示例#8
0
        public void IsValidId_returns_false_when_invalid()
        {
            var valid = new MigrationsIdGenerator().IsValidId("Rarity");

            Assert.False(valid);
        }
示例#9
0
        public void IsValidId_returns_true_when_valid()
        {
            var valid = new MigrationsIdGenerator().IsValidId("20150302100930_Rarity");

            Assert.True(valid);
        }
示例#10
0
        public void GetName_works()
        {
            var name = new MigrationsIdGenerator().GetName("20150302100620_Apple");

            Assert.Equal("Apple", name);
        }
示例#11
0
        public void CreateId_works()
        {
            var id = new MigrationsIdGenerator().GenerateId("Twilight");

            Assert.Matches("[0-9]{14}_Twilight", id);
        }
    public void IsValidId_returns_false_when_supplied_format_is_too_short()
    {
        var valid = new MigrationsIdGenerator().IsValidId("1234567890123_InitialCreate");

        Assert.False(valid);
    }