public void ImplicitTransactionsOnStoreAndTrash() { using (var conn = SQLitePortability.CreateConnection()) { conn.Open(); IDatabaseDetails details = new SQLiteDetails(); IDatabaseAccess db = new DatabaseAccess(conn, details); IKeyAccess keys = new KeyUtil(); DatabaseStorage storage = new DatabaseStorage(details, db, keys); IBeanFactory factory = new BeanFactory(); IBeanCrud crud = new BeanCrud(storage, db, keys, factory); storage.EnterFluidMode(); var bean = crud.Dispense <ThrowingBean>(); bean["foo"] = "ok"; var id = crud.Store(bean); bean.Throw = true; bean["foo"] = "fail"; try { crud.Store(bean); } catch { } Assert.Equal("ok", db.Cell <string>(true, "select foo from test where id = {0}", id)); try { crud.Trash(bean); } catch { } Assert.True(db.Cell <int>(true, "select count(*) from test") > 0); } }
public void ImplicitTransactionsOnStoreAndTrash() { using(var conn = SQLitePortability.CreateConnection()) { conn.Open(); IDatabaseDetails details = new SQLiteDetails(); IDatabaseAccess db = new DatabaseAccess(conn, details); IKeyAccess keys = new KeyUtil(); DatabaseStorage storage = new DatabaseStorage(details, db, keys); IBeanCrud crud = new BeanCrud(storage, db, keys); storage.EnterFluidMode(); var bean = crud.Dispense<ThrowingBean>(); bean["foo"] = "ok"; var id = crud.Store(bean); bean.Throw = true; bean["foo"] = "fail"; try { crud.Store(bean); } catch { } Assert.Equal("ok", db.Cell<string>(true, "select foo from test where id = {0}", id)); try { crud.Trash(bean); } catch { } Assert.True(db.Cell<int>(true, "select count(*) from test") > 0); } }
public void Paginates() { var details = new SQLiteDetails(); Assert.Equal("LIMIT 10 OFFSET 0", details.Paginate(1)); Assert.Equal("LIMIT 10 OFFSET 10", details.Paginate(2)); Assert.Equal("LIMIT 15 OFFSET 30", details.Paginate(3, 15)); Assert.Equal("LIMIT 10 OFFSET 0", details.Paginate(-1)); }
public DatabaseStorageTests_SQLite() { _conn = SQLitePortability.CreateConnection(); _conn.Open(); IDatabaseDetails details = new SQLiteDetails(); _db = new DatabaseAccess(_conn, details); _keys = new KeyUtil(); _storage = new DatabaseStorage(details, _db, _keys); }
public void UpdateSchemaWithChangedColumns() { var detail = new SQLiteDetails(); Assert.Throws <NotSupportedException>(() => { detail.UpdateSchema(null, "", "", null, new Dictionary <string, int> { { "col1", 1 }, { "col2", 2 } }, null); }); }
public void Schema() { var details = new SQLiteDetails(); _db.Exec("create table t (id, a)"); var schema = _storage.GetSchema(); Assert.Equal(1, schema.Count); var t = schema["t"]; Assert.False(t.ContainsKey("id")); Assert.Equal(SQLiteDetails.RANK_ANY, t["a"]); Assert.Null(details.GetSqlTypeFromRank(t["a"])); }
public DatabaseBeanFinderTests() { _conn = SQLitePortability.CreateConnection(); _conn.Open(); IDatabaseDetails details = new SQLiteDetails(); IDatabaseAccess db = new DatabaseAccess(_conn, details); IKeyAccess keys = new KeyUtil(); IStorage storage = new DatabaseStorage(details, db, keys); IBeanCrud crud = new BeanCrud(storage, db, keys); IBeanFinder finder = new DatabaseBeanFinder(details, db, crud); db.Exec("create table foo(x)"); db.Exec("insert into foo(x) values(1)"); db.Exec("insert into foo(x) values(2)"); db.Exec("insert into foo(x) values(3)"); _db = db; _finder = finder; }
public DatabaseBeanFinderTests() { _conn = SQLitePortability.CreateConnection(); _conn.Open(); IDatabaseDetails details = new SQLiteDetails(); IDatabaseAccess db = new DatabaseAccess(_conn, details); IKeyAccess keys = new KeyUtil(); IStorage storage = new DatabaseStorage(details, db, keys); IBeanCrud crud = new BeanCrud(storage, db, keys); IBeanFinder finder = new DatabaseBeanFinder(details, db, crud); db.Exec("create table foo(x)"); db.Exec("insert into foo(x) values(1)"); db.Exec("insert into foo(x) values(2)"); db.Exec("insert into foo(x) values(3)"); _db = db; _finder = finder; }