Example #1
0
        public void BackupDatabase_throws_with_correct_message()
        {
            using (var source = new SqliteConnection("Data Source=:memory:"))
                using (var destination = new SqliteConnection("Data Source=:memory:"))
                {
                    source.Open();
                    source.ExecuteNonQuery("CREATE TABLE Data (Value); INSERT INTO Data VALUES (0);");

                    using (source.BeginTransaction())
                    {
                        source.ExecuteNonQuery("UPDATE Data SET Value = 1;");

                        var ex = Assert.Throws <SqliteException>(() => source.BackupDatabase(destination));
                        Assert.Equal(SQLITE_BUSY, ex.SqliteErrorCode);
                    }
                }
        }
Example #2
0
        public void BackupDatabase_works()
        {
            using (var connection1 = new SqliteConnection("Data Source=:memory:"))
            {
                connection1.Open();

                connection1.ExecuteNonQuery(
                    "CREATE TABLE Person (Name TEXT);" + "INSERT INTO Person VALUES ('Waldo');");

                using (var connection2 = new SqliteConnection("Data Source=:memory:"))
                {
                    connection2.Open();
                    connection1.BackupDatabase(connection2);

                    var name = connection2.ExecuteScalar <string>("SELECT Name FROM Person;");
                    Assert.Equal("Waldo", name);
                }
            }
        }