Example #1
0
        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));
        }
Example #2
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);
                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);
            }
        }
Example #3
0
        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());
            });
        }
Example #4
0
        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());
            });
        }
Example #5
0
        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());
            });
        }
Example #6
0
        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));
        }
Example #7
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);
            }
        }
Example #8
0
        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));
        }