// [Fact(Skip = @"DbConnection timeout issue.")] // Ignored for now because even with Connection Timeout=1 the connection to a bad server // can still take over 20 seconds to fail. This is apparently because of the way timeouts work on // SqlConnection which is that the timeout specified is a minimum value and if the APIs being called // just take longer to fail than the timeout then so be it. // The code is left in place so it can be run manually to check this is working correctly anytime the // GetProviderManifestTokenChecked method is changed. public void Useful_exception_is_thrown_if_model_creation_happens_with_bad_MVC4_connection_string() { try { MutableResolver.AddResolver <IDbConnectionFactory>( k => new SqlConnectionFactory( "Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True; Connection Timeout=1;")); using (var context = new BadMvcContext()) { Assert.Throws <ProviderIncompatibleException>(() => context.Database.Initialize(force: false)).ValidateMessage( "BadLocalDBDatabaseName"); } } finally { MutableResolver.ClearResolvers(); } }
// [Fact(Skip = @"DbConnection timeout issue.")] // Ignored for now because even with Connection Timeout=1 the connection to a bad server // can still take over 20 seconds to fail. This is apparently because of the way timeouts work on // SqlConnection which is that the timeout specified is a minimum value and if the APIs being called // just take longer to fail than the timeout then so be it. // The code is left in place so it can be run manually to check this is working correctly anytime the // GetProviderManifestTokenChecked method is changed. public void Useful_exception_is_thrown_if_model_creation_happens_with_bad_MVC4_connection_string() { var previousConnectionFactory = DefaultConnectionFactoryResolver.Instance.ConnectionFactory; try { DefaultConnectionFactoryResolver.Instance.ConnectionFactory = new SqlConnectionFactory( "Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True; Connection Timeout=1"); using (var context = new BadMvcContext()) { Assert.Throws <ProviderIncompatibleException>(() => context.Database.Initialize(force: false)).ValidateMessage( "BadLocalDBDatabaseName"); } } finally { DefaultConnectionFactoryResolver.Instance.ConnectionFactory = previousConnectionFactory; } }