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 Store() { IBeanFactory factory = new BeanFactory(); factory.Options.ValidateGetColumns = false; var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil(), factory); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense <Tracer>(); // ----- Insert var id = crud.Store(bean); Assert.Equal(0L, id); Assert.Equal(0L, bean["id"]); Assert.Equal($"ad: bs: bi: ai:{id} as:{id}", bean.TraceLog); Assert.Equal($"ad: bs: bi: ai:{id} as:{id}", observer.TraceLog); // ------ Update bean.Put("p1", "test"); observer.TraceLog = ""; bean.TraceLog = ""; crud.Store(bean); Assert.Equal(0L, bean["id"]); Assert.Equal($"bs:{id} bu:{id} au:{id} as:{id}", bean.TraceLog); Assert.Equal($"bs:{id} bu:{id} au:{id} as:{id}", observer.TraceLog); }
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 Load() { IBeanFactory factory = new BeanFactory(); factory.Options.ValidateGetColumns = false; var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil(), factory); var observer = new TracingObserver(); crud.AddObserver(observer); // Load non-existing bean Assert.Null(crud.Load("any", 123)); Assert.Empty(observer.TraceLog); var bean = crud.Dispense <Tracer>(); bean.Put("p1", "test"); var id = crud.Store(bean); observer.TraceLog = ""; bean = crud.Load <Tracer>(id); Assert.Equal("ad: bl: al:" + id, bean.TraceLog); Assert.Equal("ad: bl: al:" + id, observer.TraceLog); Assert.NotNull(bean["id"]); Assert.Equal(id, bean["id"]); Assert.Equal("test", bean["p1"]); }
public void Trash() { IBeanFactory factory = new BeanFactory(); factory.Options.ValidateGetColumns = false; var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil(), factory); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense <Tracer>(); observer.TraceLog = bean.TraceLog = ""; crud.Trash(bean); Assert.Empty(bean.TraceLog); Assert.Empty(observer.TraceLog); var id = crud.Store(bean); observer.TraceLog = bean.TraceLog = ""; crud.Trash(bean); Assert.Equal("bt:" + id + " at:" + id, bean.TraceLog); Assert.Equal("bt:" + id + " at:" + id, observer.TraceLog); Assert.Equal(id, bean["id"]); Assert.Null(crud.Load <Tracer>(id)); }
public void PreventDirectInstantiation() { var crud = new BeanCrud(null, null, null); Assert.Throws<InvalidOperationException>(delegate() { crud.Store(new Tracer()); }); Assert.Throws<InvalidOperationException>(delegate() { crud.Trash(new Tracer()); }); }
public void PreventDirectInstantiation() { var crud = new BeanCrud(null, null, null); Assert.Throws <InvalidOperationException>(delegate() { crud.Store(new Tracer()); }); Assert.Throws <InvalidOperationException>(delegate() { crud.Trash(new Tracer()); }); }
public void PreventDirectInstantiation() { IBeanFactory factory = new BeanFactory(); var crud = new BeanCrud(null, null, null, factory); Assert.Throws <InvalidOperationException>(() => { crud.Store(new Tracer()); }); Assert.Throws <InvalidOperationException>(() => { crud.Trash(new Tracer()); }); }
public void Store() { var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil()); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense <Tracer>(); var id = crud.Store(bean); Assert.Equal(0L, id); Assert.Equal(0L, bean["id"]); Assert.Equal("ad: bs: as:" + id, bean.TraceLog); Assert.Equal("ad: bs: as:" + id, observer.TraceLog); }
public void Store() { IBeanFactory factory = new BeanFactory(); factory.Options.ValidateGetColumns = false; var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil(), factory); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense <Tracer>(); var id = crud.Store(bean); Assert.Equal(0L, id); Assert.Equal(0L, bean["id"]); Assert.Equal("ad: bs: as:" + id, bean.TraceLog); Assert.Equal("ad: bs: as:" + id, observer.TraceLog); }
public void Load() { var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil()); var observer = new TracingObserver(); crud.AddObserver(observer); // Load non-existing bean Assert.Null(crud.Load("any", 123)); Assert.Empty(observer.TraceLog); var bean = crud.Dispense<Tracer>(); bean.Put("p1", "test"); var id = crud.Store(bean); observer.TraceLog = ""; bean = crud.Load<Tracer>(id); Assert.Equal("ad: bl: al:" + id, bean.TraceLog); Assert.Equal("ad: bl: al:" + id, observer.TraceLog); Assert.NotNull(bean["id"]); Assert.Equal(id, bean["id"]); Assert.Equal("test", bean["p1"]); }
public void Trash() { var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil()); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense <Tracer>(); observer.TraceLog = bean.TraceLog = ""; crud.Trash(bean); Assert.Empty(bean.TraceLog); Assert.Empty(observer.TraceLog); var id = crud.Store(bean); observer.TraceLog = bean.TraceLog = ""; crud.Trash(bean); Assert.Equal("bt:" + id + " at:" + id, bean.TraceLog); Assert.Equal("bt:" + id + " at:" + id, observer.TraceLog); Assert.Equal(id, bean["id"]); Assert.Null(crud.Load <Tracer>(id)); }
public void Trash() { var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil()); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense<Tracer>(); observer.TraceLog = bean.TraceLog = ""; crud.Trash(bean); Assert.Empty(bean.TraceLog); Assert.Empty(observer.TraceLog); var id = crud.Store(bean); observer.TraceLog = bean.TraceLog = ""; crud.Trash(bean); Assert.Equal("bt:" + id + " at:" + id, bean.TraceLog); Assert.Equal("bt:" + id + " at:" + id, observer.TraceLog); Assert.Equal(id, bean["id"]); Assert.Null(crud.Load<Tracer>(id)); }
public void Store() { var crud = new BeanCrud(new InMemoryStorage(), null, new KeyUtil()); var observer = new TracingObserver(); crud.AddObserver(observer); var bean = crud.Dispense<Tracer>(); var id = crud.Store(bean); Assert.Equal(0L, id); Assert.Equal(0L, bean["id"]); Assert.Equal("ad: bs: as:" + id, bean.TraceLog); Assert.Equal("ad: bs: as:" + id, observer.TraceLog); }