private void Can_replace_connection_implementation(
            ReplaceConnectionContext context,
            LazyInternalConnection newConnection)
        {
            Database.Delete(newConnection.Connection);
            Database.Delete(typeof(ReplaceConnectionContext).DatabaseName());

            context.InternalContext.OverrideConnection(newConnection);

            context.Entities.Add(
                new PersistEntity
                {
                    Name = "Testing"
                });
            context.SaveChanges();

            Assert.Same(newConnection.Connection, context.Database.Connection);
            Assert.True(Database.Exists(newConnection.Connection));
            Assert.False(Database.Exists(typeof(ReplaceConnectionContext).DatabaseName()));

            // By pass EF just to make sure everything targetted the correct database
            var cmd = newConnection.Connection.CreateCommand();
            cmd.CommandText = "SELECT Count(*) FROM PersistEntities";
            cmd.Connection.Open();
            Assert.Equal(1, cmd.ExecuteScalar());
            cmd.Connection.Close();
        }
 public void Can_replace_connection_with_different_provider()
 {
     using (var context = new ReplaceConnectionContext())
     {
         using (var newConnection = new LazyInternalConnection(
             context,
             new DbConnectionInfo(
                 "Data Source=NewReplaceConnectionContextDatabase.sdf",
                 "System.Data.SqlServerCe.4.0")))
         {
             Can_replace_connection_implementation(context, newConnection);
         }
     }
 }
 public void Can_replace_connection()
 {
     using (var context = new ReplaceConnectionContext())
     {
         using (var newConnection = new LazyInternalConnection(
             context,
             new DbConnectionInfo(
                 SimpleConnectionString("NewReplaceConnectionContextDatabase"),
                 "System.Data.SqlClient")))
         {
             Can_replace_connection_implementation(context, newConnection);
         }
     }
 }
 public void Can_replace_connection()
 {
     using (var context = new ReplaceConnectionContext())
     using (var newConnection = new LazyInternalConnection(new DbConnectionInfo(
                                                               @"Server=.\SQLEXPRESS;Database=NewReplaceConnectionContextDatabase;Trusted_Connection=True;",
                                                               "System.Data.SqlClient")))
     {
         Can_replace_connection_implementation(context, newConnection);
     }
 }