public void ContextKey_is_assigned_to_short_full_name_by_default() { var migrationsConfiguration = new TestMigrationsConfiguration <GT <NT, NT> .GenericFuncy <GT <GT <NT, NT>, NT>, NT> >(); Assert.Equal(migrationsConfiguration.GetType().ToString(), migrationsConfiguration.ContextKey); }
public void Providers_are_assigned_by_default() { var migrationsConfiguration = new TestMigrationsConfiguration(); Assert.NotNull(migrationsConfiguration.CodeGenerator); Assert.NotNull(migrationsConfiguration.GetSqlGenerator(DbProviders.Sql)); Assert.NotNull(migrationsConfiguration.GetSqlGenerator(DbProviders.SqlCe)); }
public void GetSqlGenerator_should_throw_when_no_generator_registered_for_provider() { var migrationsConfiguration = new TestMigrationsConfiguration(); var exception = Assert.Throws <MigrationsException>(() => migrationsConfiguration.GetSqlGenerator("Foomatic")); Assert.Equal(Strings.NoSqlGeneratorForProvider("Foomatic"), exception.Message); }
public void GetSqlGenerator_should_throw_when_no_generator_registered_for_provider() { var migrationsConfiguration = new TestMigrationsConfiguration(); var exception = Assert.Throws<MigrationsException>(() => migrationsConfiguration.GetSqlGenerator("Foomatic")); Assert.Equal(Strings.NoSqlGeneratorForProvider("Foomatic"), exception.Message); }
public void Can_get_and_set_sql_generator() { var migrationsConfiguration = new TestMigrationsConfiguration(); var migrationSqlGenerator = new SqlServerMigrationSqlGenerator(); migrationsConfiguration.SetSqlGenerator(DbProviders.Sql, migrationSqlGenerator); Assert.Same(migrationSqlGenerator, migrationsConfiguration.GetSqlGenerator(DbProviders.Sql)); }
public void CommandTimeout_throws_for_negative_values() { var config = new TestMigrationsConfiguration(); Assert.Equal( Strings.ObjectContext_InvalidCommandTimeout, Assert.Throws <ArgumentException>( () => config.CommandTimeout = -1).Message); }
public void Can_get_and_set_local_history_context_factory() { var migrationsConfiguration = new TestMigrationsConfiguration(); Func <DbConnection, string, HistoryContext> factory = (c, s) => new HistoryContext(c, s); migrationsConfiguration.SetHistoryContextFactory("Foo", factory); Assert.Same(factory, migrationsConfiguration.GetHistoryContextFactory("Foo")); }
public void Can_get_and_set_context_key() { var migrationsConfiguration = new TestMigrationsConfiguration { ContextKey = "Foo" }; Assert.Equal("Foo", migrationsConfiguration.ContextKey); }
public void GetHistoryContextFactory_should_return_root_service_when_not_locally_registered() { var migrationsConfiguration = new TestMigrationsConfiguration(); var historyContextFactory = migrationsConfiguration .GetHistoryContextFactory(ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName); Assert.NotNull(historyContextFactory); Assert.Same(DbConfiguration.DependencyResolver.GetService <Func <DbConnection, string, HistoryContext> >(), historyContextFactory); }
public void ContextKey_restricts_length_to_context_key_max_length() { var migrationsConfiguration = new TestMigrationsConfiguration { ContextKey = new string('a', 600) }; Assert.Equal(new string('a', HistoryContext.ContextKeyMaxLength), migrationsConfiguration.ContextKey); }
public void GetHistoryContextFactory_should_return_root_service_when_not_locally_registered() { var migrationsConfiguration = new TestMigrationsConfiguration(); var historyContextFactory = migrationsConfiguration .GetHistoryContextFactory(ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName); Assert.NotNull(historyContextFactory); Assert.Same(DbConfiguration.DependencyResolver.GetService<Func<DbConnection, string, HistoryContext>>(), historyContextFactory); }
public void Can_get_and_set_local_history_context_factory() { var migrationsConfiguration = new TestMigrationsConfiguration(); Func<DbConnection, string, HistoryContext> factory = (c, s) => new HistoryContext(c, s); migrationsConfiguration.SetHistoryContextFactory("Foo", factory); Assert.Same(factory, migrationsConfiguration.GetHistoryContextFactory("Foo")); }
public void Can_get_and_set_migration_context_properties() { var migrationsConfiguration = new TestMigrationsConfiguration { AutomaticMigrationsEnabled = false, CodeGenerator = new CSharpMigrationCodeGenerator(), ContextType = typeof(ShopContext_v1) }; Assert.False(migrationsConfiguration.AutomaticMigrationsEnabled); Assert.NotNull(migrationsConfiguration.CodeGenerator); Assert.NotNull(migrationsConfiguration.ContextType); }
public void Setting_HistoryContextFactory_to_null_results_in_default_factory_being_used() { var config = new TestMigrationsConfiguration(); HistoryContextFactory factory = (e, c) => { throw new NotImplementedException(); }; config.HistoryContextFactory = factory; Assert.Same(factory, config.HistoryContextFactory); config.HistoryContextFactory = null; Assert.IsType <HistoryContextFactory>(config.HistoryContextFactory); Assert.NotSame(factory, config.HistoryContextFactory); }
public void Properties_check_for_bad_arguments() { var config = new TestMigrationsConfiguration(); Assert.Equal( "value", Assert.Throws <ArgumentNullException>(() => config.CodeGenerator = null).ParamName); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws <ArgumentException>(() => config.ContextKey = null).Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws <ArgumentException>(() => config.ContextKey = "").Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws <ArgumentException>(() => config.ContextKey = " ").Message); Assert.Equal( "value", Assert.Throws <ArgumentNullException>(() => config.ContextType = null).ParamName); Assert.Equal( Strings.DbMigrationsConfiguration_ContextType("Random"), Assert.Throws <ArgumentException>(() => config.ContextType = typeof(Random)).Message); Assert.Equal( "value", Assert.Throws <ArgumentNullException>(() => config.MigrationsAssembly = null).ParamName); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws <ArgumentException>(() => config.MigrationsDirectory = null).Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws <ArgumentException>(() => config.MigrationsDirectory = "").Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws <ArgumentException>(() => config.MigrationsDirectory = " ").Message); Assert.Equal( Strings.DbMigrationsConfiguration_RootedPath(@"\Test"), Assert.Throws <MigrationsException>(() => config.MigrationsDirectory = @"\Test").Message); }
public void GetHistoryContextFactory_should_return_per_provider_service_when_not_locally_registered() { var migrationsConfiguration = new TestMigrationsConfiguration(); try { Func<DbConnection, string, HistoryContext> factory = (c, s) => new HistoryContext(c, s); MutableResolver.AddResolver<Func<DbConnection, string, HistoryContext>>(_ => factory); Assert.Same(factory, migrationsConfiguration.GetHistoryContextFactory("Foo")); } finally { MutableResolver.ClearResolvers(); } }
public void GetHistoryContextFactory_should_return_per_provider_service_when_not_locally_registered() { var migrationsConfiguration = new TestMigrationsConfiguration(); try { Func <DbConnection, string, HistoryContext> factory = (c, s) => new HistoryContext(c, s); MutableResolver.AddResolver <Func <DbConnection, string, HistoryContext> >(_ => factory); Assert.Same(factory, migrationsConfiguration.GetHistoryContextFactory("Foo")); } finally { MutableResolver.ClearResolvers(); } }
public void Setting_HistoryContextFactory_to_null_results_in_default_factory_being_used() { var config = new TestMigrationsConfiguration(); HistoryContextFactory factory = (e, c) => { throw new NotImplementedException(); }; config.HistoryContextFactory = factory; Assert.Same(factory, config.HistoryContextFactory); config.HistoryContextFactory = null; Assert.IsType<HistoryContextFactory>(config.HistoryContextFactory); Assert.NotSame(factory, config.HistoryContextFactory); }
public void CommandTimeout_throws_for_negative_values() { var config = new TestMigrationsConfiguration(); Assert.Equal( Strings.ObjectContext_InvalidCommandTimeout, Assert.Throws<ArgumentException>( () => config.CommandTimeout = -1).Message); }
public void Properties_check_for_bad_arguments() { var config = new TestMigrationsConfiguration(); Assert.Equal( "value", Assert.Throws<ArgumentNullException>(() => config.CodeGenerator = null).ParamName); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws<ArgumentException>(() => config.ContextKey = null).Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws<ArgumentException>(() => config.ContextKey = "").Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws<ArgumentException>(() => config.ContextKey = " ").Message); Assert.Equal( "value", Assert.Throws<ArgumentNullException>(() => config.ContextType = null).ParamName); Assert.Equal( Strings.DbMigrationsConfiguration_ContextType("Random"), Assert.Throws<ArgumentException>(() => config.ContextType = typeof(Random)).Message); Assert.Equal( "value", Assert.Throws<ArgumentNullException>(() => config.MigrationsAssembly = null).ParamName); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws<ArgumentException>(() => config.MigrationsDirectory = null).Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws<ArgumentException>(() => config.MigrationsDirectory = "").Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("value"), Assert.Throws<ArgumentException>(() => config.MigrationsDirectory = " ").Message); Assert.Equal( Strings.DbMigrationsConfiguration_RootedPath(@"\Test"), Assert.Throws<MigrationsException>(() => config.MigrationsDirectory = @"\Test").Message); }
public void ContextKey_is_assigned_by_default() { var migrationsConfiguration = new TestMigrationsConfiguration(); Assert.Equal(migrationsConfiguration.GetType().FullName, migrationsConfiguration.ContextKey); }