Beispiel #1
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"]);
        }
Beispiel #2
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));
        }
Beispiel #3
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));
        }
Beispiel #4
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"]);
        }
Beispiel #5
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));
        }
Beispiel #6
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));
        }
Beispiel #7
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));
        }