Exemple #1
0
        public void MigrateDatabaseToLatestVersion_throws_when_given_invalid_connection_name()
        {
            var init = new MigrateDatabaseToLatestVersion <EmptyContext, TestMigrationsConfiguration>("YouWontFindMe");

            Assert.Equal(
                Strings.DbContext_ConnectionStringNotFound("YouWontFindMe"),
                Assert.Throws <InvalidOperationException>(() => init.InitializeDatabase(new EmptyContext())).Message);
        }
Exemple #2
0
        public void MigrateDatabaseToLatestVersion_uses_passed_migrations_configuration()
        {
            var configuration = new CustomTestMigrationsConfiguration();
            var init          = new MigrateDatabaseToLatestVersion <EmptyContext, TestMigrationsConfiguration>(false, configuration);

            init.InitializeDatabase(new EmptyContext("MigrateDatabaseToLatestVersionNamedConnectionTest"));

            Assert.Equal("System.Data.Entity.DatabaseInitializerTests+EmptyContext", configuration.CustomSeedDatabase);
        }
Exemple #3
0
        public void MigrateDatabaseToLatestVersion_uses_passed_context()
        {
            var init = new MigrateDatabaseToLatestVersion <EmptyContext, TestMigrationsConfiguration>(true);

            TestMigrationsConfiguration.SeedDatabase = null;

            init.InitializeDatabase(new EmptyContext("MigrateDatabaseToLatestVersionNamedConnectionTest"));

            Assert.Equal("MigrationInitFromConfig", TestMigrationsConfiguration.SeedDatabase);
        }
Exemple #4
0
        public void MigrateDatabaseToLatestVersion_uses_own_context()
        {
            var init = new MigrateDatabaseToLatestVersion <EmptyContext, TestMigrationsConfiguration>(false);

            TestMigrationsConfiguration.SeedDatabase = null;

            init.InitializeDatabase(new EmptyContext("MigrateDatabaseToLatestVersionNamedConnectionTest"));

            Assert.NotEqual("MigrationInitFromConfig", TestMigrationsConfiguration.SeedDatabase);
            Assert.Equal("System.Data.Entity.DatabaseInitializerTests+EmptyContext", TestMigrationsConfiguration.SeedDatabase);
        }
Exemple #5
0
        public void MigrateDatabaseToLatestVersion_invokes_migrations_pipeline_to_latest_version()
        {
            var init = new MigrateDatabaseToLatestVersion <EmptyContext, TestMigrationsConfiguration>();

            TestMigrationsConfiguration.SeedCalled = false;

            init.InitializeDatabase(new EmptyContext());

            // If seed gets called we know the migrations pipeline was invoked to update to the latest version
            Assert.True(TestMigrationsConfiguration.SeedCalled);
        }
Exemple #6
0
        public void MigrateDatabaseToLatestVersion_seed_doesnt_pollute_supplied_context()
        {
            SeedingMigrationsConfiguration.DbContextUsedForSeeding = null;

            using (var context = new FakeForMdtlvsgpsc())
            {
                var init = new MigrateDatabaseToLatestVersion <FakeForMdtlvsgpsc, SeedingMigrationsConfiguration>(useSuppliedContext: true);
                init.InitializeDatabase(context);

                Assert.Equal(0, context.ChangeTracker.Entries().Count());
                Assert.Same(context, SeedingMigrationsConfiguration.DbContextUsedForSeeding);
            }
        }