Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public void RowToBean()
        {
            var crud = new BeanCrud(new InMemoryStorage(), null, null);
            var observer = new TracingObserver();
            crud.AddObserver(observer);

            var bean = crud.RowToBean<Tracer>(new Dictionary<string, object> {
                { "s", "hello" }
            });

            Assert.Null(bean["id"]);
            Assert.Equal("hello", bean["s"]);
            Assert.Equal("ad: bl: al:", bean.TraceLog);
            Assert.Equal("ad: bl: al:", observer.TraceLog);

            observer.TraceLog = "";

            bean = crud.RowToBean<Tracer>(new Dictionary<string, object> {
                { "id", 123 },
                { "s", "see you" }
            });

            Assert.Equal(123, bean["id"]);
            Assert.Equal("see you", bean["s"]);
            Assert.Equal("ad: bl: al:123", bean.TraceLog);
            Assert.Equal("ad: bl: al:123", observer.TraceLog);

            Assert.Null(crud.Load("temp", null));
        }
Exemplo n.º 3
0
        public void RowToBean()
        {
            IBeanFactory factory = new BeanFactory();

            factory.Options.ValidateGetColumns = false;
            var crud     = new BeanCrud(new InMemoryStorage(), null, null, factory);
            var observer = new TracingObserver();

            crud.AddObserver(observer);

            var bean = crud.RowToBean <Tracer>(new Dictionary <string, object> {
                { "s", "hello" }
            });

            Assert.Null(bean["id"]);
            Assert.Equal("hello", bean["s"]);
            Assert.Equal("ad: bl: al:", bean.TraceLog);
            Assert.Equal("ad: bl: al:", observer.TraceLog);

            observer.TraceLog = "";

            bean = crud.RowToBean <Tracer>(new Dictionary <string, object> {
                { "id", 123 },
                { "s", "see you" }
            });

            Assert.Equal(123, bean["id"]);
            Assert.Equal("see you", bean["s"]);
            Assert.Equal("ad: bl: al:123", bean.TraceLog);
            Assert.Equal("ad: bl: al:123", observer.TraceLog);

            Assert.Null(crud.Load("temp", null));
        }
Exemplo n.º 4
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"]);
        }
Exemplo n.º 5
0
        public void Dispense_Hooks()
        {
            var crud = new BeanCrud(null, null, null);
            var observer = new TracingObserver();
            crud.AddObserver(observer);

            var bean = crud.Dispense<Tracer>();
            Assert.Equal("tracer", bean.GetKind());

            Assert.Equal("ad:", bean.TraceLog);
            Assert.Equal("ad:", observer.TraceLog);
            Assert.Same(bean, observer.LastBean);
        }
Exemplo n.º 6
0
        public void Dispense_Hooks()
        {
            var crud     = new BeanCrud(null, null, null);
            var observer = new TracingObserver();

            crud.AddObserver(observer);

            var bean = crud.Dispense <Tracer>();

            Assert.Equal("tracer", bean.GetKind());

            Assert.Equal("ad:", bean.TraceLog);
            Assert.Equal("ad:", observer.TraceLog);
            Assert.Same(bean, observer.LastBean);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void Dispense_Hooks()
        {
            IBeanFactory factory = new BeanFactory();

            factory.Options.ValidateGetColumns = false;
            var crud     = new BeanCrud(null, null, null, factory);
            var observer = new TracingObserver();

            crud.AddObserver(observer);

            var bean = crud.Dispense <Tracer>();

            Assert.Equal("tracer", bean.GetKind());

            Assert.Equal("ad:", bean.TraceLog);
            Assert.Equal("ad:", observer.TraceLog);
            Assert.Same(bean, observer.LastBean);
        }
Exemplo n.º 9
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>();

            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);
        }
Exemplo n.º 10
0
        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"]);
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
0
        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);
        }